[6a3a178] | 1 | /**
|
---|
| 2 | * @license
|
---|
| 3 | * Copyright Google LLC 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 | */
|
---|
| 8 | /// <amd-module name="@angular/compiler-cli/linker/src/ast/ast_host" />
|
---|
| 9 | /**
|
---|
| 10 | * An abstraction for getting information from an AST while being agnostic to the underlying AST
|
---|
| 11 | * implementation.
|
---|
| 12 | */
|
---|
| 13 | export interface AstHost<TExpression> {
|
---|
| 14 | /**
|
---|
| 15 | * Get the name of the symbol represented by the given expression node, or `null` if it is not a
|
---|
| 16 | * symbol.
|
---|
| 17 | */
|
---|
| 18 | getSymbolName(node: TExpression): string | null;
|
---|
| 19 | /**
|
---|
| 20 | * Return `true` if the given expression is a string literal, or false otherwise.
|
---|
| 21 | */
|
---|
| 22 | isStringLiteral(node: TExpression): boolean;
|
---|
| 23 | /**
|
---|
| 24 | * Parse the string value from the given expression, or throw if it is not a string literal.
|
---|
| 25 | */
|
---|
| 26 | parseStringLiteral(str: TExpression): string;
|
---|
| 27 | /**
|
---|
| 28 | * Return `true` if the given expression is a numeric literal, or false otherwise.
|
---|
| 29 | */
|
---|
| 30 | isNumericLiteral(node: TExpression): boolean;
|
---|
| 31 | /**
|
---|
| 32 | * Parse the numeric value from the given expression, or throw if it is not a numeric literal.
|
---|
| 33 | */
|
---|
| 34 | parseNumericLiteral(num: TExpression): number;
|
---|
| 35 | /**
|
---|
| 36 | * Return `true` if the given expression can be considered a boolean literal, or false otherwise.
|
---|
| 37 | *
|
---|
| 38 | * Note that this should also cover the special case of some minified code where `true` and
|
---|
| 39 | * `false` are replaced by `!0` and `!1` respectively.
|
---|
| 40 | */
|
---|
| 41 | isBooleanLiteral(node: TExpression): boolean;
|
---|
| 42 | /**
|
---|
| 43 | * Parse the boolean value from the given expression, or throw if it is not a boolean literal.
|
---|
| 44 | *
|
---|
| 45 | * Note that this should also cover the special case of some minified code where `true` and
|
---|
| 46 | * `false` are replaced by `!0` and `!1` respectively.
|
---|
| 47 | */
|
---|
| 48 | parseBooleanLiteral(bool: TExpression): boolean;
|
---|
| 49 | /**
|
---|
| 50 | * Return `true` if the given expression is an array literal, or false otherwise.
|
---|
| 51 | */
|
---|
| 52 | isArrayLiteral(node: TExpression): boolean;
|
---|
| 53 | /**
|
---|
| 54 | * Parse an array of expressions from the given expression, or throw if it is not an array
|
---|
| 55 | * literal.
|
---|
| 56 | */
|
---|
| 57 | parseArrayLiteral(array: TExpression): TExpression[];
|
---|
| 58 | /**
|
---|
| 59 | * Return `true` if the given expression is an object literal, or false otherwise.
|
---|
| 60 | */
|
---|
| 61 | isObjectLiteral(node: TExpression): boolean;
|
---|
| 62 | /**
|
---|
| 63 | * Parse the given expression into a map of object property names to property expressions, or
|
---|
| 64 | * throw if it is not an object literal.
|
---|
| 65 | */
|
---|
| 66 | parseObjectLiteral(obj: TExpression): Map<string, TExpression>;
|
---|
| 67 | /**
|
---|
| 68 | * Return `true` if the given expression is a function, or false otherwise.
|
---|
| 69 | */
|
---|
| 70 | isFunctionExpression(node: TExpression): boolean;
|
---|
| 71 | /**
|
---|
| 72 | * Compute the "value" of a function expression by parsing its body for a single `return`
|
---|
| 73 | * statement, extracting the returned expression, or throw if it is not possible.
|
---|
| 74 | */
|
---|
| 75 | parseReturnValue(fn: TExpression): TExpression;
|
---|
| 76 | /**
|
---|
| 77 | * Return true if the given expression is a call expression, or false otherwise.
|
---|
| 78 | */
|
---|
| 79 | isCallExpression(node: TExpression): boolean;
|
---|
| 80 | /**
|
---|
| 81 | * Returns the expression that is called in the provided call expression, or throw if it is not
|
---|
| 82 | * a call expression.
|
---|
| 83 | */
|
---|
| 84 | parseCallee(call: TExpression): TExpression;
|
---|
| 85 | /**
|
---|
| 86 | * Returns the argument expressions for the provided call expression, or throw if it is not
|
---|
| 87 | * a call expression.
|
---|
| 88 | */
|
---|
| 89 | parseArguments(call: TExpression): TExpression[];
|
---|
| 90 | /**
|
---|
| 91 | * Compute the location range of the expression in the source file, to be used for source-mapping.
|
---|
| 92 | */
|
---|
| 93 | getRange(node: TExpression): Range;
|
---|
| 94 | }
|
---|
| 95 | /**
|
---|
| 96 | * The location of the start and end of an expression in the original source file.
|
---|
| 97 | */
|
---|
| 98 | export interface Range {
|
---|
| 99 | /** 0-based character position of the range start in the source file text. */
|
---|
| 100 | startPos: number;
|
---|
| 101 | /** 0-based line index of the range start in the source file text. */
|
---|
| 102 | startLine: number;
|
---|
| 103 | /** 0-based column position of the range start in the source file text. */
|
---|
| 104 | startCol: number;
|
---|
| 105 | /** 0-based character position of the range end in the source file text. */
|
---|
| 106 | endPos: number;
|
---|
| 107 | }
|
---|