UNPKG

@angular/compiler

Version:

Angular - the compiler library

957 lines • 125 kB
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define("@angular/compiler/src/expression_parser/ast", ["require", "exports", "tslib"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BoundElementProperty = exports.ParsedVariable = exports.ParsedEvent = exports.ParsedPropertyType = exports.ParsedProperty = exports.AstMemoryEfficientTransformer = exports.AstTransformer = exports.RecursiveAstVisitor = exports.ExpressionBinding = exports.VariableBinding = exports.ASTWithSource = exports.AbsoluteSourceSpan = exports.FunctionCall = exports.SafeMethodCall = exports.MethodCall = exports.NonNullAssert = exports.PrefixNot = exports.Unary = exports.Binary = exports.Interpolation = exports.LiteralMap = exports.LiteralArray = exports.LiteralPrimitive = exports.BindingPipe = exports.KeyedWrite = exports.KeyedRead = exports.SafePropertyRead = exports.PropertyWrite = exports.PropertyRead = exports.Conditional = exports.Chain = exports.ThisReceiver = exports.ImplicitReceiver = exports.EmptyExpr = exports.Quote = exports.ASTWithName = exports.AST = exports.ParseSpan = exports.ParserError = void 0; var tslib_1 = require("tslib"); var ParserError = /** @class */ (function () { function ParserError(message, input, errLocation, ctxLocation) { this.input = input; this.errLocation = errLocation; this.ctxLocation = ctxLocation; this.message = "Parser Error: " + message + " " + errLocation + " [" + input + "] in " + ctxLocation; } return ParserError; }()); exports.ParserError = ParserError; var ParseSpan = /** @class */ (function () { function ParseSpan(start, end) { this.start = start; this.end = end; } ParseSpan.prototype.toAbsolute = function (absoluteOffset) { return new AbsoluteSourceSpan(absoluteOffset + this.start, absoluteOffset + this.end); }; return ParseSpan; }()); exports.ParseSpan = ParseSpan; var AST = /** @class */ (function () { function AST(span, /** * Absolute location of the expression AST in a source code file. */ sourceSpan) { this.span = span; this.sourceSpan = sourceSpan; } AST.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return null; }; AST.prototype.toString = function () { return 'AST'; }; return AST; }()); exports.AST = AST; var ASTWithName = /** @class */ (function (_super) { tslib_1.__extends(ASTWithName, _super); function ASTWithName(span, sourceSpan, nameSpan) { var _this = _super.call(this, span, sourceSpan) || this; _this.nameSpan = nameSpan; return _this; } return ASTWithName; }(AST)); exports.ASTWithName = ASTWithName; /** * Represents a quoted expression of the form: * * quote = prefix `:` uninterpretedExpression * prefix = identifier * uninterpretedExpression = arbitrary string * * A quoted expression is meant to be pre-processed by an AST transformer that * converts it into another AST that no longer contains quoted expressions. * It is meant to allow third-party developers to extend Angular template * expression language. The `uninterpretedExpression` part of the quote is * therefore not interpreted by the Angular's own expression parser. */ var Quote = /** @class */ (function (_super) { tslib_1.__extends(Quote, _super); function Quote(span, sourceSpan, prefix, uninterpretedExpression, location) { var _this = _super.call(this, span, sourceSpan) || this; _this.prefix = prefix; _this.uninterpretedExpression = uninterpretedExpression; _this.location = location; return _this; } Quote.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitQuote(this, context); }; Quote.prototype.toString = function () { return 'Quote'; }; return Quote; }(AST)); exports.Quote = Quote; var EmptyExpr = /** @class */ (function (_super) { tslib_1.__extends(EmptyExpr, _super); function EmptyExpr() { return _super !== null && _super.apply(this, arguments) || this; } EmptyExpr.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } // do nothing }; return EmptyExpr; }(AST)); exports.EmptyExpr = EmptyExpr; var ImplicitReceiver = /** @class */ (function (_super) { tslib_1.__extends(ImplicitReceiver, _super); function ImplicitReceiver() { return _super !== null && _super.apply(this, arguments) || this; } ImplicitReceiver.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitImplicitReceiver(this, context); }; return ImplicitReceiver; }(AST)); exports.ImplicitReceiver = ImplicitReceiver; /** * Receiver when something is accessed through `this` (e.g. `this.foo`). Note that this class * inherits from `ImplicitReceiver`, because accessing something through `this` is treated the * same as accessing it implicitly inside of an Angular template (e.g. `[attr.title]="this.title"` * is the same as `[attr.title]="title"`.). Inheriting allows for the `this` accesses to be treated * the same as implicit ones, except for a couple of exceptions like `$event` and `$any`. * TODO: we should find a way for this class not to extend from `ImplicitReceiver` in the future. */ var ThisReceiver = /** @class */ (function (_super) { tslib_1.__extends(ThisReceiver, _super); function ThisReceiver() { return _super !== null && _super.apply(this, arguments) || this; } ThisReceiver.prototype.visit = function (visitor, context) { var _a; if (context === void 0) { context = null; } return (_a = visitor.visitThisReceiver) === null || _a === void 0 ? void 0 : _a.call(visitor, this, context); }; return ThisReceiver; }(ImplicitReceiver)); exports.ThisReceiver = ThisReceiver; /** * Multiple expressions separated by a semicolon. */ var Chain = /** @class */ (function (_super) { tslib_1.__extends(Chain, _super); function Chain(span, sourceSpan, expressions) { var _this = _super.call(this, span, sourceSpan) || this; _this.expressions = expressions; return _this; } Chain.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitChain(this, context); }; return Chain; }(AST)); exports.Chain = Chain; var Conditional = /** @class */ (function (_super) { tslib_1.__extends(Conditional, _super); function Conditional(span, sourceSpan, condition, trueExp, falseExp) { var _this = _super.call(this, span, sourceSpan) || this; _this.condition = condition; _this.trueExp = trueExp; _this.falseExp = falseExp; return _this; } Conditional.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitConditional(this, context); }; return Conditional; }(AST)); exports.Conditional = Conditional; var PropertyRead = /** @class */ (function (_super) { tslib_1.__extends(PropertyRead, _super); function PropertyRead(span, sourceSpan, nameSpan, receiver, name) { var _this = _super.call(this, span, sourceSpan, nameSpan) || this; _this.receiver = receiver; _this.name = name; return _this; } PropertyRead.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitPropertyRead(this, context); }; return PropertyRead; }(ASTWithName)); exports.PropertyRead = PropertyRead; var PropertyWrite = /** @class */ (function (_super) { tslib_1.__extends(PropertyWrite, _super); function PropertyWrite(span, sourceSpan, nameSpan, receiver, name, value) { var _this = _super.call(this, span, sourceSpan, nameSpan) || this; _this.receiver = receiver; _this.name = name; _this.value = value; return _this; } PropertyWrite.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitPropertyWrite(this, context); }; return PropertyWrite; }(ASTWithName)); exports.PropertyWrite = PropertyWrite; var SafePropertyRead = /** @class */ (function (_super) { tslib_1.__extends(SafePropertyRead, _super); function SafePropertyRead(span, sourceSpan, nameSpan, receiver, name) { var _this = _super.call(this, span, sourceSpan, nameSpan) || this; _this.receiver = receiver; _this.name = name; return _this; } SafePropertyRead.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitSafePropertyRead(this, context); }; return SafePropertyRead; }(ASTWithName)); exports.SafePropertyRead = SafePropertyRead; var KeyedRead = /** @class */ (function (_super) { tslib_1.__extends(KeyedRead, _super); function KeyedRead(span, sourceSpan, obj, key) { var _this = _super.call(this, span, sourceSpan) || this; _this.obj = obj; _this.key = key; return _this; } KeyedRead.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitKeyedRead(this, context); }; return KeyedRead; }(AST)); exports.KeyedRead = KeyedRead; var KeyedWrite = /** @class */ (function (_super) { tslib_1.__extends(KeyedWrite, _super); function KeyedWrite(span, sourceSpan, obj, key, value) { var _this = _super.call(this, span, sourceSpan) || this; _this.obj = obj; _this.key = key; _this.value = value; return _this; } KeyedWrite.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitKeyedWrite(this, context); }; return KeyedWrite; }(AST)); exports.KeyedWrite = KeyedWrite; var BindingPipe = /** @class */ (function (_super) { tslib_1.__extends(BindingPipe, _super); function BindingPipe(span, sourceSpan, exp, name, args, nameSpan) { var _this = _super.call(this, span, sourceSpan, nameSpan) || this; _this.exp = exp; _this.name = name; _this.args = args; return _this; } BindingPipe.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitPipe(this, context); }; return BindingPipe; }(ASTWithName)); exports.BindingPipe = BindingPipe; var LiteralPrimitive = /** @class */ (function (_super) { tslib_1.__extends(LiteralPrimitive, _super); function LiteralPrimitive(span, sourceSpan, value) { var _this = _super.call(this, span, sourceSpan) || this; _this.value = value; return _this; } LiteralPrimitive.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitLiteralPrimitive(this, context); }; return LiteralPrimitive; }(AST)); exports.LiteralPrimitive = LiteralPrimitive; var LiteralArray = /** @class */ (function (_super) { tslib_1.__extends(LiteralArray, _super); function LiteralArray(span, sourceSpan, expressions) { var _this = _super.call(this, span, sourceSpan) || this; _this.expressions = expressions; return _this; } LiteralArray.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitLiteralArray(this, context); }; return LiteralArray; }(AST)); exports.LiteralArray = LiteralArray; var LiteralMap = /** @class */ (function (_super) { tslib_1.__extends(LiteralMap, _super); function LiteralMap(span, sourceSpan, keys, values) { var _this = _super.call(this, span, sourceSpan) || this; _this.keys = keys; _this.values = values; return _this; } LiteralMap.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitLiteralMap(this, context); }; return LiteralMap; }(AST)); exports.LiteralMap = LiteralMap; var Interpolation = /** @class */ (function (_super) { tslib_1.__extends(Interpolation, _super); function Interpolation(span, sourceSpan, strings, expressions) { var _this = _super.call(this, span, sourceSpan) || this; _this.strings = strings; _this.expressions = expressions; return _this; } Interpolation.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitInterpolation(this, context); }; return Interpolation; }(AST)); exports.Interpolation = Interpolation; var Binary = /** @class */ (function (_super) { tslib_1.__extends(Binary, _super); function Binary(span, sourceSpan, operation, left, right) { var _this = _super.call(this, span, sourceSpan) || this; _this.operation = operation; _this.left = left; _this.right = right; return _this; } Binary.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitBinary(this, context); }; return Binary; }(AST)); exports.Binary = Binary; /** * For backwards compatibility reasons, `Unary` inherits from `Binary` and mimics the binary AST * node that was originally used. This inheritance relation can be deleted in some future major, * after consumers have been given a chance to fully support Unary. */ var Unary = /** @class */ (function (_super) { tslib_1.__extends(Unary, _super); /** * During the deprecation period this constructor is private, to avoid consumers from creating * a `Unary` with the fallback properties for `Binary`. */ function Unary(span, sourceSpan, operator, expr, binaryOp, binaryLeft, binaryRight) { var _this = _super.call(this, span, sourceSpan, binaryOp, binaryLeft, binaryRight) || this; _this.operator = operator; _this.expr = expr; return _this; } /** * Creates a unary minus expression "-x", represented as `Binary` using "0 - x". */ Unary.createMinus = function (span, sourceSpan, expr) { return new Unary(span, sourceSpan, '-', expr, '-', new LiteralPrimitive(span, sourceSpan, 0), expr); }; /** * Creates a unary plus expression "+x", represented as `Binary` using "x - 0". */ Unary.createPlus = function (span, sourceSpan, expr) { return new Unary(span, sourceSpan, '+', expr, '-', expr, new LiteralPrimitive(span, sourceSpan, 0)); }; Unary.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } if (visitor.visitUnary !== undefined) { return visitor.visitUnary(this, context); } return visitor.visitBinary(this, context); }; return Unary; }(Binary)); exports.Unary = Unary; var PrefixNot = /** @class */ (function (_super) { tslib_1.__extends(PrefixNot, _super); function PrefixNot(span, sourceSpan, expression) { var _this = _super.call(this, span, sourceSpan) || this; _this.expression = expression; return _this; } PrefixNot.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitPrefixNot(this, context); }; return PrefixNot; }(AST)); exports.PrefixNot = PrefixNot; var NonNullAssert = /** @class */ (function (_super) { tslib_1.__extends(NonNullAssert, _super); function NonNullAssert(span, sourceSpan, expression) { var _this = _super.call(this, span, sourceSpan) || this; _this.expression = expression; return _this; } NonNullAssert.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitNonNullAssert(this, context); }; return NonNullAssert; }(AST)); exports.NonNullAssert = NonNullAssert; var MethodCall = /** @class */ (function (_super) { tslib_1.__extends(MethodCall, _super); function MethodCall(span, sourceSpan, nameSpan, receiver, name, args) { var _this = _super.call(this, span, sourceSpan, nameSpan) || this; _this.receiver = receiver; _this.name = name; _this.args = args; return _this; } MethodCall.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitMethodCall(this, context); }; return MethodCall; }(ASTWithName)); exports.MethodCall = MethodCall; var SafeMethodCall = /** @class */ (function (_super) { tslib_1.__extends(SafeMethodCall, _super); function SafeMethodCall(span, sourceSpan, nameSpan, receiver, name, args) { var _this = _super.call(this, span, sourceSpan, nameSpan) || this; _this.receiver = receiver; _this.name = name; _this.args = args; return _this; } SafeMethodCall.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitSafeMethodCall(this, context); }; return SafeMethodCall; }(ASTWithName)); exports.SafeMethodCall = SafeMethodCall; var FunctionCall = /** @class */ (function (_super) { tslib_1.__extends(FunctionCall, _super); function FunctionCall(span, sourceSpan, target, args) { var _this = _super.call(this, span, sourceSpan) || this; _this.target = target; _this.args = args; return _this; } FunctionCall.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } return visitor.visitFunctionCall(this, context); }; return FunctionCall; }(AST)); exports.FunctionCall = FunctionCall; /** * Records the absolute position of a text span in a source file, where `start` and `end` are the * starting and ending byte offsets, respectively, of the text span in a source file. */ var AbsoluteSourceSpan = /** @class */ (function () { function AbsoluteSourceSpan(start, end) { this.start = start; this.end = end; } return AbsoluteSourceSpan; }()); exports.AbsoluteSourceSpan = AbsoluteSourceSpan; var ASTWithSource = /** @class */ (function (_super) { tslib_1.__extends(ASTWithSource, _super); function ASTWithSource(ast, source, location, absoluteOffset, errors) { var _this = _super.call(this, new ParseSpan(0, source === null ? 0 : source.length), new AbsoluteSourceSpan(absoluteOffset, source === null ? absoluteOffset : absoluteOffset + source.length)) || this; _this.ast = ast; _this.source = source; _this.location = location; _this.errors = errors; return _this; } ASTWithSource.prototype.visit = function (visitor, context) { if (context === void 0) { context = null; } if (visitor.visitASTWithSource) { return visitor.visitASTWithSource(this, context); } return this.ast.visit(visitor, context); }; ASTWithSource.prototype.toString = function () { return this.source + " in " + this.location; }; return ASTWithSource; }(AST)); exports.ASTWithSource = ASTWithSource; var VariableBinding = /** @class */ (function () { /** * @param sourceSpan entire span of the binding. * @param key name of the LHS along with its span. * @param value optional value for the RHS along with its span. */ function VariableBinding(sourceSpan, key, value) { this.sourceSpan = sourceSpan; this.key = key; this.value = value; } return VariableBinding; }()); exports.VariableBinding = VariableBinding; var ExpressionBinding = /** @class */ (function () { /** * @param sourceSpan entire span of the binding. * @param key binding name, like ngForOf, ngForTrackBy, ngIf, along with its * span. Note that the length of the span may not be the same as * `key.source.length`. For example, * 1. key.source = ngFor, key.span is for "ngFor" * 2. key.source = ngForOf, key.span is for "of" * 3. key.source = ngForTrackBy, key.span is for "trackBy" * @param value optional expression for the RHS. */ function ExpressionBinding(sourceSpan, key, value) { this.sourceSpan = sourceSpan; this.key = key; this.value = value; } return ExpressionBinding; }()); exports.ExpressionBinding = ExpressionBinding; var RecursiveAstVisitor = /** @class */ (function () { function RecursiveAstVisitor() { } RecursiveAstVisitor.prototype.visit = function (ast, context) { // The default implementation just visits every node. // Classes that extend RecursiveAstVisitor should override this function // to selectively visit the specified node. ast.visit(this, context); }; RecursiveAstVisitor.prototype.visitUnary = function (ast, context) { this.visit(ast.expr, context); }; RecursiveAstVisitor.prototype.visitBinary = function (ast, context) { this.visit(ast.left, context); this.visit(ast.right, context); }; RecursiveAstVisitor.prototype.visitChain = function (ast, context) { this.visitAll(ast.expressions, context); }; RecursiveAstVisitor.prototype.visitConditional = function (ast, context) { this.visit(ast.condition, context); this.visit(ast.trueExp, context); this.visit(ast.falseExp, context); }; RecursiveAstVisitor.prototype.visitPipe = function (ast, context) { this.visit(ast.exp, context); this.visitAll(ast.args, context); }; RecursiveAstVisitor.prototype.visitFunctionCall = function (ast, context) { if (ast.target) { this.visit(ast.target, context); } this.visitAll(ast.args, context); }; RecursiveAstVisitor.prototype.visitImplicitReceiver = function (ast, context) { }; RecursiveAstVisitor.prototype.visitThisReceiver = function (ast, context) { }; RecursiveAstVisitor.prototype.visitInterpolation = function (ast, context) { this.visitAll(ast.expressions, context); }; RecursiveAstVisitor.prototype.visitKeyedRead = function (ast, context) { this.visit(ast.obj, context); this.visit(ast.key, context); }; RecursiveAstVisitor.prototype.visitKeyedWrite = function (ast, context) { this.visit(ast.obj, context); this.visit(ast.key, context); this.visit(ast.value, context); }; RecursiveAstVisitor.prototype.visitLiteralArray = function (ast, context) { this.visitAll(ast.expressions, context); }; RecursiveAstVisitor.prototype.visitLiteralMap = function (ast, context) { this.visitAll(ast.values, context); }; RecursiveAstVisitor.prototype.visitLiteralPrimitive = function (ast, context) { }; RecursiveAstVisitor.prototype.visitMethodCall = function (ast, context) { this.visit(ast.receiver, context); this.visitAll(ast.args, context); }; RecursiveAstVisitor.prototype.visitPrefixNot = function (ast, context) { this.visit(ast.expression, context); }; RecursiveAstVisitor.prototype.visitNonNullAssert = function (ast, context) { this.visit(ast.expression, context); }; RecursiveAstVisitor.prototype.visitPropertyRead = function (ast, context) { this.visit(ast.receiver, context); }; RecursiveAstVisitor.prototype.visitPropertyWrite = function (ast, context) { this.visit(ast.receiver, context); this.visit(ast.value, context); }; RecursiveAstVisitor.prototype.visitSafePropertyRead = function (ast, context) { this.visit(ast.receiver, context); }; RecursiveAstVisitor.prototype.visitSafeMethodCall = function (ast, context) { this.visit(ast.receiver, context); this.visitAll(ast.args, context); }; RecursiveAstVisitor.prototype.visitQuote = function (ast, context) { }; // This is not part of the AstVisitor interface, just a helper method RecursiveAstVisitor.prototype.visitAll = function (asts, context) { var e_1, _a; try { for (var asts_1 = tslib_1.__values(asts), asts_1_1 = asts_1.next(); !asts_1_1.done; asts_1_1 = asts_1.next()) { var ast = asts_1_1.value; this.visit(ast, context); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (asts_1_1 && !asts_1_1.done && (_a = asts_1.return)) _a.call(asts_1); } finally { if (e_1) throw e_1.error; } } }; return RecursiveAstVisitor; }()); exports.RecursiveAstVisitor = RecursiveAstVisitor; var AstTransformer = /** @class */ (function () { function AstTransformer() { } AstTransformer.prototype.visitImplicitReceiver = function (ast, context) { return ast; }; AstTransformer.prototype.visitThisReceiver = function (ast, context) { return ast; }; AstTransformer.prototype.visitInterpolation = function (ast, context) { return new Interpolation(ast.span, ast.sourceSpan, ast.strings, this.visitAll(ast.expressions)); }; AstTransformer.prototype.visitLiteralPrimitive = function (ast, context) { return new LiteralPrimitive(ast.span, ast.sourceSpan, ast.value); }; AstTransformer.prototype.visitPropertyRead = function (ast, context) { return new PropertyRead(ast.span, ast.sourceSpan, ast.nameSpan, ast.receiver.visit(this), ast.name); }; AstTransformer.prototype.visitPropertyWrite = function (ast, context) { return new PropertyWrite(ast.span, ast.sourceSpan, ast.nameSpan, ast.receiver.visit(this), ast.name, ast.value.visit(this)); }; AstTransformer.prototype.visitSafePropertyRead = function (ast, context) { return new SafePropertyRead(ast.span, ast.sourceSpan, ast.nameSpan, ast.receiver.visit(this), ast.name); }; AstTransformer.prototype.visitMethodCall = function (ast, context) { return new MethodCall(ast.span, ast.sourceSpan, ast.nameSpan, ast.receiver.visit(this), ast.name, this.visitAll(ast.args)); }; AstTransformer.prototype.visitSafeMethodCall = function (ast, context) { return new SafeMethodCall(ast.span, ast.sourceSpan, ast.nameSpan, ast.receiver.visit(this), ast.name, this.visitAll(ast.args)); }; AstTransformer.prototype.visitFunctionCall = function (ast, context) { return new FunctionCall(ast.span, ast.sourceSpan, ast.target.visit(this), this.visitAll(ast.args)); }; AstTransformer.prototype.visitLiteralArray = function (ast, context) { return new LiteralArray(ast.span, ast.sourceSpan, this.visitAll(ast.expressions)); }; AstTransformer.prototype.visitLiteralMap = function (ast, context) { return new LiteralMap(ast.span, ast.sourceSpan, ast.keys, this.visitAll(ast.values)); }; AstTransformer.prototype.visitUnary = function (ast, context) { switch (ast.operator) { case '+': return Unary.createPlus(ast.span, ast.sourceSpan, ast.expr.visit(this)); case '-': return Unary.createMinus(ast.span, ast.sourceSpan, ast.expr.visit(this)); default: throw new Error("Unknown unary operator " + ast.operator); } }; AstTransformer.prototype.visitBinary = function (ast, context) { return new Binary(ast.span, ast.sourceSpan, ast.operation, ast.left.visit(this), ast.right.visit(this)); }; AstTransformer.prototype.visitPrefixNot = function (ast, context) { return new PrefixNot(ast.span, ast.sourceSpan, ast.expression.visit(this)); }; AstTransformer.prototype.visitNonNullAssert = function (ast, context) { return new NonNullAssert(ast.span, ast.sourceSpan, ast.expression.visit(this)); }; AstTransformer.prototype.visitConditional = function (ast, context) { return new Conditional(ast.span, ast.sourceSpan, ast.condition.visit(this), ast.trueExp.visit(this), ast.falseExp.visit(this)); }; AstTransformer.prototype.visitPipe = function (ast, context) { return new BindingPipe(ast.span, ast.sourceSpan, ast.exp.visit(this), ast.name, this.visitAll(ast.args), ast.nameSpan); }; AstTransformer.prototype.visitKeyedRead = function (ast, context) { return new KeyedRead(ast.span, ast.sourceSpan, ast.obj.visit(this), ast.key.visit(this)); }; AstTransformer.prototype.visitKeyedWrite = function (ast, context) { return new KeyedWrite(ast.span, ast.sourceSpan, ast.obj.visit(this), ast.key.visit(this), ast.value.visit(this)); }; AstTransformer.prototype.visitAll = function (asts) { var res = []; for (var i = 0; i < asts.length; ++i) { res[i] = asts[i].visit(this); } return res; }; AstTransformer.prototype.visitChain = function (ast, context) { return new Chain(ast.span, ast.sourceSpan, this.visitAll(ast.expressions)); }; AstTransformer.prototype.visitQuote = function (ast, context) { return new Quote(ast.span, ast.sourceSpan, ast.prefix, ast.uninterpretedExpression, ast.location); }; return AstTransformer; }()); exports.AstTransformer = AstTransformer; // A transformer that only creates new nodes if the transformer makes a change or // a change is made a child node. var AstMemoryEfficientTransformer = /** @class */ (function () { function AstMemoryEfficientTransformer() { } AstMemoryEfficientTransformer.prototype.visitImplicitReceiver = function (ast, context) { return ast; }; AstMemoryEfficientTransformer.prototype.visitThisReceiver = function (ast, context) { return ast; }; AstMemoryEfficientTransformer.prototype.visitInterpolation = function (ast, context) { var expressions = this.visitAll(ast.expressions); if (expressions !== ast.expressions) return new Interpolation(ast.span, ast.sourceSpan, ast.strings, expressions); return ast; }; AstMemoryEfficientTransformer.prototype.visitLiteralPrimitive = function (ast, context) { return ast; }; AstMemoryEfficientTransformer.prototype.visitPropertyRead = function (ast, context) { var receiver = ast.receiver.visit(this); if (receiver !== ast.receiver) { return new PropertyRead(ast.span, ast.sourceSpan, ast.nameSpan, receiver, ast.name); } return ast; }; AstMemoryEfficientTransformer.prototype.visitPropertyWrite = function (ast, context) { var receiver = ast.receiver.visit(this); var value = ast.value.visit(this); if (receiver !== ast.receiver || value !== ast.value) { return new PropertyWrite(ast.span, ast.sourceSpan, ast.nameSpan, receiver, ast.name, value); } return ast; }; AstMemoryEfficientTransformer.prototype.visitSafePropertyRead = function (ast, context) { var receiver = ast.receiver.visit(this); if (receiver !== ast.receiver) { return new SafePropertyRead(ast.span, ast.sourceSpan, ast.nameSpan, receiver, ast.name); } return ast; }; AstMemoryEfficientTransformer.prototype.visitMethodCall = function (ast, context) { var receiver = ast.receiver.visit(this); var args = this.visitAll(ast.args); if (receiver !== ast.receiver || args !== ast.args) { return new MethodCall(ast.span, ast.sourceSpan, ast.nameSpan, receiver, ast.name, args); } return ast; }; AstMemoryEfficientTransformer.prototype.visitSafeMethodCall = function (ast, context) { var receiver = ast.receiver.visit(this); var args = this.visitAll(ast.args); if (receiver !== ast.receiver || args !== ast.args) { return new SafeMethodCall(ast.span, ast.sourceSpan, ast.nameSpan, receiver, ast.name, args); } return ast; }; AstMemoryEfficientTransformer.prototype.visitFunctionCall = function (ast, context) { var target = ast.target && ast.target.visit(this); var args = this.visitAll(ast.args); if (target !== ast.target || args !== ast.args) { return new FunctionCall(ast.span, ast.sourceSpan, target, args); } return ast; }; AstMemoryEfficientTransformer.prototype.visitLiteralArray = function (ast, context) { var expressions = this.visitAll(ast.expressions); if (expressions !== ast.expressions) { return new LiteralArray(ast.span, ast.sourceSpan, expressions); } return ast; }; AstMemoryEfficientTransformer.prototype.visitLiteralMap = function (ast, context) { var values = this.visitAll(ast.values); if (values !== ast.values) { return new LiteralMap(ast.span, ast.sourceSpan, ast.keys, values); } return ast; }; AstMemoryEfficientTransformer.prototype.visitUnary = function (ast, context) { var expr = ast.expr.visit(this); if (expr !== ast.expr) { switch (ast.operator) { case '+': return Unary.createPlus(ast.span, ast.sourceSpan, expr); case '-': return Unary.createMinus(ast.span, ast.sourceSpan, expr); default: throw new Error("Unknown unary operator " + ast.operator); } } return ast; }; AstMemoryEfficientTransformer.prototype.visitBinary = function (ast, context) { var left = ast.left.visit(this); var right = ast.right.visit(this); if (left !== ast.left || right !== ast.right) { return new Binary(ast.span, ast.sourceSpan, ast.operation, left, right); } return ast; }; AstMemoryEfficientTransformer.prototype.visitPrefixNot = function (ast, context) { var expression = ast.expression.visit(this); if (expression !== ast.expression) { return new PrefixNot(ast.span, ast.sourceSpan, expression); } return ast; }; AstMemoryEfficientTransformer.prototype.visitNonNullAssert = function (ast, context) { var expression = ast.expression.visit(this); if (expression !== ast.expression) { return new NonNullAssert(ast.span, ast.sourceSpan, expression); } return ast; }; AstMemoryEfficientTransformer.prototype.visitConditional = function (ast, context) { var condition = ast.condition.visit(this); var trueExp = ast.trueExp.visit(this); var falseExp = ast.falseExp.visit(this); if (condition !== ast.condition || trueExp !== ast.trueExp || falseExp !== ast.falseExp) { return new Conditional(ast.span, ast.sourceSpan, condition, trueExp, falseExp); } return ast; }; AstMemoryEfficientTransformer.prototype.visitPipe = function (ast, context) { var exp = ast.exp.visit(this); var args = this.visitAll(ast.args); if (exp !== ast.exp || args !== ast.args) { return new BindingPipe(ast.span, ast.sourceSpan, exp, ast.name, args, ast.nameSpan); } return ast; }; AstMemoryEfficientTransformer.prototype.visitKeyedRead = function (ast, context) { var obj = ast.obj.visit(this); var key = ast.key.visit(this); if (obj !== ast.obj || key !== ast.key) { return new KeyedRead(ast.span, ast.sourceSpan, obj, key); } return ast; }; AstMemoryEfficientTransformer.prototype.visitKeyedWrite = function (ast, context) { var obj = ast.obj.visit(this); var key = ast.key.visit(this); var value = ast.value.visit(this); if (obj !== ast.obj || key !== ast.key || value !== ast.value) { return new KeyedWrite(ast.span, ast.sourceSpan, obj, key, value); } return ast; }; AstMemoryEfficientTransformer.prototype.visitAll = function (asts) { var res = []; var modified = false; for (var i = 0; i < asts.length; ++i) { var original = asts[i]; var value = original.visit(this); res[i] = value; modified = modified || value !== original; } return modified ? res : asts; }; AstMemoryEfficientTransformer.prototype.visitChain = function (ast, context) { var expressions = this.visitAll(ast.expressions); if (expressions !== ast.expressions) { return new Chain(ast.span, ast.sourceSpan, expressions); } return ast; }; AstMemoryEfficientTransformer.prototype.visitQuote = function (ast, context) { return ast; }; return AstMemoryEfficientTransformer; }()); exports.AstMemoryEfficientTransformer = AstMemoryEfficientTransformer; // Bindings var ParsedProperty = /** @class */ (function () { function ParsedProperty(name, expression, type, // TODO(atscott): `keySpan` should really be required but allows `undefined` so VE does // not need to be updated. Make `keySpan` required when VE is removed. sourceSpan, keySpan, valueSpan) { this.name = name; this.expression = expression; this.type = type; this.sourceSpan = sourceSpan; this.keySpan = keySpan; this.valueSpan = valueSpan; this.isLiteral = this.type === ParsedPropertyType.LITERAL_ATTR; this.isAnimation = this.type === ParsedPropertyType.ANIMATION; } return ParsedProperty; }()); exports.ParsedProperty = ParsedProperty; var ParsedPropertyType; (function (ParsedPropertyType) { ParsedPropertyType[ParsedPropertyType["DEFAULT"] = 0] = "DEFAULT"; ParsedPropertyType[ParsedPropertyType["LITERAL_ATTR"] = 1] = "LITERAL_ATTR"; ParsedPropertyType[ParsedPropertyType["ANIMATION"] = 2] = "ANIMATION"; })(ParsedPropertyType = exports.ParsedPropertyType || (exports.ParsedPropertyType = {})); var ParsedEvent = /** @class */ (function () { // Regular events have a target // Animation events have a phase function ParsedEvent(name, targetOrPhase, type, handler, sourceSpan, handlerSpan) { this.name = name; this.targetOrPhase = targetOrPhase; this.type = type; this.handler = handler; this.sourceSpan = sourceSpan; this.handlerSpan = handlerSpan; } return ParsedEvent; }()); exports.ParsedEvent = ParsedEvent; /** * ParsedVariable represents a variable declaration in a microsyntax expression. */ var ParsedVariable = /** @class */ (function () { function ParsedVariable(name, value, sourceSpan, keySpan, valueSpan) { this.name = name; this.value = value; this.sourceSpan = sourceSpan; this.keySpan = keySpan; this.valueSpan = valueSpan; } return ParsedVariable; }()); exports.ParsedVariable = ParsedVariable; var BoundElementProperty = /** @class */ (function () { function BoundElementProperty(name, type, securityContext, value, unit, sourceSpan, keySpan, valueSpan) { this.name = name; this.type = type; this.securityContext = securityContext; this.value = value; this.unit = unit; this.sourceSpan = sourceSpan; this.keySpan = keySpan; this.valueSpan = valueSpan; } return BoundElementProperty; }()); exports.BoundElementProperty = BoundElementProperty; }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZXMvY29tcGlsZXIvc3JjL2V4cHJlc3Npb25fcGFyc2VyL2FzdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7Ozs7Ozs7Ozs7Ozs7O0lBS0g7UUFFRSxxQkFDSSxPQUFlLEVBQVMsS0FBYSxFQUFTLFdBQW1CLEVBQVMsV0FBaUI7WUFBbkUsVUFBSyxHQUFMLEtBQUssQ0FBUTtZQUFTLGdCQUFXLEdBQVgsV0FBVyxDQUFRO1lBQVMsZ0JBQVcsR0FBWCxXQUFXLENBQU07WUFDN0YsSUFBSSxDQUFDLE9BQU8sR0FBRyxtQkFBaUIsT0FBTyxTQUFJLFdBQVcsVUFBSyxLQUFLLGFBQVEsV0FBYSxDQUFDO1FBQ3hGLENBQUM7UUFDSCxrQkFBQztJQUFELENBQUMsQUFORCxJQU1DO0lBTlksa0NBQVc7SUFReEI7UUFDRSxtQkFBbUIsS0FBYSxFQUFTLEdBQVc7WUFBakMsVUFBSyxHQUFMLEtBQU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