From 3c24136b9880b871c917c392869788254da993bc Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Thu, 18 Feb 2021 22:20:45 +0000 Subject: [PATCH] =?UTF-8?q?fix(compiler):=20ensure=20JIT=20compilation=20o?= =?UTF-8?q?f=20=C9=B5=C9=B5ngDeclarePipe()=20works=20(#40929)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously the compiler was not evaluating the JIT compilation of `ɵɵngDeclarePipe()` but there was no test to check it. PR Close #40929 --- packages/compiler/src/jit_compiler_facade.ts | 3 +- .../test/render3/jit/declare_pipe_spec.ts | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 packages/core/test/render3/jit/declare_pipe_spec.ts diff --git a/packages/compiler/src/jit_compiler_facade.ts b/packages/compiler/src/jit_compiler_facade.ts index 85aba35c8c..a1ec6553db 100644 --- a/packages/compiler/src/jit_compiler_facade.ts +++ b/packages/compiler/src/jit_compiler_facade.ts @@ -54,7 +54,8 @@ export class CompilerFacadeImpl implements CompilerFacade { angularCoreEnv: CoreEnvironment, sourceMapUrl: string, declaration: R3DeclarePipeFacade): any { const meta = convertDeclarePipeFacadeToMetadata(declaration); - return compilePipeFromMetadata(meta); + const res = compilePipeFromMetadata(meta); + return this.jitExpression(res.expression, angularCoreEnv, sourceMapUrl, []); } compileInjectable( diff --git a/packages/core/test/render3/jit/declare_pipe_spec.ts b/packages/core/test/render3/jit/declare_pipe_spec.ts new file mode 100644 index 0000000000..fb87726246 --- /dev/null +++ b/packages/core/test/render3/jit/declare_pipe_spec.ts @@ -0,0 +1,30 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {ɵɵngDeclarePipe} from '@angular/core'; +import {PipeDef} from '../../../src/render3'; + +describe('Pipe declaration jit compilation', () => { + it('should compile a named Pipe declaration', () => { + const def = ɵɵngDeclarePipe({type: TestClass, name: 'foo'}) as PipeDef; + + expect(def.type).toBe(TestClass); + expect(def.name).toEqual('foo'); + expect(def.pure).toEqual(true); + }); + + it('should compile an impure Pipe declaration', () => { + const def = ɵɵngDeclarePipe({type: TestClass, name: 'foo', pure: false}) as PipeDef; + + expect(def.type).toBe(TestClass); + expect(def.name).toEqual('foo'); + expect(def.pure).toEqual(false); + }); +}); + +class TestClass {}