From 0f16e68335a291d98980e194be06fc5bbd2143cd Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 16 Feb 2016 16:01:14 -0800 Subject: [PATCH] PR Feedback --- src/compiler/factory.ts | 9 +++++---- src/compiler/transformer.ts | 17 ++++++++++------- src/compiler/types.ts | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 8b81d7d0d2..08441ac685 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -180,6 +180,7 @@ namespace ts { block.statements = createNodeArray(statements); return block; } + export function createVariableDeclaration(name: BindingPattern | Identifier, initializer?: Expression, location?: TextRange): VariableDeclaration { const node = createNode(SyntaxKind.VariableDeclaration, location); node.name = name; @@ -203,17 +204,17 @@ namespace ts { export function createLiteral(value: string): StringLiteral; export function createLiteral(value: number): LiteralExpression; export function createLiteral(value: string | number | boolean): PrimaryExpression; - export function createLiteral(value: string | number | boolean): T { + export function createLiteral(value: string | number | boolean): PrimaryExpression { if (typeof value === "number") { - const node = createNode(SyntaxKind.NumericLiteral); + const node = createNode(SyntaxKind.NumericLiteral); node.text = value.toString(); return node; } else if (typeof value === "boolean") { - return createNode(value ? SyntaxKind.TrueKeyword : SyntaxKind.FalseKeyword); + return createNode(value ? SyntaxKind.TrueKeyword : SyntaxKind.FalseKeyword); } else { - const node = createNode(SyntaxKind.StringLiteral); + const node = createNode(SyntaxKind.StringLiteral); node.text = String(value); return node; } diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index 5be2c7a41b..60f985cd6d 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -223,14 +223,16 @@ namespace ts { } /** - * Records a hoisted variable declaration within a lexical environment. + * Records a hoisted variable declaration for the provided name within a lexical environment. */ function hoistVariableDeclaration(name: Identifier): void { + const decl = createVariableDeclaration(name); if (!hoistedVariableDeclarations) { - hoistedVariableDeclarations = []; + hoistedVariableDeclarations = [decl]; + } + else { + hoistedVariableDeclarations.push(decl); } - - hoistedVariableDeclarations.push(createVariableDeclaration(name)); } /** @@ -238,10 +240,11 @@ namespace ts { */ function hoistFunctionDeclaration(func: FunctionDeclaration): void { if (!hoistedFunctionDeclarations) { - hoistedFunctionDeclarations = []; + hoistedFunctionDeclarations = [func]; + } + else { + hoistedFunctionDeclarations.push(func); } - - hoistedFunctionDeclarations.push(func); } /** diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f9e48e8c8a..2b275ea9ca 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2795,7 +2795,7 @@ namespace ts { EmitSuperHelper = 1 << 2, // Emit the basic _super helper for async methods. EmitAdvancedSuperHelper = 1 << 3, // Emit the advanced _super helper for async methods. UMDDefine = 1 << 4, // This node should be replaced with the UMD define helper. - NoLexicalEnvironment = 1 << 5, // A new LexicalEnvironment should *not* be introduced when emitting this node. + NoLexicalEnvironment = 1 << 5, // A new LexicalEnvironment should *not* be introduced when emitting this node, this is primarily used when printing a SystemJS module. SingleLine = 1 << 6, // The contents of this node should be emit on a single line. MultiLine = 1 << 7, // The contents of this node should be emit on multiple lines. AdviseOnEmitNode = 1 << 8, // The node printer should invoke the onBeforeEmitNode and onAfterEmitNode callbacks when printing this node.