Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control flow: @for and inline arrays with multiple lines #52446

Closed
cexbrayat opened this issue Oct 30, 2023 · 1 comment
Closed

Control flow: @for and inline arrays with multiple lines #52446

cexbrayat opened this issue Oct 30, 2023 · 1 comment
Assignees
Labels
area: compiler Issues related to `ngc`, Angular's template compiler core: control flow Issues related to the built-in control flow (@if, @for, @switch) state: has PR
Milestone

Comments

@cexbrayat
Copy link
Member

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

No

Description

It is currently possible to use ngFor with inline arrays:

<div *ngFor="let i of [
  { id: 1 },
  { id: 2 }
]">{{ i.id }}</div>

The current migration properly works, but the generated code is not accepted by the compiler:

@for (i of [
  { id: 1 },
  { id: 2 }
]; track i) {
  <div>{{ i.id }}</div>
}

The compiler fails with the error below

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

NG5002: Parser Error: Missing expected ] at the end of the expression [[] in /Users/cedric/Code/temp/control-flow-errors/src/app/app.component.html@0:6 [plugin angular-compiler]

    src/app/app.component.html:1:6:
      1 │ @for (i of [
        ╵       ~~~~~~

  Error occurs in the template of component AppComponent.

    src/app/app.component.ts:8:15:
      8 │   templateUrl: './app.component.html',
        ╵                ~~~~~~~~~~~~~~~~~~~~~~

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 17.0.0-rc.2
Node: 18.18.2
Package Manager: npm 9.7.1
OS: darwin arm64

Angular: 17.0.0-rc.1
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.0-rc.2
@angular-devkit/build-angular   17.0.0-rc.2
@angular-devkit/core            17.0.0-rc.2
@angular-devkit/schematics      17.0.0-rc.2
@angular/cli                    17.0.0-rc.2
@schematics/angular             17.0.0-rc.2
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.1

Anything else?

No response

@JoostK JoostK added the core: control flow Issues related to the built-in control flow (@if, @for, @switch) label Oct 30, 2023
@crisbeto crisbeto self-assigned this Oct 30, 2023
crisbeto added a commit to crisbeto/angular that referenced this issue Oct 30, 2023
…ins new line

Fixes that the regex which captures the expression of a `@for` loop block wasn't accounting for line breaks.

Fixes angular#52446.
@pkozlowski-opensource pkozlowski-opensource added the area: compiler Issues related to `ngc`, Angular's template compiler label Oct 30, 2023
@ngbot ngbot bot added this to the needsTriage milestone Oct 30, 2023
@alxhub alxhub closed this as completed in b5ef68f Oct 31, 2023
alxhub pushed a commit that referenced this issue Oct 31, 2023
…ins new line (#52447)

Fixes that the regex which captures the expression of a `@for` loop block wasn't accounting for line breaks.

Fixes #52446.

PR Close #52447
@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 Dec 1, 2023
tbondwilkinson pushed a commit to tbondwilkinson/angular that referenced this issue Dec 6, 2023
…ins new line (angular#52447)

Fixes that the regex which captures the expression of a `@for` loop block wasn't accounting for line breaks.

Fixes angular#52446.

PR Close angular#52447
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this issue Jan 23, 2024
…ins new line (angular#52447)

Fixes that the regex which captures the expression of a `@for` loop block wasn't accounting for line breaks.

Fixes angular#52446.

PR Close angular#52447
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: compiler Issues related to `ngc`, Angular's template compiler core: control flow Issues related to the built-in control flow (@if, @for, @switch) state: has PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants