From 6c1cec5c3a93bdd05844243dc20034cef87309ed Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 30 Sep 2016 15:46:35 -0700 Subject: [PATCH] Visit vardecl initializer in converted loop --- src/compiler/transformers/es6.ts | 3 ++- ...ormArrowInBlockScopedLoopVarInitializer.js | 19 +++++++++++++++++++ ...rowInBlockScopedLoopVarInitializer.symbols | 12 ++++++++++++ ...ArrowInBlockScopedLoopVarInitializer.types | 15 +++++++++++++++ ...ormArrowInBlockScopedLoopVarInitializer.ts | 8 ++++++++ 5 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/transformArrowInBlockScopedLoopVarInitializer.js create mode 100644 tests/baselines/reference/transformArrowInBlockScopedLoopVarInitializer.symbols create mode 100644 tests/baselines/reference/transformArrowInBlockScopedLoopVarInitializer.types create mode 100644 tests/cases/compiler/transformArrowInBlockScopedLoopVarInitializer.ts diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index 4f2720c150..7746dcc9c8 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -1689,7 +1689,7 @@ namespace ts { assignment = flattenVariableDestructuringToExpression(context, decl, hoistVariableDeclaration, /*nameSubstitution*/ undefined, visitor); } else { - assignment = createBinary(decl.name, SyntaxKind.EqualsToken, decl.initializer); + assignment = createBinary(decl.name, SyntaxKind.EqualsToken, visitNode(decl.initializer, visitor, isExpression)); } (assignments || (assignments = [])).push(assignment); } @@ -2201,6 +2201,7 @@ namespace ts { } } + debugger; let loopBody = visitNode(node.statement, visitor, isStatement); const currentState = convertedLoopState; diff --git a/tests/baselines/reference/transformArrowInBlockScopedLoopVarInitializer.js b/tests/baselines/reference/transformArrowInBlockScopedLoopVarInitializer.js new file mode 100644 index 0000000000..4f2e166627 --- /dev/null +++ b/tests/baselines/reference/transformArrowInBlockScopedLoopVarInitializer.js @@ -0,0 +1,19 @@ +//// [transformArrowInBlockScopedLoopVarInitializer.ts] + +// https://github.com/Microsoft/TypeScript/issues/11236 +while (true) +{ + let local = null; + var a = () => local; // <-- Lambda should be converted to function() +} + +//// [transformArrowInBlockScopedLoopVarInitializer.js] +var _loop_1 = function () { + var local = null; + a = function () { return local; }; // <-- Lambda should be converted to function() +}; +var a; +// https://github.com/Microsoft/TypeScript/issues/11236 +while (true) { + _loop_1(); +} diff --git a/tests/baselines/reference/transformArrowInBlockScopedLoopVarInitializer.symbols b/tests/baselines/reference/transformArrowInBlockScopedLoopVarInitializer.symbols new file mode 100644 index 0000000000..4c5e2cf686 --- /dev/null +++ b/tests/baselines/reference/transformArrowInBlockScopedLoopVarInitializer.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/transformArrowInBlockScopedLoopVarInitializer.ts === + +// https://github.com/Microsoft/TypeScript/issues/11236 +while (true) +{ + let local = null; +>local : Symbol(local, Decl(transformArrowInBlockScopedLoopVarInitializer.ts, 4, 7)) + + var a = () => local; // <-- Lambda should be converted to function() +>a : Symbol(a, Decl(transformArrowInBlockScopedLoopVarInitializer.ts, 5, 7)) +>local : Symbol(local, Decl(transformArrowInBlockScopedLoopVarInitializer.ts, 4, 7)) +} diff --git a/tests/baselines/reference/transformArrowInBlockScopedLoopVarInitializer.types b/tests/baselines/reference/transformArrowInBlockScopedLoopVarInitializer.types new file mode 100644 index 0000000000..6c6769dadb --- /dev/null +++ b/tests/baselines/reference/transformArrowInBlockScopedLoopVarInitializer.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/transformArrowInBlockScopedLoopVarInitializer.ts === + +// https://github.com/Microsoft/TypeScript/issues/11236 +while (true) +>true : true +{ + let local = null; +>local : any +>null : null + + var a = () => local; // <-- Lambda should be converted to function() +>a : () => any +>() => local : () => any +>local : any +} diff --git a/tests/cases/compiler/transformArrowInBlockScopedLoopVarInitializer.ts b/tests/cases/compiler/transformArrowInBlockScopedLoopVarInitializer.ts new file mode 100644 index 0000000000..4f496dc6af --- /dev/null +++ b/tests/cases/compiler/transformArrowInBlockScopedLoopVarInitializer.ts @@ -0,0 +1,8 @@ +// @target: es5 + +// https://github.com/Microsoft/TypeScript/issues/11236 +while (true) +{ + let local = null; + var a = () => local; // <-- Lambda should be converted to function() +} \ No newline at end of file