Address codereview

This commit is contained in:
Yui T 2014-12-02 13:29:49 -08:00
parent e429bd9ba0
commit a38e76b882

View File

@ -2202,14 +2202,21 @@ module ts {
// Emit identifier as an identifier
emit(node.name);
write(": ");
// Even though this is stored as identified because it is in short-hand property assignment,
// treated it as expression
// Even though this is stored as identifier treat it as an expression
// Short-hand, { x }, is equivalent of normal form { x: x }
emitExpressionIdentifier(node.name);
emitTrailingComments(node);
}
function emitShorthandPropertyAssignment(node: ShorthandPropertyDeclaration) {
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example:
// module m {
// export var y;
// }
// module m {
// export var obj = { y };
// }
// The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version
var prefix = resolver.getExpressionNamePrefix(node.name);
if (prefix) {
emitShorthandPropertyAssignmentAsNormalPropertyAssignment(node);
@ -3408,7 +3415,7 @@ module ts {
return emitPinnedOrTripleSlashComments(node);
}
// Check if node has SyntaxKind which can be emitted regardless of the ScriptTarget
// Check if the node can be emitted regardless of the ScriptTarget
switch (node.kind) {
case SyntaxKind.Identifier:
return emitIdentifier(<Identifier>node);
@ -3542,8 +3549,9 @@ module ts {
return emitShorthandPropertyAssignmentAsNormalPropertyAssignment(<ShorthandPropertyDeclaration>node);
}
}
else if (compilerOptions.target >= ScriptTarget.ES6) {
else {
// Emit node natively
Debug.assert(compilerOptions.target >= ScriptTarget.ES6, "Invalid ScriptTarget. We should emit as ES6 or above");
switch (node.kind) {
case SyntaxKind.ShorthandPropertyAssignment:
return emitShorthandPropertyAssignment(<ShorthandPropertyDeclaration>node);