Commit d7a83f9
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 596b43d commit d7a83f9
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 | |
|---|---|---|---|
| |||
1538 | 1538 | | |
1539 | 1539 | | |
1540 | 1540 | | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
1541 | 1546 | | |
1542 | | - | |
| 1547 | + | |
1543 | 1548 | | |
1544 | 1549 | | |
1545 | 1550 | | |
| |||
1656 | 1661 | | |
1657 | 1662 | | |
1658 | 1663 | | |
1659 | | - | |
| 1664 | + | |
| 1665 | + | |
1660 | 1666 | | |
1661 | | - | |
| 1667 | + | |
1662 | 1668 | | |
1663 | 1669 | | |
1664 | 1670 | | |
| |||
1730 | 1736 | | |
1731 | 1737 | | |
1732 | 1738 | | |
1733 | | - | |
1734 | | - | |
1735 | | - | |
1736 | | - | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
1737 | 1744 | | |
1738 | 1745 | | |
1739 | 1746 | | |
| |||
1865 | 1872 | | |
1866 | 1873 | | |
1867 | 1874 | | |
1868 | | - | |
| 1875 | + | |
| 1876 | + | |
1869 | 1877 | | |
1870 | 1878 | | |
1871 | 1879 | | |
| |||
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