From ecff426b7e227a211d5261adfa5e321d149ad56c Mon Sep 17 00:00:00 2001 From: Dylan Hunn Date: Fri, 8 Dec 2023 11:36:10 -0800 Subject: [PATCH] refactor(compiler): Don't emit class and style bindings on structural template views MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Template Pipeline has had a number of tricky bugs involving bindings on structural elements. Consider this template: ```
``` We were incorrectly emitting `ɵɵclassProp` on *both* the template's view, and the inner view. The solution is to just emit an extracted attribute on the enclosing template, so it still shows up in the const array, but does not affect the update block. We should look to refactor binding ingestion soon. --- .../r3_view_compiler_styling/class_bindings/TEST_CASES.json | 3 +-- packages/compiler/src/template/pipeline/src/ingest.ts | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/class_bindings/TEST_CASES.json b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/class_bindings/TEST_CASES.json index f208c6d5c2d333..28ea0398c0dbe2 100644 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/class_bindings/TEST_CASES.json +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_styling/class_bindings/TEST_CASES.json @@ -69,8 +69,7 @@ "class_binding_on_structural.js" ] } - ], - "skipForTemplatePipeline": true + ] } ] } diff --git a/packages/compiler/src/template/pipeline/src/ingest.ts b/packages/compiler/src/template/pipeline/src/ingest.ts index de5977a42247ec..6e1e959ea5a852 100644 --- a/packages/compiler/src/template/pipeline/src/ingest.ts +++ b/packages/compiler/src/template/pipeline/src/ingest.ts @@ -903,7 +903,8 @@ function ingestBinding( } if (flags & BindingFlags.OnNgTemplateElement && !(flags & BindingFlags.BindingTargetsTemplate) && - type === e.BindingType.Property) { + (type === e.BindingType.Property || type === e.BindingType.Class || + type === e.BindingType.Style)) { // This binding only exists for later const extraction, and is not an actual binding to be // created. view.create.push(ir.createExtractedAttributeOp(