From 3343ceb82df2eb1097bdfdb318ffa581fccbe20c Mon Sep 17 00:00:00 2001 From: Dylan Hunn Date: Fri, 20 Oct 2023 14:35:03 -0700 Subject: [PATCH] refactor(compiler): Update pipe test golden for alternative create order (#52289) We roughly attempt to match TemplateDefinitionBuilder's pipe creation order, by placing pipe creation instructions after their target elements. However, we cannot fully emulate the "inside-out" ordering TemplateDefinitionBuilder uses when multiple pipes apply to one element, because TemplateDefinitionBuilder creates the pipes as expressions are visited, from the leaves up. Our order is perfectly adequate though. We also add a non-compatibility-mode ordering, which just appends them to the end of the create block. This is better because it allows for more chaining opportunities. PR Close #52289 --- .../pipes/TEST_CASES.json | 6 ++--- .../pipes/pipes_my_app_def.pipeline.js | 27 +++++++++++++++++++ .../pipeline/src/phases/pipe_creation.ts | 9 ++++++- 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/pipes/pipes_my_app_def.pipeline.js diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/pipes/TEST_CASES.json b/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/pipes/TEST_CASES.json index 29a693eff8f..db3e54134d2 100644 --- a/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/pipes/TEST_CASES.json +++ b/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/pipes/TEST_CASES.json @@ -48,12 +48,12 @@ "files": [ { "expected": "pipes_my_app_def.js", + "templatePipelineExpected": "pipes_my_app_def.pipeline.js", "generated": "pipes.js" } ] } - ], - "skipForTemplatePipeline": true + ] }, { "description": "should use appropriate function for a given no of pipe arguments", @@ -114,4 +114,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/pipes/pipes_my_app_def.pipeline.js b/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/pipes/pipes_my_app_def.pipeline.js new file mode 100644 index 00000000000..5e0fb9a4053 --- /dev/null +++ b/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/pipes/pipes_my_app_def.pipeline.js @@ -0,0 +1,27 @@ +const $c0$ = $a0$ => [$a0$, 1, 2, 3, 4, 5]; +// ... +MyApp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({ + type: MyApp, + selectors: [["my-app"]], + decls: 7, + vars: 20, + template: function MyApp_Template(rf, ctx) { + if (rf & 1) { + $r3$.ɵɵtext(0); + $r3$.ɵɵpipe(1, "myPipe"); + $r3$.ɵɵpipe(2, "myPurePipe"); + $r3$.ɵɵelementStart(3, "p"); + $r3$.ɵɵtext(4); + $r3$.ɵɵpipe(5, "myPipe"); + $r3$.ɵɵpipe(6, "myPipe"); + $r3$.ɵɵelementEnd(); + } + if (rf & 2) { + $r3$.ɵɵtextInterpolate($r3$.ɵɵpipeBind2(2, 6, $r3$.ɵɵpipeBind2(1, 3, ctx.name, ctx.size), ctx.size)); + $r3$.ɵɵadvance(4); + $r3$.ɵɵtextInterpolate2("", $r3$.ɵɵpipeBindV(5, 9, $r3$.ɵɵpureFunction1(18, $c0$, ctx.name)), " ", ctx.name ? 1 : $r3$.ɵɵpipeBind1(6, 16, 2), ""); + } + }, + dependencies: [MyPipe, MyPurePipe], + encapsulation: 2 +}); diff --git a/packages/compiler/src/template/pipeline/src/phases/pipe_creation.ts b/packages/compiler/src/template/pipeline/src/phases/pipe_creation.ts index 9b77b7bb12a..f42440fea45 100644 --- a/packages/compiler/src/template/pipeline/src/phases/pipe_creation.ts +++ b/packages/compiler/src/template/pipeline/src/phases/pipe_creation.ts @@ -39,7 +39,14 @@ function processPipeBindingsInView(unit: CompilationUnit): void { ir.OpKind[updateOp.kind]}`); } - addPipeToCreationBlock(unit, updateOp.target, expr); + if (unit.job.compatibility) { + addPipeToCreationBlock(unit, updateOp.target, expr); + } else { + // When not in compatibility mode, we just add the pipe to the end of the create block. This + // is not only simpler and faster, but allows more chaining opportunities for other + // instructions. + unit.create.push(ir.createPipeOp(expr.target, expr.name)); + } }); } }