fix(ivy): fix reference to pipeBind instruction with 2 args (#26451)

PR Close #26451
This commit is contained in:
Pawel Kozlowski 2018-10-15 17:51:21 +02:00 committed by Miško Hevery
parent b2db32b715
commit 45732e5b91
2 changed files with 107 additions and 39 deletions

View File

@ -1486,6 +1486,8 @@ describe('compiler compliance', () => {
describe('pipes', () => { describe('pipes', () => {
it('should render pipes', () => {
const files = { const files = {
app: { app: {
'spec.ts': ` 'spec.ts': `
@ -1524,7 +1526,6 @@ describe('compiler compliance', () => {
} }
}; };
it('should render pipes', () => {
const MyPipeDefinition = ` const MyPipeDefinition = `
MyPipe.ngPipeDef = $r3$.ɵdefinePipe({ MyPipe.ngPipeDef = $r3$.ɵdefinePipe({
name: "myPipe", name: "myPipe",
@ -1579,6 +1580,73 @@ describe('compiler compliance', () => {
expectEmit(source, MyPurePipeDefinition, 'Invalid pure pipe definition'); expectEmit(source, MyPurePipeDefinition, 'Invalid pure pipe definition');
expectEmit(source, MyAppDefinition, 'Invalid MyApp definition'); expectEmit(source, MyAppDefinition, 'Invalid MyApp definition');
}); });
it('should use appropriate function for a given no of pipe arguments', () => {
const files = {
app: {
'spec.ts': `
import {Component, NgModule, Pipe, PipeTransform, OnDestroy} from '@angular/core';
@Pipe({
name: 'myPipe',
pure: false
})
export class MyPipe implements PipeTransform,
OnDestroy {
transform(value: any, ...args: any[]) { return value; }
ngOnDestroy(): void { }
}
@Component({
selector: 'my-app',
template: '0:{{name | myPipe}}1:{{name | myPipe:1}}2:{{name | myPipe:1:2}}3:{{name | myPipe:1:2:3}}4:{{name | myPipe:1:2:3:4}}'
})
export class MyApp {
}
@NgModule({declarations:[MyPipe, MyApp]})
export class MyModule {}
`
}
};
const MyAppDefinition = `
// ...
MyApp.ngComponentDef = $r3$.ɵdefineComponent({
type: MyApp,
selectors: [["my-app"]],
factory: function MyApp_Factory(t) { return new (t || MyApp)(); },
features: [$r3$.ɵPublicFeature],
consts: 6,
vars: 27,
template: function MyApp_Template(rf, ctx) {
if (rf & 1) {
$r3$.ɵtext(0);
$r3$.ɵpipe(1, "myPipe");
$r3$.ɵpipe(2, "myPipe");
$r3$.ɵpipe(3, "myPipe");
$r3$.ɵpipe(4, "myPipe");
$r3$.ɵpipe(5, "myPipe");
}
if (rf & 2) {
$r3$.ɵtextBinding(0, $r3$.ɵinterpolation5(
"0:", i0.ɵpipeBind1(1, 5, ctx.name),
"1:", i0.ɵpipeBind2(2, 7, ctx.name, 1),
"2:", i0.ɵpipeBind3(3, 10, ctx.name, 1, 2),
"3:", i0.ɵpipeBind4(4, 14, ctx.name, 1, 2, 3),
"4:", i0.ɵpipeBindV(5, 19, $r3$.ɵpureFunction1(25, $c0$, ctx.name)),
""
));
}
},
pipes: [MyPipe]
});`;
const result = compile(files, angularFiles);
const source = result.source;
expectEmit(source, MyAppDefinition, 'Invalid MyApp definition');
});
}); });
it('local reference', () => { it('local reference', () => {

View File

@ -78,7 +78,7 @@ export const angularCoreEnv: {[name: string]: Function} = {
'ɵprojection': r3.projection, 'ɵprojection': r3.projection,
'ɵelementProperty': r3.elementProperty, 'ɵelementProperty': r3.elementProperty,
'ɵpipeBind1': r3.pipeBind1, 'ɵpipeBind1': r3.pipeBind1,
'ɵpipeBind2': r3.pipeBind1, 'ɵpipeBind2': r3.pipeBind2,
'ɵpipeBind3': r3.pipeBind3, 'ɵpipeBind3': r3.pipeBind3,
'ɵpipeBind4': r3.pipeBind4, 'ɵpipeBind4': r3.pipeBind4,
'ɵpipeBindV': r3.pipeBindV, 'ɵpipeBindV': r3.pipeBindV,