Visitar URL original
feat(compiler): add support for safe calls in templates by crisbeto · Pull Request #44580 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20220125170648/https://github.com/angular/angular/pull/44580
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

feat(compiler): add support for safe calls in templates #44580

Closed
wants to merge 2 commits into from

Conversation

@crisbeto
Copy link
Member

@crisbeto crisbeto commented Dec 30, 2021 •

Adds support for safely calling functions that may be undefined inside template expressions. E.g. maybeUndefined?.()

Fixes #42298.

@crisbeto crisbeto changed the title feat(core): add support for safe calls in templates feat(compiler): add support for safe calls in templates Dec 30, 2021
@crisbeto crisbeto force-pushed the 42298/safe-calls branch 2 times, most recently from 03b500a to 8f34d6a Dec 30, 2021
@crisbeto crisbeto marked this pull request as ready for review Dec 30, 2021
@pullapprove pullapprove bot requested review from alxhub, dylhunn and JoostK Dec 30, 2021
@ngbot ngbot bot added this to the Backlog milestone Dec 30, 2021
@ngbot ngbot bot added this to the Backlog milestone Dec 30, 2021
@ngbot ngbot bot added this to the Backlog milestone Dec 30, 2021
alxhub
alxhub approved these changes Jan 4, 2022
template: `
<span [title]="'Your last name is ' + (person.getLastName?.() ?? 'unknown')">
Hello, {{ person.getName?.() }}!
You are a Balrog: {{ person.getSpecies?.()?.()?.()?.()?.() || 'unknown' }}
Copy link
Contributor

@alxhub alxhub Jan 4, 2022

Choose a reason for hiding this comment

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

You shall not pass (but the test should).

@dylhunn dylhunn removed their request for review Jan 4, 2022
@crisbeto crisbeto force-pushed the 42298/safe-calls branch from 8f34d6a to 000a04a Jan 6, 2022
Copy link
Member

@JoostK JoostK left a comment

I would appreciate if #44447 can land before this, especially since that one has to be cherry-picked into the patch branch (so if it lands after this there's a guaranteed cherry-pick conflict)

packages/compiler/src/expression_parser/ast.ts Outdated Show resolved Hide resolved
packages/compiler/src/expression_parser/parser.ts Outdated Show resolved Hide resolved
@crisbeto crisbeto force-pushed the 42298/safe-calls branch from 000a04a to c8ff227 Jan 7, 2022
Copy link
Member Author

@crisbeto crisbeto left a comment

I've addressed the feedback.

@crisbeto crisbeto requested a review from atscott Jan 7, 2022
crisbeto added a commit to crisbeto/angular that referenced this issue Jan 7, 2022
…y read

This was flagged during the code review of angular#44580. When generating a type check block, we were interpreting any call to `$any` as an `as any` cast, even if it's part of a `PropertyRead` (e.g. `foo.$any(1)`). This is handled correctly in other parts of the compiler, but it looks like it was missed in the type checker.
JoostK
JoostK approved these changes Jan 7, 2022
Copy link
Member

@JoostK JoostK left a comment

LGTM. Nice to see that we have all safe operators now.

atscott added a commit that referenced this issue Jan 7, 2022
…y read (#44657)

This was flagged during the code review of #44580. When generating a type check block, we were interpreting any call to `$any` as an `as any` cast, even if it's part of a `PropertyRead` (e.g. `foo.$any(1)`). This is handled correctly in other parts of the compiler, but it looks like it was missed in the type checker.

PR Close #44657
atscott added a commit that referenced this issue Jan 7, 2022
…y read (#44657)

This was flagged during the code review of #44580. When generating a type check block, we were interpreting any call to `$any` as an `as any` cast, even if it's part of a `PropertyRead` (e.g. `foo.$any(1)`). This is handled correctly in other parts of the compiler, but it looks like it was missed in the type checker.

PR Close #44657
@atscott atscott removed their request for review Jan 7, 2022
@crisbeto crisbeto force-pushed the 42298/safe-calls branch from c8ff227 to f5a09cc Jan 10, 2022
@crisbeto
Copy link
Member Author

@crisbeto crisbeto commented Jan 10, 2022

All the feedback should be addressed now. Setting to blocked until #44447 is merged in.

Adds support for safely calling functions that may be undefined inside template expressions. E.g. `maybeUndefined?.()`

Fixes angular#42298.
@crisbeto crisbeto force-pushed the 42298/safe-calls branch from f5a09cc to 7250bb7 Jan 11, 2022
@crisbeto
Copy link
Member Author

@crisbeto crisbeto commented Jan 11, 2022

Rebased on top of #44447. Unblocking.

@atscott
Copy link
Contributor

@atscott atscott commented Jan 11, 2022

This PR was merged into the repository by commit a4ab6d6.

@atscott atscott closed this in a4ab6d6 Jan 11, 2022
ramthir added a commit to ramthir/angular that referenced this issue Jan 13, 2022
Adds support for safely calling functions that may be undefined inside template expressions. E.g. `maybeUndefined?.()`

Fixes angular#42298.

PR Close angular#44580
amitbeck added a commit to amitbeck/angular that referenced this issue Jan 13, 2022
…y read (angular#44657)

This was flagged during the code review of angular#44580. When generating a type check block, we were interpreting any call to `$any` as an `as any` cast, even if it's part of a `PropertyRead` (e.g. `foo.$any(1)`). This is handled correctly in other parts of the compiler, but it looks like it was missed in the type checker.

PR Close angular#44657
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants