UNPKG

@angular/compiler

Version:

Angular - the compiler library

1,040 lines 246 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/output/output_ast", ["require", "exports", "tslib"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isNull = exports.localizedString = exports.literal = exports.ifStmt = exports.fn = exports.assertNotNull = exports.not = exports.unary = exports.literalMap = exports.literalArr = exports.typeofExpr = exports.expressionType = exports.importType = exports.importExpr = exports.variable = exports.jsDocComment = exports.leadingComment = exports.applySourceSpanToExpressionIfNeeded = exports.applySourceSpanToStatementIfNeeded = exports.collectExternalReferences = exports.findReadVarNames = exports.RecursiveAstVisitor = exports.AstTransformer = exports.ThrowStmt = exports.TryCatchStmt = exports.IfStmt = exports.ClassStmt = exports.ClassGetter = exports.ClassMethod = exports.ClassField = exports.AbstractClassPart = exports.ReturnStatement = exports.ExpressionStatement = exports.DeclareFunctionStmt = exports.DeclareVarStmt = exports.Statement = exports.JSDocComment = exports.LeadingComment = exports.StmtModifier = exports.TYPED_NULL_EXPR = exports.NULL_EXPR = exports.CATCH_STACK_VAR = exports.CATCH_ERROR_VAR = exports.SUPER_EXPR = exports.THIS_EXPR = exports.CommaExpr = exports.LiteralMapExpr = exports.LiteralMapEntry = exports.LiteralArrayExpr = exports.ReadKeyExpr = exports.ReadPropExpr = exports.BinaryOperatorExpr = exports.UnaryOperatorExpr = exports.FunctionExpr = exports.FnParam = exports.CastExpr = exports.AssertNotNull = exports.NotExpr = exports.ConditionalExpr = exports.ExternalReference = exports.ExternalExpr = exports.LocalizedString = exports.PlaceholderPiece = exports.LiteralPiece = exports.MessagePiece = exports.LiteralExpr = exports.InstantiateExpr = exports.InvokeFunctionExpr = exports.InvokeMethodExpr = exports.BuiltinMethod = exports.WritePropExpr = exports.WriteKeyExpr = exports.WriteVarExpr = exports.WrappedNodeExpr = exports.TypeofExpr = exports.ReadVarExpr = exports.BuiltinVar = exports.Expression = exports.areAllEquivalent = exports.nullSafeIsEquivalent = exports.BinaryOperator = exports.UnaryOperator = exports.NONE_TYPE = exports.FUNCTION_TYPE = exports.STRING_TYPE = exports.NUMBER_TYPE = exports.INT_TYPE = exports.BOOL_TYPE = exports.INFERRED_TYPE = exports.DYNAMIC_TYPE = exports.MapType = exports.ArrayType = exports.ExpressionType = exports.BuiltinType = exports.BuiltinTypeName = exports.Type = exports.TypeModifier = void 0; var tslib_1 = require("tslib"); //// Types var TypeModifier; (function (TypeModifier) { TypeModifier[TypeModifier["Const"] = 0] = "Const"; })(TypeModifier = exports.TypeModifier || (exports.TypeModifier = {})); var Type = /** @class */ (function () { function Type(modifiers) { if (modifiers === void 0) { modifiers = []; } this.modifiers = modifiers; } Type.prototype.hasModifier = function (modifier) { return this.modifiers.indexOf(modifier) !== -1; }; return Type; }()); exports.Type = Type; var BuiltinTypeName; (function (BuiltinTypeName) { BuiltinTypeName[BuiltinTypeName["Dynamic"] = 0] = "Dynamic"; BuiltinTypeName[BuiltinTypeName["Bool"] = 1] = "Bool"; BuiltinTypeName[BuiltinTypeName["String"] = 2] = "String"; BuiltinTypeName[BuiltinTypeName["Int"] = 3] = "Int"; BuiltinTypeName[BuiltinTypeName["Number"] = 4] = "Number"; BuiltinTypeName[BuiltinTypeName["Function"] = 5] = "Function"; BuiltinTypeName[BuiltinTypeName["Inferred"] = 6] = "Inferred"; BuiltinTypeName[BuiltinTypeName["None"] = 7] = "None"; })(BuiltinTypeName = exports.BuiltinTypeName || (exports.BuiltinTypeName = {})); var BuiltinType = /** @class */ (function (_super) { tslib_1.__extends(BuiltinType, _super); function BuiltinType(name, modifiers) { var _this = _super.call(this, modifiers) || this; _this.name = name; return _this; } BuiltinType.prototype.visitType = function (visitor, context) { return visitor.visitBuiltinType(this, context); }; return BuiltinType; }(Type)); exports.BuiltinType = BuiltinType; var ExpressionType = /** @class */ (function (_super) { tslib_1.__extends(ExpressionType, _super); function ExpressionType(value, modifiers, typeParams) { if (typeParams === void 0) { typeParams = null; } var _this = _super.call(this, modifiers) || this; _this.value = value; _this.typeParams = typeParams; return _this; } ExpressionType.prototype.visitType = function (visitor, context) { return visitor.visitExpressionType(this, context); }; return ExpressionType; }(Type)); exports.ExpressionType = ExpressionType; var ArrayType = /** @class */ (function (_super) { tslib_1.__extends(ArrayType, _super); function ArrayType(of, modifiers) { var _this = _super.call(this, modifiers) || this; _this.of = of; return _this; } ArrayType.prototype.visitType = function (visitor, context) { return visitor.visitArrayType(this, context); }; return ArrayType; }(Type)); exports.ArrayType = ArrayType; var MapType = /** @class */ (function (_super) { tslib_1.__extends(MapType, _super); function MapType(valueType, modifiers) { var _this = _super.call(this, modifiers) || this; _this.valueType = valueType || null; return _this; } MapType.prototype.visitType = function (visitor, context) { return visitor.visitMapType(this, context); }; return MapType; }(Type)); exports.MapType = MapType; exports.DYNAMIC_TYPE = new BuiltinType(BuiltinTypeName.Dynamic); exports.INFERRED_TYPE = new BuiltinType(BuiltinTypeName.Inferred); exports.BOOL_TYPE = new BuiltinType(BuiltinTypeName.Bool); exports.INT_TYPE = new BuiltinType(BuiltinTypeName.Int); exports.NUMBER_TYPE = new BuiltinType(BuiltinTypeName.Number); exports.STRING_TYPE = new BuiltinType(BuiltinTypeName.String); exports.FUNCTION_TYPE = new BuiltinType(BuiltinTypeName.Function); exports.NONE_TYPE = new BuiltinType(BuiltinTypeName.None); ///// Expressions var UnaryOperator; (function (UnaryOperator) { UnaryOperator[UnaryOperator["Minus"] = 0] = "Minus"; UnaryOperator[UnaryOperator["Plus"] = 1] = "Plus"; })(UnaryOperator = exports.UnaryOperator || (exports.UnaryOperator = {})); var BinaryOperator; (function (BinaryOperator) { BinaryOperator[BinaryOperator["Equals"] = 0] = "Equals"; BinaryOperator[BinaryOperator["NotEquals"] = 1] = "NotEquals"; BinaryOperator[BinaryOperator["Identical"] = 2] = "Identical"; BinaryOperator[BinaryOperator["NotIdentical"] = 3] = "NotIdentical"; BinaryOperator[BinaryOperator["Minus"] = 4] = "Minus"; BinaryOperator[BinaryOperator["Plus"] = 5] = "Plus"; BinaryOperator[BinaryOperator["Divide"] = 6] = "Divide"; BinaryOperator[BinaryOperator["Multiply"] = 7] = "Multiply"; BinaryOperator[BinaryOperator["Modulo"] = 8] = "Modulo"; BinaryOperator[BinaryOperator["And"] = 9] = "And"; BinaryOperator[BinaryOperator["Or"] = 10] = "Or"; BinaryOperator[BinaryOperator["BitwiseAnd"] = 11] = "BitwiseAnd"; BinaryOperator[BinaryOperator["Lower"] = 12] = "Lower"; BinaryOperator[BinaryOperator["LowerEquals"] = 13] = "LowerEquals"; BinaryOperator[BinaryOperator["Bigger"] = 14] = "Bigger"; BinaryOperator[BinaryOperator["BiggerEquals"] = 15] = "BiggerEquals"; })(BinaryOperator = exports.BinaryOperator || (exports.BinaryOperator = {})); function nullSafeIsEquivalent(base, other) { if (base == null || other == null) { return base == other; } return base.isEquivalent(other); } exports.nullSafeIsEquivalent = nullSafeIsEquivalent; function areAllEquivalent(base, other) { var len = base.length; if (len !== other.length) { return false; } for (var i = 0; i < len; i++) { if (!base[i].isEquivalent(other[i])) { return false; } } return true; } exports.areAllEquivalent = areAllEquivalent; var Expression = /** @class */ (function () { function Expression(type, sourceSpan) { this.type = type || null; this.sourceSpan = sourceSpan || null; } Expression.prototype.prop = function (name, sourceSpan) { return new ReadPropExpr(this, name, null, sourceSpan); }; Expression.prototype.key = function (index, type, sourceSpan) { return new ReadKeyExpr(this, index, type, sourceSpan); }; Expression.prototype.callMethod = function (name, params, sourceSpan) { return new InvokeMethodExpr(this, name, params, null, sourceSpan); }; Expression.prototype.callFn = function (params, sourceSpan, pure) { return new InvokeFunctionExpr(this, params, null, sourceSpan, pure); }; Expression.prototype.instantiate = function (params, type, sourceSpan) { return new InstantiateExpr(this, params, type, sourceSpan); }; Expression.prototype.conditional = function (trueCase, falseCase, sourceSpan) { if (falseCase === void 0) { falseCase = null; } return new ConditionalExpr(this, trueCase, falseCase, null, sourceSpan); }; Expression.prototype.equals = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.Equals, this, rhs, null, sourceSpan); }; Expression.prototype.notEquals = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.NotEquals, this, rhs, null, sourceSpan); }; Expression.prototype.identical = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.Identical, this, rhs, null, sourceSpan); }; Expression.prototype.notIdentical = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.NotIdentical, this, rhs, null, sourceSpan); }; Expression.prototype.minus = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.Minus, this, rhs, null, sourceSpan); }; Expression.prototype.plus = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.Plus, this, rhs, null, sourceSpan); }; Expression.prototype.divide = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.Divide, this, rhs, null, sourceSpan); }; Expression.prototype.multiply = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.Multiply, this, rhs, null, sourceSpan); }; Expression.prototype.modulo = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.Modulo, this, rhs, null, sourceSpan); }; Expression.prototype.and = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.And, this, rhs, null, sourceSpan); }; Expression.prototype.bitwiseAnd = function (rhs, sourceSpan, parens) { if (parens === void 0) { parens = true; } return new BinaryOperatorExpr(BinaryOperator.BitwiseAnd, this, rhs, null, sourceSpan, parens); }; Expression.prototype.or = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.Or, this, rhs, null, sourceSpan); }; Expression.prototype.lower = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.Lower, this, rhs, null, sourceSpan); }; Expression.prototype.lowerEquals = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.LowerEquals, this, rhs, null, sourceSpan); }; Expression.prototype.bigger = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.Bigger, this, rhs, null, sourceSpan); }; Expression.prototype.biggerEquals = function (rhs, sourceSpan) { return new BinaryOperatorExpr(BinaryOperator.BiggerEquals, this, rhs, null, sourceSpan); }; Expression.prototype.isBlank = function (sourceSpan) { // Note: We use equals by purpose here to compare to null and undefined in JS. // We use the typed null to allow strictNullChecks to narrow types. return this.equals(exports.TYPED_NULL_EXPR, sourceSpan); }; Expression.prototype.cast = function (type, sourceSpan) { return new CastExpr(this, type, sourceSpan); }; Expression.prototype.toStmt = function () { return new ExpressionStatement(this, null); }; return Expression; }()); exports.Expression = Expression; var BuiltinVar; (function (BuiltinVar) { BuiltinVar[BuiltinVar["This"] = 0] = "This"; BuiltinVar[BuiltinVar["Super"] = 1] = "Super"; BuiltinVar[BuiltinVar["CatchError"] = 2] = "CatchError"; BuiltinVar[BuiltinVar["CatchStack"] = 3] = "CatchStack"; })(BuiltinVar = exports.BuiltinVar || (exports.BuiltinVar = {})); var ReadVarExpr = /** @class */ (function (_super) { tslib_1.__extends(ReadVarExpr, _super); function ReadVarExpr(name, type, sourceSpan) { var _this = _super.call(this, type, sourceSpan) || this; if (typeof name === 'string') { _this.name = name; _this.builtin = null; } else { _this.name = null; _this.builtin = name; } return _this; } ReadVarExpr.prototype.isEquivalent = function (e) { return e instanceof ReadVarExpr && this.name === e.name && this.builtin === e.builtin; }; ReadVarExpr.prototype.isConstant = function () { return false; }; ReadVarExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitReadVarExpr(this, context); }; ReadVarExpr.prototype.set = function (value) { if (!this.name) { throw new Error("Built in variable " + this.builtin + " can not be assigned to."); } return new WriteVarExpr(this.name, value, null, this.sourceSpan); }; return ReadVarExpr; }(Expression)); exports.ReadVarExpr = ReadVarExpr; var TypeofExpr = /** @class */ (function (_super) { tslib_1.__extends(TypeofExpr, _super); function TypeofExpr(expr, type, sourceSpan) { var _this = _super.call(this, type, sourceSpan) || this; _this.expr = expr; return _this; } TypeofExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitTypeofExpr(this, context); }; TypeofExpr.prototype.isEquivalent = function (e) { return e instanceof TypeofExpr && e.expr.isEquivalent(this.expr); }; TypeofExpr.prototype.isConstant = function () { return this.expr.isConstant(); }; return TypeofExpr; }(Expression)); exports.TypeofExpr = TypeofExpr; var WrappedNodeExpr = /** @class */ (function (_super) { tslib_1.__extends(WrappedNodeExpr, _super); function WrappedNodeExpr(node, type, sourceSpan) { var _this = _super.call(this, type, sourceSpan) || this; _this.node = node; return _this; } WrappedNodeExpr.prototype.isEquivalent = function (e) { return e instanceof WrappedNodeExpr && this.node === e.node; }; WrappedNodeExpr.prototype.isConstant = function () { return false; }; WrappedNodeExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitWrappedNodeExpr(this, context); }; return WrappedNodeExpr; }(Expression)); exports.WrappedNodeExpr = WrappedNodeExpr; var WriteVarExpr = /** @class */ (function (_super) { tslib_1.__extends(WriteVarExpr, _super); function WriteVarExpr(name, value, type, sourceSpan) { var _this = _super.call(this, type || value.type, sourceSpan) || this; _this.name = name; _this.value = value; return _this; } WriteVarExpr.prototype.isEquivalent = function (e) { return e instanceof WriteVarExpr && this.name === e.name && this.value.isEquivalent(e.value); }; WriteVarExpr.prototype.isConstant = function () { return false; }; WriteVarExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitWriteVarExpr(this, context); }; WriteVarExpr.prototype.toDeclStmt = function (type, modifiers) { return new DeclareVarStmt(this.name, this.value, type, modifiers, this.sourceSpan); }; WriteVarExpr.prototype.toConstDecl = function () { return this.toDeclStmt(exports.INFERRED_TYPE, [StmtModifier.Final]); }; return WriteVarExpr; }(Expression)); exports.WriteVarExpr = WriteVarExpr; var WriteKeyExpr = /** @class */ (function (_super) { tslib_1.__extends(WriteKeyExpr, _super); function WriteKeyExpr(receiver, index, value, type, sourceSpan) { var _this = _super.call(this, type || value.type, sourceSpan) || this; _this.receiver = receiver; _this.index = index; _this.value = value; return _this; } WriteKeyExpr.prototype.isEquivalent = function (e) { return e instanceof WriteKeyExpr && this.receiver.isEquivalent(e.receiver) && this.index.isEquivalent(e.index) && this.value.isEquivalent(e.value); }; WriteKeyExpr.prototype.isConstant = function () { return false; }; WriteKeyExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitWriteKeyExpr(this, context); }; return WriteKeyExpr; }(Expression)); exports.WriteKeyExpr = WriteKeyExpr; var WritePropExpr = /** @class */ (function (_super) { tslib_1.__extends(WritePropExpr, _super); function WritePropExpr(receiver, name, value, type, sourceSpan) { var _this = _super.call(this, type || value.type, sourceSpan) || this; _this.receiver = receiver; _this.name = name; _this.value = value; return _this; } WritePropExpr.prototype.isEquivalent = function (e) { return e instanceof WritePropExpr && this.receiver.isEquivalent(e.receiver) && this.name === e.name && this.value.isEquivalent(e.value); }; WritePropExpr.prototype.isConstant = function () { return false; }; WritePropExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitWritePropExpr(this, context); }; return WritePropExpr; }(Expression)); exports.WritePropExpr = WritePropExpr; var BuiltinMethod; (function (BuiltinMethod) { BuiltinMethod[BuiltinMethod["ConcatArray"] = 0] = "ConcatArray"; BuiltinMethod[BuiltinMethod["SubscribeObservable"] = 1] = "SubscribeObservable"; BuiltinMethod[BuiltinMethod["Bind"] = 2] = "Bind"; })(BuiltinMethod = exports.BuiltinMethod || (exports.BuiltinMethod = {})); var InvokeMethodExpr = /** @class */ (function (_super) { tslib_1.__extends(InvokeMethodExpr, _super); function InvokeMethodExpr(receiver, method, args, type, sourceSpan) { var _this = _super.call(this, type, sourceSpan) || this; _this.receiver = receiver; _this.args = args; if (typeof method === 'string') { _this.name = method; _this.builtin = null; } else { _this.name = null; _this.builtin = method; } return _this; } InvokeMethodExpr.prototype.isEquivalent = function (e) { return e instanceof InvokeMethodExpr && this.receiver.isEquivalent(e.receiver) && this.name === e.name && this.builtin === e.builtin && areAllEquivalent(this.args, e.args); }; InvokeMethodExpr.prototype.isConstant = function () { return false; }; InvokeMethodExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitInvokeMethodExpr(this, context); }; return InvokeMethodExpr; }(Expression)); exports.InvokeMethodExpr = InvokeMethodExpr; var InvokeFunctionExpr = /** @class */ (function (_super) { tslib_1.__extends(InvokeFunctionExpr, _super); function InvokeFunctionExpr(fn, args, type, sourceSpan, pure) { if (pure === void 0) { pure = false; } var _this = _super.call(this, type, sourceSpan) || this; _this.fn = fn; _this.args = args; _this.pure = pure; return _this; } InvokeFunctionExpr.prototype.isEquivalent = function (e) { return e instanceof InvokeFunctionExpr && this.fn.isEquivalent(e.fn) && areAllEquivalent(this.args, e.args) && this.pure === e.pure; }; InvokeFunctionExpr.prototype.isConstant = function () { return false; }; InvokeFunctionExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitInvokeFunctionExpr(this, context); }; return InvokeFunctionExpr; }(Expression)); exports.InvokeFunctionExpr = InvokeFunctionExpr; var InstantiateExpr = /** @class */ (function (_super) { tslib_1.__extends(InstantiateExpr, _super); function InstantiateExpr(classExpr, args, type, sourceSpan) { var _this = _super.call(this, type, sourceSpan) || this; _this.classExpr = classExpr; _this.args = args; return _this; } InstantiateExpr.prototype.isEquivalent = function (e) { return e instanceof InstantiateExpr && this.classExpr.isEquivalent(e.classExpr) && areAllEquivalent(this.args, e.args); }; InstantiateExpr.prototype.isConstant = function () { return false; }; InstantiateExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitInstantiateExpr(this, context); }; return InstantiateExpr; }(Expression)); exports.InstantiateExpr = InstantiateExpr; var LiteralExpr = /** @class */ (function (_super) { tslib_1.__extends(LiteralExpr, _super); function LiteralExpr(value, type, sourceSpan) { var _this = _super.call(this, type, sourceSpan) || this; _this.value = value; return _this; } LiteralExpr.prototype.isEquivalent = function (e) { return e instanceof LiteralExpr && this.value === e.value; }; LiteralExpr.prototype.isConstant = function () { return true; }; LiteralExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitLiteralExpr(this, context); }; return LiteralExpr; }(Expression)); exports.LiteralExpr = LiteralExpr; var MessagePiece = /** @class */ (function () { function MessagePiece(text, sourceSpan) { this.text = text; this.sourceSpan = sourceSpan; } return MessagePiece; }()); exports.MessagePiece = MessagePiece; var LiteralPiece = /** @class */ (function (_super) { tslib_1.__extends(LiteralPiece, _super); function LiteralPiece() { return _super !== null && _super.apply(this, arguments) || this; } return LiteralPiece; }(MessagePiece)); exports.LiteralPiece = LiteralPiece; var PlaceholderPiece = /** @class */ (function (_super) { tslib_1.__extends(PlaceholderPiece, _super); function PlaceholderPiece() { return _super !== null && _super.apply(this, arguments) || this; } return PlaceholderPiece; }(MessagePiece)); exports.PlaceholderPiece = PlaceholderPiece; var LocalizedString = /** @class */ (function (_super) { tslib_1.__extends(LocalizedString, _super); function LocalizedString(metaBlock, messageParts, placeHolderNames, expressions, sourceSpan) { var _this = _super.call(this, exports.STRING_TYPE, sourceSpan) || this; _this.metaBlock = metaBlock; _this.messageParts = messageParts; _this.placeHolderNames = placeHolderNames; _this.expressions = expressions; return _this; } LocalizedString.prototype.isEquivalent = function (e) { // return e instanceof LocalizedString && this.message === e.message; return false; }; LocalizedString.prototype.isConstant = function () { return false; }; LocalizedString.prototype.visitExpression = function (visitor, context) { return visitor.visitLocalizedString(this, context); }; /** * Serialize the given `meta` and `messagePart` into "cooked" and "raw" strings that can be used * in a `$localize` tagged string. The format of the metadata is the same as that parsed by * `parseI18nMeta()`. * * @param meta The metadata to serialize * @param messagePart The first part of the tagged string */ LocalizedString.prototype.serializeI18nHead = function () { var MEANING_SEPARATOR = '|'; var ID_SEPARATOR = '@@'; var LEGACY_ID_INDICATOR = '␟'; var metaBlock = this.metaBlock.description || ''; if (this.metaBlock.meaning) { metaBlock = "" + this.metaBlock.meaning + MEANING_SEPARATOR + metaBlock; } if (this.metaBlock.customId) { metaBlock = "" + metaBlock + ID_SEPARATOR + this.metaBlock.customId; } if (this.metaBlock.legacyIds) { this.metaBlock.legacyIds.forEach(function (legacyId) { metaBlock = "" + metaBlock + LEGACY_ID_INDICATOR + legacyId; }); } return createCookedRawString(metaBlock, this.messageParts[0].text, this.getMessagePartSourceSpan(0)); }; LocalizedString.prototype.getMessagePartSourceSpan = function (i) { var _a, _b; return (_b = (_a = this.messageParts[i]) === null || _a === void 0 ? void 0 : _a.sourceSpan) !== null && _b !== void 0 ? _b : this.sourceSpan; }; LocalizedString.prototype.getPlaceholderSourceSpan = function (i) { var _a, _b, _c, _d; return (_d = (_b = (_a = this.placeHolderNames[i]) === null || _a === void 0 ? void 0 : _a.sourceSpan) !== null && _b !== void 0 ? _b : (_c = this.expressions[i]) === null || _c === void 0 ? void 0 : _c.sourceSpan) !== null && _d !== void 0 ? _d : this.sourceSpan; }; /** * Serialize the given `placeholderName` and `messagePart` into "cooked" and "raw" strings that * can be used in a `$localize` tagged string. * * @param placeholderName The placeholder name to serialize * @param messagePart The following message string after this placeholder */ LocalizedString.prototype.serializeI18nTemplatePart = function (partIndex) { var placeholderName = this.placeHolderNames[partIndex - 1].text; var messagePart = this.messageParts[partIndex]; return createCookedRawString(placeholderName, messagePart.text, this.getMessagePartSourceSpan(partIndex)); }; return LocalizedString; }(Expression)); exports.LocalizedString = LocalizedString; var escapeSlashes = function (str) { return str.replace(/\\/g, '\\\\'); }; var escapeStartingColon = function (str) { return str.replace(/^:/, '\\:'); }; var escapeColons = function (str) { return str.replace(/:/g, '\\:'); }; var escapeForMessagePart = function (str) { return str.replace(/`/g, '\\`').replace(/\${/g, '$\\{'); }; /** * Creates a `{cooked, raw}` object from the `metaBlock` and `messagePart`. * * The `raw` text must have various character sequences escaped: * * "\" would otherwise indicate that the next character is a control character. * * "`" and "${" are template string control sequences that would otherwise prematurely indicate * the end of a message part. * * ":" inside a metablock would prematurely indicate the end of the metablock. * * ":" at the start of a messagePart with no metablock would erroneously indicate the start of a * metablock. * * @param metaBlock Any metadata that should be prepended to the string * @param messagePart The message part of the string */ function createCookedRawString(metaBlock, messagePart, range) { if (metaBlock === '') { return { cooked: messagePart, raw: escapeForMessagePart(escapeStartingColon(escapeSlashes(messagePart))), range: range, }; } else { return { cooked: ":" + metaBlock + ":" + messagePart, raw: escapeForMessagePart(":" + escapeColons(escapeSlashes(metaBlock)) + ":" + escapeSlashes(messagePart)), range: range, }; } } var ExternalExpr = /** @class */ (function (_super) { tslib_1.__extends(ExternalExpr, _super); function ExternalExpr(value, type, typeParams, sourceSpan) { if (typeParams === void 0) { typeParams = null; } var _this = _super.call(this, type, sourceSpan) || this; _this.value = value; _this.typeParams = typeParams; return _this; } ExternalExpr.prototype.isEquivalent = function (e) { return e instanceof ExternalExpr && this.value.name === e.value.name && this.value.moduleName === e.value.moduleName && this.value.runtime === e.value.runtime; }; ExternalExpr.prototype.isConstant = function () { return false; }; ExternalExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitExternalExpr(this, context); }; return ExternalExpr; }(Expression)); exports.ExternalExpr = ExternalExpr; var ExternalReference = /** @class */ (function () { function ExternalReference(moduleName, name, runtime) { this.moduleName = moduleName; this.name = name; this.runtime = runtime; } return ExternalReference; }()); exports.ExternalReference = ExternalReference; var ConditionalExpr = /** @class */ (function (_super) { tslib_1.__extends(ConditionalExpr, _super); function ConditionalExpr(condition, trueCase, falseCase, type, sourceSpan) { if (falseCase === void 0) { falseCase = null; } var _this = _super.call(this, type || trueCase.type, sourceSpan) || this; _this.condition = condition; _this.falseCase = falseCase; _this.trueCase = trueCase; return _this; } ConditionalExpr.prototype.isEquivalent = function (e) { return e instanceof ConditionalExpr && this.condition.isEquivalent(e.condition) && this.trueCase.isEquivalent(e.trueCase) && nullSafeIsEquivalent(this.falseCase, e.falseCase); }; ConditionalExpr.prototype.isConstant = function () { return false; }; ConditionalExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitConditionalExpr(this, context); }; return ConditionalExpr; }(Expression)); exports.ConditionalExpr = ConditionalExpr; var NotExpr = /** @class */ (function (_super) { tslib_1.__extends(NotExpr, _super); function NotExpr(condition, sourceSpan) { var _this = _super.call(this, exports.BOOL_TYPE, sourceSpan) || this; _this.condition = condition; return _this; } NotExpr.prototype.isEquivalent = function (e) { return e instanceof NotExpr && this.condition.isEquivalent(e.condition); }; NotExpr.prototype.isConstant = function () { return false; }; NotExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitNotExpr(this, context); }; return NotExpr; }(Expression)); exports.NotExpr = NotExpr; var AssertNotNull = /** @class */ (function (_super) { tslib_1.__extends(AssertNotNull, _super); function AssertNotNull(condition, sourceSpan) { var _this = _super.call(this, condition.type, sourceSpan) || this; _this.condition = condition; return _this; } AssertNotNull.prototype.isEquivalent = function (e) { return e instanceof AssertNotNull && this.condition.isEquivalent(e.condition); }; AssertNotNull.prototype.isConstant = function () { return false; }; AssertNotNull.prototype.visitExpression = function (visitor, context) { return visitor.visitAssertNotNullExpr(this, context); }; return AssertNotNull; }(Expression)); exports.AssertNotNull = AssertNotNull; var CastExpr = /** @class */ (function (_super) { tslib_1.__extends(CastExpr, _super); function CastExpr(value, type, sourceSpan) { var _this = _super.call(this, type, sourceSpan) || this; _this.value = value; return _this; } CastExpr.prototype.isEquivalent = function (e) { return e instanceof CastExpr && this.value.isEquivalent(e.value); }; CastExpr.prototype.isConstant = function () { return false; }; CastExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitCastExpr(this, context); }; return CastExpr; }(Expression)); exports.CastExpr = CastExpr; var FnParam = /** @class */ (function () { function FnParam(name, type) { if (type === void 0) { type = null; } this.name = name; this.type = type; } FnParam.prototype.isEquivalent = function (param) { return this.name === param.name; }; return FnParam; }()); exports.FnParam = FnParam; var FunctionExpr = /** @class */ (function (_super) { tslib_1.__extends(FunctionExpr, _super); function FunctionExpr(params, statements, type, sourceSpan, name) { var _this = _super.call(this, type, sourceSpan) || this; _this.params = params; _this.statements = statements; _this.name = name; return _this; } FunctionExpr.prototype.isEquivalent = function (e) { return e instanceof FunctionExpr && areAllEquivalent(this.params, e.params) && areAllEquivalent(this.statements, e.statements); }; FunctionExpr.prototype.isConstant = function () { return false; }; FunctionExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitFunctionExpr(this, context); }; FunctionExpr.prototype.toDeclStmt = function (name, modifiers) { return new DeclareFunctionStmt(name, this.params, this.statements, this.type, modifiers, this.sourceSpan); }; return FunctionExpr; }(Expression)); exports.FunctionExpr = FunctionExpr; var UnaryOperatorExpr = /** @class */ (function (_super) { tslib_1.__extends(UnaryOperatorExpr, _super); function UnaryOperatorExpr(operator, expr, type, sourceSpan, parens) { if (parens === void 0) { parens = true; } var _this = _super.call(this, type || exports.NUMBER_TYPE, sourceSpan) || this; _this.operator = operator; _this.expr = expr; _this.parens = parens; return _this; } UnaryOperatorExpr.prototype.isEquivalent = function (e) { return e instanceof UnaryOperatorExpr && this.operator === e.operator && this.expr.isEquivalent(e.expr); }; UnaryOperatorExpr.prototype.isConstant = function () { return false; }; UnaryOperatorExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitUnaryOperatorExpr(this, context); }; return UnaryOperatorExpr; }(Expression)); exports.UnaryOperatorExpr = UnaryOperatorExpr; var BinaryOperatorExpr = /** @class */ (function (_super) { tslib_1.__extends(BinaryOperatorExpr, _super); function BinaryOperatorExpr(operator, lhs, rhs, type, sourceSpan, parens) { if (parens === void 0) { parens = true; } var _this = _super.call(this, type || lhs.type, sourceSpan) || this; _this.operator = operator; _this.rhs = rhs; _this.parens = parens; _this.lhs = lhs; return _this; } BinaryOperatorExpr.prototype.isEquivalent = function (e) { return e instanceof BinaryOperatorExpr && this.operator === e.operator && this.lhs.isEquivalent(e.lhs) && this.rhs.isEquivalent(e.rhs); }; BinaryOperatorExpr.prototype.isConstant = function () { return false; }; BinaryOperatorExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitBinaryOperatorExpr(this, context); }; return BinaryOperatorExpr; }(Expression)); exports.BinaryOperatorExpr = BinaryOperatorExpr; var ReadPropExpr = /** @class */ (function (_super) { tslib_1.__extends(ReadPropExpr, _super); function ReadPropExpr(receiver, name, type, sourceSpan) { var _this = _super.call(this, type, sourceSpan) || this; _this.receiver = receiver; _this.name = name; return _this; } ReadPropExpr.prototype.isEquivalent = function (e) { return e instanceof ReadPropExpr && this.receiver.isEquivalent(e.receiver) && this.name === e.name; }; ReadPropExpr.prototype.isConstant = function () { return false; }; ReadPropExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitReadPropExpr(this, context); }; ReadPropExpr.prototype.set = function (value) { return new WritePropExpr(this.receiver, this.name, value, null, this.sourceSpan); }; return ReadPropExpr; }(Expression)); exports.ReadPropExpr = ReadPropExpr; var ReadKeyExpr = /** @class */ (function (_super) { tslib_1.__extends(ReadKeyExpr, _super); function ReadKeyExpr(receiver, index, type, sourceSpan) { var _this = _super.call(this, type, sourceSpan) || this; _this.receiver = receiver; _this.index = index; return _this; } ReadKeyExpr.prototype.isEquivalent = function (e) { return e instanceof ReadKeyExpr && this.receiver.isEquivalent(e.receiver) && this.index.isEquivalent(e.index); }; ReadKeyExpr.prototype.isConstant = function () { return false; }; ReadKeyExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitReadKeyExpr(this, context); }; ReadKeyExpr.prototype.set = function (value) { return new WriteKeyExpr(this.receiver, this.index, value, null, this.sourceSpan); }; return ReadKeyExpr; }(Expression)); exports.ReadKeyExpr = ReadKeyExpr; var LiteralArrayExpr = /** @class */ (function (_super) { tslib_1.__extends(LiteralArrayExpr, _super); function LiteralArrayExpr(entries, type, sourceSpan) { var _this = _super.call(this, type, sourceSpan) || this; _this.entries = entries; return _this; } LiteralArrayExpr.prototype.isConstant = function () { return this.entries.every(function (e) { return e.isConstant(); }); }; LiteralArrayExpr.prototype.isEquivalent = function (e) { return e instanceof LiteralArrayExpr && areAllEquivalent(this.entries, e.entries); }; LiteralArrayExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitLiteralArrayExpr(this, context); }; return LiteralArrayExpr; }(Expression)); exports.LiteralArrayExpr = LiteralArrayExpr; var LiteralMapEntry = /** @class */ (function () { function LiteralMapEntry(key, value, quoted) { this.key = key; this.value = value; this.quoted = quoted; } LiteralMapEntry.prototype.isEquivalent = function (e) { return this.key === e.key && this.value.isEquivalent(e.value); }; return LiteralMapEntry; }()); exports.LiteralMapEntry = LiteralMapEntry; var LiteralMapExpr = /** @class */ (function (_super) { tslib_1.__extends(LiteralMapExpr, _super); function LiteralMapExpr(entries, type, sourceSpan) { var _this = _super.call(this, type, sourceSpan) || this; _this.entries = entries; _this.valueType = null; if (type) { _this.valueType = type.valueType; } return _this; } LiteralMapExpr.prototype.isEquivalent = function (e) { return e instanceof LiteralMapExpr && areAllEquivalent(this.entries, e.entries); }; LiteralMapExpr.prototype.isConstant = function () { return this.entries.every(function (e) { return e.value.isConstant(); }); }; LiteralMapExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitLiteralMapExpr(this, context); }; return LiteralMapExpr; }(Expression)); exports.LiteralMapExpr = LiteralMapExpr; var CommaExpr = /** @class */ (function (_super) { tslib_1.__extends(CommaExpr, _super); function CommaExpr(parts, sourceSpan) { var _this = _super.call(this, parts[parts.length - 1].type, sourceSpan) || this; _this.parts = parts; return _this; } CommaExpr.prototype.isEquivalent = function (e) { return e instanceof CommaExpr && areAllEquivalent(this.parts, e.parts); }; CommaExpr.prototype.isConstant = function () { return false; }; CommaExpr.prototype.visitExpression = function (visitor, context) { return visitor.visitCommaExpr(this, context); }; return CommaExpr; }(Expression)); exports.CommaExpr = CommaExpr; exports.THIS_EXPR = new ReadVarExpr(BuiltinVar.This, null, null); exports.SUPER_EXPR = new ReadVarExpr(BuiltinVar.Super, null, null); exports.CATCH_ERROR_VAR = new ReadVarExpr(BuiltinVar.CatchError, null, null); exports.CATCH_STACK_VAR = new ReadVarExpr(BuiltinVar.CatchStack, null, null); exports.NULL_EXPR = new LiteralExpr(null, null, null); exports.TYPED_NULL_EXPR = new LiteralExpr(null, exports.INFERRED_TYPE, null); //// Statements var StmtModifier; (function (StmtModifier) { StmtModifier[StmtModifier["Final"] = 0] = "Final"; StmtModifier[StmtModifier["Private"] = 1] = "Private"; StmtModifier[StmtModifier["Exported"] = 2] = "Exported"; StmtModifier[StmtModifier["Static"] = 3] = "Static"; })(StmtModifier = exports.StmtModifier || (exports.StmtModifier = {})); var LeadingComment = /** @class */ (function () { function LeadingComment(text, multiline, trailingNewline) { this.text = text; this.multiline = multiline; this.trailingNewline = trailingNewline; } LeadingComment.prototype.toString = function () { return this.multiline ? " " + this.text + " " : this.text; }; return LeadingComment; }()); exports.LeadingComment = LeadingComment; var JSDocComment = /** @class */ (function (_super) { tslib_1.__extends(JSDocComment, _super); function JSDocComment(tags) { var _this = _super.call(this, '', /* multiline */ true, /* trailingNewline */ true) || this; _this.tags = tags; return _this; } JSDocComment.prototype.toString = function () { return serializeTags(this.tags); }; return JSDocComment; }(LeadingComment)); exports.JSDocComment = JSDocComment; var Statement = /** @class */ (function () { function Statement(modifiers, sourceSpan, leadingComments) { if (modifiers === void 0) { modifiers = []; } if (sourceSpan === void 0) { sourceSpan = null; } this.modifiers = modifiers; this.sourceSpan = sourceSpan; this.leadingComments = leadingComments; } Statement.prototype.hasModifier = function (modifier) { return this.modifiers.indexOf(modifier) !== -1; }; Statement.prototype.addLeadingComment = function (leadingComment) { var _a; this.leadingComments = (_a = this.leadingComments) !== null && _a !== void 0 ? _a : []; this.leadingComments.push(leadingComment); }; return Statement; }()); exports.Statement = Statement; var DeclareVarStmt = /** @class */ (function (_super) { tslib_1.__extends(DeclareVarStmt, _super); function DeclareVarStmt(name, value, type, modifiers, sourceSpan, leadingComments) { var _this = _super.call(this, modifiers, sourceSpan, leadingComments) || this; _this.name = name; _this.value = value; _this.type = type || (value && value.type) || null; return _this; } DeclareVarStmt.prototype.isEquivalent = function (stmt) { return stmt instanceof DeclareVarStmt && this.name === stmt.name && (this.value ? !!stmt.value && this.value.isEquivalent(stmt.value) : !stmt.value); }; DeclareVarStmt.prototype.visitStatement = function (visitor, context) { return visitor.visitDeclareVarStmt(this, context); }; return DeclareVarStmt; }(Statement)); exports.DeclareVarStmt = DeclareVarStmt; var DeclareFunctionStmt = /** @class */ (function (_super) { tslib_1.__extends(DeclareFunctionStmt, _super); function DeclareFunctionStmt(name, params, statements, type, modifiers, sourceSpan, leadingComments) { var _this = _super.call(this, modifiers, sourceSpan, leadingComments) || this; _this.name = name; _this.params = params; _this.statements = statements; _this.type = type || null; return _this; } DeclareFunctionStmt.prototype.isEquivalent = function (stmt) { return stmt instanceof DeclareFunctionStmt && areAllEquivalent(this.params, stmt.params) && areAllEquivalent(this.statements, stmt.statements); }; DeclareFunctionStmt.prototype.visitStatement = function (visitor, context) { return visitor.visitDeclareFunctionStmt(this, context); }; return DeclareFunctionStmt; }(Statement)); exports.DeclareFunctionStmt = DeclareFunctionStmt; var ExpressionStatement = /** @class */ (function (_super) { tslib_1.__extends(ExpressionStatement, _super); function ExpressionStatement(expr, sourceSpan, leadingComments) { var _this = _super.call(this, [], sourceSpan, leadingComments) || this; _this.expr = expr; return _this; } ExpressionStatement.prototype.isEquivalent = function (stmt) { return stmt instanceof ExpressionStatement && this.expr.isEquivalent(stmt.expr); }; ExpressionStatement.prototype.visitStatement = function (visitor, context) { return visit