@@ -3,10 +3,20 @@ import { callExpression, decoratorArgument, hasProperties, withIdentifier } from
3
3
import { ifTrue , listToMaybe , Maybe , unwrapFirst } from '../util/function' ;
4
4
import { logger } from '../util/logger' ;
5
5
import { getAnimations , getInlineStyle , getTemplate } from '../util/ngQuery' ;
6
- import { getDecoratorPropertyInitializer , isStringLiteralLike , maybeNodeArray } from '../util/utils' ;
6
+ import { getDecoratorPropertyInitializer , isBooleanLiteralLike , isStringLiteralLike , maybeNodeArray } from '../util/utils' ;
7
7
import { Config } from './config' ;
8
8
import { 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' ;
10
20
import { AbstractResolver , MetadataUrls } from './urlResolvers/abstractResolver' ;
11
21
import { PathResolver } from './urlResolvers/pathResolver' ;
12
22
import { UrlResolver } from './urlResolvers/urlResolver' ;
@@ -26,9 +36,9 @@ export class MetadataReader {
26
36
this . urlResolver = this . urlResolver || new UrlResolver ( new PathResolver ( ) ) ;
27
37
}
28
38
29
- read ( d : ts . ClassDeclaration ) : DirectiveMetadata | undefined {
39
+ read ( d : ts . ClassDeclaration ) : DirectiveMetadata | ComponentMetadata | PipeMetadata | ModuleMetadata | InjectableMetadata | undefined {
30
40
const componentMetadata = unwrapFirst < ComponentMetadata | undefined > (
31
- maybeNodeArray ( d . decorators ! ) . map ( dec => {
41
+ maybeNodeArray ( ts . createNodeArray ( d . decorators ) ) . map ( dec => {
32
42
return Maybe . lift ( dec )
33
43
. bind ( callExpression )
34
44
. bind ( withIdentifier ( 'Component' ) as any )
@@ -37,15 +47,42 @@ export class MetadataReader {
37
47
) ;
38
48
39
49
const directiveMetadata = unwrapFirst < DirectiveMetadata | undefined > (
40
- maybeNodeArray ( d . decorators ! ) . map ( dec =>
50
+ maybeNodeArray ( ts . createNodeArray ( d . decorators ) ) . map ( dec =>
41
51
Maybe . lift ( dec )
42
52
. bind ( callExpression )
43
53
. bind ( withIdentifier ( 'Directive' ) as any )
44
54
. fmap ( ( ) => this . readDirectiveMetadata ( d , dec ) )
45
55
)
46
56
) ;
47
57
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 ;
49
86
}
50
87
51
88
protected readDirectiveMetadata ( d : ts . ClassDeclaration , dec : ts . Decorator ) : DirectiveMetadata {
@@ -55,6 +92,24 @@ export class MetadataReader {
55
92
return new DirectiveMetadata ( d , dec , selector ) ;
56
93
}
57
94
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
+
58
113
protected readComponentMetadata ( d : ts . ClassDeclaration , dec : ts . Decorator ) : ComponentMetadata {
59
114
const expr = this . getDecoratorArgument ( dec ) ;
60
115
const directiveMetadata = this . readDirectiveMetadata ( d , dec ) ;
0 commit comments