From a38e76b882aaf5ce15eabba2b267723a2471a6b1 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 2 Dec 2014 13:29:49 -0800 Subject: [PATCH] Address codereview --- src/compiler/emitter.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 303ca6264cb..e71e7920476 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -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(node); @@ -3542,8 +3549,9 @@ module ts { return emitShorthandPropertyAssignmentAsNormalPropertyAssignment(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(node);