mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 20:51:43 -06:00
correctly recognize captured loop variables in destructuring assignment
This commit is contained in:
parent
f06423bffc
commit
7344d9ca47
@ -7474,11 +7474,10 @@ namespace ts {
|
||||
|
||||
// check if node is used as LHS in some assignment expression
|
||||
let isAssigned = false;
|
||||
if (current.parent.kind === SyntaxKind.BinaryExpression) {
|
||||
isAssigned = (<BinaryExpression>current.parent).left === current && isAssignmentOperator((<BinaryExpression>current.parent).operatorToken.kind);
|
||||
if (isAssignmentTarget(current)) {
|
||||
isAssigned = true;
|
||||
}
|
||||
|
||||
if ((current.parent.kind === SyntaxKind.PrefixUnaryExpression || current.parent.kind === SyntaxKind.PostfixUnaryExpression)) {
|
||||
else if ((current.parent.kind === SyntaxKind.PrefixUnaryExpression || current.parent.kind === SyntaxKind.PostfixUnaryExpression)) {
|
||||
const expr = <PrefixUnaryExpression | PostfixUnaryExpression>current.parent;
|
||||
isAssigned = expr.operator === SyntaxKind.PlusPlusToken || expr.operator === SyntaxKind.MinusMinusToken;
|
||||
}
|
||||
|
||||
42
tests/baselines/reference/capturedLetConstInLoop12.js
Normal file
42
tests/baselines/reference/capturedLetConstInLoop12.js
Normal file
@ -0,0 +1,42 @@
|
||||
//// [capturedLetConstInLoop12.ts]
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
(() => [i] = [i + 1])();
|
||||
}
|
||||
})();
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
(() => ({a:i} = {a:i + 1}))();
|
||||
}
|
||||
})();
|
||||
|
||||
//// [capturedLetConstInLoop12.js]
|
||||
(function () {
|
||||
"use strict";
|
||||
var _loop_1 = function(i) {
|
||||
(function () { return (_a = [i + 1], i = _a[0], _a); var _a; })();
|
||||
out_i_1 = i;
|
||||
};
|
||||
var out_i_1;
|
||||
for (var i = 0; i < 4; i++) {
|
||||
_loop_1(i);
|
||||
i = out_i_1;
|
||||
}
|
||||
})();
|
||||
(function () {
|
||||
"use strict";
|
||||
var _loop_2 = function(i) {
|
||||
(function () { return (_a = { a: i + 1 }, i = _a.a, _a); var _a; })();
|
||||
out_i_2 = i;
|
||||
};
|
||||
var out_i_2;
|
||||
for (var i = 0; i < 4; i++) {
|
||||
_loop_2(i);
|
||||
i = out_i_2;
|
||||
}
|
||||
})();
|
||||
30
tests/baselines/reference/capturedLetConstInLoop12.symbols
Normal file
30
tests/baselines/reference/capturedLetConstInLoop12.symbols
Normal file
@ -0,0 +1,30 @@
|
||||
=== tests/cases/compiler/capturedLetConstInLoop12.ts ===
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
>i : Symbol(i, Decl(capturedLetConstInLoop12.ts, 3, 12))
|
||||
>i : Symbol(i, Decl(capturedLetConstInLoop12.ts, 3, 12))
|
||||
>i : Symbol(i, Decl(capturedLetConstInLoop12.ts, 3, 12))
|
||||
|
||||
(() => [i] = [i + 1])();
|
||||
>i : Symbol(i, Decl(capturedLetConstInLoop12.ts, 3, 12))
|
||||
>i : Symbol(i, Decl(capturedLetConstInLoop12.ts, 3, 12))
|
||||
}
|
||||
})();
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
>i : Symbol(i, Decl(capturedLetConstInLoop12.ts, 11, 12))
|
||||
>i : Symbol(i, Decl(capturedLetConstInLoop12.ts, 11, 12))
|
||||
>i : Symbol(i, Decl(capturedLetConstInLoop12.ts, 11, 12))
|
||||
|
||||
(() => ({a:i} = {a:i + 1}))();
|
||||
>a : Symbol(a, Decl(capturedLetConstInLoop12.ts, 12, 17))
|
||||
>i : Symbol(i, Decl(capturedLetConstInLoop12.ts, 11, 12))
|
||||
>a : Symbol(a, Decl(capturedLetConstInLoop12.ts, 12, 25))
|
||||
>i : Symbol(i, Decl(capturedLetConstInLoop12.ts, 11, 12))
|
||||
}
|
||||
})();
|
||||
65
tests/baselines/reference/capturedLetConstInLoop12.types
Normal file
65
tests/baselines/reference/capturedLetConstInLoop12.types
Normal file
@ -0,0 +1,65 @@
|
||||
=== tests/cases/compiler/capturedLetConstInLoop12.ts ===
|
||||
(function() {
|
||||
>(function() { "use strict"; for (let i = 0; i < 4; i++) { (() => [i] = [i + 1])(); }})() : void
|
||||
>(function() { "use strict"; for (let i = 0; i < 4; i++) { (() => [i] = [i + 1])(); }}) : () => void
|
||||
>function() { "use strict"; for (let i = 0; i < 4; i++) { (() => [i] = [i + 1])(); }} : () => void
|
||||
|
||||
"use strict";
|
||||
>"use strict" : string
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
>i : number
|
||||
>0 : number
|
||||
>i < 4 : boolean
|
||||
>i : number
|
||||
>4 : number
|
||||
>i++ : number
|
||||
>i : number
|
||||
|
||||
(() => [i] = [i + 1])();
|
||||
>(() => [i] = [i + 1])() : [number]
|
||||
>(() => [i] = [i + 1]) : () => [number]
|
||||
>() => [i] = [i + 1] : () => [number]
|
||||
>[i] = [i + 1] : [number]
|
||||
>[i] : [number]
|
||||
>i : number
|
||||
>[i + 1] : [number]
|
||||
>i + 1 : number
|
||||
>i : number
|
||||
>1 : number
|
||||
}
|
||||
})();
|
||||
|
||||
(function() {
|
||||
>(function() { "use strict"; for (let i = 0; i < 4; i++) { (() => ({a:i} = {a:i + 1}))(); }})() : void
|
||||
>(function() { "use strict"; for (let i = 0; i < 4; i++) { (() => ({a:i} = {a:i + 1}))(); }}) : () => void
|
||||
>function() { "use strict"; for (let i = 0; i < 4; i++) { (() => ({a:i} = {a:i + 1}))(); }} : () => void
|
||||
|
||||
"use strict";
|
||||
>"use strict" : string
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
>i : number
|
||||
>0 : number
|
||||
>i < 4 : boolean
|
||||
>i : number
|
||||
>4 : number
|
||||
>i++ : number
|
||||
>i : number
|
||||
|
||||
(() => ({a:i} = {a:i + 1}))();
|
||||
>(() => ({a:i} = {a:i + 1}))() : { a: number; }
|
||||
>(() => ({a:i} = {a:i + 1})) : () => { a: number; }
|
||||
>() => ({a:i} = {a:i + 1}) : () => { a: number; }
|
||||
>({a:i} = {a:i + 1}) : { a: number; }
|
||||
>{a:i} = {a:i + 1} : { a: number; }
|
||||
>{a:i} : { a: number; }
|
||||
>a : number
|
||||
>i : number
|
||||
>{a:i + 1} : { a: number; }
|
||||
>a : number
|
||||
>i + 1 : number
|
||||
>i : number
|
||||
>1 : number
|
||||
}
|
||||
})();
|
||||
15
tests/cases/compiler/capturedLetConstInLoop12.ts
Normal file
15
tests/cases/compiler/capturedLetConstInLoop12.ts
Normal file
@ -0,0 +1,15 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
(() => [i] = [i + 1])();
|
||||
}
|
||||
})();
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
(() => ({a:i} = {a:i + 1}))();
|
||||
}
|
||||
})();
|
||||
Loading…
x
Reference in New Issue
Block a user