@angular/compiler
Version:
Angular - the compiler library
1,029 lines • 217 kB
JavaScript
/**
* @license
* Copyright Google Inc. 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 });
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 = null; }
this.modifiers = modifiers;
if (!modifiers) {
this.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) {
if (modifiers === void 0) { modifiers = null; }
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 (modifiers === void 0) { modifiers = null; }
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) {
if (modifiers === void 0) { modifiers = null; }
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) {
if (modifiers === void 0) { modifiers = null; }
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 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) {
return new InvokeFunctionExpr(this, params, null, sourceSpan);
};
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);
};
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) {
var _this = _super.call(this, type, sourceSpan) || this;
_this.fn = fn;
_this.args = args;
return _this;
}
InvokeFunctionExpr.prototype.isEquivalent = function (e) {
return e instanceof InvokeFunctionExpr && this.fn.isEquivalent(e.fn) &&
areAllEquivalent(this.args, e.args);
};
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 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) {
if (modifiers === void 0) { modifiers = null; }
return new DeclareFunctionStmt(name, this.params, this.statements, this.type, modifiers, this.sourceSpan);
};
return FunctionExpr;
}(Expression));
exports.FunctionExpr = FunctionExpr;
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 Statement = /** @class */ (function () {
function Statement(modifiers, sourceSpan) {
this.modifiers = modifiers || [];
this.sourceSpan = sourceSpan || null;
}
Statement.prototype.hasModifier = function (modifier) { return this.modifiers.indexOf(modifier) !== -1; };
return Statement;
}());
exports.Statement = Statement;
var DeclareVarStmt = /** @class */ (function (_super) {
tslib_1.__extends(DeclareVarStmt, _super);
function DeclareVarStmt(name, value, type, modifiers, sourceSpan) {
if (modifiers === void 0) { modifiers = null; }
var _this = _super.call(this, modifiers, sourceSpan) || 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) {
if (modifiers === void 0) { modifiers = null; }
var _this = _super.call(this, modifiers, sourceSpan) || 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) {
var _this = _super.call(this, null, sourceSpan) || 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 visitor.visitExpressionStmt(this, context);
};
return ExpressionStatement;
}(Statement));
exports.ExpressionStatement = ExpressionStatement;
var ReturnStatement = /** @class */ (function (_super) {
tslib_1.__extends(ReturnStatement, _super);
function ReturnStatement(value, sourceSpan) {
var _this = _super.call(this, null, sourceSpan) || this;
_this.value = value;
return _this;
}
ReturnStatement.prototype.isEquivalent = function (stmt) {
return stmt instanceof ReturnStatement && this.value.isEquivalent(stmt.value);
};
ReturnStatement.prototype.visitStatement = function (visitor, context) {
return visitor.visitReturnStmt(this, context);
};
return ReturnStatement;
}(Statement));
exports.ReturnStatement = ReturnStatement;
var AbstractClassPart = /** @class */ (function () {
function AbstractClassPart(type, modifiers) {
this.modifiers = modifiers;
if (!modifiers) {
this.modifiers = [];
}
this.type = type || null;
}
AbstractClassPart.prototype.hasModifier = function (modifier) { return this.modifiers.indexOf(modifier) !== -1; };
return AbstractClassPart;
}());
exports.AbstractClassPart = AbstractClassPart;
var ClassField = /** @class */ (function (_super) {
tslib_1.__extends(ClassField, _super);
function ClassField(name, type, modifiers, initializer) {
if (modifiers === void 0) { modifiers = null; }
var _this = _super.call(this, type, modifiers) || this;
_this.name = name;
_this.initializer = initializer;
return _this;
}
ClassField.prototype.isEquivalent = function (f) { return this.name === f.name; };
return ClassField;
}(AbstractClassPart));
exports.ClassField = ClassField;
var ClassMethod = /** @class */ (function (_super) {
tslib_1.__extends(ClassMethod, _super);
function ClassMethod(name, params, body, type, modifiers) {
if (modifiers === void 0) { modifiers = null; }
var _this = _super.call(this, type, modifiers) || this;
_this.name = name;
_this.params = params;
_this.body = body;
return _this;
}
ClassMethod.prototype.isEquivalent = function (m) {
return this.name === m.name && areAllEquivalent(this.body, m.body);
};
return ClassMethod;
}(AbstractClassPart));
exports.ClassMethod = ClassMethod;
var ClassGetter = /** @class */ (function (_super) {
tslib_1.__extends(ClassGetter, _super);
function ClassGetter(name, body, type, modifiers) {
if (modifiers === void 0) { modifiers = null; }
var _this = _super.call(this, type, modifiers) || this;
_this.name = name;
_this.body = body;
return _this;
}
ClassGetter.prototype.isEquivalent = function (m) {
return this.name === m.name && areAllEquivalent(this.body, m.body);
};
return ClassGetter;
}(AbstractClassPart));
exports.ClassGetter = ClassGetter;
var ClassStmt = /** @class */ (function (_super) {
tslib_1.__extends(ClassStmt, _super);
function ClassStmt(name, parent, fields, getters, constructorMethod, methods, modifiers, sourceSpan) {
if (modifiers === void 0) { modifiers = null; }
var _this = _super.call(this, modifiers, sourceSpan) || this;
_this.name = name;
_this.parent = parent;
_this.fields = fields;
_this.getters = getters;
_this.constructorMethod = constructorMethod;
_this.methods = methods;
return _this;
}
ClassStmt.prototype.isEquivalent = function (stmt) {
return stmt instanceof ClassStmt && this.name === stmt.name &&
nullSafeIsEquivalent(this.parent, stmt.parent) &&
areAllEquivalent(this.fields, stmt.fields) &&
areAllEquivalent(this.getters, stmt.getters) &&
this.constructorMethod.isEquivalent(stmt.constructorMethod) &&
areAllEquivalent(this.methods, stmt.methods);
};
ClassStmt.prototype.visitStatement = function (visitor, context) {
return visitor.visitDeclareClassStmt(this, context);
};
return ClassStmt;
}(Statement));
exports.ClassStmt = ClassStmt;
var IfStmt = /** @class */ (function (_super) {
tslib_1.__extends(IfStmt, _super);
function IfStmt(condition, trueCase, falseCase, sourceSpan) {
if (falseCase === void 0) { falseCase = []; }
var _this = _super.call(this, null, sourceSpan) || this;
_this.condition = condition;
_this.trueCase = trueCase;
_this.falseCase = falseCase;
return _this;
}
IfStmt.prototype.isEquivalent = function (stmt) {
return stmt instanceof IfStmt && this.condition.isEquivalent(stmt.condition) &&
areAllEquivalent(this.trueCase, stmt.trueCase) &&
areAllEquivalent(this.falseCase, stmt.falseCase);
};
IfStmt.prototype.visitStatement = function (visitor, context) {
return visitor.visitIfStmt(this, context);
};
return IfStmt;
}(Statement));
exports.IfStmt = IfStmt;
var CommentStmt = /** @class */ (function (_super) {
tslib_1.__extends(CommentStmt, _super);
function CommentStmt(comment, multiline, sourceSpan) {
if (multiline === void 0) { multiline = false; }
var _this = _super.call(this, null, sourceSpan) || this;
_this.comment = comment;
_this.multiline = multiline;
return _this;
}
CommentStmt.prototype.isEquivalent = function (stmt) { return stmt instanceof CommentStmt; };
CommentStmt.prototype.visitStatement = function (visitor, context) {
return visitor.visitCommentStmt(this, context);
};
return CommentStmt;
}(Statement));
exports.CommentStmt = CommentStmt;
var JSDocCommentStmt = /** @class */ (function (_super) {
tslib_1.__extends(JSDocCommentStmt, _super);
function JSDocCommentStmt(tags, sourceSpan) {
if (tags === void 0) { tags = []; }
var _this = _super.call(this, null, sourceSpan) || this;
_this.tags = tags;
return _this;
}
JSDocCommentStmt.prototype.isEquivalent = function (stmt) {
return stmt instanceof JSDocCommentStmt && this.toString() === stmt.toString();
};
JSDocCommentStmt.prototype.visitStatement = function (visitor, context) {
return visitor.visitJSDocCommentStmt(this, context);
};
JSDocCommentStmt.prototype.toString = function () { return serializeTags(this.tags); };
return JSDocCommentStmt;
}(Statement));
exports.JSDocCommentStmt = JSDocCommentStmt;
var TryCatchStmt = /** @class */ (function (_super) {
tslib_1.__extends(TryCatchStmt, _super);
function TryCatchStmt(bodyStmts, catchStmts, sourceSpan) {
var _this = _super.call(this, null, sourceSpan) || this;
_this.bodyStmts = bodyStmts;
_this.catchStmts = catchStmts;
return _this;
}
TryCatchStmt.prototype.isEquivalent = function (stmt) {
return stmt instanceof TryCatchStmt && areAllEquivalent(this.bodyStmts, stmt.bodyStmts) &&
areAllEquivalent(this.catchStmts, stmt.catchStmts);
};
TryCatchStmt.prototype.visitStatement = function (visitor, context) {
return visitor.visitTryCatchStmt(this, context);
};
return TryCatchStmt;
}(Statement));
exports.TryCatchStmt = TryCatchStmt;
var ThrowStmt = /** @class */ (function (_super) {
tslib_1.__extends(ThrowStmt, _super);
function ThrowStmt(error, sourceSpan) {
var _this = _super.call(this, null, sourceSpan) || this;
_this.error = error;
return _this;
}
ThrowStmt.prototype.isEquivalent = function (stmt) {
return stmt instanceof TryCatchStmt && this.error.isEquivalent(stmt.error);
};
ThrowStmt.prototype.visitStatement = function (visitor, context) {
return visitor.visitThrowStmt(this, context);
};
return ThrowStmt;
}(Statement));
exports.ThrowStmt = ThrowStmt;
var AstTransformer = /** @class */ (function () {
function AstTransformer() {
}
AstTransformer.prototype.transformExpr = function (expr, context) { return expr; };
AstTransformer.prototype.transformStmt = function (stmt, context) { return stmt; };
AstTransformer.prototype.visitReadVarExpr = function (ast, context) { return this.transformExpr(ast, context); };
AstTransformer.prototype.visitWrappedNodeExpr = function (ast, context) {
return this.transformExpr(ast, context);
};
AstTransformer.prototype.visitTypeofExpr = function (expr, context) {
return this.transformExpr(new TypeofExpr(expr.expr.visitExpression(this, context), expr.type, expr.sourceSpan), context);
};
AstTransformer.prototype.visitWriteVarExpr = function (expr, context) {
return this.transformExpr(new WriteVarExpr(expr.name, expr.value.visitExpression(this, context), expr.type, expr.sourceSpan), context);
};
AstTransformer.prototype.visitWriteKeyExpr = function (expr, context) {
return this.transformExpr(new WriteKeyExpr(expr.receiver.visitExpression(this, context), expr.index.visitExpression(this, context), expr.value.visitExpression(this, context), expr.type, expr.sourceSpan), context);
};
AstTransformer.prototype.visitWritePropExpr = function (expr, context) {
return this.transformExpr(new WritePropExpr(expr.receiver.visitExpression(this, context), expr.name, expr.value.visitExpression(this, context), expr.type, expr.sourceSpan), context);
};
AstTransformer.prototype.visitInvokeMethodExpr = function (ast, context) {
var method = ast.builtin || ast.name;
return this.transformExpr(new InvokeMethodExpr(ast.receiver.visitExpression(this, context), method, this.visitAllExpressions(ast.args, context), ast.type, ast.sourceSpan), context);
};
AstTransformer.prototype.visitInvokeFunctionExpr = function (ast, context) {
return this.transformExpr(new InvokeFunctionExpr(ast.fn.visitExpression(this, context), this.visitAllExpressions(ast.args, context), ast.type, ast.sourceSpan), context);
};
AstTransformer.prototype.visitInstantiateExpr = function (ast, context) {
return this.transformExpr(new InstantiateExpr(ast.classExpr.visitExpression(this, context), this.visitAllExpressions(ast.args, context), ast.type, ast.sourceSpan), context);
};
AstTransformer.prototype.visitLiteralExpr = function (ast, context) { return this.transformExpr(ast, context); };
AstTransformer.prototype.visitExternalExpr = function (ast, context) {
return this.transformExpr(ast, context);
};
AstTransformer.prototype.visitConditionalExpr = function (ast, context) {
return this.transformExpr(new ConditionalExpr(ast.condition.visitExpression(this, context), ast.trueCase.visitExpression(this, context), ast.falseCase.visitExpression(this, context), ast.type