@@ -9,7 +9,7 @@ import {ConstantPool} from '@angular/compiler';
99import * as fs from 'fs' ;
1010import * as ts from 'typescript' ;
1111
12- import { ComponentDecoratorHandler , DirectiveDecoratorHandler , InjectableDecoratorHandler , NgModuleDecoratorHandler , PipeDecoratorHandler , ResourceLoader , SelectorScopeRegistry } from '../../ngtsc/annotations' ;
12+ import { BaseDefDecoratorHandler , ComponentDecoratorHandler , DirectiveDecoratorHandler , InjectableDecoratorHandler , NgModuleDecoratorHandler , PipeDecoratorHandler , ResourceLoader , SelectorScopeRegistry } from '../../ngtsc/annotations' ;
1313import { Decorator } from '../../ngtsc/host' ;
1414import { CompileResult , DecoratorHandler } from '../../ngtsc/transform' ;
1515
@@ -18,8 +18,8 @@ import {ParsedClass} from './parsing/parsed_class';
1818import { ParsedFile } from './parsing/parsed_file' ;
1919import { isDefined } from './utils' ;
2020
21- export interface AnalyzedClass < T = any > extends ParsedClass {
22- handler : DecoratorHandler < T > ;
21+ export interface AnalyzedClass < A = any , M = any > extends ParsedClass {
22+ handler : DecoratorHandler < A , M > ;
2323 analysis : any ;
2424 diagnostics ?: ts . Diagnostic [ ] ;
2525 compilation : CompileResult [ ] ;
@@ -31,9 +31,9 @@ export interface AnalyzedFile {
3131 constantPool : ConstantPool ;
3232}
3333
34- export interface MatchingHandler < T > {
35- handler : DecoratorHandler < T > ;
36- decorator : Decorator ;
34+ export interface MatchingHandler < A , M > {
35+ handler : DecoratorHandler < A , M > ;
36+ match : M ;
3737}
3838
3939/**
@@ -46,7 +46,8 @@ export class FileResourceLoader implements ResourceLoader {
4646export class Analyzer {
4747 resourceLoader = new FileResourceLoader ( ) ;
4848 scopeRegistry = new SelectorScopeRegistry ( this . typeChecker , this . host ) ;
49- handlers : DecoratorHandler < any > [ ] = [
49+ handlers : DecoratorHandler < any , any > [ ] = [
50+ new BaseDefDecoratorHandler ( this . typeChecker , this . host ) ,
5051 new ComponentDecoratorHandler (
5152 this . typeChecker , this . host , this . scopeRegistry , false , this . resourceLoader ) ,
5253 new DirectiveDecoratorHandler ( this . typeChecker , this . host , this . scopeRegistry , false ) ,
@@ -76,20 +77,23 @@ export class Analyzer {
7677
7778 protected analyzeClass ( file : ts . SourceFile , pool : ConstantPool , clazz : ParsedClass ) : AnalyzedClass
7879 | undefined {
79- const matchingHandlers =
80- this . handlers . map ( handler => ( { handler, decorator : handler . detect ( clazz . decorators ) } ) )
81- . filter ( isMatchingHandler ) ;
80+ const matchingHandlers = this . handlers
81+ . map ( handler => ( {
82+ handler,
83+ match : handler . detect ( clazz . declaration , clazz . decorators ) ,
84+ } ) )
85+ . filter ( isMatchingHandler ) ;
8286
8387 if ( matchingHandlers . length > 1 ) {
8488 throw new Error ( 'TODO.Diagnostic: Class has multiple Angular decorators.' ) ;
8589 }
8690
87- if ( matchingHandlers . length == 0 ) {
91+ if ( matchingHandlers . length === 0 ) {
8892 return undefined ;
8993 }
9094
91- const { handler, decorator } = matchingHandlers [ 0 ] ;
92- const { analysis, diagnostics} = handler . analyze ( clazz . declaration , decorator ) ;
95+ const { handler, match } = matchingHandlers [ 0 ] ;
96+ const { analysis, diagnostics} = handler . analyze ( clazz . declaration , match ) ;
9397 let compilation = handler . compile ( clazz . declaration , analysis , pool ) ;
9498 if ( ! Array . isArray ( compilation ) ) {
9599 compilation = [ compilation ] ;
@@ -98,6 +102,7 @@ export class Analyzer {
98102 }
99103}
100104
101- function isMatchingHandler < T > ( handler : Partial < MatchingHandler < T > > ) : handler is MatchingHandler < T > {
102- return ! ! handler . decorator ;
103- }
105+ function isMatchingHandler < A , M > ( handler : Partial < MatchingHandler < A , M > > ) :
106+ handler is MatchingHandler < A , M > {
107+ return ! ! handler . match ;
108+ }
0 commit comments