mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Emit FunctionPropertyAssignments in their native form when emitting in ES6 mode.
This commit is contained in:
parent
44f30c8ba9
commit
d5ef6226da
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ var C = (function () {
|
||||
})();
|
||||
// object literals
|
||||
var o = {
|
||||
f: function () {
|
||||
f() {
|
||||
const c = 0;
|
||||
n = c;
|
||||
},
|
||||
|
||||
@ -220,7 +220,7 @@ var C = (function () {
|
||||
})();
|
||||
// object literals
|
||||
var o = {
|
||||
f: function () {
|
||||
f() {
|
||||
const c28 = 0;
|
||||
},
|
||||
f2: function () {
|
||||
|
||||
@ -282,7 +282,7 @@ var C = (function () {
|
||||
})();
|
||||
// object literals
|
||||
var o = {
|
||||
f: function () {
|
||||
f() {
|
||||
let l = 0;
|
||||
n = l;
|
||||
},
|
||||
|
||||
@ -240,7 +240,7 @@ var C = (function () {
|
||||
})();
|
||||
// object literals
|
||||
var o = {
|
||||
f: function () {
|
||||
f() {
|
||||
let l28 = 0;
|
||||
},
|
||||
f2: function () {
|
||||
|
||||
@ -32,7 +32,7 @@ var x3 = {
|
||||
a: 0,
|
||||
b,
|
||||
c,
|
||||
d: function () {
|
||||
d() {
|
||||
},
|
||||
x3,
|
||||
parent: x3
|
||||
|
||||
@ -2,5 +2,5 @@
|
||||
var v = { [e]() { } };
|
||||
|
||||
//// [parserComputedPropertyName3.js]
|
||||
var v = { [e]: function () {
|
||||
var v = { [e]() {
|
||||
} };
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user