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
Diagnostic to flag cases where control flow can break content projection #52726
Conversation
9665aea
to
424bf5d
Compare
* of a control flow expression *would have been projected* into a specific slot, if the control | ||
* flow node didn't exist. | ||
*/ | ||
class TcbControlFlowContentProjectionOp extends TcbOp { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't totally sure if another TcbOp
was the right place to put this since it doesn't add any statements to the TCB, but I saw that we have some precedent for cases in the TcbDomSchemaCheckerOp
. My main concern was to isolate the check from everything else in the TCB. The other option was to put it in a private method inside the Scope
, but that class is pretty large as it is.
424bf5d
to
ff32dce
Compare
cac5480
to
ab83508
Compare
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
packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts
Outdated
Show resolved
Hide resolved
const blockName = controlFlowNode instanceof TmplAstIfBlockBranch ? '@if' : '@for'; | ||
const lines = [ | ||
`Node matches the "${slotSelector}" slot of the "${ | ||
componentName}" component, but will not be projected because the surrounding ${ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"will not be projected" may be inaccurate if there is a default slot. Perhaps this should have two forms ("will not be projected" and "will be projected into the default projection slot" or smth like that) or generalize to e.g. "will not be projected there".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the wording a bit to mention that it won't be projected into that slot.
ab83508
to
c8e2b98
Compare
I've addressed most of the feedback and will bring up the discussion around using a warning versus an error later today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'm indifferent on warning vs error.
reviewed-for: fw-core, public-api
…T nodes When doing directive matching in the compiler, we need to be able to create a selector from an AST node. We already have the utility, but these changes simplify the public API and expose it so it can be used in `compiler-cli`.
…spaces during template type checking These changes expose the `ngContentSelectors` and `preserveWhitespaces` metadata to the TCB so they can be used in the next commit to implement a new diagnostic.
…tainer The control flow projection diagnostic will mention `ng-container` as a workaround for projection multiple nodes. These changes add a couple of tests to ensure that the approach works.
5a0f84f
to
f49fa26
Compare
f49fa26
to
f6548e9
Compare
…ent projection This is a follow-up to the fix from angular#52414. It adds a diagnostic that will tell users when a control flow is preventing its direct descendants from being projected into a specific component slot.
…T nodes (angular#52726) When doing directive matching in the compiler, we need to be able to create a selector from an AST node. We already have the utility, but these changes simplify the public API and expose it so it can be used in `compiler-cli`. PR Close angular#52726
…spaces during template type checking (angular#52726) These changes expose the `ngContentSelectors` and `preserveWhitespaces` metadata to the TCB so they can be used in the next commit to implement a new diagnostic. PR Close angular#52726
…tainer (angular#52726) The control flow projection diagnostic will mention `ng-container` as a workaround for projection multiple nodes. These changes add a couple of tests to ensure that the approach works. PR Close angular#52726
…ent projection (angular#52726) This is a follow-up to the fix from angular#52414. It adds a diagnostic that will tell users when a control flow is preventing its direct descendants from being projected into a specific component slot. PR Close angular#52726
… from AST nodes (angular#52726)" (angular#53012) This reverts commit adbea7b. PR Close angular#53012
…rveWhitespaces during template type checking (angular#52726)" (angular#53012) This reverts commit 4550a81. PR Close angular#53012
…h ng-container (angular#52726)" (angular#53012) This reverts commit 181f8e4. PR Close angular#53012
…nts content projection (angular#52726)" (angular#53012) This reverts commit b4d022e. PR Close angular#53012
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. |
…T nodes (angular#52726) When doing directive matching in the compiler, we need to be able to create a selector from an AST node. We already have the utility, but these changes simplify the public API and expose it so it can be used in `compiler-cli`. PR Close angular#52726
…spaces during template type checking (angular#52726) These changes expose the `ngContentSelectors` and `preserveWhitespaces` metadata to the TCB so they can be used in the next commit to implement a new diagnostic. PR Close angular#52726
…tainer (angular#52726) The control flow projection diagnostic will mention `ng-container` as a workaround for projection multiple nodes. These changes add a couple of tests to ensure that the approach works. PR Close angular#52726
…ent projection (angular#52726) This is a follow-up to the fix from angular#52414. It adds a diagnostic that will tell users when a control flow is preventing its direct descendants from being projected into a specific component slot. PR Close angular#52726
…T nodes (angular#52726) When doing directive matching in the compiler, we need to be able to create a selector from an AST node. We already have the utility, but these changes simplify the public API and expose it so it can be used in `compiler-cli`. PR Close angular#52726
…spaces during template type checking (angular#52726) These changes expose the `ngContentSelectors` and `preserveWhitespaces` metadata to the TCB so they can be used in the next commit to implement a new diagnostic. PR Close angular#52726
…tainer (angular#52726) The control flow projection diagnostic will mention `ng-container` as a workaround for projection multiple nodes. These changes add a couple of tests to ensure that the approach works. PR Close angular#52726
…ent projection (angular#52726) This is a follow-up to the fix from angular#52414. It adds a diagnostic that will tell users when a control flow is preventing its direct descendants from being projected into a specific component slot. PR Close angular#52726
…T nodes (angular#52726) When doing directive matching in the compiler, we need to be able to create a selector from an AST node. We already have the utility, but these changes simplify the public API and expose it so it can be used in `compiler-cli`. PR Close angular#52726
…spaces during template type checking (angular#52726) These changes expose the `ngContentSelectors` and `preserveWhitespaces` metadata to the TCB so they can be used in the next commit to implement a new diagnostic. PR Close angular#52726
…tainer (angular#52726) The control flow projection diagnostic will mention `ng-container` as a workaround for projection multiple nodes. These changes add a couple of tests to ensure that the approach works. PR Close angular#52726
…ent projection (angular#52726) This is a follow-up to the fix from angular#52414. It adds a diagnostic that will tell users when a control flow is preventing its direct descendants from being projected into a specific component slot. PR Close angular#52726
These changes are a follow-up to the fix from #52414. They add a new diagnostic to the compiler that will flag cases where an element would've been projected into a specific slot of a component, but it isn't because it exists inside of a control flow node that has multiple root nodes. Aside from the diagnostic, I have to move some code around so it can be reused. Includes the following commits:
refactor(compiler): expose utility for creating CSS selectors from AST nodes
When doing directive matching in the compiler, we need to be able to create a selector from an AST node. We already have the utility, but these changes simplify the public API and expose it so it can be used in
compiler-cli
.refactor(compiler-cli): expose ng-content selectors and preserveWhitespaces during template type checking
These changes expose the
ngContentSelectors
andpreserveWhitespaces
metadata to the TCB so they can be used in the next commit to implement a new diagnostic.test(core): add tests for control flow content projection with ng-container
The control flow projection diagnostic will mention
ng-container
as a workaround for projection multiple nodes. These changes add a couple of tests to ensure that the approach works.fix(compiler-cli): add diagnostic for control flow that prevents content projection
This is a follow-up to the fix from #52414. It adds a diagnostic that will tell users when a control flow is preventing its direct descendants from being projected into a specific component slot.