Skip to content

Comments

Diagnostic to flag cases where control flow can break content projection#52726

Closed
crisbeto wants to merge 4 commits intoangular:mainfrom
crisbeto:control-flow-diagnostic
Closed

Diagnostic to flag cases where control flow can break content projection#52726
crisbeto wants to merge 4 commits intoangular:mainfrom
crisbeto:control-flow-diagnostic

Conversation

@crisbeto
Copy link
Member

@crisbeto crisbeto commented Nov 9, 2023

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 and preserveWhitespaces 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.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release area: compiler Issues related to `ngc`, Angular's template compiler labels Nov 9, 2023
@ngbot ngbot bot modified the milestone: Backlog Nov 9, 2023
@crisbeto crisbeto force-pushed the control-flow-diagnostic branch from 9665aea to 424bf5d Compare November 9, 2023 09:30
Copy link
Member Author

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.

@crisbeto crisbeto force-pushed the control-flow-diagnostic branch from 424bf5d to ff32dce Compare November 9, 2023 09:37
@crisbeto crisbeto changed the title Diagnostic to flag cases where contrl flow can break content projection Diagnostic to flag cases where control flow can break content projection Nov 9, 2023
@crisbeto crisbeto force-pushed the control-flow-diagnostic branch 2 times, most recently from cac5480 to ab83508 Compare November 9, 2023 10:21
@crisbeto crisbeto requested a review from JoostK November 9, 2023 10:48
@crisbeto crisbeto marked this pull request as ready for review November 9, 2023 10:48
Copy link
Member

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".

Copy link
Member Author

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.

@crisbeto crisbeto force-pushed the control-flow-diagnostic branch from ab83508 to c8e2b98 Compare November 14, 2023 08:43
@crisbeto
Copy link
Member Author

I've addressed most of the feedback and will bring up the discussion around using a warning versus an error later today.

Copy link
Contributor

@jessicajaniuk jessicajaniuk left a 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

@pullapprove pullapprove bot requested a review from dylhunn November 15, 2023 14:22
…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.
@crisbeto crisbeto force-pushed the control-flow-diagnostic branch 2 times, most recently from 5a0f84f to f49fa26 Compare November 16, 2023 18:04
@crisbeto crisbeto force-pushed the control-flow-diagnostic branch from f49fa26 to f6548e9 Compare November 16, 2023 18:30
…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.
AndrewKushnir pushed a commit that referenced this pull request Nov 17, 2023
AndrewKushnir pushed a commit that referenced this pull request Nov 17, 2023
AndrewKushnir pushed a commit that referenced this pull request Nov 17, 2023
…rveWhitespaces during template type checking (#52726)" (#53012)

This reverts commit 4550a81.

PR Close #53012
AndrewKushnir pushed a commit that referenced this pull request Nov 17, 2023
AndrewKushnir pushed a commit that referenced this pull request Nov 17, 2023
@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 Dec 18, 2023
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…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
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…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
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…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
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…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
rlmestre pushed a commit to rlmestre/angular that referenced this pull request Jan 26, 2024
…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
rlmestre pushed a commit to rlmestre/angular that referenced this pull request Jan 26, 2024
…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
rlmestre pushed a commit to rlmestre/angular that referenced this pull request Jan 26, 2024
…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
rlmestre pushed a commit to rlmestre/angular that referenced this pull request Jan 26, 2024
…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
amilamen pushed a commit to amilamen/angular that referenced this pull request Jan 26, 2024
…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
amilamen pushed a commit to amilamen/angular that referenced this pull request Jan 26, 2024
…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
amilamen pushed a commit to amilamen/angular that referenced this pull request Jan 26, 2024
…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
amilamen pushed a commit to amilamen/angular that referenced this pull request Jan 26, 2024
…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
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 target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants