@@ -10,6 +10,8 @@ import {AST, ASTWithSource, BindingPipe, MethodCall, PropertyWrite, SafeMethodCa
10
10
import * as ts from 'typescript' ;
11
11
12
12
import { AbsoluteFsPath } from '../../file_system' ;
13
+ import { ClassDeclaration } from '../../reflection' ;
14
+ import { ComponentScopeReader } from '../../scope' ;
13
15
import { isAssignment } from '../../util/src/typescript' ;
14
16
import { DirectiveSymbol , DomBindingSymbol , ElementSymbol , ExpressionSymbol , InputBindingSymbol , OutputBindingSymbol , ReferenceSymbol , Symbol , SymbolKind , TemplateSymbol , TsNodeSymbolInfo , TypeCheckableDirectiveMeta , VariableSymbol } from '../api' ;
15
17
@@ -24,8 +26,12 @@ import {TcbDirectiveOutputsOp} from './type_check_block';
24
26
*/
25
27
export class SymbolBuilder {
26
28
constructor (
27
- private readonly typeChecker : ts . TypeChecker , private readonly shimPath : AbsoluteFsPath ,
28
- private readonly typeCheckBlock : ts . Node , private readonly templateData : TemplateData ) { }
29
+ private readonly typeChecker : ts . TypeChecker ,
30
+ private readonly shimPath : AbsoluteFsPath ,
31
+ private readonly typeCheckBlock : ts . Node ,
32
+ private readonly templateData : TemplateData ,
33
+ private readonly componentScopeReader : ComponentScopeReader ,
34
+ ) { }
29
35
30
36
getSymbol ( node : TmplAstTemplate | TmplAstElement ) : TemplateSymbol | ElementSymbol | null ;
31
37
getSymbol ( node : TmplAstReference | TmplAstVariable ) : ReferenceSymbol | VariableSymbol | null ;
@@ -99,21 +105,24 @@ export class SymbolBuilder {
99
105
. map ( node => {
100
106
const symbol = this . getSymbolOfTsNode ( node . parent ) ;
101
107
if ( symbol === null || symbol . tsSymbol === null ||
102
- symbol . tsSymbol . declarations . length === 0 ) {
108
+ symbol . tsSymbol . valueDeclaration === undefined ||
109
+ ! ts . isClassDeclaration ( symbol . tsSymbol . valueDeclaration ) ) {
103
110
return null ;
104
111
}
105
- const meta = this . getDirectiveMeta ( element , symbol . tsSymbol . declarations [ 0 ] ) ;
112
+ const meta = this . getDirectiveMeta ( element , symbol . tsSymbol . valueDeclaration ) ;
106
113
if ( meta === null ) {
107
114
return null ;
108
115
}
109
116
117
+ const ngModule = this . getDirectiveModule ( symbol . tsSymbol . valueDeclaration ) ;
110
118
const selector = meta . selector ?? null ;
111
119
const isComponent = meta . isComponent ?? null ;
112
120
const directiveSymbol : DirectiveSymbol = {
113
121
...symbol ,
114
122
tsSymbol : symbol . tsSymbol ,
115
123
selector,
116
124
isComponent,
125
+ ngModule,
117
126
kind : SymbolKind . Directive
118
127
} ;
119
128
return directiveSymbol ;
@@ -132,6 +141,14 @@ export class SymbolBuilder {
132
141
return directives . find ( m => m . ref . node === directiveDeclaration ) ?? null ;
133
142
}
134
143
144
+ private getDirectiveModule ( declaration : ts . ClassDeclaration ) : ClassDeclaration | null {
145
+ const scope = this . componentScopeReader . getScopeForComponent ( declaration as ClassDeclaration ) ;
146
+ if ( scope === null || scope === 'error' ) {
147
+ return null ;
148
+ }
149
+ return scope . ngModule ;
150
+ }
151
+
135
152
private getSymbolOfBoundEvent ( eventBinding : TmplAstBoundEvent ) : OutputBindingSymbol | null {
136
153
// Outputs are a `ts.CallExpression` that look like one of the two:
137
154
// * _outputHelper(_t1["outputField"]).subscribe(handler);
@@ -239,17 +256,21 @@ export class SymbolBuilder {
239
256
}
240
257
241
258
const symbol = this . getSymbolOfTsNode ( declaration ) ;
242
- if ( symbol === null || symbol . tsSymbol === null ) {
259
+ if ( symbol === null || symbol . tsSymbol === null ||
260
+ symbol . tsSymbol . valueDeclaration === undefined ||
261
+ ! ts . isClassDeclaration ( symbol . tsSymbol . valueDeclaration ) ) {
243
262
return null ;
244
263
}
245
264
265
+ const ngModule = this . getDirectiveModule ( symbol . tsSymbol . valueDeclaration ) ;
246
266
return {
247
267
kind : SymbolKind . Directive ,
248
268
tsSymbol : symbol . tsSymbol ,
249
269
tsType : symbol . tsType ,
250
270
shimLocation : symbol . shimLocation ,
251
271
isComponent,
252
272
selector,
273
+ ngModule,
253
274
} ;
254
275
}
255
276
0 commit comments