@@ -3,10 +3,20 @@ import { callExpression, decoratorArgument, hasProperties, withIdentifier } from
33import { ifTrue , listToMaybe , Maybe , unwrapFirst } from '../util/function' ;
44import { logger } from '../util/logger' ;
55import { getAnimations , getInlineStyle , getTemplate } from '../util/ngQuery' ;
6- import { getDecoratorPropertyInitializer , isStringLiteralLike , maybeNodeArray } from '../util/utils' ;
6+ import { getDecoratorPropertyInitializer , isBooleanLiteralLike , isStringLiteralLike , maybeNodeArray } from '../util/utils' ;
77import { Config } from './config' ;
88import { FileResolver } from './fileResolver/fileResolver' ;
9- import { AnimationMetadata , CodeWithSourceMap , ComponentMetadata , DirectiveMetadata , StyleMetadata , TemplateMetadata } from './metadata' ;
9+ import {
10+ AnimationMetadata ,
11+ CodeWithSourceMap ,
12+ ComponentMetadata ,
13+ DirectiveMetadata ,
14+ InjectableMetadata ,
15+ ModuleMetadata ,
16+ PipeMetadata ,
17+ StyleMetadata ,
18+ TemplateMetadata
19+ } from './metadata' ;
1020import { AbstractResolver , MetadataUrls } from './urlResolvers/abstractResolver' ;
1121import { PathResolver } from './urlResolvers/pathResolver' ;
1222import { UrlResolver } from './urlResolvers/urlResolver' ;
@@ -26,9 +36,9 @@ export class MetadataReader {
2636 this . urlResolver = this . urlResolver || new UrlResolver ( new PathResolver ( ) ) ;
2737 }
2838
29- read ( d : ts . ClassDeclaration ) : DirectiveMetadata | undefined {
39+ read ( d : ts . ClassDeclaration ) : DirectiveMetadata | ComponentMetadata | PipeMetadata | ModuleMetadata | InjectableMetadata | undefined {
3040 const componentMetadata = unwrapFirst < ComponentMetadata | undefined > (
31- maybeNodeArray ( d . decorators ! ) . map ( dec => {
41+ maybeNodeArray ( ts . createNodeArray ( d . decorators ) ) . map ( dec => {
3242 return Maybe . lift ( dec )
3343 . bind ( callExpression )
3444 . bind ( withIdentifier ( 'Component' ) as any )
@@ -37,15 +47,42 @@ export class MetadataReader {
3747 ) ;
3848
3949 const directiveMetadata = unwrapFirst < DirectiveMetadata | undefined > (
40- maybeNodeArray ( d . decorators ! ) . map ( dec =>
50+ maybeNodeArray ( ts . createNodeArray ( d . decorators ) ) . map ( dec =>
4151 Maybe . lift ( dec )
4252 . bind ( callExpression )
4353 . bind ( withIdentifier ( 'Directive' ) as any )
4454 . fmap ( ( ) => this . readDirectiveMetadata ( d , dec ) )
4555 )
4656 ) ;
4757
48- return directiveMetadata || componentMetadata || undefined ;
58+ const pipeMetadata = unwrapFirst < PipeMetadata | undefined > (
59+ maybeNodeArray ( ts . createNodeArray ( d . decorators ) ) . map ( dec =>
60+ Maybe . lift ( dec )
61+ . bind ( callExpression )
62+ . bind ( withIdentifier ( 'Pipe' ) as any )
63+ . fmap ( ( ) => this . readPipeMetadata ( d , dec ) )
64+ )
65+ ) ;
66+
67+ const moduleMetadata = unwrapFirst < ModuleMetadata | undefined > (
68+ maybeNodeArray ( ts . createNodeArray ( d . decorators ) ) . map ( dec =>
69+ Maybe . lift ( dec )
70+ . bind ( callExpression )
71+ . bind ( withIdentifier ( 'NgModule' ) as any )
72+ . fmap ( ( ) => this . readModuleMetadata ( d , dec ) )
73+ )
74+ ) ;
75+
76+ const injectableMetadata = unwrapFirst < InjectableMetadata | undefined > (
77+ maybeNodeArray ( ts . createNodeArray ( d . decorators ) ) . map ( dec =>
78+ Maybe . lift ( dec )
79+ . bind ( callExpression )
80+ . bind ( withIdentifier ( 'Injectable' ) as any )
81+ . fmap ( ( ) => this . readInjectableMetadata ( d , dec ) )
82+ )
83+ ) ;
84+
85+ return directiveMetadata || componentMetadata || pipeMetadata || moduleMetadata || injectableMetadata ;
4986 }
5087
5188 protected readDirectiveMetadata ( d : ts . ClassDeclaration , dec : ts . Decorator ) : DirectiveMetadata {
@@ -55,6 +92,24 @@ export class MetadataReader {
5592 return new DirectiveMetadata ( d , dec , selector ) ;
5693 }
5794
95+ protected readPipeMetadata ( d : ts . ClassDeclaration , dec : ts . Decorator ) : DirectiveMetadata {
96+ const nameExpression = getDecoratorPropertyInitializer ( dec , 'name' ) ;
97+ const name = nameExpression && isStringLiteralLike ( nameExpression ) ? nameExpression . text : undefined ;
98+
99+ const pureExpression = getDecoratorPropertyInitializer ( dec , 'pure' ) ;
100+ const pure = pureExpression && isBooleanLiteralLike ( pureExpression ) ? pureExpression : undefined ;
101+
102+ return new PipeMetadata ( d , dec , name , pure ) ;
103+ }
104+
105+ protected readModuleMetadata ( d : ts . ClassDeclaration , dec : ts . Decorator ) : DirectiveMetadata {
106+ return new ModuleMetadata ( d , dec ) ;
107+ }
108+
109+ protected readInjectableMetadata ( d : ts . ClassDeclaration , dec : ts . Decorator ) : DirectiveMetadata {
110+ return new InjectableMetadata ( d , dec ) ;
111+ }
112+
58113 protected readComponentMetadata ( d : ts . ClassDeclaration , dec : ts . Decorator ) : ComponentMetadata {
59114 const expr = this . getDecoratorArgument ( dec ) ;
60115 const directiveMetadata = this . readDirectiveMetadata ( d , dec ) ;
0 commit comments