@@ -45,7 +45,10 @@ export class ComponentResourceCollector {
45
45
resolvedTemplates : ResolvedResource [ ] = [ ] ;
46
46
resolvedStylesheets : ResolvedResource [ ] = [ ] ;
47
47
48
- constructor ( public typeChecker : ts . TypeChecker , private _fileSystem : FileSystem ) { }
48
+ constructor (
49
+ public typeChecker : ts . TypeChecker ,
50
+ private _fileSystem : FileSystem ,
51
+ ) { }
49
52
50
53
visitNode ( node : ts . Node ) {
51
54
if ( node . kind === ts . SyntaxKind . ClassDeclaration ) {
@@ -95,8 +98,12 @@ export class ComponentResourceCollector {
95
98
96
99
const propertyName = getPropertyNameText ( property . name ) ;
97
100
98
- if ( propertyName === 'styles' && ts . isArrayLiteralExpression ( property . initializer ) ) {
99
- property . initializer . elements . forEach ( el => {
101
+ if ( propertyName === 'styles' ) {
102
+ const elements = ts . isArrayLiteralExpression ( property . initializer )
103
+ ? property . initializer . elements
104
+ : [ property . initializer ] ;
105
+
106
+ elements . forEach ( el => {
100
107
if ( ts . isStringLiteralLike ( el ) ) {
101
108
// Need to add an offset of one to the start because the template quotes are
102
109
// not part of the template content.
@@ -135,16 +142,15 @@ export class ComponentResourceCollector {
135
142
if ( propertyName === 'styleUrls' && ts . isArrayLiteralExpression ( property . initializer ) ) {
136
143
property . initializer . elements . forEach ( el => {
137
144
if ( ts . isStringLiteralLike ( el ) ) {
138
- const stylesheetPath = this . _fileSystem . resolve ( sourceFileDirPath , el . text ) ;
139
- const stylesheet = this . resolveExternalStylesheet ( stylesheetPath , node ) ;
140
-
141
- if ( stylesheet ) {
142
- this . resolvedStylesheets . push ( stylesheet ) ;
143
- }
145
+ this . _trackExternalStylesheet ( sourceFileDirPath , el , node ) ;
144
146
}
145
147
} ) ;
146
148
}
147
149
150
+ if ( propertyName === 'styleUrl' && ts . isStringLiteralLike ( property . initializer ) ) {
151
+ this . _trackExternalStylesheet ( sourceFileDirPath , property . initializer , node ) ;
152
+ }
153
+
148
154
if ( propertyName === 'templateUrl' && ts . isStringLiteralLike ( property . initializer ) ) {
149
155
const templateUrl = property . initializer . text ;
150
156
const templatePath = this . _fileSystem . resolve ( sourceFileDirPath , templateUrl ) ;
@@ -197,6 +203,19 @@ export class ComponentResourceCollector {
197
203
getCharacterAndLineOfPosition : pos => getLineAndCharacterFromPosition ( lineStartsMap , pos ) ,
198
204
} ;
199
205
}
206
+
207
+ private _trackExternalStylesheet (
208
+ sourceFileDirPath : string ,
209
+ node : ts . StringLiteralLike ,
210
+ container : ts . ClassDeclaration ,
211
+ ) {
212
+ const stylesheetPath = this . _fileSystem . resolve ( sourceFileDirPath , node . text ) ;
213
+ const stylesheet = this . resolveExternalStylesheet ( stylesheetPath , container ) ;
214
+
215
+ if ( stylesheet ) {
216
+ this . resolvedStylesheets . push ( stylesheet ) ;
217
+ }
218
+ }
200
219
}
201
220
202
221
/** Strips the BOM from a string. */
0 commit comments