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
This commit is contained in:
Dylan Hunn 2023-10-20 14:35:03 -07:00
parent 0491fba523
commit 3343ceb82d
3 changed files with 38 additions and 4 deletions

View file

@ -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 @@
]
}
]
}
}

View file

@ -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
});

View file

@ -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));
}
});
}
}