Skip to content

Template type checking support for @let#56199

Closed
crisbeto wants to merge 8 commits intoangular:mainfrom
crisbeto:let-ttc
Closed

Template type checking support for @let#56199
crisbeto wants to merge 8 commits intoangular:mainfrom
crisbeto:let-ttc

Conversation

@crisbeto
Copy link
Copy Markdown
Member

@crisbeto crisbeto commented May 31, 2024

These changes include the code necessary to type check @let declarations. Also some prerequisites for the language service integration.

refactor(compiler-cli): add compiler flag for testing let declarations

Adds a private _enableLetSyntax flag that allows for let declarations to be enabled in tests.

refactor(compiler): integrate let declarations into the template binder

Integrates the let declarations into the template binder which will be used to power the scoping behavior of the new syntax.

refactor(compiler-cli): integrate let declarations into the template type checker

Integrates let declarations into the template type checker by producing corresponding constants in the TCB.
This also includes a couple of custom diagnostics to flag usages of let before they're declared and illegal writes to let declarations. We can't rely on TS for these checks, because it includes the variable name in the diagnostic.

refactor(compiler-cli): integrate let declaration into the indexer

Adds support for let declarations in the template indexer.

refactor(compiler-cli): support resolving the symbol of let declaration

Updates the symbol builder to handle resolving the symbol of a let declaration.

refactor(compiler-cli): support completions for let declarations

Adds support for let declarations inside the CompletionEngine.

refactor(compiler-cli): account for let declarations in two-way binding check

Updates the check that prevent writes to template variables in two-way bindings to account for let declarations.
Also fixes some old tests that weren't properly setting up two-way bindings.

refactor(compiler-cli): add diagnostic for duplicate let declarations

Adds a template diagnostic that will flag cases where multiple @let declarations use the same name.

@crisbeto crisbeto added target: patch This PR is targeted for the next patch release area: compiler Issues related to `ngc`, Angular's template compiler labels May 31, 2024
@ngbot ngbot bot modified the milestone: Backlog May 31, 2024
@crisbeto crisbeto requested review from JoostK, atscott and dylhunn May 31, 2024 07:46
@crisbeto crisbeto added the action: review The PR is still awaiting reviews from at least one requested reviewer label May 31, 2024
@crisbeto crisbeto marked this pull request as ready for review May 31, 2024 07:46
@pullapprove pullapprove bot requested a review from devversion May 31, 2024 07:46
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Context for this type is that we were repeating Reference | Variable in a bunch of places which would now have to include LetDeclaration. I moved it out to a type to make it easier to manage.

Adds a private `_enableLetSyntax` flag that allows for let declarations to be enabled in tests.
Copy link
Copy Markdown
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

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

I haven't seen any diagnostics for duplicate @let declaration identifiers in the same scope.

Comment on lines 2844 to 2853
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we want to allow this? I feel like I'd rather not allow this, at least initially, unless there's some use-cases that benefit from this ability?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I initially had it set up to flag cases like this as well, but I changed it after talking with @alxhub about it. My thinking is:

  1. It matches how local references work so it would be more familiar for users.
  2. There's no technical reason why we can't support it since the value is guaranteed to be defined before child views attempt to reference it. There's one edge case where they can read an un-initialized variable, but I have safeguards against it in a future commit.
  3. At least to me, it makes sense to "hoist" it, if we treat embedded views as JS functions.

Also worth noting that @let will be in developer preview initially and I'll keep an eye on feedback around this

Integrates the let declarations into the template binder which will be used to power the scoping behavior of the new syntax.
crisbeto added 6 commits June 4, 2024 12:02
…type checker

Integrates let declarations into the template type checker by producing corresponding constants in the TCB.

This also includes a couple of custom diagnostics to flag usages of let before they're declared and illegal writes to let declarations. We can't rely on TS for these checks, because it includes the variable name in the diagnostic.
Adds support for let declarations in the template indexer.
Updates the symbol builder to handle resolving the symbol of a let declaration.
Adds support for let declarations inside the `CompletionEngine`.
…ng check

Updates the check that prevent writes to template variables in two-way bindings to account for let declarations.

Also fixes some old tests that weren't properly setting up two-way bindings.
Adds a template diagnostic that will flag cases where multiple `@let` declarations use the same name.
@crisbeto
Copy link
Copy Markdown
Member Author

crisbeto commented Jun 4, 2024

@JoostK I've addressed the feedback and added another commit for duplicate declarations.

Copy link
Copy Markdown
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

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

reviewed-for: language-service

@pullapprove pullapprove bot requested a review from AndrewKushnir June 4, 2024 16:08
Copy link
Copy Markdown
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

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

Reviewed-for: public-api

Copy link
Copy Markdown
Contributor

@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

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

reviewed-for: public-api

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jun 4, 2024
@crisbeto
Copy link
Copy Markdown
Member Author

crisbeto commented Jun 4, 2024

Caretaker note: there's one pre-existing broken target that can be ignored.

thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
…er (#56199)

Integrates the let declarations into the template binder which will be used to power the scoping behavior of the new syntax.

PR Close #56199
thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
…type checker (#56199)

Integrates let declarations into the template type checker by producing corresponding constants in the TCB.

This also includes a couple of custom diagnostics to flag usages of let before they're declared and illegal writes to let declarations. We can't rely on TS for these checks, because it includes the variable name in the diagnostic.

PR Close #56199
@thePunderWoman
Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit 9aea8a0.

thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
…56199)

Adds support for let declarations in the template indexer.

PR Close #56199
thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
…on (#56199)

Updates the symbol builder to handle resolving the symbol of a let declaration.

PR Close #56199
thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
)

Adds support for let declarations inside the `CompletionEngine`.

PR Close #56199
thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
…ng check (#56199)

Updates the check that prevent writes to template variables in two-way bindings to account for let declarations.

Also fixes some old tests that weren't properly setting up two-way bindings.

PR Close #56199
thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
…#56199)

Adds a template diagnostic that will flag cases where multiple `@let` declarations use the same name.

PR Close #56199
thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
#56199)

Adds a private `_enableLetSyntax` flag that allows for let declarations to be enabled in tests.

PR Close #56199
thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
…er (#56199)

Integrates the let declarations into the template binder which will be used to power the scoping behavior of the new syntax.

PR Close #56199
thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
…type checker (#56199)

Integrates let declarations into the template type checker by producing corresponding constants in the TCB.

This also includes a couple of custom diagnostics to flag usages of let before they're declared and illegal writes to let declarations. We can't rely on TS for these checks, because it includes the variable name in the diagnostic.

PR Close #56199
thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
…56199)

Adds support for let declarations in the template indexer.

PR Close #56199
thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
…on (#56199)

Updates the symbol builder to handle resolving the symbol of a let declaration.

PR Close #56199
thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
)

Adds support for let declarations inside the `CompletionEngine`.

PR Close #56199
thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
…ng check (#56199)

Updates the check that prevent writes to template variables in two-way bindings to account for let declarations.

Also fixes some old tests that weren't properly setting up two-way bindings.

PR Close #56199
thePunderWoman pushed a commit that referenced this pull request Jun 4, 2024
…#56199)

Adds a template diagnostic that will flag cases where multiple `@let` declarations use the same name.

PR Close #56199
@angular-automatic-lock-bot
Copy link
Copy Markdown

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 Jul 15, 2024
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 merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants