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:
parent
2ecaa40e64
commit
ef1c6d8c26
|
@ -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';
|
||||
|
|
|
@ -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)),
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue