handle cases when body of for-of statement is expanded after loop conversion (#13677)
This commit is contained in:
parent
e679b2ee76
commit
abc30b26c7
|
@ -2316,7 +2316,7 @@ namespace ts {
|
|||
addRange(statements, convertedLoopBodyStatements);
|
||||
}
|
||||
else {
|
||||
const statement = visitNode(node.statement, visitor, isStatement);
|
||||
const statement = visitNode(node.statement, visitor, isStatement, /*optional*/ false, liftToBlock);
|
||||
if (isBlock(statement)) {
|
||||
addRange(statements, statement.statements);
|
||||
bodyLocation = statement;
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
//// [nestedLoopWithOnlyInnerLetCaptured.ts]
|
||||
declare let doSomething;
|
||||
|
||||
for (let a1 of [])
|
||||
for (let a2 of a1.someArray)
|
||||
doSomething(() => a2);
|
||||
|
||||
//// [nestedLoopWithOnlyInnerLetCaptured.js]
|
||||
for (var _i = 0, _a = []; _i < _a.length; _i++) {
|
||||
var a1 = _a[_i];
|
||||
var _loop_1 = function (a2) {
|
||||
doSomething(function () { return a2; });
|
||||
};
|
||||
for (var _b = 0, _c = a1.someArray; _b < _c.length; _b++) {
|
||||
var a2 = _c[_b];
|
||||
_loop_1(a2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
=== tests/cases/compiler/nestedLoopWithOnlyInnerLetCaptured.ts ===
|
||||
declare let doSomething;
|
||||
>doSomething : Symbol(doSomething, Decl(nestedLoopWithOnlyInnerLetCaptured.ts, 0, 11))
|
||||
|
||||
for (let a1 of [])
|
||||
>a1 : Symbol(a1, Decl(nestedLoopWithOnlyInnerLetCaptured.ts, 2, 8))
|
||||
|
||||
for (let a2 of a1.someArray)
|
||||
>a2 : Symbol(a2, Decl(nestedLoopWithOnlyInnerLetCaptured.ts, 3, 12))
|
||||
>a1 : Symbol(a1, Decl(nestedLoopWithOnlyInnerLetCaptured.ts, 2, 8))
|
||||
|
||||
doSomething(() => a2);
|
||||
>doSomething : Symbol(doSomething, Decl(nestedLoopWithOnlyInnerLetCaptured.ts, 0, 11))
|
||||
>a2 : Symbol(a2, Decl(nestedLoopWithOnlyInnerLetCaptured.ts, 3, 12))
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
=== tests/cases/compiler/nestedLoopWithOnlyInnerLetCaptured.ts ===
|
||||
declare let doSomething;
|
||||
>doSomething : any
|
||||
|
||||
for (let a1 of [])
|
||||
>a1 : any
|
||||
>[] : undefined[]
|
||||
|
||||
for (let a2 of a1.someArray)
|
||||
>a2 : any
|
||||
>a1.someArray : any
|
||||
>a1 : any
|
||||
>someArray : any
|
||||
|
||||
doSomething(() => a2);
|
||||
>doSomething(() => a2) : any
|
||||
>doSomething : any
|
||||
>() => a2 : () => any
|
||||
>a2 : any
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
// @target: es5
|
||||
declare let doSomething;
|
||||
|
||||
for (let a1 of [])
|
||||
for (let a2 of a1.someArray)
|
||||
doSomething(() => a2);
|
Loading…
Reference in a new issue