@@ -18,9 +18,7 @@ import (
18
18
)
19
19
20
20
type fileLoader struct {
21
- host CompilerHost
22
- programOptions ProgramOptions
23
- compilerOptions * core.CompilerOptions
21
+ opts ProgramOptions
24
22
resolver * module.Resolver
25
23
defaultLibraryPath string
26
24
comparePathsOptions tspath.ComparePathsOptions
@@ -52,24 +50,21 @@ type jsxRuntimeImportSpecifier struct {
52
50
}
53
51
54
52
func processAllProgramFiles (
55
- host CompilerHost ,
56
- programOptions ProgramOptions ,
57
- compilerOptions * core.CompilerOptions ,
53
+ opts ProgramOptions ,
58
54
resolver * module.Resolver ,
59
- rootFiles []string ,
60
55
libs []string ,
61
56
singleThreaded bool ,
62
57
) processedFiles {
58
+ compilerOptions := opts .Config .CompilerOptions ()
59
+ rootFiles := opts .Config .FileNames ()
63
60
supportedExtensions := tsoptions .GetSupportedExtensions (compilerOptions , nil /*extraFileExtensions*/ )
64
61
loader := fileLoader {
65
- host : host ,
66
- programOptions : programOptions ,
67
- compilerOptions : compilerOptions ,
62
+ opts : opts ,
68
63
resolver : resolver ,
69
- defaultLibraryPath : tspath .GetNormalizedAbsolutePath (host . DefaultLibraryPath (), host .GetCurrentDirectory ()),
64
+ defaultLibraryPath : tspath .GetNormalizedAbsolutePath (opts . Host . DefaultLibraryPath (), opts . Host .GetCurrentDirectory ()),
70
65
comparePathsOptions : tspath.ComparePathsOptions {
71
- UseCaseSensitiveFileNames : host .FS ().UseCaseSensitiveFileNames (),
72
- CurrentDirectory : host .GetCurrentDirectory (),
66
+ UseCaseSensitiveFileNames : opts . Host .FS ().UseCaseSensitiveFileNames (),
67
+ CurrentDirectory : opts . Host .GetCurrentDirectory (),
73
68
},
74
69
wg : core .NewWorkGroup (singleThreaded ),
75
70
rootTasks : make ([]* parseTask , 0 , len (rootFiles )+ len (libs )),
@@ -138,23 +133,24 @@ func processAllProgramFiles(
138
133
139
134
func (p * fileLoader ) addRootTasks (files []string , isLib bool ) {
140
135
for _ , fileName := range files {
141
- absPath := tspath .GetNormalizedAbsolutePath (fileName , p .host .GetCurrentDirectory ())
142
- if core .Tristate .IsTrue (p .compilerOptions .AllowNonTsExtensions ) || slices .Contains (p .supportedExtensions , tspath .TryGetExtensionFromPath (absPath )) {
136
+ absPath := tspath .GetNormalizedAbsolutePath (fileName , p .opts . Host .GetCurrentDirectory ())
137
+ if core .Tristate .IsTrue (p .opts . Config . CompilerOptions () .AllowNonTsExtensions ) || slices .Contains (p .supportedExtensions , tspath .TryGetExtensionFromPath (absPath )) {
143
138
p .rootTasks = append (p .rootTasks , & parseTask {normalizedFilePath : absPath , isLib : isLib })
144
139
}
145
140
}
146
141
}
147
142
148
143
func (p * fileLoader ) addAutomaticTypeDirectiveTasks () {
149
144
var containingDirectory string
150
- if p .compilerOptions .ConfigFilePath != "" {
151
- containingDirectory = tspath .GetDirectoryPath (p .compilerOptions .ConfigFilePath )
145
+ compilerOptions := p .opts .Config .CompilerOptions ()
146
+ if compilerOptions .ConfigFilePath != "" {
147
+ containingDirectory = tspath .GetDirectoryPath (compilerOptions .ConfigFilePath )
152
148
} else {
153
- containingDirectory = p .host .GetCurrentDirectory ()
149
+ containingDirectory = p .opts . Host .GetCurrentDirectory ()
154
150
}
155
151
containingFileName := tspath .CombinePaths (containingDirectory , module .InferredTypesContainingFile )
156
152
157
- automaticTypeDirectiveNames := module .GetAutomaticTypeDirectiveNames (p . compilerOptions , p .host )
153
+ automaticTypeDirectiveNames := module .GetAutomaticTypeDirectiveNames (compilerOptions , p .opts . Host )
158
154
for _ , name := range automaticTypeDirectiveNames {
159
155
resolved := p .resolver .ResolveTypeReferenceDirective (name , containingFileName , core .ModuleKindNodeNext , nil )
160
156
if resolved .IsResolved () {
@@ -265,15 +261,16 @@ func (t *parseTask) start(loader *fileLoader) {
265
261
t .addSubTask (resolvedPath , false )
266
262
}
267
263
264
+ compilerOptions := loader .opts .Config .CompilerOptions ()
268
265
for _ , ref := range file .TypeReferenceDirectives {
269
- resolutionMode := getModeForTypeReferenceDirectiveInFile (ref , file , t .metadata , loader . compilerOptions )
266
+ resolutionMode := getModeForTypeReferenceDirectiveInFile (ref , file , t .metadata , compilerOptions )
270
267
resolved := loader .resolver .ResolveTypeReferenceDirective (ref .FileName , file .FileName (), resolutionMode , nil )
271
268
if resolved .IsResolved () {
272
269
t .addSubTask (resolved .ResolvedFileName , false )
273
270
}
274
271
}
275
272
276
- if loader . compilerOptions .NoLib != core .TSTrue {
273
+ if compilerOptions .NoLib != core .TSTrue {
277
274
for _ , lib := range file .LibReferenceDirectives {
278
275
name , ok := tsoptions .GetLibFileName (lib .FileName )
279
276
if ! ok {
@@ -314,8 +311,8 @@ func (p *fileLoader) loadSourceFileMetaData(fileName string) *ast.SourceFileMeta
314
311
}
315
312
316
313
func (p * fileLoader ) parseSourceFile (fileName string ) * ast.SourceFile {
317
- path := tspath .ToPath (fileName , p .host . GetCurrentDirectory (), p .host .FS ().UseCaseSensitiveFileNames ())
318
- sourceFile := p .host . GetSourceFile (fileName , path , p .compilerOptions .GetEmitScriptTarget ())
314
+ path := tspath .ToPath (fileName , p .opts . Host . GetCurrentDirectory (), p .opts . Host .FS ().UseCaseSensitiveFileNames ())
315
+ sourceFile := p .opts . Host . GetSourceFile (fileName , path , p .opts . Config . CompilerOptions () .GetEmitScriptTarget ())
319
316
return sourceFile
320
317
}
321
318
@@ -354,14 +351,15 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(file *ast.SourceFile,
354
351
isJavaScriptFile := ast .IsSourceFileJS (file )
355
352
isExternalModuleFile := ast .IsExternalModule (file )
356
353
357
- if isJavaScriptFile || (! file .IsDeclarationFile && (p .compilerOptions .GetIsolatedModules () || isExternalModuleFile )) {
358
- if p .compilerOptions .ImportHelpers .IsTrue () {
354
+ compilerOptions := p .opts .Config .CompilerOptions ()
355
+ if isJavaScriptFile || (! file .IsDeclarationFile && (compilerOptions .GetIsolatedModules () || isExternalModuleFile )) {
356
+ if compilerOptions .ImportHelpers .IsTrue () {
359
357
specifier := p .createSyntheticImport (externalHelpersModuleNameText , file )
360
358
moduleNames = append (moduleNames , specifier )
361
359
importHelpersImportSpecifier = specifier
362
360
}
363
361
364
- jsxImport := ast .GetJSXRuntimeImport (ast .GetJSXImplicitImportBase (p . compilerOptions , file ), p . compilerOptions )
362
+ jsxImport := ast .GetJSXRuntimeImport (ast .GetJSXImplicitImportBase (compilerOptions , file ), compilerOptions )
365
363
if jsxImport != "" {
366
364
specifier := p .createSyntheticImport (jsxImport , file )
367
365
moduleNames = append (moduleNames , specifier )
@@ -398,9 +396,9 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(file *ast.SourceFile,
398
396
// Don't add the file if it has a bad extension (e.g. 'tsx' if we don't have '--allowJs')
399
397
// This may still end up being an untyped module -- the file won't be included but imports will be allowed.
400
398
hasAllowedExtension := false
401
- if p . compilerOptions .ResolveJsonModule .IsTrue () {
399
+ if compilerOptions .ResolveJsonModule .IsTrue () {
402
400
hasAllowedExtension = tspath .FileExtensionIsOneOf (resolvedFileName , tspath .SupportedTSExtensionsWithJsonFlat )
403
- } else if p . compilerOptions .AllowJs .IsTrue () {
401
+ } else if compilerOptions .AllowJs .IsTrue () {
404
402
hasAllowedExtension = tspath .FileExtensionIsOneOf (resolvedFileName , tspath .SupportedJSExtensionsFlat ) || tspath .FileExtensionIsOneOf (resolvedFileName , tspath .SupportedTSExtensionsFlat )
405
403
} else {
406
404
hasAllowedExtension = tspath .FileExtensionIsOneOf (resolvedFileName , tspath .SupportedTSExtensionsFlat )
@@ -430,7 +428,7 @@ func (p *fileLoader) resolveModuleNames(entries []*ast.Node, file *ast.SourceFil
430
428
if moduleName == "" {
431
429
continue
432
430
}
433
- resolvedModule := p .resolver .ResolveModuleName (moduleName , file .FileName (), getModeForUsageLocation (file , meta , entry , p .compilerOptions ), nil )
431
+ resolvedModule := p .resolver .ResolveModuleName (moduleName , file .FileName (), getModeForUsageLocation (file , meta , entry , p .opts . Config . CompilerOptions () ), nil )
434
432
resolvedModules = append (resolvedModules , & resolution {node : entry , resolvedModule : resolvedModule })
435
433
}
436
434
@@ -457,7 +455,7 @@ type resolution struct {
457
455
458
456
func (p * fileLoader ) getCompilerOptionsForFile (file * ast.SourceFile ) * core.CompilerOptions {
459
457
// !!! return getRedirectReferenceForResolution(file)?.commandLine.options || options;
460
- return p .compilerOptions
458
+ return p .opts . Config . CompilerOptions ()
461
459
}
462
460
463
461
func getModeForTypeReferenceDirectiveInFile (ref * ast.FileReference , file * ast.SourceFile , meta * ast.SourceFileMetaData , options * core.CompilerOptions ) core.ResolutionMode {
0 commit comments