refactor(compiler-cli): rename the `BuiltinFn` type to the more generic `KnownFn` (#35191)
This is in preparation of using the `KnownFn` type for known TypeScript helpers (in addition to built-in functions/methods). This will in turn allow simplifying the detection of both imported and emitted TypeScript helpers. PR Close #35191
This commit is contained in:
parent
b6e8847967
commit
14744f27c5
|
@ -8,4 +8,4 @@
|
|||
|
||||
export {DynamicValue} from './src/dynamic';
|
||||
export {ForeignFunctionResolver, PartialEvaluator} from './src/interface';
|
||||
export {BuiltinFn, EnumValue, ResolvedValue, ResolvedValueArray, ResolvedValueMap} from './src/result';
|
||||
export {EnumValue, KnownFn, ResolvedValue, ResolvedValueArray, ResolvedValueMap} from './src/result';
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
import * as ts from 'typescript';
|
||||
|
||||
import {DynamicValue} from './dynamic';
|
||||
import {BuiltinFn, ResolvedValue, ResolvedValueArray} from './result';
|
||||
import {KnownFn, ResolvedValue, ResolvedValueArray} from './result';
|
||||
|
||||
export class ArraySliceBuiltinFn extends BuiltinFn {
|
||||
export class ArraySliceBuiltinFn extends KnownFn {
|
||||
constructor(private lhs: ResolvedValueArray) { super(); }
|
||||
|
||||
evaluate(node: ts.CallExpression, args: ResolvedValueArray): ResolvedValue {
|
||||
|
@ -23,7 +23,7 @@ export class ArraySliceBuiltinFn extends BuiltinFn {
|
|||
}
|
||||
}
|
||||
|
||||
export class ArrayConcatBuiltinFn extends BuiltinFn {
|
||||
export class ArrayConcatBuiltinFn extends KnownFn {
|
||||
constructor(private lhs: ResolvedValueArray) { super(); }
|
||||
|
||||
evaluate(node: ts.CallExpression, args: ResolvedValueArray): ResolvedValue {
|
||||
|
@ -41,7 +41,7 @@ export class ArrayConcatBuiltinFn extends BuiltinFn {
|
|||
}
|
||||
}
|
||||
|
||||
export class ObjectAssignBuiltinFn extends BuiltinFn {
|
||||
export class ObjectAssignBuiltinFn extends KnownFn {
|
||||
evaluate(node: ts.CallExpression, args: ResolvedValueArray): ResolvedValue {
|
||||
if (args.length === 0) {
|
||||
return DynamicValue.fromUnsupportedSyntax(node);
|
||||
|
|
|
@ -18,7 +18,7 @@ import {ArrayConcatBuiltinFn, ArraySliceBuiltinFn} from './builtin';
|
|||
import {DynamicValue} from './dynamic';
|
||||
import {ForeignFunctionResolver} from './interface';
|
||||
import {resolveKnownDeclaration} from './known_declaration';
|
||||
import {BuiltinFn, EnumValue, ResolvedModule, ResolvedValue, ResolvedValueArray, ResolvedValueMap} from './result';
|
||||
import {EnumValue, KnownFn, ResolvedModule, ResolvedValue, ResolvedValueArray, ResolvedValueMap} from './result';
|
||||
import {evaluateTsHelperInline} from './ts_helpers';
|
||||
|
||||
|
||||
|
@ -404,7 +404,7 @@ export class StaticInterpreter {
|
|||
}
|
||||
|
||||
// If the call refers to a builtin function, attempt to evaluate the function.
|
||||
if (lhs instanceof BuiltinFn) {
|
||||
if (lhs instanceof KnownFn) {
|
||||
return lhs.evaluate(node, this.evaluateFunctionArguments(node, context));
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import {DynamicValue} from './dynamic';
|
|||
* available statically.
|
||||
*/
|
||||
export type ResolvedValue = number | boolean | string | null | undefined | Reference | EnumValue |
|
||||
ResolvedValueArray | ResolvedValueMap | ResolvedModule | BuiltinFn | DynamicValue<unknown>;
|
||||
ResolvedValueArray | ResolvedValueMap | ResolvedModule | KnownFn | DynamicValue<unknown>;
|
||||
|
||||
/**
|
||||
* An array of `ResolvedValue`s.
|
||||
|
@ -76,8 +76,10 @@ export class EnumValue {
|
|||
}
|
||||
|
||||
/**
|
||||
* An implementation of a builtin function, such as `Array.prototype.slice`.
|
||||
* An implementation of a known function that can be statically evaluated.
|
||||
* It could be a built-in function or method (such as `Array.prototype.slice`) or a TypeScript
|
||||
* helper (such as `__spread`).
|
||||
*/
|
||||
export abstract class BuiltinFn {
|
||||
export abstract class KnownFn {
|
||||
abstract evaluate(node: ts.CallExpression, args: ResolvedValueArray): ResolvedValue;
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ import {ResolvedValue, ResolvedValueArray} from './result';
|
|||
|
||||
|
||||
/**
|
||||
* Instance of the `Object.assign` builtin function. Used for evaluating
|
||||
* the "__assign" TypeScript helper.
|
||||
* Instance of the known `Object.assign` built-in function. Used for evaluating
|
||||
* the `__assign` TypeScript helper.
|
||||
*/
|
||||
const objectAssignBuiltinFn = new ObjectAssignBuiltinFn();
|
||||
|
||||
|
|
Loading…
Reference in New Issue