feat(ivy): JIT support for compilation of @Pipes (#24703)

Adds support for compiling @Pipe in JIT mode, along with tests
to verify that certain aspects of compilation are correct.

PR Close #24703
This commit is contained in:
Alex Rickabaugh
2018-06-26 10:44:05 -07:00
committed by Miško Hevery
parent dbdcfed2bd
commit 3d52174bf1
6 changed files with 71 additions and 4 deletions

View File

@ -12,9 +12,9 @@ import {InjectorDef, defineInjectable} from '@angular/core/src/di/defs';
import {Injectable} from '@angular/core/src/di/injectable';
import {inject, setCurrentInjector} from '@angular/core/src/di/injector';
import {ivyEnabled} from '@angular/core/src/ivy_switch';
import {Component, HostBinding, HostListener} from '@angular/core/src/metadata/directives';
import {Component, HostBinding, HostListener, Pipe} from '@angular/core/src/metadata/directives';
import {NgModule, NgModuleDefInternal} from '@angular/core/src/metadata/ng_module';
import {ComponentDefInternal} from '@angular/core/src/render3/interfaces/definition';
import {ComponentDefInternal, PipeDefInternal} from '@angular/core/src/render3/interfaces/definition';
ivyEnabled && describe('render3 jit', () => {
let injector: any;
@ -212,6 +212,27 @@ ivyEnabled && describe('render3 jit', () => {
expect(cmpDef.hostBindings).toBeDefined();
expect(cmpDef.hostBindings !.length).toBe(2);
});
it('should compile @Pipes without errors', () => {
@Pipe({name: 'test-pipe', pure: false})
class P {
}
const pipeDef = (P as any).ngPipeDef as PipeDefInternal<P>;
expect(pipeDef.name).toBe('test-pipe');
expect(pipeDef.pure).toBe(false, 'pipe should not be pure');
expect(pipeDef.factory() instanceof P)
.toBe(true, 'factory() should create an instance of the pipe');
});
it('should default @Pipe to pure: true', () => {
@Pipe({name: 'test-pipe'})
class P {
}
const pipeDef = (P as any).ngPipeDef as PipeDefInternal<P>;
expect(pipeDef.pure).toBe(true, 'pipe should be pure');
});
});
it('ensure at least one spec exists', () => {});

View File

@ -16,6 +16,7 @@ const INTERFACE_EXCEPTIONS = new Set<string>([
'DirectiveDef',
'InjectorDef',
'NgModuleDef',
'ɵPipeDef',
]);
describe('r3 jit environment', () => {