Rewrite the tree instead of hacking text together for downlevel object literals with computed properties.

This commit is contained in:
Daniel Rosenwasser
2015-02-20 14:16:09 -08:00
parent 0fd783f3ef
commit 51129a704d
44 changed files with 412 additions and 455 deletions

View File

@@ -21,6 +21,12 @@ module ts {
diagnosticMessage: DiagnosticMessage;
typeName?: DeclarationName;
}
interface SynthesizedNode extends Node {
leadingCommentRanges?: CommentRange[];
trailingCommentRanges?: CommentRange[];
}
type GetSymbolAccessibilityDiagnostic = (symbolAccesibilityResult: SymbolAccessiblityResult) => SymbolAccessibilityDiagnostic;
interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter {
@@ -2514,7 +2520,198 @@ module ts {
write("}");
}
function emitDownlevelObjectLiteralWithComputedProperties(node: ObjectLiteralExpression, firstComputedPropertyIndex: number) {
function createSynthesizedNode(kind: SyntaxKind): Node {
var node = createNode(kind);
node.pos = -1;
node.end = -1;
return node;
}
function emitDownlevelObjectLiteralWithComputedProperties(node: ObjectLiteralExpression, firstComputedPropertyIndex: number): void {
var parenthesizedObjectLiteral = createDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex);
return emit(parenthesizedObjectLiteral);
}
function createDownlevelObjectLiteralWithComputedProperties(originalObjectLiteral: ObjectLiteralExpression, firstComputedPropertyIndex: number): ParenthesizedExpression {
// For computed properties, we need to create a unique handle to the object
// literal so we can modify it without risking internal assignments tainting the object.
var tempVar = createAndRecordTempVariable(originalObjectLiteral);
// Hold onto the initial non-computed properties in a new object literal,
// then create the rest through property accesses on the temp variable.
var initialObjectLiteral = <ObjectLiteralExpression>createSynthesizedNode(SyntaxKind.ObjectLiteralExpression);
initialObjectLiteral.properties = <NodeArray<ObjectLiteralElement>>originalObjectLiteral.properties.slice(0, firstComputedPropertyIndex);
initialObjectLiteral.flags |= NodeFlags.MultiLine;
// The comma expressions that will patch the object literal.
var propertyPatches = createBinaryExpression(SyntaxKind.EqualsToken, tempVar, initialObjectLiteral);
ts.forEach(originalObjectLiteral.properties, property => {
var patchedProperty = tryCreatePatchingPropertyAssignment(originalObjectLiteral, tempVar, property);
if (patchedProperty) {
// TODO(drosen): Preserve comments
//var leadingComments = getLeadingCommentRanges(currentSourceFile.text, property.pos);
//var trailingComments = getTrailingCommentRanges(currentSourceFile.text, property.end);
//addCommentsToSynthesizedNode(patchedProperty, leadingComments, trailingComments);
propertyPatches = createBinaryExpression(SyntaxKind.CommaToken, propertyPatches, patchedProperty);
}
});
propertyPatches = createBinaryExpression(SyntaxKind.CommaToken, propertyPatches, tempVar);
var result = createParenthesizedExpression(propertyPatches);
// TODO(drosen): Preserve comments
// var leadingComments = getLeadingCommentRanges(currentSourceFile.text, originalObjectLiteral.pos);
// var trailingComments = getTrailingCommentRanges(currentSourceFile.text, originalObjectLiteral.end);
//addCommentsToSynthesizedNode(result, leadingComments, trailingComments);
return result;
}
function addCommentsToSynthesizedNode(node: SynthesizedNode, leadingCommentRanges: CommentRange[], trailingCommentRanges: CommentRange[]): void {
node.leadingCommentRanges = leadingCommentRanges;
node.trailingCommentRanges = trailingCommentRanges;
}
// Returns 'undefined' if a property has already been accounted for.
function tryCreatePatchingPropertyAssignment(objectLiteral: ObjectLiteralExpression, tempVar: Identifier, property: ObjectLiteralElement): Expression {
var leftHandSide = createMemberAccessForPropertyName(tempVar, property.name);
var rightHandSide: Expression;
if (property.kind === SyntaxKind.PropertyAssignment) {
rightHandSide = (<PropertyAssignment>property).initializer;
}
else if (property.kind === SyntaxKind.ShorthandPropertyAssignment) {
var prefix = createIdentifier(resolver.getExpressionNamePrefix((<ShorthandPropertyAssignment>property).name));
rightHandSide = createPropertyAccessExpression(prefix, (<ShorthandPropertyAssignment>property).name);
}
else if (property.kind === SyntaxKind.MethodDeclaration) {
emitFunctionDeclaration(<MethodDeclaration>property);
}
else if (property.kind === SyntaxKind.GetAccessor || property.kind === SyntaxKind.SetAccessor) {
var accessors = getAllAccessorDeclarations(objectLiteral.properties, <AccessorDeclaration>property);
// Only emit the first accessor.
if (accessors.firstAccessor !== property) {
return undefined;
}
var propertyDescriptor = <ObjectLiteralExpression>createSynthesizedNode(SyntaxKind.ObjectLiteralExpression);
var descriptorProperties = <NodeArray<ObjectLiteralElement>>[];
if (accessors.getAccessor) {
var getProperty = createPropertyAssignment(createIdentifier("get"), createFunctionExpressionForAccessor(accessors.getAccessor));
descriptorProperties.push(getProperty);
}
if (accessors.setAccessor) {
var setProperty = createPropertyAssignment(createIdentifier("set"), createFunctionExpressionForAccessor(accessors.setAccessor));
descriptorProperties.push(setProperty);
}
var trueExpr = <PrimaryExpression>createSynthesizedNode(SyntaxKind.TrueKeyword);
var enumerableTrue = createPropertyAssignment(createIdentifier("enumerable"), trueExpr);
descriptorProperties.push(enumerableTrue);
var configurableTrue = createPropertyAssignment(createIdentifier("configurable"), trueExpr);
descriptorProperties.push(configurableTrue);
propertyDescriptor.properties = descriptorProperties;
var objectDotDefineProperty = createPropertyAccessExpression(createIdentifier("Object"), createIdentifier("defineProperty"));
rightHandSide = createCallExpression(objectDotDefineProperty, createNodeArray(propertyDescriptor));
}
else {
Debug.fail(`ObjectLiteralElement kind ${property.kind} not accounted for.`);
}
return createBinaryExpression(SyntaxKind.EqualsToken, leftHandSide, rightHandSide);
}
function createParenthesizedExpression(expression: Expression) {
var result = <ParenthesizedExpression>createSynthesizedNode(SyntaxKind.ParenthesizedExpression);
result.expression = expression;
return result;
}
function createNodeArray<T extends Node>(...elements: T[]): NodeArray<T> {
return <NodeArray<T>>elements;
}
function createBinaryExpression(operator: SyntaxKind, left: Expression, right: Expression): BinaryExpression {
var result = <BinaryExpression>createSynthesizedNode(SyntaxKind.BinaryExpression);
result.operator = operator;
result.left = left;
result.right = right;
return result;
}
function createMemberAccessForPropertyName(expression: LeftHandSideExpression, memberName: DeclarationName): PropertyAccessExpression | ElementAccessExpression {
if (memberName.kind === SyntaxKind.Identifier) {
return createPropertyAccessExpression(expression, <Identifier>memberName);
}
else if (memberName.kind === SyntaxKind.StringLiteral || memberName.kind === SyntaxKind.NumericLiteral) {
return createElementAccessExpression(expression, <LiteralExpression>memberName);
}
else if (memberName.kind === SyntaxKind.ComputedPropertyName) {
return createElementAccessExpression(expression, (<ComputedPropertyName>memberName).expression);
}
else {
Debug.fail(`Kind '${memberName.kind}' not accounted for.`);
}
}
function createPropertyAssignment(name: LiteralExpression | Identifier, initializer: Expression) {
var result = <PropertyAssignment>createSynthesizedNode(SyntaxKind.PropertyAssignment);
result.name = name;
result.initializer = initializer;
return result;
}
function createFunctionExpressionForAccessor(accessor: AccessorDeclaration): FunctionExpression {
var result = <FunctionExpression>createSynthesizedNode(SyntaxKind.FunctionExpression);
result.parameters = accessor.parameters;
result.body = accessor.body;
return result;
}
function createPropertyAccessExpression(expression: LeftHandSideExpression, name: Identifier): PropertyAccessExpression {
var result = <PropertyAccessExpression>createSynthesizedNode(SyntaxKind.PropertyAccessExpression);
result.expression = expression;
result.name = name;
return result;
}
function createElementAccessExpression(expression: LeftHandSideExpression, argumentExpression: Expression): ElementAccessExpression {
var result = <ElementAccessExpression>createSynthesizedNode(SyntaxKind.ElementAccessExpression);
result.expression = expression;
result.argumentExpression = argumentExpression;
return result;
}
function createIdentifier(name: string) {
var result = <Identifier>createSynthesizedNode(SyntaxKind.Identifier);
result.text = name;
return result;
}
function createCallExpression(invokedExpression: MemberExpression, arguments: NodeArray<Expression>) {
var result = <CallExpression>createSynthesizedNode(SyntaxKind.CallExpression);
result.expression = invokedExpression;
result.arguments = arguments;
return result;
}
function emitDownlevelObjectLiteralWithComputedProperties2(node: ObjectLiteralExpression, firstComputedPropertyIndex: number) {
var multiLine = (node.flags & NodeFlags.MultiLine) !== 0;
var properties = node.properties;
@@ -2587,7 +2784,7 @@ module ts {
write("})");
emitEnd(property);
}
else {
else {
emitLeadingComments(property);
emitStart(property.name);
emit(tempVar);

View File

@@ -2,5 +2,5 @@
var v = { *[foo()]() { } }
//// [FunctionPropertyAssignments5_es6.js]
var v = (_a = {}, _a[foo()] = function () { }, _a);
var v = function () { }(_a = {}, _a[foo()] = , _a);
var _a;

View File

@@ -20,18 +20,5 @@ var v = {
var s;
var n;
var a;
var v = (_a = {},
_a[s] = function () { },
_a[n] = function () { },
_a[s + s] = function () { },
_a[s + n] = function () { },
_a[+s] = function () { },
_a[""] = function () { },
_a[0] = function () { },
_a[a] = function () { },
_a[true] = function () { },
_a["hello bye"] = function () { },
_a["hello " + a + " bye"] = function () { },
_a
);
var v = function () { }function () { }function () { }function () { }function () { }function () { }function () { }function () { }function () { }function () { }function () { }(_a = {}, _a[s] = , _a[n] = , _a[s + s] = , _a[s + n] = , _a[+s] = , _a[""] = , _a[0] = , _a[a] = , _a[true] = , _a["hello bye"] = , _a["hello " + a + " bye"] = , _a);
var _a;

View File

@@ -20,74 +20,17 @@ var v = {
var s;
var n;
var a;
var v = (_a = {},
Object.defineProperty(_a, s, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, n, {
set: function (v) { },
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, s + s, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, s + n, {
set: function (v) { },
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, +s, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, "", {
set: function (v) { },
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, 0, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, a, {
set: function (v) { },
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, true, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, "hello bye", {
set: function (v) { },
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, "hello " + a + " bye", {
get: function () {
return 0;
},
enumerable: true,
configurable: true
}),
_a
);
var v = (_a = {}, _a[s] = Object.defineProperty({ get: function () {
return 0;
}, enumerable: true, configurable: true }), _a[n] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[s + s] = Object.defineProperty({ get: function () {
return 0;
}, enumerable: true, configurable: true }), _a[s + n] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[+s] = Object.defineProperty({ get: function () {
return 0;
}, enumerable: true, configurable: true }), _a[""] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[0] = Object.defineProperty({ get: function () {
return 0;
}, enumerable: true, configurable: true }), _a[a] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a[true] = Object.defineProperty({ get: function () {
return 0;
}, enumerable: true, configurable: true }), _a["hello bye"] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a["hello " + a + " bye"] = Object.defineProperty({ get: function () {
return 0;
}, enumerable: true, configurable: true }), _a);
var _a;

View File

@@ -7,9 +7,6 @@ function foo() {
//// [computedPropertyNames18_ES5.js]
function foo() {
var obj = (_a = {},
_a[this.bar] = 0,
_a
);
var obj = (_a = {}, _a[this.bar] = 0, _a);
var _a;
}

View File

@@ -8,9 +8,6 @@ module M {
//// [computedPropertyNames19_ES5.js]
var M;
(function (M) {
var obj = (_a = {},
_a[this.bar] = 0,
_a
);
var obj = (_a = {}, _a[this.bar] = 0, _a);
var _a;
})(M || (M = {}));

View File

@@ -5,20 +5,7 @@ var v = {
}
//// [computedPropertyNames1_ES5.js]
var v = (_a = {},
Object.defineProperty(_a, 0 + 1, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, 0 + 1, {
set: function (v) { } //No error
,
enumerable: true,
configurable: true
}),
_a
);
var v = (_a = {}, _a[0 + 1] = Object.defineProperty({ get: function () {
return 0;
}, enumerable: true, configurable: true }), _a[0 + 1] = Object.defineProperty({ set: function (v) { }, enumerable: true, configurable: true }), _a);
var _a;

View File

@@ -4,8 +4,5 @@ var obj = {
}
//// [computedPropertyNames20_ES5.js]
var obj = (_a = {},
_a[this.bar] = 0,
_a
);
var obj = (_a = {}, _a[this.bar] = 0, _a);
var _a;

View File

@@ -13,10 +13,7 @@ var C = (function () {
function C() {
}
C.prototype.bar = function () {
var obj = (_a = {},
_a[this.bar()] = function () { },
_a
);
var obj = function () { }(_a = {}, _a[this.bar()] = , _a);
return 0;
var _a;
};

View File

@@ -34,10 +34,7 @@ var C = (function (_super) {
_super.apply(this, arguments);
}
C.prototype.foo = function () {
var obj = (_a = {},
_a[_super.prototype.bar.call(this)] = function () { },
_a
);
var obj = function () { }(_a = {}, _a[_super.prototype.bar.call(this)] = , _a);
return 0;
var _a;
};

View File

@@ -26,10 +26,7 @@ var C = (function (_super) {
__extends(C, _super);
function C() {
_super.call(this);
var obj = (_a = {},
_a[(_super.call(this), "prop")] = function () { },
_a
);
var obj = function () { }(_a = {}, _a[(_super.call(this), "prop")] = , _a);
var _a;
}
return C;

View File

@@ -17,10 +17,7 @@ var C = (function () {
C.prototype.bar = function () {
var _this = this;
(function () {
var obj = (_a = {},
_a[_this.bar()] = function () { },
_a
);
var obj = function () { }(_a = {}, _a[_this.bar()] = , _a);
var _a;
});
return 0;

View File

@@ -32,13 +32,7 @@ var C = (function (_super) {
function C() {
_super.call(this);
(function () {
var obj = (_a = {},
// Ideally, we would capture this. But the reference is
// illegal, and not capturing this is consistent with
//treatment of other similar violations.
_a[(_super.call(this), "prop")] = function () { },
_a
);
var obj = function () { }(_a = {}, _a[(_super.call(this), "prop")] = , _a);
var _a;
});
}

View File

@@ -38,10 +38,7 @@ var C = (function (_super) {
C.prototype.foo = function () {
var _this = this;
(function () {
var obj = (_a = {},
_a[_super.prototype.bar.call(_this)] = function () { },
_a
);
var obj = function () { }(_a = {}, _a[_super.prototype.bar.call(_this)] = , _a);
var _a;
});
return 0;

View File

@@ -17,10 +17,7 @@ var C = (function () {
function C() {
}
C.prototype.bar = function () {
var obj = (_a = {},
_a[foo()] = function () { },
_a
);
var obj = function () { }(_a = {}, _a[foo()] = , _a);
return 0;
var _a;
};

View File

@@ -17,10 +17,7 @@ var C = (function () {
function C() {
}
C.bar = function () {
var obj = (_a = {},
_a[foo()] = function () { },
_a
);
var obj = function () { }(_a = {}, _a[foo()] = , _a);
return 0;
var _a;
};

View File

@@ -4,8 +4,5 @@ var o = {
};
//// [computedPropertyNames46_ES5.js]
var o = (_a = {},
_a["" || 0] = 0,
_a
);
var o = (_a = {}, _a["" || 0] = 0, _a);
var _a;

View File

@@ -14,8 +14,5 @@ var E2;
(function (E2) {
E2[E2["x"] = 0] = "x";
})(E2 || (E2 = {}));
var o = (_a = {},
_a[0 /* x */ || 0 /* x */] = 0,
_a
);
var o = (_a = {}, _a[0 /* x */ || 0 /* x */] = 0, _a);
var _a;

View File

@@ -23,16 +23,7 @@ var E;
E[E["x"] = 0] = "x";
})(E || (E = {}));
var a;
extractIndexer((_a = {},
_a[a] = "",
_a
)); // Should return string
extractIndexer((_b = {},
_b[0 /* x */] = "",
_b
)); // Should return string
extractIndexer((_c = {},
_c["" || 0] = "",
_c
)); // Should return any (widened form of undefined)
extractIndexer((_a = {}, _a[a] = "", _a)); // Should return string
extractIndexer((_b = {}, _b[0 /* x */] = "", _b)); // Should return string
extractIndexer((_c = {}, _c["" || 0] = "", _c)); // Should return any (widened form of undefined)
var _a, _b, _c;

View File

@@ -27,41 +27,17 @@ var x = {
//// [computedPropertyNames49_ES5.js]
var x = (_a = {
p1: 10
},
Object.defineProperty(_a, 1 + 1, {
get: function () {
throw 10;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, 1 + 1, {
get: function () {
return 10;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, 1 + 1, {
set: function () {
// just throw
throw 10;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, "foo", {
get: function () {
if (1 == 1) {
return 10;
}
},
enumerable: true,
configurable: true
}),
,
_a.p2 = 20,
_a
);
p1: 10
}, _a.p1 = 10, _a[1 + 1] = Object.defineProperty({ get: function () {
throw 10;
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ get: function () {
return 10;
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ set: function () {
// just throw
throw 10;
}, enumerable: true, configurable: true }), _a.foo = Object.defineProperty({ get: function () {
if (1 == 1) {
return 10;
}
}, enumerable: true, configurable: true }), _a.p2 = 20, _a);
var _a;

View File

@@ -20,18 +20,5 @@ var v = {
var s;
var n;
var a;
var v = (_a = {},
_a[s] = 0,
_a[n] = n,
_a[s + s] = 1,
_a[s + n] = 2,
_a[+s] = s,
_a[""] = 0,
_a[0] = 0,
_a[a] = 1,
_a[true] = 0,
_a["hello bye"] = 0,
_a["hello " + a + " bye"] = 0,
_a
);
var v = (_a = {}, _a[s] = 0, _a[n] = n, _a[s + s] = 1, _a[s + n] = 2, _a[+s] = s, _a[""] = 0, _a[0] = 0, _a[a] = 1, _a[true] = 0, _a["hello bye"] = 0, _a["hello " + a + " bye"] = 0, _a);
var _a;

View File

@@ -27,37 +27,22 @@ var x = {
//// [computedPropertyNames50_ES5.js]
var x = (_a = {
p1: 10,
get foo() {
if (1 == 1) {
return 10;
}
}
},
Object.defineProperty(_a, 1 + 1, {
get: function () {
throw 10;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, 1 + 1, {
set: function () {
// just throw
throw 10;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, 1 + 1, {
get: function () {
p1: 10,
get foo() {
if (1 == 1) {
return 10;
},
enumerable: true,
configurable: true
}),
,
_a.p2 = 20,
_a
);
}
}
}, _a.p1 = 10, _a.foo = Object.defineProperty({ get: function () {
if (1 == 1) {
return 10;
}
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ get: function () {
throw 10;
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ set: function () {
// just throw
throw 10;
}, enumerable: true, configurable: true }), _a[1 + 1] = Object.defineProperty({ get: function () {
return 10;
}, enumerable: true, configurable: true }), _a.p2 = 20, _a);
var _a;

View File

@@ -11,13 +11,5 @@ var v = {
//// [computedPropertyNames5_ES5.js]
var b;
var v = (_a = {},
_a[b] = 0,
_a[true] = 1,
_a[[]] = 0,
_a[{}] = 0,
_a[undefined] = undefined,
_a[null] = null,
_a
);
var v = (_a = {}, _a[b] = 0, _a[true] = 1, _a[[]] = 0, _a[{}] = 0, _a[undefined] = undefined, _a[null] = null, _a);
var _a;

View File

@@ -12,10 +12,5 @@ var v = {
var p1;
var p2;
var p3;
var v = (_a = {},
_a[p1] = 0,
_a[p2] = 1,
_a[p3] = 2,
_a
);
var v = (_a = {}, _a[p1] = 0, _a[p2] = 1, _a[p3] = 2, _a);
var _a;

View File

@@ -11,8 +11,5 @@ var E;
(function (E) {
E[E["member"] = 0] = "member";
})(E || (E = {}));
var v = (_a = {},
_a[0 /* member */] = 0,
_a
);
var v = (_a = {}, _a[0 /* member */] = 0, _a);
var _a;

View File

@@ -12,10 +12,6 @@ function f<T, U extends string>() {
function f() {
var t;
var u;
var v = (_a = {},
_a[t] = 0,
_a[u] = 1,
_a
);
var v = (_a = {}, _a[t] = 0, _a[u] = 1, _a);
var _a;
}

View File

@@ -12,10 +12,5 @@ var v = {
//// [computedPropertyNames9_ES5.js]
function f(x) { }
var v = (_a = {},
_a[f("")] = 0,
_a[f(0)] = 0,
_a[f(true)] = 0,
_a
);
var v = (_a = {}, _a[f("")] = 0, _a[f(0)] = 0, _a[f(true)] = 0, _a);
var _a;

View File

@@ -9,9 +9,5 @@ var o: I = {
}
//// [computedPropertyNamesContextualType10_ES5.js]
var o = (_a = {},
_a[+"foo"] = "",
_a[+"bar"] = 0,
_a
);
var o = (_a = {}, _a[+"foo"] = "", _a[+"bar"] = 0, _a);
var _a;

View File

@@ -10,11 +10,7 @@ var o: I = {
}
//// [computedPropertyNamesContextualType1_ES5.js]
var o = (_a = {},
_a["" + 0] = function (y) {
return y.length;
},
_a["" + 1] = function (y) { return y.length; },
_a
);
var o = function (y) {
return y.length;
}(_a = {}, _a["" + 0] = , _a["" + 1] = function (y) { return y.length; }, _a);
var _a;

View File

@@ -10,11 +10,7 @@ var o: I = {
}
//// [computedPropertyNamesContextualType2_ES5.js]
var o = (_a = {},
_a[+"foo"] = function (y) {
return y.length;
},
_a[+"bar"] = function (y) { return y.length; },
_a
);
var o = function (y) {
return y.length;
}(_a = {}, _a[+"foo"] = , _a[+"bar"] = function (y) { return y.length; }, _a);
var _a;

View File

@@ -9,11 +9,7 @@ var o: I = {
}
//// [computedPropertyNamesContextualType3_ES5.js]
var o = (_a = {},
_a[+"foo"] = function (y) {
return y.length;
},
_a[+"bar"] = function (y) { return y.length; },
_a
);
var o = function (y) {
return y.length;
}(_a = {}, _a[+"foo"] = , _a[+"bar"] = function (y) { return y.length; }, _a);
var _a;

View File

@@ -10,9 +10,5 @@ var o: I = {
}
//// [computedPropertyNamesContextualType4_ES5.js]
var o = (_a = {},
_a["" + "foo"] = "",
_a["" + "bar"] = 0,
_a
);
var o = (_a = {}, _a["" + "foo"] = "", _a["" + "bar"] = 0, _a);
var _a;

View File

@@ -10,9 +10,5 @@ var o: I = {
}
//// [computedPropertyNamesContextualType5_ES5.js]
var o = (_a = {},
_a[+"foo"] = "",
_a[+"bar"] = 0,
_a
);
var o = (_a = {}, _a[+"foo"] = "", _a[+"bar"] = 0, _a);
var _a;

View File

@@ -15,12 +15,7 @@ foo({
//// [computedPropertyNamesContextualType6_ES5.js]
foo((_a = {
p: "",
0: function () { }
},
_a["hi" + "bye"] = true,
_a[0 + 1] = 0,
_a[+"hi"] = [0],
_a
));
p: "",
0: function () { }
}, _a.p = "", _a[0] = function () { }, _a["hi" + "bye"] = true, _a[0 + 1] = 0, _a[+"hi"] = [0], _a));
var _a;

View File

@@ -15,12 +15,7 @@ foo({
//// [computedPropertyNamesContextualType7_ES5.js]
foo((_a = {
p: "",
0: function () { }
},
_a["hi" + "bye"] = true,
_a[0 + 1] = 0,
_a[+"hi"] = [0],
_a
));
p: "",
0: function () { }
}, _a.p = "", _a[0] = function () { }, _a["hi" + "bye"] = true, _a[0 + 1] = 0, _a[+"hi"] = [0], _a));
var _a;

View File

@@ -10,9 +10,5 @@ var o: I = {
}
//// [computedPropertyNamesContextualType8_ES5.js]
var o = (_a = {},
_a["" + "foo"] = "",
_a["" + "bar"] = 0,
_a
);
var o = (_a = {}, _a["" + "foo"] = "", _a["" + "bar"] = 0, _a);
var _a;

View File

@@ -10,9 +10,5 @@ var o: I = {
}
//// [computedPropertyNamesContextualType9_ES5.js]
var o = (_a = {},
_a[+"foo"] = "",
_a[+"bar"] = 0,
_a
);
var o = (_a = {}, _a[+"foo"] = "", _a[+"bar"] = 0, _a);
var _a;

View File

@@ -7,23 +7,9 @@ var v = {
}
//// [computedPropertyNamesDeclarationEmit5_ES5.js]
var v = (_a = {},
_a["" + ""] = 0,
_a["" + ""] = function () { },
Object.defineProperty(_a, "" + "", {
get: function () {
return 0;
},
enumerable: true,
configurable: true
}),
Object.defineProperty(_a, "" + "", {
set: function (x) { },
enumerable: true,
configurable: true
}),
_a
);
var v = function () { }(_a = {}, _a["" + ""] = 0, _a["" + ""] = , _a["" + ""] = Object.defineProperty({ get: function () {
return 0;
}, enumerable: true, configurable: true }), _a["" + ""] = Object.defineProperty({ set: function (x) { }, enumerable: true, configurable: true }), _a);
var _a;

View File

@@ -6,11 +6,8 @@ var v = {
}
//// [computedPropertyNamesSourceMap2_ES5.js]
var v = (_a = {},
_a["hello"] = function () {
debugger;
},
_a
);
var v = function () {
debugger;
}(_a = {}, _a["hello"] = , _a);
var _a;
//# sourceMappingURL=computedPropertyNamesSourceMap2_ES5.js.map

View File

@@ -1,2 +1,2 @@
//// [computedPropertyNamesSourceMap2_ES5.js.map]
{"version":3,"file":"computedPropertyNamesSourceMap2_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap2_ES5.ts"],"names":["[\"hello\"]"],"mappings":"AAAA,IAAI,CAAC,GAAG,CAAR,EAAA;IACI,AADJ,EAAA,CACK,OAAO,CAAC;QACLA,QAAQA,CAACA;IACbA,CAACA;IAHL,EAAA;CAIC,CAAA;IAJD,EAAA"}
{"version":3,"file":"computedPropertyNamesSourceMap2_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap2_ES5.ts"],"names":["[\"hello\"]"],"mappings":"AAAA,IAAI,CAAC,GAAG;IAEAA,QAAQA,CAACA;AACbA,CAACA,AAJA,CACA,EAAA,GADA,EAAA,EACA,EAAA,CACK,OAAO,CAFA,GAAA,EACA,EAAA,AADA,CAKA,CAAA;IAJD,EAAA"}

View File

@@ -8,100 +8,138 @@ sources: computedPropertyNamesSourceMap2_ES5.ts
emittedFile:tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap2_ES5.js
sourceFile:computedPropertyNamesSourceMap2_ES5.ts
-------------------------------------------------------------------
>>>var v = (_a = {},
>>>var v = function () {
1 >
2 >^^^^
3 > ^
4 > ^^^
5 > ^
6 > ^^
7 > ^^^^^^^^^^^^^^^^^^^^^->
5 > ^^^^^^->
1 >
2 >var
3 > v
4 > =
5 >
6 >
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
2 >Emitted(1, 5) Source(1, 5) + SourceIndex(0)
3 >Emitted(1, 6) Source(1, 6) + SourceIndex(0)
4 >Emitted(1, 9) Source(1, 9) + SourceIndex(0)
5 >Emitted(1, 10) Source(1, 1) + SourceIndex(0)
6 >Emitted(1, 12) Source(1, 1) + SourceIndex(0)
---
>>> _a["hello"] = function () {
>>> debugger;
1->^^^^
2 >
3 > ^^
4 > ^
5 > ^^^^^^^
6 > ^
7 > ^^^->
1->var v = {
>
2 >
3 >
4 > var v = {
> [
5 > "hello"
6 > ]
1->Emitted(2, 5) Source(2, 5) + SourceIndex(0)
2 >Emitted(2, 5) Source(1, 1) + SourceIndex(0)
3 >Emitted(2, 7) Source(1, 1) + SourceIndex(0)
4 >Emitted(2, 8) Source(2, 6) + SourceIndex(0)
5 >Emitted(2, 15) Source(2, 13) + SourceIndex(0)
6 >Emitted(2, 16) Source(2, 14) + SourceIndex(0)
---
>>> debugger;
1->^^^^^^^^
2 > ^^^^^^^^
3 > ^
1->() {
>
2 > debugger
3 > ;
1->Emitted(3, 9) Source(3, 9) + SourceIndex(0) name (["hello"])
2 >Emitted(3, 17) Source(3, 17) + SourceIndex(0) name (["hello"])
3 >Emitted(3, 18) Source(3, 18) + SourceIndex(0) name (["hello"])
---
>>> },
1 >^^^^
2 > ^
3 > ^^->
1 >
>
2 > }
1 >Emitted(4, 5) Source(4, 5) + SourceIndex(0) name (["hello"])
2 >Emitted(4, 6) Source(4, 6) + SourceIndex(0) name (["hello"])
---
>>> _a
1->^^^^
2 > ^^
1->
2 >
1->Emitted(5, 5) Source(1, 1) + SourceIndex(0)
2 >Emitted(5, 7) Source(1, 1) + SourceIndex(0)
---
>>>);
1 >^
2 > ^
3 > ^^^^^^->
1 >var v = {
2 > ^^^^^^^^
3 > ^
4 > ^^^^^^^^^^^^^^^^^^^->
1->{
> ["hello"]() {
> debugger;
> }
>}
2 >
1 >Emitted(6, 2) Source(5, 2) + SourceIndex(0)
2 >Emitted(6, 3) Source(5, 2) + SourceIndex(0)
>
2 > debugger
3 > ;
1->Emitted(2, 5) Source(3, 9) + SourceIndex(0) name (["hello"])
2 >Emitted(2, 13) Source(3, 17) + SourceIndex(0) name (["hello"])
3 >Emitted(2, 14) Source(3, 18) + SourceIndex(0) name (["hello"])
---
>>>}(_a = {}, _a["hello"] = , _a);
1->
2 >^
3 >
4 > ^
5 > ^^
6 > ^^^
7 > ^^
8 > ^^
9 > ^^
10> ^
11> ^^^^^^^
12> ^
13> ^^^
14> ^^
15> ^^
16>
17> ^
18> ^
1->
>
2 >}
3 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found
3 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 2) Source(0, 6) + SourceIndex(0) name (["hello"]) Span encoded by the emitter:Emitted(3, 2) Source(0, NaN) + SourceIndex(0) nameIndex (-1)
3 >
4 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column
4 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 2) Source(0, 6) + SourceIndex(0) name (["hello"]) Span encoded by the emitter:Emitted(3, 3) Source(1, 1) + SourceIndex(0) nameIndex (-1)
4 >
5 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span:
5 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 3) Source(1, 6) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 5) Source(1, 1) + SourceIndex(0) nameIndex (-1)
5 >
6 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span:
6 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 5) Source(1, 6) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 8) Source(0, NaN) + SourceIndex(0) nameIndex (-1)
6 >
7 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found
7 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 8) Source(0, 6) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 10) Source(0, NaN) + SourceIndex(0) nameIndex (-1)
7 >
8 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column
8 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 8) Source(0, 6) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 12) Source(1, 1) + SourceIndex(0) nameIndex (-1)
8 >
9 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found
9 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 10) Source(0, 6) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 14) Source(1, 1) + SourceIndex(0) nameIndex (-1)
9 >
10> !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column
10> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 10) Source(0, 6) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 15) Source(2, 6) + SourceIndex(0) nameIndex (-1)
10> var v = {
> [
11> !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span:
11> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 12) Source(1, 6) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 22) Source(2, 13) + SourceIndex(0) nameIndex (-1)
11> "hello"
12> !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span:
12> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 14) Source(1, 6) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 23) Source(0, NaN) + SourceIndex(0) nameIndex (-1)
12>
13> !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span:
13> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 15) Source(2, 11) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 26) Source(0, NaN) + SourceIndex(0) nameIndex (-1)
13>
14> !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span:
14> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 22) Source(2, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 28) Source(1, 1) + SourceIndex(0) nameIndex (-1)
14>
15> !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found
15> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 23) Source(0, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 30) Source(1, 1) + SourceIndex(0) nameIndex (-1)
15>
16> !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column
16> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 23) Source(0, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 30) Source(0, NaN) + SourceIndex(0) nameIndex (-1)
16>
17> !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found
17> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 26) Source(0, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 31) Source(5, 2) + SourceIndex(0) nameIndex (-1)
17>
18> !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column
18> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 26) Source(0, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 32) Source(5, 2) + SourceIndex(0) nameIndex (-1)
18>
1->Emitted(3, 1) Source(4, 5) + SourceIndex(0) name (["hello"])
2 >Emitted(3, 2) Source(4, 6) + SourceIndex(0) name (["hello"])
3 >Emitted(3, 2) Source(0, NaN) + SourceIndex(0)
4 >Emitted(3, 3) Source(1, 1) + SourceIndex(0)
5 >Emitted(3, 5) Source(1, 1) + SourceIndex(0)
6 >Emitted(3, 8) Source(0, NaN) + SourceIndex(0)
7 >Emitted(3, 10) Source(0, NaN) + SourceIndex(0)
8 >Emitted(3, 12) Source(1, 1) + SourceIndex(0)
9 >Emitted(3, 14) Source(1, 1) + SourceIndex(0)
10>Emitted(3, 15) Source(2, 6) + SourceIndex(0)
11>Emitted(3, 22) Source(2, 13) + SourceIndex(0)
12>Emitted(3, 23) Source(0, NaN) + SourceIndex(0)
13>Emitted(3, 26) Source(0, NaN) + SourceIndex(0)
14>Emitted(3, 28) Source(1, 1) + SourceIndex(0)
15>Emitted(3, 30) Source(1, 1) + SourceIndex(0)
16>Emitted(3, 30) Source(0, NaN) + SourceIndex(0)
17>Emitted(3, 31) Source(5, 2) + SourceIndex(0)
18>Emitted(3, 32) Source(5, 2) + SourceIndex(0)
---
>>>var _a;
1->^^^^
1 >^^^^
2 > ^^
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
1->
1 >!!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span:
1 >!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 28) Source(1, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 5) Source(1, 1) + SourceIndex(0) nameIndex (-1)
1 >
2 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span:
2 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 30) Source(1, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 7) Source(1, 1) + SourceIndex(0) nameIndex (-1)
2 >
1->Emitted(7, 5) Source(1, 1) + SourceIndex(0)
2 >Emitted(7, 7) Source(1, 1) + SourceIndex(0)
1 >Emitted(4, 5) Source(1, 1) + SourceIndex(0)
2 >Emitted(4, 7) Source(1, 1) + SourceIndex(0)
---
!!!! **** There are more source map entries in the sourceMap's mapping than what was encoded
!!!! **** Remaining decoded string: ,AADA,CAKA,CAAA;IAJD,EAAA
>>>//# sourceMappingURL=computedPropertyNamesSourceMap2_ES5.js.map

View File

@@ -2,5 +2,5 @@
var v = { [e]() { } };
//// [parserES5ComputedPropertyName3.js]
var v = (_a = {}, _a[e] = function () { }, _a);
var v = function () { }(_a = {}, _a[e] = , _a);
var _a;

View File

@@ -2,9 +2,5 @@
var v = { get [e]() { } };
//// [parserES5ComputedPropertyName4.js]
var v = (_a = {}, Object.defineProperty(_a, e, {
get: function () { },
enumerable: true,
configurable: true
}), _a);
var v = (_a = {}, _a[e] = Object.defineProperty({ get: function () { }, enumerable: true, configurable: true }), _a);
var _a;

View File

@@ -11,10 +11,6 @@ var y: {
//// [privateIndexer2.js]
// private indexers not allowed
var x = (_a = {},
_a[x] = string,
_a.string = ,
_a
);
var x = (_a = {}, _a[x] = string, _a.string = , _a);
var y;
var _a;