feat(ivy): dummy handler for @Pipe to cause decorator removal (#24677)

Currently ngtsc does not compile @Pipe. This has a side effect
of not removing the @Pipe decorator.

This adds a dummy DecoratorHandler that compiles @Pipe into an
empty ngPipeDef. Eventually this will be replaced with a full
implementation, but for now this solution allows compield code
to be tree-shaken properly.

PR Close #24677
This commit is contained in:
Alex Rickabaugh 2018-06-20 15:59:15 -07:00 committed by Miško Hevery
parent 2ecaa40e64
commit ef1c6d8c26
3 changed files with 42 additions and 1 deletions

View File

@ -10,4 +10,5 @@ export {ComponentDecoratorHandler} from './src/component';
export {DirectiveDecoratorHandler} from './src/directive';
export {InjectableDecoratorHandler} from './src/injectable';
export {NgModuleDecoratorHandler} from './src/ng_module';
export {PipeDecoratorHandler} from './src/pipe';
export {CompilationScope, SelectorScopeRegistry} from './src/selector_scope';

View File

@ -0,0 +1,39 @@
/**
* @license
* Copyright Google Inc. 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 {Expression, ExpressionType, LiteralExpr, R3DependencyMetadata, R3InjectableMetadata, R3ResolvedDependencyType, WrappedNodeExpr, compileInjectable as compileIvyInjectable} from '@angular/compiler';
import * as ts from 'typescript';
import {Decorator, ReflectionHost} from '../../host';
import {AnalysisOutput, CompileResult, DecoratorHandler} from '../../transform';
import {isAngularCore} from './util';
export class PipeDecoratorHandler implements DecoratorHandler<string> {
constructor(private reflector: ReflectionHost, private isCore: boolean) {}
detect(decorator: Decorator[]): Decorator|undefined {
return decorator.find(
decorator => decorator.name === 'Pipe' && (this.isCore || isAngularCore(decorator)));
}
analyze(node: ts.ClassDeclaration, decorator: Decorator): AnalysisOutput<string> {
return {
analysis: 'test',
};
}
compile(node: ts.ClassDeclaration, analysis: string): CompileResult {
return {
name: 'ngPipeDef',
initializer: new LiteralExpr(null),
statements: [],
type: new ExpressionType(new LiteralExpr(null)),
};
}
}

View File

@ -12,7 +12,7 @@ import * as ts from 'typescript';
import * as api from '../transformers/api';
import {ComponentDecoratorHandler, DirectiveDecoratorHandler, InjectableDecoratorHandler, NgModuleDecoratorHandler, SelectorScopeRegistry} from './annotations';
import {ComponentDecoratorHandler, DirectiveDecoratorHandler, InjectableDecoratorHandler, NgModuleDecoratorHandler, PipeDecoratorHandler, SelectorScopeRegistry} from './annotations';
import {CompilerHost} from './compiler_host';
import {TypeScriptReflectionHost} from './metadata';
import {IvyCompilation, ivyTransformFactory} from './transform';
@ -101,6 +101,7 @@ export class NgtscProgram implements api.Program {
new DirectiveDecoratorHandler(checker, reflector, scopeRegistry, isCore),
new InjectableDecoratorHandler(reflector, isCore),
new NgModuleDecoratorHandler(checker, reflector, scopeRegistry, isCore),
new PipeDecoratorHandler(reflector, isCore),
];
const coreImportsFrom = isCore && getR3SymbolsFile(this.tsProgram) || null;