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

Literal Array trailing comma in expressions causes error #20773

Closed
FrancescoBorzi opened this issue Dec 4, 2017 · 4 comments
Closed

Literal Array trailing comma in expressions causes error #20773

FrancescoBorzi opened this issue Dec 4, 2017 · 4 comments
Labels
area: compiler Issues related to `ngc`, Angular's template compiler compiler: parser core: binding & interpolation Issue related to property/attribute binding or text interpolation freq1: low P4 A relatively minor issue that is not relevant to core functions state: confirmed state: has PR type: bug/fix workaround1: obvious
Milestone

Comments

@FrancescoBorzi
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

The following works:

<div
  *ngIf="[
  'first value',
  'last value'
  ].indexOf(myVar) > -1"
></div>

the following gives error:

<div
  *ngIf="[
  'first value',
  'last value',
  ].indexOf(myVar) > -1"
></div>

the difference is the trailing comma in the array of the *ngIf condition.

Expected behavior

It should work still it's still valid javascript

Environment


Browser:
Chrome (desktop) Version:  62.0.3202.94 (Official Build) (64-bit)

Environment:

Angular CLI: 1.5.5
Node: 8.9.1
OS: linux x64
Angular: 5.0.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.5.5
@angular-devkit/build-optimizer: 0.0.34
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.38
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.5
@schematics/angular: 0.1.8
typescript: 2.4.2
webpack: 3.8.1

@IgorMinar IgorMinar added the area: core Issues related to the framework runtime label Dec 5, 2017
@mhevery mhevery added the feature Issue that requests a new feature label Dec 5, 2017
@ngbot ngbot bot added this to the Backlog milestone Jan 23, 2018
trotyl added a commit to trotyl/angular that referenced this issue Feb 17, 2018
trotyl added a commit to trotyl/angular that referenced this issue Feb 17, 2018
@mgol
Copy link
Member

mgol commented Feb 22, 2018

It's not just *ngIf but any expression, e.g. an event handler.

Note that it works in AngularJS.

@pkozlowski-opensource pkozlowski-opensource changed the title Array trailing comma in *ngIf condition causes error Literal Array trailing comma in expressions causes error Mar 9, 2019
@eddybrando
Copy link

eddybrando commented Apr 4, 2019

It's even not just arrays, but also objects.

The following returns a syntax error when parsing the template during ng serve:

<div [ngClass]="{
  'class-foo': foo,
  'class-bar': !foo,
}">Lorem</div>

This is compiled without errors, tho:

<div [ngClass]="{
  'class-foo': foo,
  'class-bar': !foo
}">Lorem</div>

Both are valid Typescript. Since Typescript 2.9 traling commas are not allowed, but only on rest parameters (see breaking changes description and related fix).

Both should compile without errors, so I guess this is a bug with the way Angular compiles the templates, right?

@eddybrando
Copy link

@mhevery, I believe this is wrongly tagged as "feature" instead of "bug/fix" for the reasons exposed above.

@pkozlowski-opensource pkozlowski-opensource added the core: binding & interpolation Issue related to property/attribute binding or text interpolation label Mar 12, 2020
@JoostK JoostK added area: compiler Issues related to `ngc`, Angular's template compiler state: confirmed state: has PR triage #1 and removed area: core Issues related to the framework runtime labels May 29, 2020
@jelbourn jelbourn added P4 A relatively minor issue that is not relevant to core functions and removed severity1: confusing labels Oct 1, 2020
mhevery pushed a commit that referenced this issue Dec 2, 2020
Allows `[1, 2, ]` syntax in angular expressions.

closes #20773

PR Close #22277
@mhevery mhevery closed this as completed in 8d613c1 Dec 2, 2020
@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 2, 2021
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 compiler: parser core: binding & interpolation Issue related to property/attribute binding or text interpolation freq1: low P4 A relatively minor issue that is not relevant to core functions state: confirmed state: has PR type: bug/fix workaround1: obvious
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants