Commit 6ec7a42
fix(compiler-cli): avoid conflicts with built-in global variables in for loop blocks (#53319)
Currently we generate the following TCB for a `@for` loop:
```ts
// @for (item of items; track item) {...}
for (const item of this.items) {
var _t1 = item;
// Do things with `_t1`
}
```
This is problematic if the item name is the same as a global variable (e.g. `document`), because when the TCB has references to that variable (e.g. `document.createElement`), it'll find the loop initializer instead of the global variable.
These changes fix the issue by generating the following instead:
```ts
for (const _t1 of this.items) {
// Do things with `_t1`
}
```
Fixes #53293.
PR Close #533191 parent 187ba05 commit 6ec7a42
File tree
3 files changed
+58
-20
lines changed- packages/compiler-cli
- src/ngtsc/typecheck
- src
- test
- test/ngtsc
3 files changed
+58
-20
lines changedLines changed: 16 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1444 | 1444 | | |
1445 | 1445 | | |
1446 | 1446 | | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
1447 | 1452 | | |
1448 | | - | |
| 1453 | + | |
1449 | 1454 | | |
1450 | 1455 | | |
1451 | 1456 | | |
| |||
1561 | 1566 | | |
1562 | 1567 | | |
1563 | 1568 | | |
1564 | | - | |
| 1569 | + | |
| 1570 | + | |
1565 | 1571 | | |
1566 | | - | |
| 1572 | + | |
1567 | 1573 | | |
1568 | 1574 | | |
1569 | 1575 | | |
| |||
1635 | 1641 | | |
1636 | 1642 | | |
1637 | 1643 | | |
1638 | | - | |
1639 | | - | |
1640 | | - | |
1641 | | - | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
1642 | 1649 | | |
1643 | 1650 | | |
1644 | 1651 | | |
| |||
1770 | 1777 | | |
1771 | 1778 | | |
1772 | 1779 | | |
1773 | | - | |
| 1780 | + | |
| 1781 | + | |
1774 | 1782 | | |
1775 | 1783 | | |
1776 | 1784 | | |
| |||
Lines changed: 8 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1545 | 1545 | | |
1546 | 1546 | | |
1547 | 1547 | | |
1548 | | - | |
| 1548 | + | |
1549 | 1549 | | |
1550 | 1550 | | |
1551 | 1551 | | |
| |||
1558 | 1558 | | |
1559 | 1559 | | |
1560 | 1560 | | |
1561 | | - | |
| 1561 | + | |
1562 | 1562 | | |
1563 | 1563 | | |
1564 | 1564 | | |
| |||
1576 | 1576 | | |
1577 | 1577 | | |
1578 | 1578 | | |
1579 | | - | |
| 1579 | + | |
1580 | 1580 | | |
1581 | 1581 | | |
1582 | 1582 | | |
| |||
1592 | 1592 | | |
1593 | 1593 | | |
1594 | 1594 | | |
1595 | | - | |
| 1595 | + | |
1596 | 1596 | | |
1597 | 1597 | | |
1598 | 1598 | | |
| |||
1609 | 1609 | | |
1610 | 1610 | | |
1611 | 1611 | | |
1612 | | - | |
1613 | | - | |
| 1612 | + | |
1614 | 1613 | | |
1615 | | - | |
1616 | | - | |
| 1614 | + | |
1617 | 1615 | | |
1618 | 1616 | | |
1619 | 1617 | | |
1620 | 1618 | | |
1621 | 1619 | | |
1622 | | - | |
1623 | | - | |
1624 | | - | |
1625 | | - | |
| 1620 | + | |
| 1621 | + | |
1626 | 1622 | | |
1627 | 1623 | | |
1628 | 1624 | | |
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5019 | 5019 | | |
5020 | 5020 | | |
5021 | 5021 | | |
| 5022 | + | |
| 5023 | + | |
| 5024 | + | |
| 5025 | + | |
| 5026 | + | |
| 5027 | + | |
| 5028 | + | |
| 5029 | + | |
| 5030 | + | |
| 5031 | + | |
| 5032 | + | |
| 5033 | + | |
| 5034 | + | |
| 5035 | + | |
| 5036 | + | |
| 5037 | + | |
| 5038 | + | |
| 5039 | + | |
| 5040 | + | |
| 5041 | + | |
| 5042 | + | |
| 5043 | + | |
| 5044 | + | |
| 5045 | + | |
| 5046 | + | |
| 5047 | + | |
| 5048 | + | |
| 5049 | + | |
| 5050 | + | |
| 5051 | + | |
| 5052 | + | |
| 5053 | + | |
| 5054 | + | |
| 5055 | + | |
5022 | 5056 | | |
5023 | 5057 | | |
5024 | 5058 | | |
0 commit comments