Visit vardecl initializer in converted loop

This commit is contained in:
Ron Buckton 2016-09-30 15:46:35 -07:00
parent 09712124f4
commit 6c1cec5c3a
5 changed files with 56 additions and 1 deletions

View file

@ -1689,7 +1689,7 @@ namespace ts {
assignment = flattenVariableDestructuringToExpression(context, decl, hoistVariableDeclaration, /*nameSubstitution*/ undefined, visitor);
}
else {
assignment = createBinary(<Identifier>decl.name, SyntaxKind.EqualsToken, decl.initializer);
assignment = createBinary(<Identifier>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;

View file

@ -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();
}

View file

@ -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))
}

View file

@ -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
}

View file

@ -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()
}