Skip to content

Commit be50eea

Browse files
authored
Fix merge lexical environment to *always* respect prologue statements (#24602) (#24654)
1 parent 825c8e7 commit be50eea

5 files changed

+46
-1
lines changed

src/compiler/visitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ namespace ts {
14681468
}
14691469

14701470
return isNodeArray(statements)
1471-
? setTextRange(createNodeArray(concatenate(declarations, statements)), statements)
1471+
? setTextRange(createNodeArray(prependStatements(statements.slice(), declarations)), statements)
14721472
: prependStatements(statements, declarations);
14731473
}
14741474

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [destructuringTempOccursAfterPrologue.ts]
2+
function test(p: any) {
3+
'use strict';
4+
p = { prop: p } = p;
5+
}
6+
7+
//// [destructuringTempOccursAfterPrologue.js]
8+
function test(p) {
9+
'use strict';
10+
var _a;
11+
p = (_a = p, p = _a.prop, _a);
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/compiler/destructuringTempOccursAfterPrologue.ts ===
2+
function test(p: any) {
3+
>test : Symbol(test, Decl(destructuringTempOccursAfterPrologue.ts, 0, 0))
4+
>p : Symbol(p, Decl(destructuringTempOccursAfterPrologue.ts, 0, 14))
5+
6+
'use strict';
7+
p = { prop: p } = p;
8+
>p : Symbol(p, Decl(destructuringTempOccursAfterPrologue.ts, 0, 14))
9+
>prop : Symbol(prop, Decl(destructuringTempOccursAfterPrologue.ts, 2, 9))
10+
>p : Symbol(p, Decl(destructuringTempOccursAfterPrologue.ts, 0, 14))
11+
>p : Symbol(p, Decl(destructuringTempOccursAfterPrologue.ts, 0, 14))
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/compiler/destructuringTempOccursAfterPrologue.ts ===
2+
function test(p: any) {
3+
>test : (p: any) => void
4+
>p : any
5+
6+
'use strict';
7+
>'use strict' : "use strict"
8+
9+
p = { prop: p } = p;
10+
>p = { prop: p } = p : any
11+
>p : any
12+
>{ prop: p } = p : any
13+
>{ prop: p } : { prop: any; }
14+
>prop : any
15+
>p : any
16+
>p : any
17+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function test(p: any) {
2+
'use strict';
3+
p = { prop: p } = p;
4+
}

0 commit comments

Comments
 (0)