From f62876bbcb45200f729ff6336dbe5aefe535f296 Mon Sep 17 00:00:00 2001 From: cexbrayat Date: Wed, 4 Jul 2018 01:13:54 +0200 Subject: [PATCH] fix(ivy): pipes are pure by default (#24750) PR Close #24750 --- .../src/ngtsc/annotations/src/pipe.ts | 2 +- .../compiler-cli/test/ngtsc/ngtsc_spec.ts | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts b/packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts index 06a208291e..c3da6204eb 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/pipe.ts @@ -50,7 +50,7 @@ export class PipeDecoratorHandler implements DecoratorHandler { } this.scopeRegistry.registerPipe(clazz, pipeName); - let pure = false; + let pure = true; if (pipe.has('pure')) { const pureValue = staticallyResolve(pipe.get('pure') !, this.checker); if (typeof pureValue !== 'boolean') { diff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts index 48e230e17e..1ea38268bc 100644 --- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts +++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts @@ -270,6 +270,31 @@ describe('ngtsc behavioral tests', () => { expect(dtsContents).toContain('static ngPipeDef: i0.ɵPipeDef;'); }); + it('should compile pure Pipes without errors', () => { + writeConfig(); + write('test.ts', ` + import {Pipe} from '@angular/core'; + + @Pipe({ + name: 'test-pipe', + }) + export class TestPipe {} + `); + + const exitCode = main(['-p', basePath], errorSpy); + expect(errorSpy).not.toHaveBeenCalled(); + expect(exitCode).toBe(0); + + const jsContents = getContents('test.js'); + const dtsContents = getContents('test.d.ts'); + + expect(jsContents) + .toContain( + 'TestPipe.ngPipeDef = i0.ɵdefinePipe({ name: "test-pipe", type: TestPipe, ' + + 'factory: function TestPipe_Factory() { return new TestPipe(); }, pure: true })'); + expect(dtsContents).toContain('static ngPipeDef: i0.ɵPipeDef;'); + }); + it('should compile Pipes with dependencies', () => { writeConfig(); write('test.ts', `