Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Comments

Close side panel

fix(compiler-cli): avoid conflicts with built-in global variables in for loop blocks#53319

Closed
crisbeto wants to merge 1 commit intoangular:mainangular/angular:mainfrom
crisbeto:53293/for-loop-varcrisbeto/angular:53293/for-loop-varCopy head branch name to clipboard
Closed

fix(compiler-cli): avoid conflicts with built-in global variables in for loop blocks#53319
crisbeto wants to merge 1 commit intoangular:mainangular/angular:mainfrom
crisbeto:53293/for-loop-varcrisbeto/angular:53293/for-loop-varCopy head branch name to clipboard

Conversation

@crisbeto
Copy link
Member

@crisbeto crisbeto commented Dec 2, 2023

Currently we generate the following TCB for a @for loop:

// @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:

for (const _t1 of this.items) {
  // Do things with `_t1`
}

Fixes #53293.

…for loop blocks

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 angular#53293.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release area: compiler Issues related to `ngc`, Angular's template compiler labels Dec 2, 2023
@ngbot ngbot bot modified the milestone: Backlog Dec 2, 2023
@crisbeto crisbeto requested a review from atscott December 2, 2023 08:53
@crisbeto crisbeto marked this pull request as ready for review December 2, 2023 08:53
@crisbeto crisbeto removed the request for review from atscott December 4, 2023 04:16
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Dec 4, 2023
@dylhunn
Copy link
Contributor

dylhunn commented Dec 5, 2023

This PR was merged into the repository by commit d7a83f9.

@dylhunn dylhunn closed this in d7a83f9 Dec 5, 2023
dylhunn pushed a commit that referenced this pull request Dec 5, 2023
…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 #53319
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 5, 2024
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…for loop blocks (angular#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 angular#53293.

PR Close angular#53319
rlmestre pushed a commit to rlmestre/angular that referenced this pull request Jan 26, 2024
…for loop blocks (angular#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 angular#53293.

PR Close angular#53319
amilamen pushed a commit to amilamen/angular that referenced this pull request Jan 26, 2024
…for loop blocks (angular#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 angular#53293.

PR Close angular#53319
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Control flow schematic: @for (document of <collection>; track document) results in template not compiling

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.