-
Notifications
You must be signed in to change notification settings - Fork 29.2k
fix(compiler): capture data bindings for content projection purposes in blocks #54876
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 10 additions & 3 deletions
13
...ler-cli/test/compliance/test_cases/r3_view_compiler_control_flow/for_element_root_node.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...est/compliance/test_cases/r3_view_compiler_control_flow/for_element_root_node_template.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| consts: [["foo", "1", "bar", "2"], ["empty-foo", "1", "empty-bar", "2"]] | ||
| consts: [["foo", "1", "bar", "2", 3, "binding"], ["empty-foo", "1", "empty-bar", "2", 3, "binding"]] | ||
| … | ||
| $r3$.ɵɵrepeaterCreate(0, MyApp_For_1_Template, 2, 1, "div", 0, i0.ɵɵrepeaterTrackByIdentity, false, MyApp_ForEmpty_2_Template, 2, 0, "span", 1); | ||
| $r3$.ɵɵrepeaterCreate(0, MyApp_For_1_Template, 2, 2, "div", 0, i0.ɵɵrepeaterTrackByIdentity, false, MyApp_ForEmpty_2_Template, 2, 1, "span", 1); |
11 changes: 9 additions & 2 deletions
11
...iler-cli/test/compliance/test_cases/r3_view_compiler_control_flow/if_element_root_node.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...test/compliance/test_cases/r3_view_compiler_control_flow/if_element_root_node_template.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| consts: [["foo", "1", "bar", "2"]] | ||
| consts: [["foo", "1", "bar", "2", 3, "binding"]] | ||
| … | ||
| $r3$.ɵɵtemplate(0, MyApp_Conditional_0_Template, 2, 1, "div", 0); | ||
| $r3$.ɵɵtemplate(0, MyApp_Conditional_0_Template, 2, 2, "div", 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -359,7 +359,7 @@ function ingestIfBlock(unit: ViewCompilationUnit, ifBlock: t.IfBlock): void { | |
| cView.contextVariables.set(ifCase.expressionAlias.name, ir.CTX_REF); | ||
| } | ||
|
|
||
| let ifCaseI18nMeta = undefined; | ||
| let ifCaseI18nMeta: i18n.BlockPlaceholder|undefined = undefined; | ||
| if (ifCase.i18n !== undefined) { | ||
| if (!(ifCase.i18n instanceof i18n.BlockPlaceholder)) { | ||
| throw Error(`Unhandled i18n metadata type for if block: ${ifCase.i18n?.constructor.name}`); | ||
|
|
@@ -402,7 +402,7 @@ function ingestSwitchBlock(unit: ViewCompilationUnit, switchBlock: t.SwitchBlock | |
| let conditions: Array<ir.ConditionalCaseExpr> = []; | ||
| for (const switchCase of switchBlock.cases) { | ||
| const cView = unit.job.allocateView(unit.xref); | ||
| let switchCaseI18nMeta = undefined; | ||
| let switchCaseI18nMeta: i18n.BlockPlaceholder|undefined = undefined; | ||
| if (switchCase.i18n !== undefined) { | ||
| if (!(switchCase.i18n instanceof i18n.BlockPlaceholder)) { | ||
| throw Error( | ||
|
|
@@ -1269,18 +1269,28 @@ function ingestControlFlowInsertionPoint( | |
| } | ||
| } | ||
|
|
||
| // If we've found a single root node, its tag name and *static* attributes can be copied | ||
| // to the surrounding template to be used for content projection. Note that it's important | ||
| // that we don't copy any bound attributes since they don't participate in content projection | ||
| // and they can be used in directive matching (in the case of `Template.templateAttrs`). | ||
| // If we've found a single root node, its tag name and attributes can be | ||
| // copied to the surrounding template to be used for content projection. | ||
| if (root !== null) { | ||
| // Collect the static attributes for content projection purposes. | ||
| for (const attr of root.attributes) { | ||
| const securityContext = domSchema.securityContext(NG_TEMPLATE_TAG_NAME, attr.name, true); | ||
| unit.update.push(ir.createBindingOp( | ||
| xref, ir.BindingKind.Attribute, attr.name, o.literal(attr.value), null, securityContext, | ||
| true, false, null, asMessage(attr.i18n), attr.sourceSpan)); | ||
| } | ||
|
|
||
| // Also collect the inputs since they participate in content projection as well. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // Note that TDB used to collect the outputs as well, but it wasn't passing them into | ||
| // the template instruction. Here we just don't collect them. | ||
| for (const attr of root.inputs) { | ||
| if (attr.type !== e.BindingType.Animation && attr.type !== e.BindingType.Attribute) { | ||
| const securityContext = domSchema.securityContext(NG_TEMPLATE_TAG_NAME, attr.name, true); | ||
| unit.create.push(ir.createExtractedAttributeOp( | ||
| xref, ir.BindingKind.Property, null, attr.name, null, null, null, securityContext)); | ||
| } | ||
| } | ||
|
|
||
| const tagName = root instanceof t.Element ? root.name : root.tagName; | ||
|
|
||
| // Don't pass along `ng-template` tag name since it enables directive matching. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Unrelated change, I just saw that vscode was flagging this as an error.