@@ -49,7 +49,8 @@ type processedFiles struct {
49
49
jsxRuntimeImportSpecifiers map [tspath.Path ]* jsxRuntimeImportSpecifier
50
50
importHelpersImportSpecifiers map [tspath.Path ]* ast.Node
51
51
// List of present unsupported extensions
52
- unsupportedExtensions []string
52
+ unsupportedExtensions []string
53
+ sourceFilesFoundSearchingNodeModules collections.Set [tspath.Path ]
53
54
}
54
55
55
56
type jsxRuntimeImportSpecifier struct {
@@ -111,6 +112,7 @@ func processAllProgramFiles(
111
112
var jsxRuntimeImportSpecifiers map [tspath.Path ]* jsxRuntimeImportSpecifier
112
113
var importHelpersImportSpecifiers map [tspath.Path ]* ast.Node
113
114
var unsupportedExtensions []string
115
+ var sourceFilesFoundSearchingNodeModules collections.Set [tspath.Path ]
114
116
115
117
loader .parseTasks .collect (& loader , loader .rootTasks , func (task * parseTask , _ []tspath.Path ) {
116
118
if task .isRedirected {
@@ -153,22 +155,26 @@ func processAllProgramFiles(
153
155
if slices .Contains (tspath .SupportedJSExtensionsFlat , extension ) {
154
156
unsupportedExtensions = core .AppendIfUnique (unsupportedExtensions , extension )
155
157
}
158
+ if task .fromExternalLibrary {
159
+ sourceFilesFoundSearchingNodeModules .Add (path )
160
+ }
156
161
})
157
162
loader .sortLibs (libFiles )
158
163
159
164
allFiles := append (libFiles , files ... )
160
165
161
166
return processedFiles {
162
- resolver : loader .resolver ,
163
- files : allFiles ,
164
- filesByPath : filesByPath ,
165
- projectReferenceFileMapper : loader .projectReferenceFileMapper ,
166
- resolvedModules : resolvedModules ,
167
- typeResolutionsInFile : typeResolutionsInFile ,
168
- sourceFileMetaDatas : sourceFileMetaDatas ,
169
- jsxRuntimeImportSpecifiers : jsxRuntimeImportSpecifiers ,
170
- importHelpersImportSpecifiers : importHelpersImportSpecifiers ,
171
- unsupportedExtensions : unsupportedExtensions ,
167
+ resolver : loader .resolver ,
168
+ files : allFiles ,
169
+ filesByPath : filesByPath ,
170
+ projectReferenceFileMapper : loader .projectReferenceFileMapper ,
171
+ resolvedModules : resolvedModules ,
172
+ typeResolutionsInFile : typeResolutionsInFile ,
173
+ sourceFileMetaDatas : sourceFileMetaDatas ,
174
+ jsxRuntimeImportSpecifiers : jsxRuntimeImportSpecifiers ,
175
+ importHelpersImportSpecifiers : importHelpersImportSpecifiers ,
176
+ unsupportedExtensions : unsupportedExtensions ,
177
+ sourceFilesFoundSearchingNodeModules : sourceFilesFoundSearchingNodeModules ,
172
178
}
173
179
}
174
180
@@ -180,7 +186,7 @@ func (p *fileLoader) addRootTasks(files []string, isLib bool) {
180
186
for _ , fileName := range files {
181
187
absPath := tspath .GetNormalizedAbsolutePath (fileName , p .opts .Host .GetCurrentDirectory ())
182
188
if core .Tristate .IsTrue (p .opts .Config .CompilerOptions ().AllowNonTsExtensions ) || slices .Contains (p .supportedExtensions , tspath .TryGetExtensionFromPath (absPath )) {
183
- p .rootTasks = append (p .rootTasks , & parseTask {normalizedFilePath : absPath , isLib : isLib })
189
+ p .rootTasks = append (p .rootTasks , & parseTask {normalizedFilePath : absPath , isLib : isLib , root : true })
184
190
}
185
191
}
186
192
}
@@ -327,38 +333,38 @@ func (p *fileLoader) resolveTripleslashPathReference(moduleName string, containi
327
333
}
328
334
}
329
335
330
- func (p * fileLoader ) resolveTypeReferenceDirectives (file * ast.SourceFile , meta ast.SourceFileMetaData ) (
331
- toParse []resolvedRef ,
332
- typeResolutionsInFile module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ],
333
- ) {
334
- if len (file .TypeReferenceDirectives ) != 0 {
335
- toParse = make ([]resolvedRef , 0 , len (file .TypeReferenceDirectives ))
336
- typeResolutionsInFile = make (module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ], len (file .TypeReferenceDirectives ))
337
- for _ , ref := range file .TypeReferenceDirectives {
338
- redirect := p .projectReferenceFileMapper .getRedirectForResolution (file )
339
- resolutionMode := getModeForTypeReferenceDirectiveInFile (ref , file , meta , module .GetCompilerOptionsWithRedirect (p .opts .Config .CompilerOptions (), redirect ))
340
- resolved := p .resolver .ResolveTypeReferenceDirective (ref .FileName , file .FileName (), resolutionMode , redirect )
341
- typeResolutionsInFile [module.ModeAwareCacheKey {Name : ref .FileName , Mode : resolutionMode }] = resolved
342
- if resolved .IsResolved () {
343
- toParse = append (toParse , resolvedRef {
344
- fileName : resolved .ResolvedFileName ,
345
- increaseDepth : resolved .IsExternalLibraryImport ,
346
- elideOnDepth : false ,
347
- })
348
- }
336
+ func (p * fileLoader ) resolveTypeReferenceDirectives (t * parseTask ) {
337
+ file := t .file
338
+ if len (file .TypeReferenceDirectives ) == 0 {
339
+ return
340
+ }
341
+ meta := t .metadata
342
+
343
+ typeResolutionsInFile := make (module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ], len (file .TypeReferenceDirectives ))
344
+ for _ , ref := range file .TypeReferenceDirectives {
345
+ redirect := p .projectReferenceFileMapper .getRedirectForResolution (file )
346
+ resolutionMode := getModeForTypeReferenceDirectiveInFile (ref , file , meta , module .GetCompilerOptionsWithRedirect (p .opts .Config .CompilerOptions (), redirect ))
347
+ resolved := p .resolver .ResolveTypeReferenceDirective (ref .FileName , file .FileName (), resolutionMode , redirect )
348
+ typeResolutionsInFile [module.ModeAwareCacheKey {Name : ref .FileName , Mode : resolutionMode }] = resolved
349
+ if resolved .IsResolved () {
350
+ t .addSubTask (resolvedRef {
351
+ fileName : resolved .ResolvedFileName ,
352
+ increaseDepth : resolved .IsExternalLibraryImport ,
353
+ elideOnDepth : false ,
354
+ isFromExternalLibrary : resolved .IsExternalLibraryImport ,
355
+ }, false )
349
356
}
350
357
}
351
- return toParse , typeResolutionsInFile
358
+
359
+ t .typeResolutionsInFile = typeResolutionsInFile
352
360
}
353
361
354
362
const externalHelpersModuleNameText = "tslib" // TODO(jakebailey): dedupe
355
363
356
- func (p * fileLoader ) resolveImportsAndModuleAugmentations (file * ast.SourceFile , meta ast.SourceFileMetaData ) (
357
- toParse []resolvedRef ,
358
- resolutionsInFile module.ModeAwareCache [* module.ResolvedModule ],
359
- importHelpersImportSpecifier * ast.Node ,
360
- jsxRuntimeImportSpecifier_ * jsxRuntimeImportSpecifier ,
361
- ) {
364
+ func (p * fileLoader ) resolveImportsAndModuleAugmentations (t * parseTask ) {
365
+ file := t .file
366
+ meta := t .metadata
367
+
362
368
moduleNames := make ([]* ast.Node , 0 , len (file .Imports ())+ len (file .ModuleAugmentations )+ 2 )
363
369
364
370
isJavaScriptFile := ast .IsSourceFileJS (file )
@@ -370,14 +376,14 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(file *ast.SourceFile,
370
376
if optionsForFile .ImportHelpers .IsTrue () {
371
377
specifier := p .createSyntheticImport (externalHelpersModuleNameText , file )
372
378
moduleNames = append (moduleNames , specifier )
373
- importHelpersImportSpecifier = specifier
379
+ t . importHelpersImportSpecifier = specifier
374
380
}
375
381
376
382
jsxImport := ast .GetJSXRuntimeImport (ast .GetJSXImplicitImportBase (optionsForFile , file ), optionsForFile )
377
383
if jsxImport != "" {
378
384
specifier := p .createSyntheticImport (jsxImport , file )
379
385
moduleNames = append (moduleNames , specifier )
380
- jsxRuntimeImportSpecifier_ = & jsxRuntimeImportSpecifier {
386
+ t . jsxRuntimeImportSpecifier = & jsxRuntimeImportSpecifier {
381
387
moduleReference : jsxImport ,
382
388
specifier : specifier ,
383
389
}
@@ -395,8 +401,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(file *ast.SourceFile,
395
401
}
396
402
397
403
if len (moduleNames ) != 0 {
398
- toParse = make ([]resolvedRef , 0 , len (moduleNames ))
399
- resolutionsInFile = make (module.ModeAwareCache [* module.ResolvedModule ], len (moduleNames ))
404
+ resolutionsInFile := make (module.ModeAwareCache [* module.ResolvedModule ], len (moduleNames ))
400
405
401
406
for index , entry := range moduleNames {
402
407
moduleName := entry .Text ()
@@ -433,16 +438,17 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(file *ast.SourceFile,
433
438
(importIndex < 0 || (importIndex < len (file .Imports ()) && (ast .IsInJSFile (file .Imports ()[importIndex ]) || file .Imports ()[importIndex ].Flags & ast .NodeFlagsJSDoc == 0 )))
434
439
435
440
if shouldAddFile {
436
- toParse = append (toParse , resolvedRef {
437
- fileName : resolvedFileName ,
438
- increaseDepth : resolvedModule .IsExternalLibraryImport ,
439
- elideOnDepth : isJsFileFromNodeModules ,
440
- })
441
+ t .addSubTask (resolvedRef {
442
+ fileName : resolvedFileName ,
443
+ increaseDepth : resolvedModule .IsExternalLibraryImport ,
444
+ elideOnDepth : isJsFileFromNodeModules ,
445
+ isFromExternalLibrary : resolvedModule .IsExternalLibraryImport ,
446
+ }, false )
441
447
}
442
448
}
443
- }
444
449
445
- return toParse , resolutionsInFile , importHelpersImportSpecifier , jsxRuntimeImportSpecifier_
450
+ t .resolutionsInFile = resolutionsInFile
451
+ }
446
452
}
447
453
448
454
// Returns a DiagnosticMessage if we won't include a resolved module due to its extension.
0 commit comments