fix(compiler): properly implement pure pipes and change pipe syntax

Pure pipes as well as arrays and maps are
implemented via proxy functions. This is
faster than the previous implementation
and also generates less code.

BREAKING CHANGE:
- pipes now take a variable number of arguments, and not an array that contains all arguments.
This commit is contained in:
Tobias Bosch
2016-04-22 15:33:32 -07:00
parent d6626309fd
commit 152a117d5c
48 changed files with 698 additions and 283 deletions
@@ -208,14 +208,14 @@ export function main() {
describe('null', () => {
it('should return null when given null', () => {
var pipe = new AsyncPipe(null);
expect(pipe.transform(null, [])).toEqual(null);
expect(pipe.transform(null)).toEqual(null);
});
});
describe('other types', () => {
it('should throw when given an invalid object', () => {
var pipe = new AsyncPipe(null);
expect(() => pipe.transform(<any>"some bogus object", [])).toThrowError();
expect(() => pipe.transform(<any>"some bogus object")).toThrowError();
});
});
});
@@ -42,39 +42,39 @@ export function main() {
if (browserDetection.supportsIntlApi) {
describe("transform", () => {
it('should format each component correctly', () => {
expect(pipe.transform(date, ['y'])).toEqual('2015');
expect(pipe.transform(date, ['yy'])).toEqual('15');
expect(pipe.transform(date, ['M'])).toEqual('6');
expect(pipe.transform(date, ['MM'])).toEqual('06');
expect(pipe.transform(date, ['MMM'])).toEqual('Jun');
expect(pipe.transform(date, ['MMMM'])).toEqual('June');
expect(pipe.transform(date, ['d'])).toEqual('15');
expect(pipe.transform(date, ['E'])).toEqual('Mon');
expect(pipe.transform(date, ['EEEE'])).toEqual('Monday');
expect(pipe.transform(date, ['H'])).toEqual('21');
expect(pipe.transform(date, ['j'])).toEqual('9 PM');
expect(pipe.transform(date, ['m'])).toEqual('43');
expect(pipe.transform(date, ['s'])).toEqual('11');
expect(pipe.transform(date, 'y')).toEqual('2015');
expect(pipe.transform(date, 'yy')).toEqual('15');
expect(pipe.transform(date, 'M')).toEqual('6');
expect(pipe.transform(date, 'MM')).toEqual('06');
expect(pipe.transform(date, 'MMM')).toEqual('Jun');
expect(pipe.transform(date, 'MMMM')).toEqual('June');
expect(pipe.transform(date, 'd')).toEqual('15');
expect(pipe.transform(date, 'E')).toEqual('Mon');
expect(pipe.transform(date, 'EEEE')).toEqual('Monday');
expect(pipe.transform(date, 'H')).toEqual('21');
expect(pipe.transform(date, 'j')).toEqual('9 PM');
expect(pipe.transform(date, 'm')).toEqual('43');
expect(pipe.transform(date, 's')).toEqual('11');
});
it('should format common multi component patterns', () => {
expect(pipe.transform(date, ['yMEd'])).toEqual('Mon, 6/15/2015');
expect(pipe.transform(date, ['MEd'])).toEqual('Mon, 6/15');
expect(pipe.transform(date, ['MMMd'])).toEqual('Jun 15');
expect(pipe.transform(date, ['yMMMMEEEEd'])).toEqual('Monday, June 15, 2015');
expect(pipe.transform(date, ['jms'])).toEqual('9:43:11 PM');
expect(pipe.transform(date, ['ms'])).toEqual('43:11');
expect(pipe.transform(date, 'yMEd')).toEqual('Mon, 6/15/2015');
expect(pipe.transform(date, 'MEd')).toEqual('Mon, 6/15');
expect(pipe.transform(date, 'MMMd')).toEqual('Jun 15');
expect(pipe.transform(date, 'yMMMMEEEEd')).toEqual('Monday, June 15, 2015');
expect(pipe.transform(date, 'jms')).toEqual('9:43:11 PM');
expect(pipe.transform(date, 'ms')).toEqual('43:11');
});
it('should format with pattern aliases', () => {
expect(pipe.transform(date, ['medium'])).toEqual('Jun 15, 2015, 9:43:11 PM');
expect(pipe.transform(date, ['short'])).toEqual('6/15/2015, 9:43 PM');
expect(pipe.transform(date, ['fullDate'])).toEqual('Monday, June 15, 2015');
expect(pipe.transform(date, ['longDate'])).toEqual('June 15, 2015');
expect(pipe.transform(date, ['mediumDate'])).toEqual('Jun 15, 2015');
expect(pipe.transform(date, ['shortDate'])).toEqual('6/15/2015');
expect(pipe.transform(date, ['mediumTime'])).toEqual('9:43:11 PM');
expect(pipe.transform(date, ['shortTime'])).toEqual('9:43 PM');
expect(pipe.transform(date, 'medium')).toEqual('Jun 15, 2015, 9:43:11 PM');
expect(pipe.transform(date, 'short')).toEqual('6/15/2015, 9:43 PM');
expect(pipe.transform(date, 'fullDate')).toEqual('Monday, June 15, 2015');
expect(pipe.transform(date, 'longDate')).toEqual('June 15, 2015');
expect(pipe.transform(date, 'mediumDate')).toEqual('Jun 15, 2015');
expect(pipe.transform(date, 'shortDate')).toEqual('6/15/2015');
expect(pipe.transform(date, 'mediumTime')).toEqual('9:43:11 PM');
expect(pipe.transform(date, 'shortTime')).toEqual('9:43 PM');
});
});
}
@@ -26,33 +26,33 @@ export function main() {
describe("transform", () => {
it("should return 0 text if value is 0", () => {
var val = pipe.transform(0, [mapping]);
var val = pipe.transform(0, mapping);
expect(val).toEqual('No messages.');
});
it("should return 1 text if value is 1", () => {
var val = pipe.transform(1, [mapping]);
var val = pipe.transform(1, mapping);
expect(val).toEqual('One message.');
});
it("should return other text if value is anything other than 0 or 1", () => {
var val = pipe.transform(6, [mapping]);
var val = pipe.transform(6, mapping);
expect(val).toEqual('There are some messages.');
});
it("should interpolate the value into the text where indicated", () => {
var val = pipe.transform(6, [interpolatedMapping]);
var val = pipe.transform(6, interpolatedMapping);
expect(val).toEqual('There are 6 messages, that is 6.');
});
it("should use 'other' if value is undefined", () => {
var messageLength;
var val = pipe.transform(messageLength, [interpolatedMapping]);
var val = pipe.transform(messageLength, interpolatedMapping);
expect(val).toEqual('There are messages, that is .');
});
it("should not support bad arguments",
() => { expect(() => pipe.transform(0, ['hey'])).toThrowError(); });
() => { expect(() => pipe.transform(0, 'hey')).toThrowError(); });
});
});
@@ -24,28 +24,28 @@ export function main() {
describe("transform", () => {
it("should return male text if value is male", () => {
var val = pipe.transform('male', [mapping]);
var val = pipe.transform('male', mapping);
expect(val).toEqual('Invite him.');
});
it("should return female text if value is female", () => {
var val = pipe.transform('female', [mapping]);
var val = pipe.transform('female', mapping);
expect(val).toEqual('Invite her.');
});
it("should return other text if value is anything other than male or female", () => {
var val = pipe.transform('Anything else', [mapping]);
var val = pipe.transform('Anything else', mapping);
expect(val).toEqual('Invite them.');
});
it("should use 'other' if value is undefined", () => {
var gender;
var val = pipe.transform(gender, [mapping]);
var val = pipe.transform(gender, mapping);
expect(val).toEqual('Invite them.');
});
it("should not support bad arguments",
() => { expect(() => pipe.transform('male', ['hey'])).toThrowError(); });
() => { expect(() => pipe.transform('male', 'hey')).toThrowError(); });
});
});
@@ -24,17 +24,17 @@ export function main() {
describe("transform", () => {
it('should return correct value for numbers', () => {
expect(pipe.transform(12345, [])).toEqual('12,345');
expect(pipe.transform(123, ['.2'])).toEqual('123.00');
expect(pipe.transform(1, ['3.'])).toEqual('001');
expect(pipe.transform(1.1, ['3.4-5'])).toEqual('001.1000');
expect(pipe.transform(12345)).toEqual('12,345');
expect(pipe.transform(123, '.2')).toEqual('123.00');
expect(pipe.transform(1, '3.')).toEqual('001');
expect(pipe.transform(1.1, '3.4-5')).toEqual('001.1000');
expect(pipe.transform(1.123456, ['3.4-5'])).toEqual('001.12346');
expect(pipe.transform(1.1234, [])).toEqual('1.123');
expect(pipe.transform(1.123456, '3.4-5')).toEqual('001.12346');
expect(pipe.transform(1.1234)).toEqual('1.123');
});
it("should not support other objects",
() => { expect(() => pipe.transform(new Object(), [])).toThrowError(); });
() => { expect(() => pipe.transform(new Object())).toThrowError(); });
});
});
@@ -45,12 +45,12 @@ export function main() {
describe("transform", () => {
it('should return correct value for numbers', () => {
expect(pipe.transform(1.23, [])).toEqual('123%');
expect(pipe.transform(1.2, ['.2'])).toEqual('120.00%');
expect(pipe.transform(1.23)).toEqual('123%');
expect(pipe.transform(1.2, '.2')).toEqual('120.00%');
});
it("should not support other objects",
() => { expect(() => pipe.transform(new Object(), [])).toThrowError(); });
() => { expect(() => pipe.transform(new Object())).toThrowError(); });
});
});
@@ -61,12 +61,12 @@ export function main() {
describe("transform", () => {
it('should return correct value for numbers', () => {
expect(pipe.transform(123, [])).toEqual('USD123');
expect(pipe.transform(12, ['EUR', false, '.2'])).toEqual('EUR12.00');
expect(pipe.transform(123)).toEqual('USD123');
expect(pipe.transform(12, 'EUR', false, '.2')).toEqual('EUR12.00');
});
it("should not support other objects",
() => { expect(() => pipe.transform(new Object(), [])).toThrowError(); });
() => { expect(() => pipe.transform(new Object())).toThrowError(); });
});
});
}
@@ -31,34 +31,34 @@ export function main() {
describe("transform", () => {
it("should not support input other than strings and numbers", () => {
expect(() => pipe.transform({}, ["Douglas", "Hugh"])).toThrow();
expect(() => pipe.transform([1, 2, 3], ["Douglas", "Hugh"])).toThrow();
expect(() => pipe.transform({}, "Douglas", "Hugh")).toThrow();
expect(() => pipe.transform([1, 2, 3], "Douglas", "Hugh")).toThrow();
});
it("should not support patterns other than strings and regular expressions", () => {
expect(() => pipe.transform(str, [{}, "Hugh"])).toThrow();
expect(() => pipe.transform(str, [null, "Hugh"])).toThrow();
expect(() => pipe.transform(str, [123, "Hugh"])).toThrow();
expect(() => pipe.transform(str, {}, "Hugh")).toThrow();
expect(() => pipe.transform(str, null, "Hugh")).toThrow();
expect(() => pipe.transform(str, 123, "Hugh")).toThrow();
});
it("should not support replacements other than strings and functions", () => {
expect(() => pipe.transform(str, ["Douglas", {}])).toThrow();
expect(() => pipe.transform(str, ["Douglas", null])).toThrow();
expect(() => pipe.transform(str, ["Douglas", 123])).toThrow();
expect(() => pipe.transform(str, "Douglas", {})).toThrow();
expect(() => pipe.transform(str, "Douglas", null)).toThrow();
expect(() => pipe.transform(str, "Douglas", 123)).toThrow();
});
it("should return a new string with the pattern replaced", () => {
var result1 = pipe.transform(str, ["Douglas", "Hugh"]);
var result1 = pipe.transform(str, "Douglas", "Hugh");
var result2 = pipe.transform(str, [RegExpWrapper.create("a"), "_"]);
var result2 = pipe.transform(str, RegExpWrapper.create("a"), "_");
var result3 = pipe.transform(str, [RegExpWrapper.create("a", "i"), "_"]);
var result3 = pipe.transform(str, RegExpWrapper.create("a", "i"), "_");
var f = (x => { return "Adams!"; });
var result4 = pipe.transform(str, ["Adams", f]);
var result4 = pipe.transform(str, "Adams", f);
var result5 = pipe.transform(someNumber, ["2", "4"]);
var result5 = pipe.transform(someNumber, "2", "4");
expect(result1).toEqual("Hugh Adams");
expect(result2).toEqual("Dougl_s Ad_ms");
@@ -42,47 +42,47 @@ export function main() {
it('should return all items after START index when START is positive and END is omitted',
() => {
expect(pipe.transform(list, [3])).toEqual([4, 5]);
expect(pipe.transform(str, [3])).toEqual('wxyz');
expect(pipe.transform(list, 3)).toEqual([4, 5]);
expect(pipe.transform(str, 3)).toEqual('wxyz');
});
it('should return last START items when START is negative and END is omitted', () => {
expect(pipe.transform(list, [-3])).toEqual([3, 4, 5]);
expect(pipe.transform(str, [-3])).toEqual('xyz');
expect(pipe.transform(list, -3)).toEqual([3, 4, 5]);
expect(pipe.transform(str, -3)).toEqual('xyz');
});
it('should return all items between START and END index when START and END are positive',
() => {
expect(pipe.transform(list, [1, 3])).toEqual([2, 3]);
expect(pipe.transform(str, [1, 3])).toEqual('uv');
expect(pipe.transform(list, 1, 3)).toEqual([2, 3]);
expect(pipe.transform(str, 1, 3)).toEqual('uv');
});
it('should return all items between START and END from the end when START and END are negative',
() => {
expect(pipe.transform(list, [-4, -2])).toEqual([2, 3]);
expect(pipe.transform(str, [-4, -2])).toEqual('wx');
expect(pipe.transform(list, -4, -2)).toEqual([2, 3]);
expect(pipe.transform(str, -4, -2)).toEqual('wx');
});
it('should return an empty value if START is greater than END', () => {
expect(pipe.transform(list, [4, 2])).toEqual([]);
expect(pipe.transform(str, [4, 2])).toEqual('');
expect(pipe.transform(list, 4, 2)).toEqual([]);
expect(pipe.transform(str, 4, 2)).toEqual('');
});
it('should return an empty value if START greater than input length', () => {
expect(pipe.transform(list, [99])).toEqual([]);
expect(pipe.transform(str, [99])).toEqual('');
expect(pipe.transform(list, 99)).toEqual([]);
expect(pipe.transform(str, 99)).toEqual('');
});
// Makes Edge to disconnect when running the full unit test campaign
// TODO: remove when issue is solved: https://github.com/angular/angular/issues/4756
if (!browserDetection.isEdge) {
it('should return entire input if START is negative and greater than input length', () => {
expect(pipe.transform(list, [-99])).toEqual([1, 2, 3, 4, 5]);
expect(pipe.transform(str, [-99])).toEqual('tuvwxyz');
expect(pipe.transform(list, -99)).toEqual([1, 2, 3, 4, 5]);
expect(pipe.transform(str, -99)).toEqual('tuvwxyz');
});
it('should not modify the input list', () => {
expect(pipe.transform(list, [2])).toEqual([3, 4, 5]);
expect(pipe.transform(list, 2)).toEqual([3, 4, 5]);
expect(list).toEqual([1, 2, 3, 4, 5]);
});
}
@@ -103,6 +103,11 @@ export function main() {
.callMethod(o.BuiltinMethod.SubscribeObservable, [o.variable('listener')])
.toStmt()))
.toEqual('observable.listen(listener);');
expect(
emitStmt(
o.variable('fn').callMethod(o.BuiltinMethod.bind, [o.variable('someObj')]).toStmt()))
.toEqual('fn;');
});
it('should support literals', () => {
@@ -95,6 +95,11 @@ export function main() {
.callMethod(o.BuiltinMethod.SubscribeObservable, [o.variable('listener')])
.toStmt()))
.toEqual('observable.subscribe(listener);');
expect(
emitStmt(
o.variable('fn').callMethod(o.BuiltinMethod.bind, [o.variable('someObj')]).toStmt()))
.toEqual('fn.bind(someObj);');
});
it('should support literals', () => {
@@ -88,8 +88,12 @@ export function main() {
expect(expressions['concatedArray']).toEqual([0, 1]);
expect(expressions['invokeMethodExternalInstance'])
.toEqual({'data': 'someValue', 'param': 'someParam'});
expect(expressions['invokeMethodExternalInstanceViaBind'])
.toEqual({'data': 'someValue', 'param': 'someParam'});
expect(expressions['invokeMethodDynamicInstance'])
.toEqual({'data': 'someValue', 'dynamicProp': 'dynamicValue', 'param': 'someParam'});
expect(expressions['invokeMethodDynamicInstanceViaBind'])
.toEqual({'data': 'someValue', 'dynamicProp': 'dynamicValue', 'param': 'someParam'});
});
it('should support conditionals', () => {
@@ -116,10 +116,24 @@ var _getExpressionsStmts: o.Statement[] = [
'invokeMethodExternalInstance',
o.variable('externalInstance').callMethod('someMethod', [o.literal('someParam')])
],
[
'invokeMethodExternalInstanceViaBind',
o.variable('externalInstance')
.prop('someMethod')
.callMethod(o.BuiltinMethod.bind, [o.variable('externalInstance')])
.callFn([o.literal('someParam')])
],
[
'invokeMethodDynamicInstance',
o.variable('dynamicInstance').callMethod('dynamicMethod', [o.literal('someParam')])
],
[
'invokeMethodDynamicInstanceViaBind',
o.variable('dynamicInstance')
.prop('dynamicMethod')
.callMethod(o.BuiltinMethod.bind, [o.variable('dynamicInstance')])
.callFn([o.literal('someParam')])
],
[
'concatedArray',
o.literalArr([o.literal(0)])
@@ -96,6 +96,11 @@ export function main() {
.callMethod(o.BuiltinMethod.SubscribeObservable, [o.variable('listener')])
.toStmt()))
.toEqual('observable.subscribe(listener);');
expect(
emitStmt(
o.variable('fn').callMethod(o.BuiltinMethod.bind, [o.variable('someObj')]).toStmt()))
.toEqual('fn.bind(someObj);');
});
it('should support literals', () => {
@@ -460,6 +460,13 @@ export function main() {
}));
it('should associate pipes right-to-left', fakeAsync(() => {
var ctx = _bindSimpleValue('name | multiArgPipe:"a":"b" | multiArgPipe:0:1', Person);
ctx.componentInstance.name = 'value';
ctx.detectChanges(false);
expect(renderLog.loggedValues).toEqual(['value a b default 0 1 default']);
}));
it('should support calling pure pipes with different number of arguments', fakeAsync(() => {
var ctx = _bindSimpleValue('name | multiArgPipe:"a":"b" | multiArgPipe:0:1:2', Person);
ctx.componentInstance.name = 'value';
ctx.detectChanges(false);
@@ -491,6 +498,56 @@ export function main() {
expect(renderLog.log).toEqual(['someProp=Megatron']);
}));
it('should call pure pipes only if the arguments change', fakeAsync(() => {
var ctx = _bindSimpleValue('name | countingPipe', Person);
// change from undefined -> null
ctx.componentInstance.name = null;
ctx.detectChanges(false);
expect(renderLog.loggedValues).toEqual(['null state:0']);
ctx.detectChanges(false);
expect(renderLog.loggedValues).toEqual(['null state:0']);
// change from null -> some value
ctx.componentInstance.name = 'bob';
ctx.detectChanges(false);
expect(renderLog.loggedValues).toEqual(['null state:0', 'bob state:1']);
ctx.detectChanges(false);
expect(renderLog.loggedValues).toEqual(['null state:0', 'bob state:1']);
// change from some value -> some other value
ctx.componentInstance.name = 'bart';
ctx.detectChanges(false);
expect(renderLog.loggedValues)
.toEqual(['null state:0', 'bob state:1', 'bart state:2']);
ctx.detectChanges(false);
expect(renderLog.loggedValues)
.toEqual(['null state:0', 'bob state:1', 'bart state:2']);
}));
it('should call pure pipes that are used multiple times only when the arguments change',
fakeAsync(() => {
var ctx = createCompFixture(`<div [someProp]="name | countingPipe"></div><div [someProp]="age | countingPipe"></div>`, Person);
ctx.componentInstance.name = 'a';
ctx.componentInstance.age = 10;
ctx.detectChanges(false);
expect(renderLog.loggedValues).toEqual(['a state:0', '10 state:1']);
ctx.detectChanges(false);
expect(renderLog.loggedValues).toEqual(['a state:0', '10 state:1']);
ctx.componentInstance.age = 11;
ctx.detectChanges(false);
expect(renderLog.loggedValues).toEqual(['a state:0', '10 state:1', '11 state:2']);
}));
it('should call impure pipes on each change detection run', fakeAsync(() => {
var ctx = _bindSimpleValue('name | countingImpurePipe', Person);
ctx.componentInstance.name = 'bob';
ctx.detectChanges(false);
expect(renderLog.loggedValues).toEqual(['bob state:0']);
ctx.detectChanges(false);
expect(renderLog.loggedValues).toEqual(['bob state:0', 'bob state:1']);
}));
});
describe('event expressions', () => {
@@ -1014,6 +1071,7 @@ const ALL_DIRECTIVES = CONST_EXPR([
const ALL_PIPES = CONST_EXPR([
forwardRef(() => CountingPipe),
forwardRef(() => CountingImpurePipe),
forwardRef(() => MultiArgPipe),
forwardRef(() => PipeWithOnDestroy),
forwardRef(() => IdentityPipe),
@@ -1086,7 +1144,13 @@ class DirectiveLog {
@Pipe({name: 'countingPipe'})
class CountingPipe implements PipeTransform {
state: number = 0;
transform(value, args = null) { return `${value} state:${this.state ++}`; }
transform(value) { return `${value} state:${this.state ++}`; }
}
@Pipe({name: 'countingImpurePipe', pure: false})
class CountingImpurePipe implements PipeTransform {
state: number = 0;
transform(value) { return `${value} state:${this.state ++}`; }
}
@Pipe({name: 'pipeWithOnDestroy'})
@@ -1095,27 +1159,22 @@ class PipeWithOnDestroy implements PipeTransform, OnDestroy {
ngOnDestroy() { this.directiveLog.add('pipeWithOnDestroy', 'ngOnDestroy'); }
transform(value, args = null) { return null; }
transform(value) { return null; }
}
@Pipe({name: 'identityPipe'})
class IdentityPipe implements PipeTransform {
transform(value, args = null) { return value; }
transform(value) { return value; }
}
@Pipe({name: 'wrappedPipe'})
class WrappedPipe implements PipeTransform {
transform(value, args = null) { return WrappedValue.wrap(value); }
transform(value) { return WrappedValue.wrap(value); }
}
@Pipe({name: 'multiArgPipe'})
class MultiArgPipe implements PipeTransform {
transform(value, args = null) {
var arg1 = args[0];
var arg2 = args[1];
var arg3 = args.length > 2 ? args[2] : 'default';
return `${value} ${arg1} ${arg2} ${arg3}`;
}
transform(value, arg1, arg2, arg3 = 'default') { return `${value} ${arg1} ${arg2} ${arg3}`; }
}
@Component({selector: 'test-cmp', template: '', directives: ALL_DIRECTIVES, pipes: ALL_PIPES})
@@ -2136,7 +2136,7 @@ class SomeViewport {
@Pipe({name: 'double'})
class DoublePipe implements PipeTransform, OnDestroy {
ngOnDestroy() {}
transform(value, args = null) { return `${value}${value}`; }
transform(value) { return `${value}${value}`; }
}
@Directive({selector: '[emitter]', outputs: ['event']})
@@ -152,10 +152,10 @@ class MyComp {
@Pipe({name: 'somePipe', pure: true})
class PlatformPipe implements PipeTransform {
transform(value: any, args: any[]): any { return 'somePlatformPipe'; }
transform(value: any): any { return 'somePlatformPipe'; }
}
@Pipe({name: 'somePipe', pure: true})
class CustomPipe implements PipeTransform {
transform(value: any, args: any[]): any { return 'someCustomPipe'; }
transform(value: any): any { return 'someCustomPipe'; }
}
@@ -232,38 +232,38 @@ class PushComponentNeedsChangeDetectorRef {
}
@Pipe({name: 'purePipe', pure: true})
class PurePipe {
class PurePipe implements PipeTransform {
constructor() {}
transform(value: any, args: any[] = null): any { return this; }
transform(value: any): any { return this; }
}
@Pipe({name: 'impurePipe', pure: false})
class ImpurePipe {
class ImpurePipe implements PipeTransform {
constructor() {}
transform(value: any, args: any[] = null): any { return this; }
transform(value: any): any { return this; }
}
@Pipe({name: 'pipeNeedsChangeDetectorRef'})
class PipeNeedsChangeDetectorRef {
constructor(public changeDetectorRef: ChangeDetectorRef) {}
transform(value: any, args: any[] = null): any { return this; }
transform(value: any): any { return this; }
}
@Pipe({name: 'pipeNeedsService'})
export class PipeNeedsService implements PipeTransform {
service: any;
constructor(@Inject("service") service) { this.service = service; }
transform(value: any, args: any[] = null): any { return this; }
transform(value: any): any { return this; }
}
@Pipe({name: 'duplicatePipe'})
export class DuplicatePipe1 implements PipeTransform {
transform(value: any, args: any[] = null): any { return this; }
transform(value: any): any { return this; }
}
@Pipe({name: 'duplicatePipe'})
export class DuplicatePipe2 implements PipeTransform {
transform(value: any, args: any[] = null): any { return this; }
transform(value: any): any { return this; }
}
@Component({selector: 'root'})
@@ -654,7 +654,7 @@ export function main() {
it('should cache pure pipes', fakeAsync(() => {
var el = createComp(
'<div [simpleDirective]="true | purePipe"></div><div [simpleDirective]="true | purePipe"></div>',
'<div [simpleDirective]="true | purePipe"></div><div *ngIf="true" [simpleDirective]="true | purePipe"></div>',
tcb);
var purePipe1 = el.children[0].inject(SimpleDirective).value;
var purePipe2 = el.children[1].inject(SimpleDirective).value;