Emit computed properties in ES3/ES5 properly.
This commit is contained in:
parent
d6b2c6d0bb
commit
ddb63d286b
|
@ -271,7 +271,7 @@ module ts {
|
|||
});
|
||||
}
|
||||
|
||||
function getAllAccessorDeclarations(node: ClassDeclaration, accessor: AccessorDeclaration) {
|
||||
function getAllAccessorDeclarations(declarations: NodeArray<Declaration>, accessor: AccessorDeclaration) {
|
||||
var firstAccessor: AccessorDeclaration;
|
||||
var getAccessor: AccessorDeclaration;
|
||||
var setAccessor: AccessorDeclaration;
|
||||
|
@ -288,7 +288,7 @@ module ts {
|
|||
}
|
||||
}
|
||||
else {
|
||||
forEach(node.members,(member: Declaration) => {
|
||||
forEach(declarations, (member: Declaration) => {
|
||||
if ((member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) &&
|
||||
(<Identifier>member.name).text === (<Identifier>accessor.name).text &&
|
||||
(member.flags & NodeFlags.Static) === (accessor.flags & NodeFlags.Static)) {
|
||||
|
@ -1116,8 +1116,8 @@ module ts {
|
|||
if (hasDynamicName(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var accessors = getAllAccessorDeclarations(<ClassDeclaration>node.parent, node);
|
||||
|
||||
var accessors = getAllAccessorDeclarations((<ClassDeclaration>node.parent).members, node);
|
||||
if (node === accessors.firstAccessor) {
|
||||
emitJsDocComments(accessors.getAccessor);
|
||||
emitJsDocComments(accessors.setAccessor);
|
||||
|
@ -2220,7 +2220,10 @@ module ts {
|
|||
|
||||
// This function specifically handles numeric/string literals for enum and accessor 'identifiers'.
|
||||
// In a sense, it does not actually emit identifiers as much as it declares a name for a specific property.
|
||||
// For example, this is utilized when feeding in a result to Object.defineProperty.
|
||||
function emitExpressionForPropertyName(node: DeclarationName) {
|
||||
Debug.assert(node.kind !== SyntaxKind.BindingElement);
|
||||
|
||||
if (node.kind === SyntaxKind.StringLiteral) {
|
||||
emitLiteral(<LiteralExpression>node);
|
||||
}
|
||||
|
@ -2417,22 +2420,167 @@ module ts {
|
|||
}
|
||||
}
|
||||
|
||||
function emitObjectLiteral(node: ObjectLiteralExpression) {
|
||||
function emitObjectLiteralBody(node: ObjectLiteralExpression, numElements: number) {
|
||||
write("{");
|
||||
var properties = node.properties;
|
||||
if (properties.length) {
|
||||
|
||||
if (numElements > 0) {
|
||||
var properties = node.properties;
|
||||
var multiLine = (node.flags & NodeFlags.MultiLine) !== 0;
|
||||
if (!multiLine) {
|
||||
write(" ");
|
||||
}
|
||||
emitList(properties, 0, properties.length, /*multiLine*/ multiLine,
|
||||
emitList(properties, 0, numElements, /*multiLine*/ multiLine,
|
||||
/*trailingComma*/ properties.hasTrailingComma && languageVersion >= ScriptTarget.ES5);
|
||||
if (!multiLine) {
|
||||
write(" ");
|
||||
}
|
||||
}
|
||||
|
||||
write("}");
|
||||
}
|
||||
|
||||
function emitDownlevelObjectLiteralWithComputedProperties(node: ObjectLiteralExpression, firstComputedPropertyIndex: number) {
|
||||
var multiLine = (node.flags & NodeFlags.MultiLine) !== 0;
|
||||
var properties = node.properties;
|
||||
|
||||
write("(");
|
||||
|
||||
// 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 = createTempVariable(node);
|
||||
recordTempDeclaration(tempVar);
|
||||
|
||||
// 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);
|
||||
|
||||
if (multiLine) {
|
||||
increaseIndent();
|
||||
}
|
||||
|
||||
for (var i = firstComputedPropertyIndex, n = properties.length; i < n; i++) {
|
||||
writeSeparator();
|
||||
|
||||
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, <AccessorDeclaration>property);
|
||||
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();
|
||||
writeSeparator();
|
||||
write("})");
|
||||
emitEnd(property);
|
||||
}
|
||||
else {
|
||||
emitLeadingComments(property);
|
||||
emitStart(property.name);
|
||||
emit(tempVar);
|
||||
emitMemberAccessForPropertyName(property.name);
|
||||
emitEnd(property.name);
|
||||
|
||||
write(" = ");
|
||||
|
||||
if (property.kind === SyntaxKind.PropertyAssignment) {
|
||||
emit((<PropertyAssignment>property).initializer);
|
||||
}
|
||||
else if (property.kind === SyntaxKind.ShorthandPropertyAssignment) {
|
||||
emitExpressionIdentifier((<ShorthandPropertyAssignment>property).name);
|
||||
}
|
||||
else if (property.kind === SyntaxKind.MethodDeclaration) {
|
||||
emitFunctionDeclaration(<MethodDeclaration>property);
|
||||
}
|
||||
else {
|
||||
Debug.fail("ObjectLiteralElement type not accounted for: " + property.kind);
|
||||
}
|
||||
}
|
||||
|
||||
emitEnd(property);
|
||||
}
|
||||
|
||||
writeSeparator();
|
||||
emit(tempVar);
|
||||
|
||||
write(")");
|
||||
|
||||
if (multiLine) {
|
||||
decreaseIndent();
|
||||
}
|
||||
|
||||
function writeSeparator() {
|
||||
if (multiLine) {
|
||||
write(",");
|
||||
writeLine();
|
||||
}
|
||||
else {
|
||||
write(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitObjectLiteral(node: ObjectLiteralExpression) {
|
||||
if (languageVersion >= ScriptTarget.ES6) {
|
||||
emitObjectLiteralBody(node, node.properties.length);
|
||||
return;
|
||||
}
|
||||
|
||||
var properties = node.properties;
|
||||
|
||||
// Find the first computed property.
|
||||
// Everything until that point can be emitted as part of the initial object literal.
|
||||
var numInitialNonComputedProperties = properties.length;
|
||||
forEach(properties, (property, i) => {
|
||||
if (hasDynamicName(properties[i])) {
|
||||
numInitialNonComputedProperties = i;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
var hasComputedProperty = numInitialNonComputedProperties !== properties.length;
|
||||
if (hasComputedProperty) {
|
||||
emitDownlevelObjectLiteralWithComputedProperties(node, numInitialNonComputedProperties);
|
||||
}
|
||||
else {
|
||||
emitObjectLiteralBody(node, properties.length);
|
||||
}
|
||||
}
|
||||
|
||||
function emitComputedPropertyName(node: ComputedPropertyName) {
|
||||
write("[");
|
||||
|
@ -2464,7 +2612,7 @@ module ts {
|
|||
// export var obj = { y };
|
||||
// }
|
||||
// The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version
|
||||
if (languageVersion < ScriptTarget.ES6 || resolver.getExpressionNamePrefix(node.name)) {
|
||||
if (languageVersion <= ScriptTarget.ES5 || resolver.getExpressionNamePrefix(node.name)) {
|
||||
// Emit identifier as an identifier
|
||||
write(": ");
|
||||
// Even though this is stored as identifier treat it as an expression
|
||||
|
@ -3446,6 +3594,7 @@ module ts {
|
|||
}
|
||||
|
||||
function emitMemberAccessForPropertyName(memberName: DeclarationName) {
|
||||
// TODO: (jfreeman,drosen): comment on why this is emitNode instead of emit here.
|
||||
if (memberName.kind === SyntaxKind.StringLiteral || memberName.kind === SyntaxKind.NumericLiteral) {
|
||||
write("[");
|
||||
emitNode(memberName);
|
||||
|
@ -3495,13 +3644,14 @@ module ts {
|
|||
emitLeadingComments(member);
|
||||
emitStart(member);
|
||||
emitStart((<MethodDeclaration>member).name);
|
||||
emitNode(node.name);
|
||||
emitNode(node.name); // TODO (shkamat,drosen): comment for why emitNode instead of emit.
|
||||
if (!(member.flags & NodeFlags.Static)) {
|
||||
write(".prototype");
|
||||
}
|
||||
emitMemberAccessForPropertyName((<MethodDeclaration>member).name);
|
||||
emitEnd((<MethodDeclaration>member).name);
|
||||
write(" = ");
|
||||
// TODO (drosen): Should we performing emitStart twice on emitStart(member)?
|
||||
emitStart(member);
|
||||
emitFunctionDeclaration(<MethodDeclaration>member);
|
||||
emitEnd(member);
|
||||
|
@ -3510,7 +3660,7 @@ module ts {
|
|||
emitTrailingComments(member);
|
||||
}
|
||||
else if (member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) {
|
||||
var accessors = getAllAccessorDeclarations(node, <AccessorDeclaration>member);
|
||||
var accessors = getAllAccessorDeclarations(node.members, <AccessorDeclaration>member);
|
||||
if (member === accessors.firstAccessor) {
|
||||
writeLine();
|
||||
emitStart(member);
|
||||
|
@ -3521,6 +3671,7 @@ module ts {
|
|||
write(".prototype");
|
||||
}
|
||||
write(", ");
|
||||
// TODO: Shouldn't emitStart on name occur *here*?
|
||||
emitExpressionForPropertyName((<AccessorDeclaration>member).name);
|
||||
emitEnd((<AccessorDeclaration>member).name);
|
||||
write(", {");
|
||||
|
|
|
@ -2,4 +2,5 @@
|
|||
var v = { [yield]: foo }
|
||||
|
||||
//// [FunctionDeclaration8_es6.js]
|
||||
var v = { [yield]: foo };
|
||||
var v = (_a = {}, _a[yield] = foo, _a);
|
||||
var _a;
|
||||
|
|
|
@ -5,5 +5,6 @@ function * foo() {
|
|||
|
||||
//// [FunctionDeclaration9_es6.js]
|
||||
function foo() {
|
||||
var v = { []: foo };
|
||||
var v = (_a = {}, _a[] = foo, _a);
|
||||
var _a;
|
||||
}
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
var v = { *[foo()]() { } }
|
||||
|
||||
//// [FunctionPropertyAssignments5_es6.js]
|
||||
var v = { [foo()]: function () {
|
||||
} };
|
||||
var v = (_a = {}, _a[foo()] = function () {
|
||||
}, _a);
|
||||
var _a;
|
||||
|
|
|
@ -20,27 +20,28 @@ var v = {
|
|||
var s;
|
||||
var n;
|
||||
var a;
|
||||
var v = {
|
||||
[s]: function () {
|
||||
var v = (_a = {},
|
||||
_a[s] = function () {
|
||||
},
|
||||
[n]: function () {
|
||||
_a[n] = function () {
|
||||
},
|
||||
[s + s]: function () {
|
||||
_a[s + s] = function () {
|
||||
},
|
||||
[s + n]: function () {
|
||||
_a[s + n] = function () {
|
||||
},
|
||||
[+s]: function () {
|
||||
_a[+s] = function () {
|
||||
},
|
||||
[""]: function () {
|
||||
_a[""] = function () {
|
||||
},
|
||||
[0]: function () {
|
||||
_a[0] = function () {
|
||||
},
|
||||
[a]: function () {
|
||||
_a[a] = function () {
|
||||
},
|
||||
[true]: function () {
|
||||
_a[true] = function () {
|
||||
},
|
||||
["hello bye"]: function () {
|
||||
_a["hello bye"] = function () {
|
||||
},
|
||||
["hello " + a + " bye"]: function () {
|
||||
}
|
||||
};
|
||||
_a["hello " + a + " bye"] = function () {
|
||||
},
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -20,33 +20,78 @@ var v = {
|
|||
var s;
|
||||
var n;
|
||||
var a;
|
||||
var v = {
|
||||
get [s]() {
|
||||
return 0;
|
||||
},
|
||||
set [n](v) {
|
||||
},
|
||||
get [s + s]() {
|
||||
return 0;
|
||||
},
|
||||
set [s + n](v) {
|
||||
},
|
||||
get [+s]() {
|
||||
return 0;
|
||||
},
|
||||
set [""](v) {
|
||||
},
|
||||
get [0]() {
|
||||
return 0;
|
||||
},
|
||||
set [a](v) {
|
||||
},
|
||||
get [true]() {
|
||||
return 0;
|
||||
},
|
||||
set ["hello bye"](v) {
|
||||
},
|
||||
get ["hello " + a + " bye"]() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
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;
|
||||
|
|
|
@ -7,7 +7,8 @@ function foo() {
|
|||
|
||||
//// [computedPropertyNames18_ES5.js]
|
||||
function foo() {
|
||||
var obj = {
|
||||
[this.bar]: 0
|
||||
};
|
||||
var obj = (_a = {},
|
||||
_a[this.bar] = 0,
|
||||
_a);
|
||||
var _a;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ module M {
|
|||
//// [computedPropertyNames19_ES5.js]
|
||||
var M;
|
||||
(function (M) {
|
||||
var obj = {
|
||||
[this.bar]: 0
|
||||
};
|
||||
var obj = (_a = {},
|
||||
_a[this.bar] = 0,
|
||||
_a);
|
||||
var _a;
|
||||
})(M || (M = {}));
|
||||
|
|
|
@ -5,10 +5,20 @@ var v = {
|
|||
}
|
||||
|
||||
//// [computedPropertyNames1_ES5.js]
|
||||
var v = {
|
||||
get [0 + 1]() {
|
||||
return 0;
|
||||
},
|
||||
set [0 + 1](v) {
|
||||
} //No error
|
||||
};
|
||||
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;
|
||||
|
|
|
@ -4,6 +4,7 @@ var obj = {
|
|||
}
|
||||
|
||||
//// [computedPropertyNames20_ES5.js]
|
||||
var obj = {
|
||||
[this.bar]: 0
|
||||
};
|
||||
var obj = (_a = {},
|
||||
_a[this.bar] = 0,
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -13,11 +13,12 @@ var C = (function () {
|
|||
function C() {
|
||||
}
|
||||
C.prototype.bar = function () {
|
||||
var obj = {
|
||||
[this.bar()]: function () {
|
||||
}
|
||||
};
|
||||
var obj = (_a = {},
|
||||
_a[this.bar()] = function () {
|
||||
},
|
||||
_a);
|
||||
return 0;
|
||||
var _a;
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
|
|
|
@ -15,7 +15,8 @@ var C = (function () {
|
|||
C.prototype.bar = function () {
|
||||
return 0;
|
||||
};
|
||||
C.prototype[{ [this.bar()]: 1 }[0]] = function () {
|
||||
C.prototype[(_a = {}, _a[this.bar()] = 1, _a)[0]] = function () {
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
var _a;
|
||||
|
|
|
@ -34,11 +34,12 @@ var C = (function (_super) {
|
|||
_super.apply(this, arguments);
|
||||
}
|
||||
C.prototype.foo = function () {
|
||||
var obj = {
|
||||
[_super.prototype.bar.call(this)]: function () {
|
||||
}
|
||||
};
|
||||
var obj = (_a = {},
|
||||
_a[_super.prototype.bar.call(this)] = function () {
|
||||
},
|
||||
_a);
|
||||
return 0;
|
||||
var _a;
|
||||
};
|
||||
return C;
|
||||
})(Base);
|
||||
|
|
|
@ -34,7 +34,8 @@ var C = (function (_super) {
|
|||
}
|
||||
// Gets emitted as super, not _super, which is consistent with
|
||||
// use of super in static properties initializers.
|
||||
C.prototype[{ [super.bar.call(this)]: 1 }[0]] = function () {
|
||||
C.prototype[(_a = {}, _a[super.bar.call(this)] = 1, _a)[0]] = function () {
|
||||
};
|
||||
return C;
|
||||
})(Base);
|
||||
var _a;
|
||||
|
|
|
@ -26,10 +26,11 @@ var C = (function (_super) {
|
|||
__extends(C, _super);
|
||||
function C() {
|
||||
_super.call(this);
|
||||
var obj = {
|
||||
[(_super.call(this), "prop")]: function () {
|
||||
}
|
||||
};
|
||||
var obj = (_a = {},
|
||||
_a[(_super.call(this), "prop")] = function () {
|
||||
},
|
||||
_a);
|
||||
var _a;
|
||||
}
|
||||
return C;
|
||||
})(Base);
|
||||
|
|
|
@ -17,10 +17,11 @@ var C = (function () {
|
|||
C.prototype.bar = function () {
|
||||
var _this = this;
|
||||
(function () {
|
||||
var obj = {
|
||||
[_this.bar()]: function () {
|
||||
} // needs capture
|
||||
};
|
||||
var obj = (_a = {},
|
||||
_a[_this.bar()] = function () {
|
||||
},
|
||||
_a);
|
||||
var _a;
|
||||
});
|
||||
return 0;
|
||||
};
|
||||
|
|
|
@ -32,13 +32,14 @@ var C = (function (_super) {
|
|||
function C() {
|
||||
_super.call(this);
|
||||
(function () {
|
||||
var obj = {
|
||||
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.
|
||||
[(_super.call(this), "prop")]: function () {
|
||||
}
|
||||
};
|
||||
_a[(_super.call(this), "prop")] = function () {
|
||||
},
|
||||
_a);
|
||||
var _a;
|
||||
});
|
||||
}
|
||||
return C;
|
||||
|
|
|
@ -38,10 +38,11 @@ var C = (function (_super) {
|
|||
C.prototype.foo = function () {
|
||||
var _this = this;
|
||||
(function () {
|
||||
var obj = {
|
||||
[_super.prototype.bar.call(_this)]: function () {
|
||||
} // needs capture
|
||||
};
|
||||
var obj = (_a = {},
|
||||
_a[_super.prototype.bar.call(_this)] = function () {
|
||||
},
|
||||
_a);
|
||||
var _a;
|
||||
});
|
||||
return 0;
|
||||
};
|
||||
|
|
|
@ -17,11 +17,12 @@ var C = (function () {
|
|||
function C() {
|
||||
}
|
||||
C.prototype.bar = function () {
|
||||
var obj = {
|
||||
[foo()]: function () {
|
||||
}
|
||||
};
|
||||
var obj = (_a = {},
|
||||
_a[foo()] = function () {
|
||||
},
|
||||
_a);
|
||||
return 0;
|
||||
var _a;
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
|
|
|
@ -17,11 +17,12 @@ var C = (function () {
|
|||
function C() {
|
||||
}
|
||||
C.bar = function () {
|
||||
var obj = {
|
||||
[foo()]: function () {
|
||||
}
|
||||
};
|
||||
var obj = (_a = {},
|
||||
_a[foo()] = function () {
|
||||
},
|
||||
_a);
|
||||
return 0;
|
||||
var _a;
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
|
|
|
@ -4,6 +4,7 @@ var o = {
|
|||
};
|
||||
|
||||
//// [computedPropertyNames46_ES5.js]
|
||||
var o = {
|
||||
["" || 0]: 0
|
||||
};
|
||||
var o = (_a = {},
|
||||
_a["" || 0] = 0,
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -14,6 +14,7 @@ var E2;
|
|||
(function (E2) {
|
||||
E2[E2["x"] = 0] = "x";
|
||||
})(E2 || (E2 = {}));
|
||||
var o = {
|
||||
[0 /* x */ || 0 /* x */]: 0
|
||||
};
|
||||
var o = (_a = {},
|
||||
_a[0 /* x */ || 0 /* x */] = 0,
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -23,12 +23,13 @@ var E;
|
|||
E[E["x"] = 0] = "x";
|
||||
})(E || (E = {}));
|
||||
var a;
|
||||
extractIndexer({
|
||||
[a]: ""
|
||||
}); // Should return string
|
||||
extractIndexer({
|
||||
[0 /* x */]: ""
|
||||
}); // Should return string
|
||||
extractIndexer({
|
||||
["" || 0]: ""
|
||||
}); // 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;
|
||||
|
|
|
@ -20,16 +20,17 @@ var v = {
|
|||
var s;
|
||||
var n;
|
||||
var a;
|
||||
var v = {
|
||||
[s]: 0,
|
||||
[n]: n,
|
||||
[s + s]: 1,
|
||||
[s + n]: 2,
|
||||
[+s]: s,
|
||||
[""]: 0,
|
||||
[0]: 0,
|
||||
[a]: 1,
|
||||
[true]: 0,
|
||||
["hello bye"]: 0,
|
||||
["hello " + a + " bye"]: 0
|
||||
};
|
||||
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;
|
||||
|
|
|
@ -11,11 +11,12 @@ var v = {
|
|||
|
||||
//// [computedPropertyNames5_ES5.js]
|
||||
var b;
|
||||
var v = {
|
||||
[b]: 0,
|
||||
[true]: 1,
|
||||
[[]]: 0,
|
||||
[{}]: 0,
|
||||
[undefined]: undefined,
|
||||
[null]: null
|
||||
};
|
||||
var v = (_a = {},
|
||||
_a[b] = 0,
|
||||
_a[true] = 1,
|
||||
_a[[]] = 0,
|
||||
_a[{}] = 0,
|
||||
_a[undefined] = undefined,
|
||||
_a[null] = null,
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -12,8 +12,9 @@ var v = {
|
|||
var p1;
|
||||
var p2;
|
||||
var p3;
|
||||
var v = {
|
||||
[p1]: 0,
|
||||
[p2]: 1,
|
||||
[p3]: 2
|
||||
};
|
||||
var v = (_a = {},
|
||||
_a[p1] = 0,
|
||||
_a[p2] = 1,
|
||||
_a[p3] = 2,
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -11,6 +11,7 @@ var E;
|
|||
(function (E) {
|
||||
E[E["member"] = 0] = "member";
|
||||
})(E || (E = {}));
|
||||
var v = {
|
||||
[0 /* member */]: 0
|
||||
};
|
||||
var v = (_a = {},
|
||||
_a[0 /* member */] = 0,
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -12,8 +12,9 @@ function f<T, U extends string>() {
|
|||
function f() {
|
||||
var t;
|
||||
var u;
|
||||
var v = {
|
||||
[t]: 0,
|
||||
[u]: 1
|
||||
};
|
||||
var v = (_a = {},
|
||||
_a[t] = 0,
|
||||
_a[u] = 1,
|
||||
_a);
|
||||
var _a;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,9 @@ var v = {
|
|||
//// [computedPropertyNames9_ES5.js]
|
||||
function f(x) {
|
||||
}
|
||||
var v = {
|
||||
[f("")]: 0,
|
||||
[f(0)]: 0,
|
||||
[f(true)]: 0
|
||||
};
|
||||
var v = (_a = {},
|
||||
_a[f("")] = 0,
|
||||
_a[f(0)] = 0,
|
||||
_a[f(true)] = 0,
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -9,7 +9,8 @@ var o: I = {
|
|||
}
|
||||
|
||||
//// [computedPropertyNamesContextualType10_ES5.js]
|
||||
var o = {
|
||||
[+"foo"]: "",
|
||||
[+"bar"]: 0
|
||||
};
|
||||
var o = (_a = {},
|
||||
_a[+"foo"] = "",
|
||||
_a[+"bar"] = 0,
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -10,9 +10,10 @@ var o: I = {
|
|||
}
|
||||
|
||||
//// [computedPropertyNamesContextualType1_ES5.js]
|
||||
var o = {
|
||||
["" + 0]: function (y) {
|
||||
var o = (_a = {},
|
||||
_a["" + 0] = function (y) {
|
||||
return y.length;
|
||||
},
|
||||
["" + 1]: function (y) { return y.length; }
|
||||
};
|
||||
_a["" + 1] = function (y) { return y.length; },
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -10,9 +10,10 @@ var o: I = {
|
|||
}
|
||||
|
||||
//// [computedPropertyNamesContextualType2_ES5.js]
|
||||
var o = {
|
||||
[+"foo"]: function (y) {
|
||||
var o = (_a = {},
|
||||
_a[+"foo"] = function (y) {
|
||||
return y.length;
|
||||
},
|
||||
[+"bar"]: function (y) { return y.length; }
|
||||
};
|
||||
_a[+"bar"] = function (y) { return y.length; },
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -9,9 +9,10 @@ var o: I = {
|
|||
}
|
||||
|
||||
//// [computedPropertyNamesContextualType3_ES5.js]
|
||||
var o = {
|
||||
[+"foo"]: function (y) {
|
||||
var o = (_a = {},
|
||||
_a[+"foo"] = function (y) {
|
||||
return y.length;
|
||||
},
|
||||
[+"bar"]: function (y) { return y.length; }
|
||||
};
|
||||
_a[+"bar"] = function (y) { return y.length; },
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -10,7 +10,8 @@ var o: I = {
|
|||
}
|
||||
|
||||
//// [computedPropertyNamesContextualType4_ES5.js]
|
||||
var o = {
|
||||
["" + "foo"]: "",
|
||||
["" + "bar"]: 0
|
||||
};
|
||||
var o = (_a = {},
|
||||
_a["" + "foo"] = "",
|
||||
_a["" + "bar"] = 0,
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -10,7 +10,8 @@ var o: I = {
|
|||
}
|
||||
|
||||
//// [computedPropertyNamesContextualType5_ES5.js]
|
||||
var o = {
|
||||
[+"foo"]: "",
|
||||
[+"bar"]: 0
|
||||
};
|
||||
var o = (_a = {},
|
||||
_a[+"foo"] = "",
|
||||
_a[+"bar"] = 0,
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -14,11 +14,13 @@ foo({
|
|||
});
|
||||
|
||||
//// [computedPropertyNamesContextualType6_ES5.js]
|
||||
foo({
|
||||
foo((_a = {
|
||||
p: "",
|
||||
0: function () {
|
||||
},
|
||||
["hi" + "bye"]: true,
|
||||
[0 + 1]: 0,
|
||||
[+"hi"]: [0]
|
||||
});
|
||||
}
|
||||
},
|
||||
_a["hi" + "bye"] = true,
|
||||
_a[0 + 1] = 0,
|
||||
_a[+"hi"] = [0],
|
||||
_a));
|
||||
var _a;
|
||||
|
|
|
@ -14,11 +14,13 @@ foo({
|
|||
});
|
||||
|
||||
//// [computedPropertyNamesContextualType7_ES5.js]
|
||||
foo({
|
||||
foo((_a = {
|
||||
p: "",
|
||||
0: function () {
|
||||
},
|
||||
["hi" + "bye"]: true,
|
||||
[0 + 1]: 0,
|
||||
[+"hi"]: [0]
|
||||
});
|
||||
}
|
||||
},
|
||||
_a["hi" + "bye"] = true,
|
||||
_a[0 + 1] = 0,
|
||||
_a[+"hi"] = [0],
|
||||
_a));
|
||||
var _a;
|
||||
|
|
|
@ -10,7 +10,8 @@ var o: I = {
|
|||
}
|
||||
|
||||
//// [computedPropertyNamesContextualType8_ES5.js]
|
||||
var o = {
|
||||
["" + "foo"]: "",
|
||||
["" + "bar"]: 0
|
||||
};
|
||||
var o = (_a = {},
|
||||
_a["" + "foo"] = "",
|
||||
_a["" + "bar"] = 0,
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -10,7 +10,8 @@ var o: I = {
|
|||
}
|
||||
|
||||
//// [computedPropertyNamesContextualType9_ES5.js]
|
||||
var o = {
|
||||
[+"foo"]: "",
|
||||
[+"bar"]: 0
|
||||
};
|
||||
var o = (_a = {},
|
||||
_a[+"foo"] = "",
|
||||
_a[+"bar"] = 0,
|
||||
_a);
|
||||
var _a;
|
||||
|
|
|
@ -7,16 +7,25 @@ var v = {
|
|||
}
|
||||
|
||||
//// [computedPropertyNamesDeclarationEmit5_ES5.js]
|
||||
var v = {
|
||||
["" + ""]: 0,
|
||||
["" + ""]: function () {
|
||||
var v = (_a = {},
|
||||
_a["" + ""] = 0,
|
||||
_a["" + ""] = function () {
|
||||
},
|
||||
get ["" + ""]() {
|
||||
return 0;
|
||||
},
|
||||
set ["" + ""](x) {
|
||||
}
|
||||
};
|
||||
Object.defineProperty(_a, "" + "", {
|
||||
get: function () {
|
||||
return 0;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
}),
|
||||
Object.defineProperty(_a, "" + "", {
|
||||
set: function (x) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
}),
|
||||
_a);
|
||||
var _a;
|
||||
|
||||
|
||||
//// [computedPropertyNamesDeclarationEmit5_ES5.d.ts]
|
||||
|
|
|
@ -6,9 +6,10 @@ var v = {
|
|||
}
|
||||
|
||||
//// [computedPropertyNamesSourceMap2_ES5.js]
|
||||
var v = {
|
||||
["hello"]: function () {
|
||||
var v = (_a = {},
|
||||
_a["hello"] = function () {
|
||||
debugger;
|
||||
}
|
||||
};
|
||||
},
|
||||
_a);
|
||||
var _a;
|
||||
//# sourceMappingURL=computedPropertyNamesSourceMap2_ES5.js.map
|
|
@ -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;IACJ,CAAC,OAAO,CAAC;QACLA,QAAQA,CAACA;IACbA,CAACA;CACJ,CAAA"}
|
||||
{"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"}
|
|
@ -8,36 +8,49 @@ sources: computedPropertyNamesSourceMap2_ES5.ts
|
|||
emittedFile:tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap2_ES5.js
|
||||
sourceFile:computedPropertyNamesSourceMap2_ES5.ts
|
||||
-------------------------------------------------------------------
|
||||
>>>var v = {
|
||||
>>>var v = (_a = {},
|
||||
1 >
|
||||
2 >^^^^
|
||||
3 > ^
|
||||
4 > ^^^
|
||||
5 > ^^^^^^^^^^^^^^^^^^^^^->
|
||||
5 > ^
|
||||
6 > ^^
|
||||
7 > ^^^^^^^^^^^^^^^^^^^^^->
|
||||
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)
|
||||
---
|
||||
>>> ["hello"]: function () {
|
||||
>>> _a["hello"] = function () {
|
||||
1->^^^^
|
||||
2 > ^
|
||||
3 > ^^^^^^^
|
||||
4 > ^
|
||||
5 > ^^^^^->
|
||||
1->{
|
||||
2 >
|
||||
3 > ^^
|
||||
4 > ^
|
||||
5 > ^^^^^^^
|
||||
6 > ^
|
||||
7 > ^^^->
|
||||
1->var v = {
|
||||
>
|
||||
2 > [
|
||||
3 > "hello"
|
||||
4 > ]
|
||||
2 >
|
||||
3 >
|
||||
4 > var v = {
|
||||
> [
|
||||
5 > "hello"
|
||||
6 > ]
|
||||
1->Emitted(2, 5) Source(2, 5) + SourceIndex(0)
|
||||
2 >Emitted(2, 6) Source(2, 6) + SourceIndex(0)
|
||||
3 >Emitted(2, 13) Source(2, 13) + SourceIndex(0)
|
||||
4 >Emitted(2, 14) Source(2, 14) + 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->^^^^^^^^
|
||||
|
@ -51,23 +64,41 @@ sourceFile:computedPropertyNamesSourceMap2_ES5.ts
|
|||
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"])
|
||||
---
|
||||
>>>};
|
||||
1 >^
|
||||
2 > ^
|
||||
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
|
||||
1 >
|
||||
>}
|
||||
2 >
|
||||
1 >Emitted(5, 2) Source(5, 2) + SourceIndex(0)
|
||||
2 >Emitted(5, 3) Source(5, 2) + SourceIndex(0)
|
||||
>>> _a);
|
||||
1->^^^^
|
||||
2 > ^^
|
||||
3 > ^
|
||||
4 > ^
|
||||
1->
|
||||
2 >
|
||||
3 > var v = {
|
||||
> ["hello"]() {
|
||||
> debugger;
|
||||
> }
|
||||
> }
|
||||
4 >
|
||||
1->Emitted(5, 5) Source(1, 1) + SourceIndex(0)
|
||||
2 >Emitted(5, 7) Source(1, 1) + SourceIndex(0)
|
||||
3 >Emitted(5, 8) Source(5, 2) + SourceIndex(0)
|
||||
4 >Emitted(5, 9) Source(5, 2) + SourceIndex(0)
|
||||
---
|
||||
>>>var _a;
|
||||
1 >^^^^
|
||||
2 > ^^
|
||||
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
|
||||
1 >
|
||||
2 >
|
||||
1 >Emitted(6, 5) Source(1, 1) + SourceIndex(0)
|
||||
2 >Emitted(6, 7) Source(1, 1) + SourceIndex(0)
|
||||
---
|
||||
>>>//# sourceMappingURL=computedPropertyNamesSourceMap2_ES5.js.map
|
|
@ -2,4 +2,5 @@
|
|||
var v = { [e]: 1 };
|
||||
|
||||
//// [parserES5ComputedPropertyName2.js]
|
||||
var v = { [e]: 1 };
|
||||
var v = (_a = {}, _a[e] = 1, _a);
|
||||
var _a;
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
var v = { [e]() { } };
|
||||
|
||||
//// [parserES5ComputedPropertyName3.js]
|
||||
var v = { [e]: function () {
|
||||
} };
|
||||
var v = (_a = {}, _a[e] = function () {
|
||||
}, _a);
|
||||
var _a;
|
||||
|
|
|
@ -2,5 +2,9 @@
|
|||
var v = { get [e]() { } };
|
||||
|
||||
//// [parserES5ComputedPropertyName4.js]
|
||||
var v = { get [e]() {
|
||||
} };
|
||||
var v = (_a = {}, Object.defineProperty(_a, e, {
|
||||
get: function () {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true, }), _a);
|
||||
var _a;
|
||||
|
|
|
@ -11,8 +11,9 @@ var y: {
|
|||
|
||||
//// [privateIndexer2.js]
|
||||
// private indexers not allowed
|
||||
var x = {
|
||||
[x]: string,
|
||||
string:
|
||||
};
|
||||
var x = (_a = {},
|
||||
_a[x] = string,
|
||||
_a.string = ,
|
||||
_a);
|
||||
var y;
|
||||
var _a;
|
||||
|
|
Loading…
Reference in a new issue