Template type checking support for @let#56199
Conversation
There was a problem hiding this comment.
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.
JoostK
left a comment
There was a problem hiding this comment.
I haven't seen any diagnostics for duplicate @let declaration identifiers in the same scope.
packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
- It matches how local references work so it would be more familiar for users.
- 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.
- 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
packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts
Outdated
Show resolved
Hide resolved
Integrates the let declarations into the template binder which will be used to power the scoping behavior of the new syntax.
…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.
|
@JoostK I've addressed the feedback and added another commit for duplicate declarations. |
thePunderWoman
left a comment
There was a problem hiding this comment.
reviewed-for: public-api
|
Caretaker note: there's one pre-existing broken target that can be ignored. |
…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
|
This PR was merged into the repository by commit 9aea8a0. |
) Adds support for let declarations inside the `CompletionEngine`. PR Close #56199
…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
) Adds support for let declarations inside the `CompletionEngine`. PR Close #56199
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
These changes include the code necessary to type check
@letdeclarations. Also some prerequisites for the language service integration.refactor(compiler-cli): add compiler flag for testing let declarations
Adds a private
_enableLetSyntaxflag 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
@letdeclarations use the same name.