Emit FunctionPropertyAssignments in their native form when emitting in ES6 mode.

This commit is contained in:
Cyrus Najmabadi 2014-12-03 02:09:15 -08:00
parent 44f30c8ba9
commit d5ef6226da
8 changed files with 32 additions and 14 deletions

View File

@ -3244,7 +3244,7 @@ module ts {
switch (node.kind) {
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
return !(<FunctionExpression>node).typeParameters && !forEach((<FunctionExpression>node).parameters, p => p.type);
return isContextSensitiveFunctionLikeDeclaration(<FunctionExpression>node);
case SyntaxKind.ObjectLiteralExpression:
return forEach((<ObjectLiteralExpression>node).properties, isContextSensitiveExpression);
case SyntaxKind.ArrayLiteralExpression:
@ -3259,7 +3259,7 @@ module ts {
return isContextSensitiveExpression((<LonghandPropertyAssignment>node).initializer);
case SyntaxKind.Method:
if (isObjectLiteralMethod(node)) {
return !(<MethodDeclaration>node).typeParameters && !forEach((<MethodDeclaration>node).parameters, p => p.type);
return isContextSensitiveFunctionLikeDeclaration(<MethodDeclaration>node);
}
return false;
}
@ -3267,6 +3267,10 @@ module ts {
return false;
}
function isContextSensitiveFunctionLikeDeclaration(node: FunctionLikeDeclaration) {
return !(<MethodDeclaration>node).typeParameters && !forEach((<MethodDeclaration>node).parameters, p => p.type);
}
function getTypeWithoutConstructors(type: Type): Type {
if (type.flags & TypeFlags.ObjectType) {
var resolved = resolveObjectOrUnionTypeMembers(<ObjectType>type);

View File

@ -2228,7 +2228,11 @@ module ts {
write("]");
}
function emitObjectLiteralMethod(node: MethodDeclaration) {
function emitDownlevelMethod(node: MethodDeclaration) {
if (!isObjectLiteralMethod(node)) {
return;
}
emitLeadingComments(node);
emit(node.name);
write(": ");
@ -2236,6 +2240,17 @@ module ts {
emitSignatureAndBody(node);
emitTrailingComments(node);
}
function emitMethod(node: MethodDeclaration) {
if (!isObjectLiteralMethod(node)) {
return;
}
emitLeadingComments(node);
emit(node.name);
emitSignatureAndBody(node);
emitTrailingComments(node);
}
function emitPropertyAssignment(node: PropertyDeclaration) {
emitLeadingComments(node);
@ -3536,11 +3551,6 @@ module ts {
return emitObjectLiteral(<ObjectLiteralExpression>node);
case SyntaxKind.LonghandPropertyAssignment:
return emitPropertyAssignment(<PropertyDeclaration>node);
case SyntaxKind.Method:
if (isObjectLiteralMethod(node)) {
return emitObjectLiteralMethod(<MethodDeclaration>node);
}
break;
case SyntaxKind.ComputedPropertyName:
return emitComputedPropertyName(<ComputedPropertyName>node);
case SyntaxKind.PropertyAccessExpression:
@ -3643,6 +3653,8 @@ module ts {
switch (node.kind) {
case SyntaxKind.ShorthandPropertyAssignment:
return emitDownlevelShorthandPropertyAssignment(<ShorthandPropertyAssignment>node);
case SyntaxKind.Method:
return emitDownlevelMethod(<MethodDeclaration>node);
}
}
else {
@ -3651,6 +3663,8 @@ module ts {
switch (node.kind) {
case SyntaxKind.ShorthandPropertyAssignment:
return emitShorthandPropertyAssignment(<ShorthandPropertyAssignment>node);
case SyntaxKind.Method:
return emitMethod(<MethodDeclaration>node);
}
}
}

View File

@ -265,7 +265,7 @@ var C = (function () {
})();
// object literals
var o = {
f: function () {
f() {
const c = 0;
n = c;
},

View File

@ -220,7 +220,7 @@ var C = (function () {
})();
// object literals
var o = {
f: function () {
f() {
const c28 = 0;
},
f2: function () {

View File

@ -282,7 +282,7 @@ var C = (function () {
})();
// object literals
var o = {
f: function () {
f() {
let l = 0;
n = l;
},

View File

@ -240,7 +240,7 @@ var C = (function () {
})();
// object literals
var o = {
f: function () {
f() {
let l28 = 0;
},
f2: function () {

View File

@ -32,7 +32,7 @@ var x3 = {
a: 0,
b,
c,
d: function () {
d() {
},
x3,
parent: x3

View File

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