UNPKG

2.56 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google Inc. All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import * as ts from 'typescript';
9import { CollectorOptions } from './collector';
10import { MetadataEntry, MetadataError, MetadataValue } from './schema';
11import { Symbols } from './symbols';
12export declare function isPrimitive(value: any): boolean;
13export interface ImportSpecifierMetadata {
14 name: string;
15 propertyName?: string;
16}
17export interface ImportMetadata {
18 defaultName?: string;
19 namespace?: string;
20 namedImports?: ImportSpecifierMetadata[];
21 from: string;
22}
23export declare function errorSymbol(message: string, node?: ts.Node, context?: {
24 [name: string]: string;
25}, sourceFile?: ts.SourceFile): MetadataError;
26/**
27 * Produce a symbolic representation of an expression folding values into their final value when
28 * possible.
29 */
30export declare class Evaluator {
31 private symbols;
32 private nodeMap;
33 private options;
34 constructor(symbols: Symbols, nodeMap: Map<MetadataEntry, ts.Node>, options?: CollectorOptions);
35 nameOf(node: ts.Node): string | MetadataError;
36 /**
37 * Returns true if the expression represented by `node` can be folded into a literal expression.
38 *
39 * For example, a literal is always foldable. This means that literal expressions such as `1.2`
40 * `"Some value"` `true` `false` are foldable.
41 *
42 * - An object literal is foldable if all the properties in the literal are foldable.
43 * - An array literal is foldable if all the elements are foldable.
44 * - A call is foldable if it is a call to a Array.prototype.concat or a call to CONST_EXPR.
45 * - A property access is foldable if the object is foldable.
46 * - A array index is foldable if index expression is foldable and the array is foldable.
47 * - Binary operator expressions are foldable if the left and right expressions are foldable and
48 * it is one of '+', '-', '*', '/', '%', '||', and '&&'.
49 * - An identifier is foldable if a value can be found for its symbol in the evaluator symbol
50 * table.
51 */
52 isFoldable(node: ts.Node): boolean;
53 private isFoldableWorker(node, folding);
54 /**
55 * Produce a JSON serialiable object representing `node`. The foldable values in the expression
56 * tree are folded. For example, a node representing `1 + 2` is folded into `3`.
57 */
58 evaluateNode(node: ts.Node, preferReference?: boolean): MetadataValue;
59}