From a391d70baa1055b08bccf3725c787e0007e3504f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 23 Feb 2015 17:44:48 -0800 Subject: [PATCH 1/7] Stop using rewrites for object literal downlevel emit. --- src/compiler/emitter.ts | 195 +++++++++++++++++- .../baselines/reference/ES5SymbolProperty1.js | 7 +- .../reference/FunctionDeclaration8_es6.js | 4 +- .../reference/FunctionDeclaration9_es6.js | 4 +- .../FunctionPropertyAssignments5_es6.js | 3 +- .../reference/computedPropertyNames10_ES5.js | 16 +- .../reference/computedPropertyNames11_ES5.js | 60 +++++- .../reference/computedPropertyNames18_ES5.js | 7 +- .../reference/computedPropertyNames19_ES5.js | 7 +- .../reference/computedPropertyNames1_ES5.js | 16 +- .../reference/computedPropertyNames20_ES5.js | 7 +- .../reference/computedPropertyNames22_ES5.js | 6 +- .../reference/computedPropertyNames23_ES5.js | 4 +- .../reference/computedPropertyNames25_ES5.js | 6 +- .../reference/computedPropertyNames26_ES5.js | 4 +- .../reference/computedPropertyNames28_ES5.js | 6 +- .../reference/computedPropertyNames29_ES5.js | 6 +- .../reference/computedPropertyNames30_ES5.js | 9 +- .../reference/computedPropertyNames31_ES5.js | 6 +- .../reference/computedPropertyNames33_ES5.js | 6 +- .../reference/computedPropertyNames34_ES5.js | 6 +- .../reference/computedPropertyNames46_ES5.js | 7 +- .../reference/computedPropertyNames47_ES5.js | 7 +- .../reference/computedPropertyNames48_ES5.js | 21 +- .../reference/computedPropertyNames49_ES5.js | 51 +++-- .../reference/computedPropertyNames4_ES5.js | 27 +-- .../reference/computedPropertyNames50_ES5.js | 50 +++-- .../reference/computedPropertyNames5_ES5.js | 17 +- .../reference/computedPropertyNames6_ES5.js | 11 +- .../reference/computedPropertyNames7_ES5.js | 7 +- .../reference/computedPropertyNames8_ES5.js | 9 +- .../reference/computedPropertyNames9_ES5.js | 11 +- ...mputedPropertyNamesContextualType10_ES5.js | 9 +- ...omputedPropertyNamesContextualType1_ES5.js | 8 +- ...omputedPropertyNamesContextualType2_ES5.js | 8 +- ...omputedPropertyNamesContextualType3_ES5.js | 8 +- ...omputedPropertyNamesContextualType4_ES5.js | 9 +- ...omputedPropertyNamesContextualType5_ES5.js | 9 +- ...omputedPropertyNamesContextualType6_ES5.js | 17 +- ...omputedPropertyNamesContextualType7_ES5.js | 17 +- ...omputedPropertyNamesContextualType8_ES5.js | 9 +- ...omputedPropertyNamesContextualType9_ES5.js | 9 +- ...mputedPropertyNamesDeclarationEmit5_ES5.js | 18 +- .../computedPropertyNamesSourceMap2_ES5.js | 10 +- ...computedPropertyNamesSourceMap2_ES5.js.map | 2 +- ...dPropertyNamesSourceMap2_ES5.sourcemap.txt | 191 +++++++---------- .../parserES5ComputedPropertyName2.js | 4 +- .../parserES5ComputedPropertyName3.js | 3 +- .../parserES5ComputedPropertyName4.js | 7 +- tests/baselines/reference/privateIndexer2.js | 9 +- 50 files changed, 624 insertions(+), 326 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3247b5ff1d117..78a4ea54b6994 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2555,6 +2555,195 @@ module ts { } } + function emitObjectLiteralBody(node: ObjectLiteralExpression, numElements: number): void { + if (numElements === 0) { + write("{}"); + return; + } + + write("{"); + + if (numElements > 0) { + var properties = node.properties; + + + // If we are not doing a downlevel transformation for object literals, + // then try to preserve the original shape of the object literal. + // Otherwise just try to preserve the formatting. + if (numElements === properties.length) { + emitLinePreservingList(node, properties, /* allowTrailingComma */ languageVersion >= ScriptTarget.ES5, /* spacesBetweenBraces */ true); + } + else { + var multiLine = (node.flags & NodeFlags.MultiLine) !== 0; + if (!multiLine) { + write(" "); + } + else { + increaseIndent(); + } + + emitList(properties, 0, numElements, /*multiLine*/ multiLine, /*trailingComma*/ false); + + if (!multiLine) { + write(" "); + } + else { + decreaseIndent(); + } + } + } + + write("}"); + } + + function emitDownlevelObjectLiteralWithComputedProperties(node: ObjectLiteralExpression, firstComputedPropertyIndex: number) { + var multiLine = (node.flags & NodeFlags.MultiLine) !== 0; + var properties = node.properties; + + write("("); + + if (multiLine) { + increaseIndent(); + } + + // 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(node); + + // Write out the first non-computed properties + // (or all properties if none of them are computed), + // then emit the rest through indexing on the temp variable. + emit(tempVar) + write(" = "); + emitObjectLiteralBody(node, firstComputedPropertyIndex); + + + for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) { + writeComma(); + + var property = properties[i]; + + emitStart(property) + if (property.kind === SyntaxKind.GetAccessor || property.kind === SyntaxKind.SetAccessor) { + // TODO (drosen): Reconcile with 'emitMemberFunctions'. + var accessors = getAllAccessorDeclarations(node.properties, property); + if (property !== accessors.firstAccessor) { + continue; + } + write("Object.defineProperty("); + emit(tempVar); + write(", "); + emitStart(node.name); + emitExpressionForPropertyName(property.name); + emitEnd(property.name); + write(", {"); + increaseIndent(); + if (accessors.getAccessor) { + writeLine() + emitLeadingComments(accessors.getAccessor); + write("get: "); + emitStart(accessors.getAccessor); + write("function "); + emitSignatureAndBody(accessors.getAccessor); + emitEnd(accessors.getAccessor); + emitTrailingComments(accessors.getAccessor); + write(","); + } + if (accessors.setAccessor) { + writeLine(); + emitLeadingComments(accessors.setAccessor); + write("set: "); + emitStart(accessors.setAccessor); + write("function "); + emitSignatureAndBody(accessors.setAccessor); + emitEnd(accessors.setAccessor); + emitTrailingComments(accessors.setAccessor); + write(","); + } + writeLine(); + write("enumerable: true,"); + writeLine(); + write("configurable: true"); + decreaseIndent(); + writeLine(); + write("})"); + emitEnd(property); + } + else { + emitLeadingComments(property); + emitStart(property.name); + emit(tempVar); + emitMemberAccessForPropertyName(property.name); + emitEnd(property.name); + + write(" = "); + + if (property.kind === SyntaxKind.PropertyAssignment) { + emit((property).initializer); + } + else if (property.kind === SyntaxKind.ShorthandPropertyAssignment) { + emitExpressionIdentifier((property).name); + } + else if (property.kind === SyntaxKind.MethodDeclaration) { + emitFunctionDeclaration(property); + } + else { + Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind); + } + } + + emitEnd(property); + } + + writeComma(); + emit(tempVar); + + if (multiLine) { + decreaseIndent(); + writeLine(); + } + + write(")"); + + function writeComma() { + if (multiLine) { + write(","); + writeLine(); + } + else { + write(", "); + } + } + } + + function emitObjectLiteral(node: ObjectLiteralExpression): void { + var properties = node.properties; + + if (languageVersion < ScriptTarget.ES6) { + var numProperties = properties.length; + + // Find the first computed property. + // Everything until that point can be emitted as part of the initial object literal. + var numInitialNonComputedProperties = numProperties; + for (var i = 0, n = properties.length; i < n; i++) { + if (properties[i].name.kind === SyntaxKind.ComputedPropertyName) { + numInitialNonComputedProperties = i; + break; + } + } + + var hasComputedProperty = numInitialNonComputedProperties !== properties.length; + if (hasComputedProperty) { + emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties); + return; + } + } + + // Ordinary case: either the object has no computed properties + // or we're compiling with an ES6+ target. + emitObjectLiteralBody(node, properties.length); + } + function createSynthesizedNode(kind: SyntaxKind): Node { var node = createNode(kind); node.pos = -1; @@ -2563,7 +2752,7 @@ module ts { return node; } - function emitDownlevelObjectLiteralWithComputedProperties(node: ObjectLiteralExpression, firstComputedPropertyIndex: number): void { + function emitDownlevelObjectLiteralWithComputedPropertiesThroughRewrite(node: ObjectLiteralExpression, firstComputedPropertyIndex: number): void { var parenthesizedObjectLiteral = createDownlevelObjectLiteralWithComputedProperties(node, firstComputedPropertyIndex); return emit(parenthesizedObjectLiteral); } @@ -2763,7 +2952,7 @@ module ts { return result; } - function emitObjectLiteral(node: ObjectLiteralExpression): void { + function emitObjectLiteralThroughRewrite(node: ObjectLiteralExpression): void { var properties = node.properties; if (languageVersion < ScriptTarget.ES6) { @@ -2781,7 +2970,7 @@ module ts { var hasComputedProperty = numInitialNonComputedProperties !== properties.length; if (hasComputedProperty) { - emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties); + emitDownlevelObjectLiteralWithComputedPropertiesThroughRewrite(node, numInitialNonComputedProperties); return; } } diff --git a/tests/baselines/reference/ES5SymbolProperty1.js b/tests/baselines/reference/ES5SymbolProperty1.js index e977df7dc6b1e..1073a33163de7 100644 --- a/tests/baselines/reference/ES5SymbolProperty1.js +++ b/tests/baselines/reference/ES5SymbolProperty1.js @@ -12,8 +12,9 @@ obj[Symbol.foo]; //// [ES5SymbolProperty1.js] var Symbol; -var obj = (_a = {}, _a[Symbol.foo] = -0, -_a); +var obj = (_a = {}, + _a[Symbol.foo] = 0, + _a +); obj[Symbol.foo]; var _a; diff --git a/tests/baselines/reference/FunctionDeclaration8_es6.js b/tests/baselines/reference/FunctionDeclaration8_es6.js index 3f6d2499cef8b..64f6bff50c05d 100644 --- a/tests/baselines/reference/FunctionDeclaration8_es6.js +++ b/tests/baselines/reference/FunctionDeclaration8_es6.js @@ -2,7 +2,5 @@ var v = { [yield]: foo } //// [FunctionDeclaration8_es6.js] -var v = (_a = {}, _a[yield] = -foo, -_a); +var v = (_a = {}, _a[yield] = foo, _a); var _a; diff --git a/tests/baselines/reference/FunctionDeclaration9_es6.js b/tests/baselines/reference/FunctionDeclaration9_es6.js index 04c946a96ebdd..bca309d2d62f0 100644 --- a/tests/baselines/reference/FunctionDeclaration9_es6.js +++ b/tests/baselines/reference/FunctionDeclaration9_es6.js @@ -5,8 +5,6 @@ function * foo() { //// [FunctionDeclaration9_es6.js] function foo() { - var v = (_a = {}, _a[] = - foo, - _a); + var v = (_a = {}, _a[] = foo, _a); var _a; } diff --git a/tests/baselines/reference/FunctionPropertyAssignments5_es6.js b/tests/baselines/reference/FunctionPropertyAssignments5_es6.js index 0b786632bdf94..188a843f7517d 100644 --- a/tests/baselines/reference/FunctionPropertyAssignments5_es6.js +++ b/tests/baselines/reference/FunctionPropertyAssignments5_es6.js @@ -2,6 +2,5 @@ var v = { *[foo()]() { } } //// [FunctionPropertyAssignments5_es6.js] -var v = (_a = {}, _a[foo()] = function () { }, -_a); +var v = (_a = {}, _a[foo()] = function () { }, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames10_ES5.js b/tests/baselines/reference/computedPropertyNames10_ES5.js index ececb28b8cc49..14d9235b12b4f 100644 --- a/tests/baselines/reference/computedPropertyNames10_ES5.js +++ b/tests/baselines/reference/computedPropertyNames10_ES5.js @@ -20,6 +20,18 @@ 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 = (_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 _a; diff --git a/tests/baselines/reference/computedPropertyNames11_ES5.js b/tests/baselines/reference/computedPropertyNames11_ES5.js index d8450deb76580..64c0b0bd67e35 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES5.js +++ b/tests/baselines/reference/computedPropertyNames11_ES5.js @@ -20,6 +20,62 @@ var v = { var s; var n; var 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 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 _a; diff --git a/tests/baselines/reference/computedPropertyNames18_ES5.js b/tests/baselines/reference/computedPropertyNames18_ES5.js index 0ccc0fb4e0058..b65c7fd4f7dd5 100644 --- a/tests/baselines/reference/computedPropertyNames18_ES5.js +++ b/tests/baselines/reference/computedPropertyNames18_ES5.js @@ -7,8 +7,9 @@ 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; } diff --git a/tests/baselines/reference/computedPropertyNames19_ES5.js b/tests/baselines/reference/computedPropertyNames19_ES5.js index a18cb7b95c3dd..36f3e66c7c268 100644 --- a/tests/baselines/reference/computedPropertyNames19_ES5.js +++ b/tests/baselines/reference/computedPropertyNames19_ES5.js @@ -8,8 +8,9 @@ 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 = {})); diff --git a/tests/baselines/reference/computedPropertyNames1_ES5.js b/tests/baselines/reference/computedPropertyNames1_ES5.js index 36a7fd6052dcb..4fdec28c7aa41 100644 --- a/tests/baselines/reference/computedPropertyNames1_ES5.js +++ b/tests/baselines/reference/computedPropertyNames1_ES5.js @@ -5,6 +5,18 @@ var v = { } //// [computedPropertyNames1_ES5.js] -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 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 _a; diff --git a/tests/baselines/reference/computedPropertyNames20_ES5.js b/tests/baselines/reference/computedPropertyNames20_ES5.js index 21af64d7e4107..65acd7fa08f14 100644 --- a/tests/baselines/reference/computedPropertyNames20_ES5.js +++ b/tests/baselines/reference/computedPropertyNames20_ES5.js @@ -4,7 +4,8 @@ var obj = { } //// [computedPropertyNames20_ES5.js] -var obj = (_a = {}, _a[this.bar] = -0, -_a); +var obj = (_a = {}, + _a[this.bar] = 0, + _a +); var _a; diff --git a/tests/baselines/reference/computedPropertyNames22_ES5.js b/tests/baselines/reference/computedPropertyNames22_ES5.js index e3e685aa54bec..e82bf673b52f1 100644 --- a/tests/baselines/reference/computedPropertyNames22_ES5.js +++ b/tests/baselines/reference/computedPropertyNames22_ES5.js @@ -13,8 +13,10 @@ var C = (function () { function C() { } C.prototype.bar = function () { - var obj = (_a = {}, _a[this.bar()] = function () { }, - _a); + var obj = (_a = {}, + _a[this.bar()] = function () { }, + _a + ); return 0; var _a; }; diff --git a/tests/baselines/reference/computedPropertyNames23_ES5.js b/tests/baselines/reference/computedPropertyNames23_ES5.js index 7b5a5a101a546..33a6d95ec47ba 100644 --- a/tests/baselines/reference/computedPropertyNames23_ES5.js +++ b/tests/baselines/reference/computedPropertyNames23_ES5.js @@ -15,9 +15,7 @@ var C = (function () { C.prototype.bar = function () { return 0; }; - C.prototype[(_a = {}, _a[this.bar()] = - 1, - _a)[0]] = function () { }; + C.prototype[(_a = {}, _a[this.bar()] = 1, _a)[0]] = function () { }; return C; })(); var _a; diff --git a/tests/baselines/reference/computedPropertyNames25_ES5.js b/tests/baselines/reference/computedPropertyNames25_ES5.js index bd2212b72b316..b6a8d254b2687 100644 --- a/tests/baselines/reference/computedPropertyNames25_ES5.js +++ b/tests/baselines/reference/computedPropertyNames25_ES5.js @@ -34,8 +34,10 @@ 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 = (_a = {}, + _a[_super.prototype.bar.call(this)] = function () { }, + _a + ); return 0; var _a; }; diff --git a/tests/baselines/reference/computedPropertyNames26_ES5.js b/tests/baselines/reference/computedPropertyNames26_ES5.js index 5df2f6dc1b61c..60f6590be9d46 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES5.js +++ b/tests/baselines/reference/computedPropertyNames26_ES5.js @@ -34,9 +34,7 @@ var C = (function (_super) { } // Gets emitted as super, not _super, which is consistent with // use of super in static properties initializers. - C.prototype[(_a = {}, _a[super.bar.call(this)] = - 1, - _a)[0]] = function () { }; + C.prototype[(_a = {}, _a[super.bar.call(this)] = 1, _a)[0]] = function () { }; return C; })(Base); var _a; diff --git a/tests/baselines/reference/computedPropertyNames28_ES5.js b/tests/baselines/reference/computedPropertyNames28_ES5.js index 7e548d4d6d3d8..5940c498db812 100644 --- a/tests/baselines/reference/computedPropertyNames28_ES5.js +++ b/tests/baselines/reference/computedPropertyNames28_ES5.js @@ -26,8 +26,10 @@ var C = (function (_super) { __extends(C, _super); function C() { _super.call(this); - var obj = (_a = {}, _a[(_super.call(this), "prop")] = function () { }, - _a); + var obj = (_a = {}, + _a[(_super.call(this), "prop")] = function () { }, + _a + ); var _a; } return C; diff --git a/tests/baselines/reference/computedPropertyNames29_ES5.js b/tests/baselines/reference/computedPropertyNames29_ES5.js index 27c7cd979882d..4682ae9105eea 100644 --- a/tests/baselines/reference/computedPropertyNames29_ES5.js +++ b/tests/baselines/reference/computedPropertyNames29_ES5.js @@ -17,8 +17,10 @@ var C = (function () { C.prototype.bar = function () { var _this = this; (function () { - var obj = (_a = {}, _a[_this.bar()] = function () { }, - _a); + var obj = (_a = {}, + _a[_this.bar()] = function () { }, + _a + ); var _a; }); return 0; diff --git a/tests/baselines/reference/computedPropertyNames30_ES5.js b/tests/baselines/reference/computedPropertyNames30_ES5.js index 505b149f62d64..05196e23c5b7d 100644 --- a/tests/baselines/reference/computedPropertyNames30_ES5.js +++ b/tests/baselines/reference/computedPropertyNames30_ES5.js @@ -32,8 +32,13 @@ var C = (function (_super) { function C() { _super.call(this); (function () { - var obj = (_a = {}, _a[(_super.call(this), "prop")] = function () { }, - _a); + 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 _a; }); } diff --git a/tests/baselines/reference/computedPropertyNames31_ES5.js b/tests/baselines/reference/computedPropertyNames31_ES5.js index 0c8cbac455f26..173e3c7222b99 100644 --- a/tests/baselines/reference/computedPropertyNames31_ES5.js +++ b/tests/baselines/reference/computedPropertyNames31_ES5.js @@ -38,8 +38,10 @@ 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 = (_a = {}, + _a[_super.prototype.bar.call(_this)] = function () { }, + _a + ); var _a; }); return 0; diff --git a/tests/baselines/reference/computedPropertyNames33_ES5.js b/tests/baselines/reference/computedPropertyNames33_ES5.js index 84df68fcc106a..38029893bb165 100644 --- a/tests/baselines/reference/computedPropertyNames33_ES5.js +++ b/tests/baselines/reference/computedPropertyNames33_ES5.js @@ -15,8 +15,10 @@ var C = (function () { function C() { } C.prototype.bar = function () { - var obj = (_a = {}, _a[foo()] = function () { }, - _a); + var obj = (_a = {}, + _a[foo()] = function () { }, + _a + ); return 0; var _a; }; diff --git a/tests/baselines/reference/computedPropertyNames34_ES5.js b/tests/baselines/reference/computedPropertyNames34_ES5.js index 9e1de33be7c7f..4e5790c53b108 100644 --- a/tests/baselines/reference/computedPropertyNames34_ES5.js +++ b/tests/baselines/reference/computedPropertyNames34_ES5.js @@ -15,8 +15,10 @@ var C = (function () { function C() { } C.bar = function () { - var obj = (_a = {}, _a[foo()] = function () { }, - _a); + var obj = (_a = {}, + _a[foo()] = function () { }, + _a + ); return 0; var _a; }; diff --git a/tests/baselines/reference/computedPropertyNames46_ES5.js b/tests/baselines/reference/computedPropertyNames46_ES5.js index 3e4329b8a2046..307dadcbe9115 100644 --- a/tests/baselines/reference/computedPropertyNames46_ES5.js +++ b/tests/baselines/reference/computedPropertyNames46_ES5.js @@ -4,7 +4,8 @@ var o = { }; //// [computedPropertyNames46_ES5.js] -var o = (_a = {}, _a["" || 0] = -0, -_a); +var o = (_a = {}, + _a["" || 0] = 0, + _a +); var _a; diff --git a/tests/baselines/reference/computedPropertyNames47_ES5.js b/tests/baselines/reference/computedPropertyNames47_ES5.js index 7874a25976f8f..6ba31fe3b0695 100644 --- a/tests/baselines/reference/computedPropertyNames47_ES5.js +++ b/tests/baselines/reference/computedPropertyNames47_ES5.js @@ -14,7 +14,8 @@ 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; diff --git a/tests/baselines/reference/computedPropertyNames48_ES5.js b/tests/baselines/reference/computedPropertyNames48_ES5.js index f3f9941aeae7c..859fb7a179c4c 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES5.js +++ b/tests/baselines/reference/computedPropertyNames48_ES5.js @@ -23,13 +23,16 @@ 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; diff --git a/tests/baselines/reference/computedPropertyNames49_ES5.js b/tests/baselines/reference/computedPropertyNames49_ES5.js index a64d9431a9ab7..3427ea665a051 100644 --- a/tests/baselines/reference/computedPropertyNames49_ES5.js +++ b/tests/baselines/reference/computedPropertyNames49_ES5.js @@ -27,20 +27,41 @@ var x = { //// [computedPropertyNames49_ES5.js] var x = (_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) { + 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 }), _a.p2 = -20, -_a); + }, + 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 +); var _a; diff --git a/tests/baselines/reference/computedPropertyNames4_ES5.js b/tests/baselines/reference/computedPropertyNames4_ES5.js index 255b14eb97053..f91476c79c160 100644 --- a/tests/baselines/reference/computedPropertyNames4_ES5.js +++ b/tests/baselines/reference/computedPropertyNames4_ES5.js @@ -20,17 +20,18 @@ 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; diff --git a/tests/baselines/reference/computedPropertyNames50_ES5.js b/tests/baselines/reference/computedPropertyNames50_ES5.js index a0703eeac0581..a74561295bec3 100644 --- a/tests/baselines/reference/computedPropertyNames50_ES5.js +++ b/tests/baselines/reference/computedPropertyNames50_ES5.js @@ -27,25 +27,37 @@ var x = { //// [computedPropertyNames50_ES5.js] var x = (_a = { - p1: 10, - get foo() { - if (1 == 1) { - return 10; + p1: 10, + get foo() { + if (1 == 1) { + return 10; + } } - } -}, _a.p1 = -10, _a.foo = Object.defineProperty({ get: function () { - if (1 == 1) { + }, + 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 () { 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); + }, + enumerable: true, + configurable: true + }), + , + _a.p2 = 20, + _a +); var _a; diff --git a/tests/baselines/reference/computedPropertyNames5_ES5.js b/tests/baselines/reference/computedPropertyNames5_ES5.js index 722c0f3a74d77..58c5af2efa3b4 100644 --- a/tests/baselines/reference/computedPropertyNames5_ES5.js +++ b/tests/baselines/reference/computedPropertyNames5_ES5.js @@ -11,12 +11,13 @@ 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; diff --git a/tests/baselines/reference/computedPropertyNames6_ES5.js b/tests/baselines/reference/computedPropertyNames6_ES5.js index 4e3ed1b2e9f46..7e9c62029403d 100644 --- a/tests/baselines/reference/computedPropertyNames6_ES5.js +++ b/tests/baselines/reference/computedPropertyNames6_ES5.js @@ -12,9 +12,10 @@ 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; diff --git a/tests/baselines/reference/computedPropertyNames7_ES5.js b/tests/baselines/reference/computedPropertyNames7_ES5.js index 3e1bcc1151cc3..886cd8d85eb7d 100644 --- a/tests/baselines/reference/computedPropertyNames7_ES5.js +++ b/tests/baselines/reference/computedPropertyNames7_ES5.js @@ -11,7 +11,8 @@ 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; diff --git a/tests/baselines/reference/computedPropertyNames8_ES5.js b/tests/baselines/reference/computedPropertyNames8_ES5.js index 4db9ed2ec133c..6eceee81adb10 100644 --- a/tests/baselines/reference/computedPropertyNames8_ES5.js +++ b/tests/baselines/reference/computedPropertyNames8_ES5.js @@ -12,9 +12,10 @@ function f() { 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; } diff --git a/tests/baselines/reference/computedPropertyNames9_ES5.js b/tests/baselines/reference/computedPropertyNames9_ES5.js index a7c4a74d5ec8f..6c1d7bcb4d076 100644 --- a/tests/baselines/reference/computedPropertyNames9_ES5.js +++ b/tests/baselines/reference/computedPropertyNames9_ES5.js @@ -12,9 +12,10 @@ 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; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.js index 5ea0512467478..1f7a3ae123e57 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.js @@ -9,8 +9,9 @@ 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; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.js index a799449541141..c4bfde03531ef 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType1_ES5.js @@ -10,7 +10,9 @@ 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 = (_a = {}, + _a["" + 0] = function (y) { return y.length; }, + _a["" + 1] = function (y) { return y.length; }, + _a +); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.js index 0c6b80bbabb6c..945475f8533f2 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.js @@ -10,7 +10,9 @@ 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 = (_a = {}, + _a[+"foo"] = function (y) { return y.length; }, + _a[+"bar"] = function (y) { return y.length; }, + _a +); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.js index 4336808c558f9..98042f201e339 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType3_ES5.js @@ -9,7 +9,9 @@ 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 = (_a = {}, + _a[+"foo"] = function (y) { return y.length; }, + _a[+"bar"] = function (y) { return y.length; }, + _a +); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.js index b813da3049684..b17f91be38b41 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType4_ES5.js @@ -10,8 +10,9 @@ 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; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.js index f75389de3e9d9..c7a728e5ef85f 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType5_ES5.js @@ -10,8 +10,9 @@ 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; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.js index bc724320d148c..c97b7c5b1f865 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.js @@ -15,13 +15,12 @@ foo({ //// [computedPropertyNamesContextualType6_ES5.js] foo((_a = { - p: "", - 0: function () { } -}, _a.p = -"", _a[0] = -function () { }, _a["hi" + "bye"] = -true, _a[0 + 1] = -0, _a[+"hi"] = -[0], -_a)); + p: "", + 0: function () { } + }, + _a["hi" + "bye"] = true, + _a[0 + 1] = 0, + _a[+"hi"] = [0], + _a +)); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js index 8d2386a1d1460..9ca7e826aa713 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.js @@ -15,13 +15,12 @@ foo({ //// [computedPropertyNamesContextualType7_ES5.js] foo((_a = { - p: "", - 0: function () { } -}, _a.p = -"", _a[0] = -function () { }, _a["hi" + "bye"] = -true, _a[0 + 1] = -0, _a[+"hi"] = -[0], -_a)); + p: "", + 0: function () { } + }, + _a["hi" + "bye"] = true, + _a[0 + 1] = 0, + _a[+"hi"] = [0], + _a +)); var _a; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.js index 626f3d1a8e251..419ea906550b5 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.js @@ -10,8 +10,9 @@ 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; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.js b/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.js index c28db4ded9785..d3beb8b8deb73 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.js @@ -10,8 +10,9 @@ 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; diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js index a0666f166d4a6..e77eb79dc709e 100644 --- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit5_ES5.js @@ -7,9 +7,21 @@ var v = { } //// [computedPropertyNamesDeclarationEmit5_ES5.js] -var v = (_a = {}, _a["" + ""] = -0, _a["" + ""] = function () { }, _a["" + ""] = Object.defineProperty({ get: function () { return 0; }, enumerable: true, configurable: true }), _a["" + ""] = Object.defineProperty({ set: function (x) { }, enumerable: true, configurable: true }), -_a); +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 _a; diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js index c5af22ef39891..39e393c46cce6 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js +++ b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js @@ -6,9 +6,11 @@ var v = { } //// [computedPropertyNamesSourceMap2_ES5.js] -var v = (_a = {}, _a["hello"] = function () { - debugger; -}, -_a); +var v = (_a = {}, + _a["hello"] = function () { + debugger; + }, + _a +); var _a; //# sourceMappingURL=computedPropertyNamesSourceMap2_ES5.js.map \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js.map index 82a729df95734..2d9d4ea308818 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js.map +++ b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.js.map @@ -1,2 +1,2 @@ //// [computedPropertyNamesSourceMap2_ES5.js.map] -{"version":3,"file":"computedPropertyNamesSourceMap2_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap2_ES5.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,AADA,CACA,EAAA,GADA,EAAA,EACA,EAAA,CACK,OAAO,CAFA,GAAA;IAGA,QAAQ,CAAC;AACb,CAAC,AAJA;AACA,EAAA,AADA,CAKA,CAAA;IAJD,EAAA"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.sourcemap.txt index 33a3a2b4c2c7b..4c49c91499b28 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.sourcemap.txt +++ b/tests/baselines/reference/computedPropertyNamesSourceMap2_ES5.sourcemap.txt @@ -8,153 +8,100 @@ sources: computedPropertyNamesSourceMap2_ES5.ts emittedFile:tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap2_ES5.js sourceFile:computedPropertyNamesSourceMap2_ES5.ts ------------------------------------------------------------------- ->>>var v = (_a = {}, _a["hello"] = function () { +>>>var v = (_a = {}, 1 > 2 >^^^^ 3 > ^ 4 > ^^^ -5 > -6 > ^ -7 > ^^ -8 > ^^^ -9 > ^^ -10> ^^ -11> ^^ -12> ^ -13> ^^^^^^^ -14> ^ -15> ^^^ +5 > ^ +6 > ^^ +7 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > 2 >var 3 > v 4 > = -5 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found -5 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 9) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 9) Source(0, NaN) + SourceIndex(0) nameIndex (-1) 5 > -6 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column -6 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 9) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 10) Source(1, 1) + SourceIndex(0) nameIndex (-1) -6 > -7 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -7 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 10) Source(1, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 12) Source(1, 1) + SourceIndex(0) nameIndex (-1) -7 > -8 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -8 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 12) Source(1, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 15) Source(0, NaN) + 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(1, 15) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 17) Source(0, NaN) + 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(1, 15) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 19) Source(1, 1) + SourceIndex(0) nameIndex (-1) -10> -11> !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found -11> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 17) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 21) Source(1, 1) + SourceIndex(0) nameIndex (-1) -11> -12> !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column -12> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 17) Source(0, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 22) Source(2, 6) + SourceIndex(0) nameIndex (-1) -12> var v = { - > [ -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(1, 19) Source(1, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 29) Source(2, 13) + SourceIndex(0) nameIndex (-1) -13> "hello" -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(1, 21) Source(1, 9) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 30) Source(0, NaN) + SourceIndex(0) nameIndex (-1) -14> -15> !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -15> !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 22) Source(2, 14) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(1, 33) Source(0, NaN) + SourceIndex(0) nameIndex (-1) -15> +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, 9) Source(0, NaN) + SourceIndex(0) -6 >Emitted(1, 10) Source(1, 1) + SourceIndex(0) -7 >Emitted(1, 12) Source(1, 1) + SourceIndex(0) -8 >Emitted(1, 15) Source(0, NaN) + SourceIndex(0) -9 >Emitted(1, 17) Source(0, NaN) + SourceIndex(0) -10>Emitted(1, 19) Source(1, 1) + SourceIndex(0) -11>Emitted(1, 21) Source(1, 1) + SourceIndex(0) -12>Emitted(1, 22) Source(2, 6) + SourceIndex(0) -13>Emitted(1, 29) Source(2, 13) + SourceIndex(0) -14>Emitted(1, 30) Source(0, NaN) + SourceIndex(0) -15>Emitted(1, 33) Source(0, NaN) + SourceIndex(0) +5 >Emitted(1, 10) Source(1, 1) + SourceIndex(0) +6 >Emitted(1, 12) Source(1, 1) + SourceIndex(0) --- ->>> debugger; -1 >^^^^ -2 > ^^^^^^^^ -3 > ^ -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(1, 29) Source(2, 21) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(2, 5) Source(3, 9) + SourceIndex(0) nameIndex (-1) -1 > -2 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found -2 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 30) Source(0, 21) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(2, 13) Source(3, 17) + SourceIndex(0) nameIndex (-1) -2 > debugger -3 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column -3 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 30) Source(0, 21) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(2, 14) Source(3, 18) + SourceIndex(0) nameIndex (-1) -3 > ; -1 >Emitted(2, 5) Source(3, 9) + SourceIndex(0) -2 >Emitted(2, 13) Source(3, 17) + SourceIndex(0) -3 >Emitted(2, 14) Source(3, 18) + SourceIndex(0) +>>> _a["hello"] = function () { +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) --- ->>>}, -1 > -2 >^ -3 > -4 > ^^^^-> -1 >!!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found -1 >!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 33) Source(0, 21) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 1) Source(4, 5) + SourceIndex(0) nameIndex (-1) +>>> 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 >!!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column -2 >!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(1, 33) Source(0, 21) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 2) Source(4, 6) + SourceIndex(0) nameIndex (-1) -2 >} -3 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -3 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(2, 5) Source(3, 21) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(3, 2) Source(0, NaN) + SourceIndex(0) nameIndex (-1) -3 > -1 >Emitted(3, 1) Source(4, 5) + SourceIndex(0) -2 >Emitted(3, 2) Source(4, 6) + SourceIndex(0) -3 >Emitted(3, 2) Source(0, NaN) + SourceIndex(0) +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 >^^ -3 > -4 > ^ -5 > ^ -6 > ^^^^-> -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(2, 13) Source(3, 29) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 1) Source(1, 1) + SourceIndex(0) nameIndex (-1) +>>> _a +1->^^^^ +2 > ^^ 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(2, 14) Source(3, 30) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 3) Source(1, 1) + SourceIndex(0) nameIndex (-1) -2 > -3 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -3 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 1) Source(4, 17) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 3) Source(0, NaN) + SourceIndex(0) nameIndex (-1) -3 > -4 > !!^^ !!^^ The decoded span from sourcemap's mapping entry does not match what was encoded for this span: -4 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 2) Source(4, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 4) Source(5, 2) + SourceIndex(0) nameIndex (-1) -4 > -5 > !!^^ !!^^ There was decoding error in the sourcemap at this location: Invalid sourceLine found -5 > !!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 2) Source(0, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(4, 5) Source(5, 2) + SourceIndex(0) nameIndex (-1) -5 > -1->Emitted(4, 1) Source(1, 1) + SourceIndex(0) -2 >Emitted(4, 3) Source(1, 1) + SourceIndex(0) -3 >Emitted(4, 3) Source(0, NaN) + SourceIndex(0) -4 >Emitted(4, 4) Source(5, 2) + SourceIndex(0) -5 >Emitted(4, 5) Source(5, 2) + SourceIndex(0) +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 = { + > ["hello"]() { + > debugger; + > } + >} +2 > +1 >Emitted(6, 2) Source(5, 2) + SourceIndex(0) +2 >Emitted(6, 3) Source(5, 2) + SourceIndex(0) --- >>>var _a; 1->^^^^ 2 > ^^ 3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1->!!^^ !!^^ There was decoding error in the sourcemap at this location: Unsupported Error Format: No entries after emitted column -1->!!^^ !!^^ Decoded span from sourcemap's mappings entry: Emitted(3, 2) Source(0, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(5, 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(4, 1) Source(1, 18) + SourceIndex(0) nameIndex (-1) Span encoded by the emitter:Emitted(5, 7) Source(1, 1) + SourceIndex(0) nameIndex (-1) 2 > -1->Emitted(5, 5) Source(1, 1) + SourceIndex(0) -2 >Emitted(5, 7) Source(1, 1) + SourceIndex(0) +1->Emitted(7, 5) Source(1, 1) + SourceIndex(0) +2 >Emitted(7, 7) Source(1, 1) + SourceIndex(0) --- -!!!! **** There are more source map entries in the sourceMap's mapping than what was encoded -!!!! **** Remaining decoded string: ,EAAA,AADA,CAKA,CAAA;IAJD,EAAA >>>//# sourceMappingURL=computedPropertyNamesSourceMap2_ES5.js.map \ No newline at end of file diff --git a/tests/baselines/reference/parserES5ComputedPropertyName2.js b/tests/baselines/reference/parserES5ComputedPropertyName2.js index 2b39e305e07dd..4569c00d7b3fc 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName2.js +++ b/tests/baselines/reference/parserES5ComputedPropertyName2.js @@ -2,7 +2,5 @@ var v = { [e]: 1 }; //// [parserES5ComputedPropertyName2.js] -var v = (_a = {}, _a[e] = -1, -_a); +var v = (_a = {}, _a[e] = 1, _a); var _a; diff --git a/tests/baselines/reference/parserES5ComputedPropertyName3.js b/tests/baselines/reference/parserES5ComputedPropertyName3.js index 3247b0251f13f..1fdb5ced65dcd 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName3.js +++ b/tests/baselines/reference/parserES5ComputedPropertyName3.js @@ -2,6 +2,5 @@ var v = { [e]() { } }; //// [parserES5ComputedPropertyName3.js] -var v = (_a = {}, _a[e] = function () { }, -_a); +var v = (_a = {}, _a[e] = function () { }, _a); var _a; diff --git a/tests/baselines/reference/parserES5ComputedPropertyName4.js b/tests/baselines/reference/parserES5ComputedPropertyName4.js index 436f967e8decd..499e9a426d900 100644 --- a/tests/baselines/reference/parserES5ComputedPropertyName4.js +++ b/tests/baselines/reference/parserES5ComputedPropertyName4.js @@ -2,6 +2,9 @@ var v = { get [e]() { } }; //// [parserES5ComputedPropertyName4.js] -var v = (_a = {}, _a[e] = Object.defineProperty({ get: function () { }, enumerable: true, configurable: true }), -_a); +var v = (_a = {}, Object.defineProperty(_a, e, { + get: function () { }, + enumerable: true, + configurable: true +}), _a); var _a; diff --git a/tests/baselines/reference/privateIndexer2.js b/tests/baselines/reference/privateIndexer2.js index 5a36a9eae18bb..1268c6e4c25a2 100644 --- a/tests/baselines/reference/privateIndexer2.js +++ b/tests/baselines/reference/privateIndexer2.js @@ -11,9 +11,10 @@ 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; From 0af4b8a2c281a6975ca961e9ba588663138755d4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 23 Feb 2015 17:50:37 -0800 Subject: [PATCH 2/7] Removed tree rewriting code --- src/compiler/emitter.ts | 243 ---------------------------------------- 1 file changed, 243 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 78a4ea54b6994..addb7234a97d0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2744,249 +2744,6 @@ module ts { emitObjectLiteralBody(node, properties.length); } - function createSynthesizedNode(kind: SyntaxKind): Node { - var node = createNode(kind); - node.pos = -1; - node.end = -1; - - return node; - } - - function emitDownlevelObjectLiteralWithComputedPropertiesThroughRewrite(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 = createSynthesizedNode(SyntaxKind.ObjectLiteralExpression); - initialObjectLiteral.properties = >originalObjectLiteral.properties.slice(0, firstComputedPropertyIndex); - initialObjectLiteral.flags |= NodeFlags.MultiLine; - - // The comma expressions that will patch the object literal. - // This will end up being something like '_a = { ... }, _a.x = 10, _a.y = 20, _a'. - var propertyPatches = createBinaryExpression(tempVar, SyntaxKind.EqualsToken, 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(propertyPatches, SyntaxKind.CommaToken, patchedProperty); - } - }); - - // Finally, return the temp variable. - propertyPatches = createBinaryExpression(propertyPatches, SyntaxKind.CommaToken, 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 - // (e.g. a 'get' accessor which has already been emitted along with its 'set' accessor). - function tryCreatePatchingPropertyAssignment(objectLiteral: ObjectLiteralExpression, tempVar: Identifier, property: ObjectLiteralElement): Expression { - var leftHandSide = createMemberAccessForPropertyName(tempVar, property.name); - var maybeRightHandSide = tryGetRightHandSideOfPatchingPropertyAssignment(objectLiteral, property); - - return maybeRightHandSide && createBinaryExpression(leftHandSide, SyntaxKind.EqualsToken, maybeRightHandSide); - } - - function tryGetRightHandSideOfPatchingPropertyAssignment(objectLiteral: ObjectLiteralExpression, property: ObjectLiteralElement) { - switch (property.kind) { - case SyntaxKind.PropertyAssignment: - return (property).initializer; - - case SyntaxKind.ShorthandPropertyAssignment: - // TODO: (andersh) Technically it isn't correct to make an identifier here since getExpressionNamePrefix returns - // a string containing a dotted name. In general I'm not a fan of mini tree rewriters as this one, elsewhere we - // manage by just emitting strings (which is a lot more performant). - //var prefix = createIdentifier(resolver.getExpressionNamePrefix((property).name)); - //return createPropertyAccessExpression(prefix, (property).name); - return createIdentifier(resolver.getExpressionNameSubstitution((property).name)); - - case SyntaxKind.MethodDeclaration: - return createFunctionExpression((property).parameters, (property).body); - - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - var { firstAccessor, getAccessor, setAccessor } = getAllAccessorDeclarations(objectLiteral.properties, property); - - // Only emit the first accessor. - if (firstAccessor !== property) { - return undefined; - } - - var propertyDescriptor = createSynthesizedNode(SyntaxKind.ObjectLiteralExpression); - - var descriptorProperties = >[]; - if (getAccessor) { - var getProperty = createPropertyAssignment(createIdentifier("get"), createFunctionExpression(getAccessor.parameters, getAccessor.body)); - descriptorProperties.push(getProperty); - } - if (setAccessor) { - var setProperty = createPropertyAssignment(createIdentifier("set"), createFunctionExpression(setAccessor.parameters, setAccessor.body)); - descriptorProperties.push(setProperty); - } - - var trueExpr = 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")); - return createCallExpression(objectDotDefineProperty, createNodeArray(propertyDescriptor)); - - default: - Debug.fail(`ObjectLiteralElement kind ${property.kind} not accounted for.`); - } - } - - function createParenthesizedExpression(expression: Expression) { - var result = createSynthesizedNode(SyntaxKind.ParenthesizedExpression); - result.expression = expression; - - return result; - } - - function createNodeArray(...elements: T[]): NodeArray { - var result = >elements; - result.pos = -1; - result.end = -1; - - return result; - } - - function createBinaryExpression(left: Expression, operator: SyntaxKind, right: Expression): BinaryExpression { - var result = createSynthesizedNode(SyntaxKind.BinaryExpression); - result.operatorToken = createSynthesizedNode(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, memberName); - } - else if (memberName.kind === SyntaxKind.StringLiteral || memberName.kind === SyntaxKind.NumericLiteral) { - return createElementAccessExpression(expression, memberName); - } - else if (memberName.kind === SyntaxKind.ComputedPropertyName) { - return createElementAccessExpression(expression, (memberName).expression); - } - else { - Debug.fail(`Kind '${memberName.kind}' not accounted for.`); - } - } - - function createPropertyAssignment(name: LiteralExpression | Identifier, initializer: Expression) { - var result = createSynthesizedNode(SyntaxKind.PropertyAssignment); - result.name = name; - result.initializer = initializer; - - return result; - } - - function createFunctionExpression(parameters: NodeArray, body: Block): FunctionExpression { - var result = createSynthesizedNode(SyntaxKind.FunctionExpression); - result.parameters = parameters; - result.body = body; - - return result; - } - - function createPropertyAccessExpression(expression: LeftHandSideExpression, name: Identifier): PropertyAccessExpression { - var result = createSynthesizedNode(SyntaxKind.PropertyAccessExpression); - result.expression = expression; - result.name = name; - - return result; - } - - function createElementAccessExpression(expression: LeftHandSideExpression, argumentExpression: Expression): ElementAccessExpression { - var result = createSynthesizedNode(SyntaxKind.ElementAccessExpression); - result.expression = expression; - result.argumentExpression = argumentExpression; - - return result; - } - - function createIdentifier(name: string) { - var result = createSynthesizedNode(SyntaxKind.Identifier); - result.text = name; - - return result; - } - - function createCallExpression(invokedExpression: MemberExpression, arguments: NodeArray) { - var result = createSynthesizedNode(SyntaxKind.CallExpression); - result.expression = invokedExpression; - result.arguments = arguments; - - return result; - } - - function emitObjectLiteralThroughRewrite(node: ObjectLiteralExpression): void { - var properties = node.properties; - - if (languageVersion < ScriptTarget.ES6) { - var numProperties = properties.length; - - // Find the first computed property. - // Everything until that point can be emitted as part of the initial object literal. - var numInitialNonComputedProperties = numProperties; - for (var i = 0, n = properties.length; i < n; i++) { - if (properties[i].name.kind === SyntaxKind.ComputedPropertyName) { - numInitialNonComputedProperties = i; - break; - } - } - - var hasComputedProperty = numInitialNonComputedProperties !== properties.length; - if (hasComputedProperty) { - emitDownlevelObjectLiteralWithComputedPropertiesThroughRewrite(node, numInitialNonComputedProperties); - return; - } - } - - // Ordinary case: either the object has no computed properties - // or we're compiling with an ES6+ target. - write("{"); - - var properties = node.properties; - if (properties.length) { - emitLinePreservingList(node, properties, /*allowTrailingComma:*/ languageVersion >= ScriptTarget.ES5, /*spacesBetweenBraces:*/ true) - } - - write("}"); - } - function emitComputedPropertyName(node: ComputedPropertyName) { write("["); emit(node.expression); From 74e6b6eccc087f736a131acb8351b586c9f6c09f Mon Sep 17 00:00:00 2001 From: steveluc Date: Thu, 2 Apr 2015 00:13:06 -0700 Subject: [PATCH 3/7] Add an exit message for the server. --- src/server/editorServices.ts | 6 ++++-- src/server/protocol.d.ts | 7 +++++++ src/server/server.ts | 10 +++++++--- src/server/session.ts | 13 +++++++++++-- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index a3814c8fec111..3dfbc05ff9ae8 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -458,7 +458,7 @@ module ts.server { var info = this.filenameToScriptInfo[args.file]; if (info) { info.setFormatOptions(args.formatOptions); - this.log("Host configuration update for file " + args.file); + this.log("Host configuration update for file " + args.file, "Info"); } } else { @@ -823,7 +823,6 @@ module ts.server { */ closeClientFile(filename: string) { - // TODO: tsconfig check var info = ts.lookUp(this.filenameToScriptInfo, filename); if (info) { this.closeOpenFile(info); @@ -856,6 +855,9 @@ module ts.server { } printProjects() { + if (!this.psLogger.isVerbose()) { + return; + } this.psLogger.startGroup(); for (var i = 0, len = this.inferredProjects.length; i < len; i++) { var project = this.inferredProjects[i]; diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index 382ce8494af8a..b425f4941a13b 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -405,6 +405,13 @@ declare module ts.server.protocol { arguments: OpenRequestArgs; } + /** + * Exit request; value of command field is "exit". Ask the server process + * to exit. + */ + export interface ExitRequest extends Request { + } + /** * Close request; value of command field is "close". Notify the * server that the client has closed a previously open file. If diff --git a/src/server/server.ts b/src/server/server.ts index 4c13be80c4cef..828deca2b2d2a 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -177,6 +177,12 @@ module ts.server { super(host, logger); } + exit() { + this.projectService.log("Exiting...","Info"); + this.projectService.closeLog(); + process.exit(0); + } + listen() { rl.on('line',(input: string) => { var message = input.trim(); @@ -184,9 +190,7 @@ module ts.server { }); rl.on('close',() => { - this.projectService.log("Exiting..."); - this.projectService.closeLog(); - process.exit(0); + this.exit(); }); } } diff --git a/src/server/session.ts b/src/server/session.ts index 80831e692844f..560f5869c0887 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -76,13 +76,14 @@ module ts.server { } export module CommandNames { + export var Brace = "brace"; export var Change = "change"; export var Close = "close"; export var Completions = "completions"; export var CompletionDetails = "completionEntryDetails"; - export var SignatureHelp = "signatureHelp"; export var Configure = "configure"; export var Definition = "definition"; + export var Exit = "exit"; export var Format = "format"; export var Formatonkey = "formatonkey"; export var Geterr = "geterr"; @@ -94,7 +95,7 @@ module ts.server { export var Reload = "reload"; export var Rename = "rename"; export var Saveto = "saveto"; - export var Brace = "brace"; + export var SignatureHelp = "signatureHelp"; export var Unknown = "unknown"; } @@ -758,6 +759,9 @@ module ts.server { })); } + exit() { + } + onMessage(message: string) { if (this.logger.isVerbose()) { this.logger.info("request: " + message); @@ -769,6 +773,11 @@ module ts.server { var errorMessage: string; var responseRequired = true; switch (request.command) { + case CommandNames.Exit: { + this.exit(); + responseRequired = false; + break; + } case CommandNames.Definition: { var defArgs = request.arguments; response = this.getDefinition(defArgs.line, defArgs.offset, defArgs.file); From d71632aa38ba4ad2023a1dfd9f319de6cd804b4f Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 6 Apr 2015 15:32:22 -0700 Subject: [PATCH 4/7] Check for omitted expressions when checking const and let declaration names --- src/compiler/checker.ts | 4 +- .../reference/arrayBindingPattern.js | 31 +++++++++++++ .../reference/arrayBindingPattern.types | 43 +++++++++++++++++++ tests/cases/compiler/arrayBindingPattern.ts | 17 ++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/arrayBindingPattern.js create mode 100644 tests/baselines/reference/arrayBindingPattern.types create mode 100644 tests/cases/compiler/arrayBindingPattern.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 54d722f53b0f7..d154bc1c93bc4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12596,7 +12596,9 @@ module ts { else { let elements = (name).elements; for (let element of elements) { - checkGrammarNameInLetOrConstDeclarations(element.name); + if (element.kind !== SyntaxKind.OmittedExpression) { + checkGrammarNameInLetOrConstDeclarations(element.name); + } } } } diff --git a/tests/baselines/reference/arrayBindingPattern.js b/tests/baselines/reference/arrayBindingPattern.js new file mode 100644 index 0000000000000..bd1b350fbe4d8 --- /dev/null +++ b/tests/baselines/reference/arrayBindingPattern.js @@ -0,0 +1,31 @@ +//// [arrayBindingPattern.ts] + +var results: string[]; + +{ + let [, b, , a] = results; + let x = { + a, + b + } +} + + +function f([, a, , b, , , , s, , , ] = results) { + a = s[1]; + b = s[2]; +} + +//// [arrayBindingPattern.js] +var results; +{ + let [, b, , a] = results; + let x = { + a, + b + }; +} +function f([, a, , b, , , , s, , ,] = results) { + a = s[1]; + b = s[2]; +} diff --git a/tests/baselines/reference/arrayBindingPattern.types b/tests/baselines/reference/arrayBindingPattern.types new file mode 100644 index 0000000000000..a157a357fe77c --- /dev/null +++ b/tests/baselines/reference/arrayBindingPattern.types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/arrayBindingPattern.ts === + +var results: string[]; +>results : string[] + +{ + let [, b, , a] = results; +>b : string +>a : string +>results : string[] + + let x = { +>x : { a: string; b: string; } +>{ a, b } : { a: string; b: string; } + + a, +>a : string + + b +>b : string + } +} + + +function f([, a, , b, , , , s, , , ] = results) { +>f : ([, a, , b, , , , s, , , ]?: string[]) => void +>a : string +>b : string +>s : string +>results : string[] + + a = s[1]; +>a = s[1] : string +>a : string +>s[1] : string +>s : string + + b = s[2]; +>b = s[2] : string +>b : string +>s[2] : string +>s : string +} diff --git a/tests/cases/compiler/arrayBindingPattern.ts b/tests/cases/compiler/arrayBindingPattern.ts new file mode 100644 index 0000000000000..61d8c6f7dda29 --- /dev/null +++ b/tests/cases/compiler/arrayBindingPattern.ts @@ -0,0 +1,17 @@ +// @target: ES6 + +var results: string[]; + +{ + let [, b, , a] = results; + let x = { + a, + b + } +} + + +function f([, a, , b, , , , s, , , ] = results) { + a = s[1]; + b = s[2]; +} \ No newline at end of file From 238a33daa0edf54f38a49ce716383cf50de53d60 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 6 Apr 2015 16:24:55 -0700 Subject: [PATCH 5/7] Rename test case --- ...ingPattern.js => arrayBindingPatternOmittedExpressions.js} | 4 ++-- ...tern.types => arrayBindingPatternOmittedExpressions.types} | 2 +- ...ingPattern.ts => arrayBindingPatternOmittedExpressions.ts} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename tests/baselines/reference/{arrayBindingPattern.js => arrayBindingPatternOmittedExpressions.js} (75%) rename tests/baselines/reference/{arrayBindingPattern.types => arrayBindingPatternOmittedExpressions.types} (83%) rename tests/cases/compiler/{arrayBindingPattern.ts => arrayBindingPatternOmittedExpressions.ts} (100%) diff --git a/tests/baselines/reference/arrayBindingPattern.js b/tests/baselines/reference/arrayBindingPatternOmittedExpressions.js similarity index 75% rename from tests/baselines/reference/arrayBindingPattern.js rename to tests/baselines/reference/arrayBindingPatternOmittedExpressions.js index bd1b350fbe4d8..a6f01d7b75cad 100644 --- a/tests/baselines/reference/arrayBindingPattern.js +++ b/tests/baselines/reference/arrayBindingPatternOmittedExpressions.js @@ -1,4 +1,4 @@ -//// [arrayBindingPattern.ts] +//// [arrayBindingPatternOmittedExpressions.ts] var results: string[]; @@ -16,7 +16,7 @@ function f([, a, , b, , , , s, , , ] = results) { b = s[2]; } -//// [arrayBindingPattern.js] +//// [arrayBindingPatternOmittedExpressions.js] var results; { let [, b, , a] = results; diff --git a/tests/baselines/reference/arrayBindingPattern.types b/tests/baselines/reference/arrayBindingPatternOmittedExpressions.types similarity index 83% rename from tests/baselines/reference/arrayBindingPattern.types rename to tests/baselines/reference/arrayBindingPatternOmittedExpressions.types index a157a357fe77c..ba1ac955b85e5 100644 --- a/tests/baselines/reference/arrayBindingPattern.types +++ b/tests/baselines/reference/arrayBindingPatternOmittedExpressions.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/arrayBindingPattern.ts === +=== tests/cases/compiler/arrayBindingPatternOmittedExpressions.ts === var results: string[]; >results : string[] diff --git a/tests/cases/compiler/arrayBindingPattern.ts b/tests/cases/compiler/arrayBindingPatternOmittedExpressions.ts similarity index 100% rename from tests/cases/compiler/arrayBindingPattern.ts rename to tests/cases/compiler/arrayBindingPatternOmittedExpressions.ts From 627c7f42117e7a440225aa3295e3a1c48c04fd9d Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 7 Apr 2015 13:17:57 -0700 Subject: [PATCH 6/7] Fix for #2619 --- src/compiler/emitter.ts | 6 ++-- .../reference/decoratorOnClassMethod11.js | 29 +++++++++++++++++++ .../reference/decoratorOnClassMethod11.types | 21 ++++++++++++++ .../class/method/decoratorOnClassMethod11.ts | 7 +++++ 4 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/decoratorOnClassMethod11.js create mode 100644 tests/baselines/reference/decoratorOnClassMethod11.types create mode 100644 tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 43db3e69cd718..1af1f7275cdc9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1136,8 +1136,8 @@ var __param = this.__param || function(index, decorator) { return function (targ if (!computedPropertyNamesToGeneratedNames) { computedPropertyNamesToGeneratedNames = []; } - - let generatedName = computedPropertyNamesToGeneratedNames[node.id]; + + let generatedName = computedPropertyNamesToGeneratedNames[getNodeId(node)]; if (generatedName) { // we have already generated a variable for this node, write that value instead. write(generatedName); @@ -1145,7 +1145,7 @@ var __param = this.__param || function(index, decorator) { return function (targ } generatedName = createAndRecordTempVariable(TempFlags.Auto).text; - computedPropertyNamesToGeneratedNames[node.id] = generatedName; + computedPropertyNamesToGeneratedNames[getNodeId(node)] = generatedName; write(generatedName); write(" = "); } diff --git a/tests/baselines/reference/decoratorOnClassMethod11.js b/tests/baselines/reference/decoratorOnClassMethod11.js new file mode 100644 index 0000000000000..085f84f1f838d --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod11.js @@ -0,0 +1,29 @@ +//// [decoratorOnClassMethod11.ts] +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; + +class C { + @dec ["1"]() { } + @dec ["b"]() { } +} + +//// [decoratorOnClassMethod11.js] +var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; +class C { + [_a = "1"]() { } + [_b = "b"]() { } +} +Object.defineProperty(C.prototype, _a, + __decorate([ + dec + ], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); +Object.defineProperty(C.prototype, _b, + __decorate([ + dec + ], C.prototype, _b, Object.getOwnPropertyDescriptor(C.prototype, _b))); +var _a, _b; diff --git a/tests/baselines/reference/decoratorOnClassMethod11.types b/tests/baselines/reference/decoratorOnClassMethod11.types new file mode 100644 index 0000000000000..1035668ed51da --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod11.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts === +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; +>dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec ["1"]() { } +>dec : unknown + + @dec ["b"]() { } +>dec : unknown +} diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts new file mode 100644 index 0000000000000..df0b847e99deb --- /dev/null +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts @@ -0,0 +1,7 @@ +// @target: ES6 +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; + +class C { + @dec ["1"]() { } + @dec ["b"]() { } +} \ No newline at end of file From 37025689163e060caa0b424423a4271660036c56 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 7 Apr 2015 13:17:57 -0700 Subject: [PATCH 7/7] Fix for #2619 --- src/compiler/emitter.ts | 6 ++-- .../reference/decoratorOnClassMethod11.js | 14 ++++----- .../reference/decoratorOnClassMethod13.js | 29 +++++++++++++++++++ .../reference/decoratorOnClassMethod13.types | 21 ++++++++++++++ .../class/method/decoratorOnClassMethod13.ts | 7 +++++ 5 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 tests/baselines/reference/decoratorOnClassMethod13.js create mode 100644 tests/baselines/reference/decoratorOnClassMethod13.types create mode 100644 tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d8493895d9cd8..940edf04191ca 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1136,8 +1136,8 @@ var __param = this.__param || function(index, decorator) { return function (targ if (!computedPropertyNamesToGeneratedNames) { computedPropertyNamesToGeneratedNames = []; } - - let generatedName = computedPropertyNamesToGeneratedNames[node.id]; + + let generatedName = computedPropertyNamesToGeneratedNames[getNodeId(node)]; if (generatedName) { // we have already generated a variable for this node, write that value instead. write(generatedName); @@ -1145,7 +1145,7 @@ var __param = this.__param || function(index, decorator) { return function (targ } generatedName = createAndRecordTempVariable(TempFlags.Auto).text; - computedPropertyNamesToGeneratedNames[node.id] = generatedName; + computedPropertyNamesToGeneratedNames[getNodeId(node)] = generatedName; write(generatedName); write(" = "); } diff --git a/tests/baselines/reference/decoratorOnClassMethod11.js b/tests/baselines/reference/decoratorOnClassMethod11.js index f8276de2fe3f7..71d4298f02cbf 100644 --- a/tests/baselines/reference/decoratorOnClassMethod11.js +++ b/tests/baselines/reference/decoratorOnClassMethod11.js @@ -1,11 +1,11 @@ //// [decoratorOnClassMethod11.ts] -module M { - class C { - decorator(target: Object, key: string): void { } - - @this.decorator - method() { } - } +module M { + class C { + decorator(target: Object, key: string): void { } + + @this.decorator + method() { } + } } //// [decoratorOnClassMethod11.js] diff --git a/tests/baselines/reference/decoratorOnClassMethod13.js b/tests/baselines/reference/decoratorOnClassMethod13.js new file mode 100644 index 0000000000000..4321bbb0156fc --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod13.js @@ -0,0 +1,29 @@ +//// [decoratorOnClassMethod13.ts] +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; + +class C { + @dec ["1"]() { } + @dec ["b"]() { } +} + +//// [decoratorOnClassMethod13.js] +var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; +class C { + [_a = "1"]() { } + [_b = "b"]() { } +} +Object.defineProperty(C.prototype, _a, + __decorate([ + dec + ], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); +Object.defineProperty(C.prototype, _b, + __decorate([ + dec + ], C.prototype, _b, Object.getOwnPropertyDescriptor(C.prototype, _b))); +var _a, _b; diff --git a/tests/baselines/reference/decoratorOnClassMethod13.types b/tests/baselines/reference/decoratorOnClassMethod13.types new file mode 100644 index 0000000000000..8c34805792f53 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod13.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts === +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; +>dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec ["1"]() { } +>dec : unknown + + @dec ["b"]() { } +>dec : unknown +} diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts new file mode 100644 index 0000000000000..df0b847e99deb --- /dev/null +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts @@ -0,0 +1,7 @@ +// @target: ES6 +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; + +class C { + @dec ["1"]() { } + @dec ["b"]() { } +} \ No newline at end of file