@@ -135,14 +135,19 @@ export class ComponentLensAnalyzer {
135135 }
136136
137137 private async getFileComponentKind ( filePath : string ) : Promise < ComponentKind > {
138- const [ sourceText , signature ] = await Promise . all ( [
139- this . host . readFileAsync
140- ? this . host . readFileAsync ( filePath )
141- : this . host . readFile ( filePath ) ,
142- this . host . getSignatureAsync
143- ? this . host . getSignatureAsync ( filePath )
144- : this . host . getSignature ( filePath ) ,
145- ] )
138+ let sourceText : string | undefined
139+ let signature : string | undefined
140+
141+ if ( this . host . readFileAsync ) {
142+ ; [ sourceText , signature ] = await Promise . all ( [
143+ this . host . readFileAsync ( filePath ) ,
144+ this . host . getSignatureAsync ! ( filePath ) ,
145+ ] )
146+ } else {
147+ sourceText = this . host . readFile ( filePath )
148+ signature = this . host . getSignature ( filePath )
149+ }
150+
146151 if ( sourceText === undefined || signature === undefined ) {
147152 return 'unknown'
148153 }
@@ -205,14 +210,15 @@ function collectImportBindings(
205210 return
206211 }
207212
208- const source = statement . moduleSpecifier . text
209213 const importClause = statement . importClause
210214 if ( ! importClause ) {
211215 return
212216 }
213217
218+ const binding : ImportBinding = { source : statement . moduleSpecifier . text }
219+
214220 if ( importClause . name ) {
215- imports . set ( importClause . name . text , { source } )
221+ imports . set ( importClause . name . text , binding )
216222 }
217223
218224 const namedBindings = importClause . namedBindings
@@ -221,12 +227,12 @@ function collectImportBindings(
221227 }
222228
223229 if ( ts . isNamespaceImport ( namedBindings ) ) {
224- imports . set ( namedBindings . name . text , { source } )
230+ imports . set ( namedBindings . name . text , binding )
225231 return
226232 }
227233
228234 for ( const element of namedBindings . elements ) {
229- imports . set ( element . name . text , { source } )
235+ imports . set ( element . name . text , binding )
230236 }
231237}
232238
@@ -332,22 +338,22 @@ function isComponentInitializer(
332338 )
333339}
334340
335- function collectJsxTags ( root : ts . Node ) : JsxTagReference [ ] {
341+ function collectJsxTags ( sourceFile : ts . SourceFile ) : JsxTagReference [ ] {
336342 const jsxTags : JsxTagReference [ ] = [ ]
337343 const visit = ( node : ts . Node ) : void => {
338344 if (
339345 ts . isJsxOpeningElement ( node ) ||
340346 ts . isJsxSelfClosingElement ( node ) ||
341347 ts . isJsxClosingElement ( node )
342348 ) {
343- const jsxTag = createJsxTagReference ( node , node . getSourceFile ( ) )
349+ const jsxTag = createJsxTagReference ( node , sourceFile )
344350 if ( jsxTag ) {
345351 jsxTags . push ( jsxTag )
346352 }
347353 }
348354 ts . forEachChild ( node , visit )
349355 }
350- ts . forEachChild ( root , visit )
356+ ts . forEachChild ( sourceFile , visit )
351357 return jsxTags
352358}
353359
0 commit comments