Skip to content

Commit d1ac8dd

Browse files
authored
Merge pull request microsoft#11288 from Microsoft/fix11236
Visit VariableDeclaration initializer in converted loop
2 parents c302893 + fecd9c3 commit d1ac8dd

5 files changed

+55
-1
lines changed

src/compiler/transformers/es6.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1689,7 +1689,7 @@ namespace ts {
16891689
assignment = flattenVariableDestructuringToExpression(context, decl, hoistVariableDeclaration, /*nameSubstitution*/ undefined, visitor);
16901690
}
16911691
else {
1692-
assignment = createBinary(<Identifier>decl.name, SyntaxKind.EqualsToken, decl.initializer);
1692+
assignment = createBinary(<Identifier>decl.name, SyntaxKind.EqualsToken, visitNode(decl.initializer, visitor, isExpression));
16931693
}
16941694
(assignments || (assignments = [])).push(assignment);
16951695
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [transformArrowInBlockScopedLoopVarInitializer.ts]
2+
3+
// https://github.com/Microsoft/TypeScript/issues/11236
4+
while (true)
5+
{
6+
let local = null;
7+
var a = () => local; // <-- Lambda should be converted to function()
8+
}
9+
10+
//// [transformArrowInBlockScopedLoopVarInitializer.js]
11+
var _loop_1 = function () {
12+
var local = null;
13+
a = function () { return local; }; // <-- Lambda should be converted to function()
14+
};
15+
var a;
16+
// https://github.com/Microsoft/TypeScript/issues/11236
17+
while (true) {
18+
_loop_1();
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/transformArrowInBlockScopedLoopVarInitializer.ts ===
2+
3+
// https://github.com/Microsoft/TypeScript/issues/11236
4+
while (true)
5+
{
6+
let local = null;
7+
>local : Symbol(local, Decl(transformArrowInBlockScopedLoopVarInitializer.ts, 4, 7))
8+
9+
var a = () => local; // <-- Lambda should be converted to function()
10+
>a : Symbol(a, Decl(transformArrowInBlockScopedLoopVarInitializer.ts, 5, 7))
11+
>local : Symbol(local, Decl(transformArrowInBlockScopedLoopVarInitializer.ts, 4, 7))
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/compiler/transformArrowInBlockScopedLoopVarInitializer.ts ===
2+
3+
// https://github.com/Microsoft/TypeScript/issues/11236
4+
while (true)
5+
>true : true
6+
{
7+
let local = null;
8+
>local : any
9+
>null : null
10+
11+
var a = () => local; // <-- Lambda should be converted to function()
12+
>a : () => any
13+
>() => local : () => any
14+
>local : any
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: es5
2+
3+
// https://github.com/Microsoft/TypeScript/issues/11236
4+
while (true)
5+
{
6+
let local = null;
7+
var a = () => local; // <-- Lambda should be converted to function()
8+
}

0 commit comments

Comments
 (0)