8000 feat(compiler): support arrow function in template by trotyl · Pull Request #30277 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

feat(compiler): support arrow function in template #30277

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 8000 occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

trotyl
Copy link
Contributor
@trotyl trotyl commented May 6, 2019

closes #14129

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #14129

Suggested by @mhevery in #12969 (comment).

What is the new behavior?

Arrow functions are now supported in template expression, like:

<li *ngFor="let item of items trackBy item => item.id">{{ item.name }}</li>

Restrictions from JavaScript syntax:

  • No async/await;
  • No generator/yield;
  • No default parameter;
  • No parameter destruction;
  • No block body;

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

]);
});

it('should parse bound events and properties via [(...)]', () => {
expectFromHtml('<div [(prop)]="v"></div>').toEqual([
['Element', 'div'],
['BoundAttribute', BindingType.Property, 'prop', 'v'],
['BoundEvent', 'propChange', null, 'v = $event'],
['BoundEvent', 'propChange', null, 'this.v = this.$event'],
Copy link
Contributor Author
@trotyl trotyl May 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't be surprise, this is really the normalized form in parser, which already works in template:

<button (click)="onClick(this.$any(this.$event))">Click Me</button>

https://stackblitz.com/edit/angular-mgjryy?file=src%2Fapp%2Fapp.component.html

@@ -80,7 +79,9 @@ class Unparser implements AstVisitor {
this._expression += ')';
}

visitImplicitReceiver(ast: ImplicitReceiver, context: any) {}
visitImplicitReceiver(ast: ImplicitReceiver, context: any) { this._expression += 'this'; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Showing this now to recognize component property against lexical identifier.

@trotyl trotyl force-pushed the template-arrow-function branch from 3670f82 to 5f362d9 Compare May 6, 2019 07:53
@trotyl trotyl marked this pull request as ready for review May 6, 2019 08:10
@trotyl trotyl requested review from a team as code owners May 6, 2019 08:10
@kara kara added the area: core Issues related to the framework runtime label May 6, 2019
@ngbot ngbot bot added this to the needsTriage milestone May 6, 2019
@mhevery
Copy link
Contributor
mhevery commented Dec 3, 2020

This is a feature which we very much would like to have. The current PR only solves the syntax for the ViewEngine but not for Ivy. It also does not account for corner cases of containing closure over other variables. So even thought we would very much like this it would take quite a lot of work to get it over the finish line. We will have to implement this with those constraints in mind.

@mhevery mhevery closed this Dec 3, 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 3, 2021
@pullapprove pullapprove bot added area: compiler Issues related to `ngc`, Angular's template compiler area: language-service Issues related to Angular's VS Code language service labels Jan 3, 2021
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Jan 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an ac 680B count? Sign in.
Labels
area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime area: language-service Issues related to Angular's VS Code language service cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support arrow functions in template syntax
4 participants
0