@@ -57,6 +57,8 @@ var tsconfigRootOptionsMap = &CommandLineOption{
57
57
Kind : CommandLineOptionTypeObject ,
58
58
ElementOptions : commandLineOptionsToMap ([]* CommandLineOption {
59
59
compilerOptionsDeclaration ,
60
+ // watchOptionsDeclaration,
61
+ typeAcquisitionDeclaration ,
60
62
extendsOptionDeclaration ,
61
63
{
62
64
Name : "references" ,
@@ -107,8 +109,8 @@ type ExtendedConfigCacheEntry struct {
107
109
type parsedTsconfig struct {
108
110
raw any
109
111
options * core.CompilerOptions
110
- // watchOptions *compiler .WatchOptions
111
- // typeAcquisition *compiler .TypeAcquisition
112
+ // watchOptions *core .WatchOptions
113
+ typeAcquisition * core .TypeAcquisition
112
114
// Note that the case of the config path has not yet been normalized, as no files have been imported into the project yet
113
115
extendedConfigPath any
114
116
}
@@ -119,8 +121,8 @@ func parseOwnConfigOfJsonSourceFile(
119
121
basePath string ,
120
122
configFileName string ,
121
123
) (* parsedTsconfig , []* ast.Diagnostic ) {
122
- options := getDefaultCompilerOptions (configFileName )
123
- // var typeAcquisition *compiler.TypeAcquisition
124
+ compilerOptions := getDefaultCompilerOptions (configFileName )
125
+ typeAcquisition := getDefaultTypeAcquisition ( configFileName )
124
126
// var watchOptions *compiler.WatchOptions
125
127
var extendedConfigPath any
126
128
var rootCompilerOptions []* ast.PropertyName
@@ -139,7 +141,14 @@ func parseOwnConfigOfJsonSourceFile(
139
141
}
140
142
if parentOption != nil && parentOption .Name != "undefined" && value != nil {
141
143
if option != nil && option .Name != "" {
142
- propertySetErrors = append (propertySetErrors , ParseCompilerOptions (option .Name , value , options )... )
144
+ var parseDiagnostics []* ast.Diagnostic
145
+ switch parentOption .Name {
146
+ case "compilerOptions" :
147
+ parseDiagnostics = ParseCompilerOptions (option .Name , value , compilerOptions )
148
+ case "typeAcquisition" :
149
+ parseDiagnostics = ParseTypeAcquisition (option .Name , value , typeAcquisition )
150
+ }
151
+ propertySetErrors = append (propertySetErrors , parseDiagnostics ... )
143
152
} else if keyText != "" {
144
153
if parentOption .ElementOptions != nil {
145
154
// !!! TODO: support suggestion
@@ -178,9 +187,9 @@ func parseOwnConfigOfJsonSourceFile(
178
187
// }
179
188
return & parsedTsconfig {
180
189
raw : json ,
181
- options : options ,
190
+ options : compilerOptions ,
182
191
// watchOptions: watchOptions,
183
- // typeAcquisition: typeAcquisition,
192
+ typeAcquisition : typeAcquisition ,
184
193
extendedConfigPath : extendedConfigPath ,
185
194
}, errors
186
195
}
@@ -479,19 +488,19 @@ type tsConfigOptions struct {
479
488
notDefined string
480
489
}
481
490
482
- func commandLineOptionsToMap (options []* CommandLineOption ) map [string ]* CommandLineOption {
491
+ func commandLineOptionsToMap (compilerOptions []* CommandLineOption ) map [string ]* CommandLineOption {
483
492
result := make (map [string ]* CommandLineOption )
484
- for i := range options {
485
- result [(options [i ]).Name ] = options [i ]
493
+ for i := range compilerOptions {
494
+ result [(compilerOptions [i ]).Name ] = compilerOptions [i ]
486
495
}
487
496
return result
488
497
}
489
498
490
499
var commandLineCompilerOptionsMap map [string ]* CommandLineOption = commandLineOptionsToMap (OptionsDeclarations )
491
500
492
- func convertMapToOptions [O optionParser ](options * collections.OrderedMap [string , any ], result O ) O {
501
+ func convertMapToOptions [O optionParser ](compilerOptions * collections.OrderedMap [string , any ], result O ) O {
493
502
// this assumes any `key`, `value` pair in `options` will have `value` already be the correct type. this function should no error handling
494
- for key , value := range options .Entries () {
503
+ for key , value := range compilerOptions .Entries () {
495
504
result .ParseOption (key , value )
496
505
}
497
506
return result
@@ -758,6 +767,14 @@ func getDefaultCompilerOptions(configFileName string) *core.CompilerOptions {
758
767
return options
759
768
}
760
769
770
+ func getDefaultTypeAcquisition (configFileName string ) * core.TypeAcquisition {
771
+ options := & core.TypeAcquisition {}
772
+ if configFileName != "" && tspath .GetBaseFileName (configFileName ) == "jsconfig.json" {
773
+ options .Enable = core .TSTrue
774
+ }
775
+ return options
776
+ }
777
+
761
778
func convertCompilerOptionsFromJsonWorker (jsonOptions any , basePath string , configFileName string ) (* core.CompilerOptions , []* ast.Diagnostic ) {
762
779
options := getDefaultCompilerOptions (configFileName )
763
780
_ , errors := convertOptionsFromJson (commandLineCompilerOptionsMap , jsonOptions , basePath , & compilerOptionsParser {options })
@@ -767,6 +784,12 @@ func convertCompilerOptionsFromJsonWorker(jsonOptions any, basePath string, conf
767
784
return options , errors
768
785
}
769
786
787
+ func convertTypeAcquisitionFromJsonWorker (jsonOptions any , basePath string , configFileName string ) (* core.TypeAcquisition , []* ast.Diagnostic ) {
788
+ options := getDefaultTypeAcquisition (configFileName )
789
+ _ , errors := convertOptionsFromJson (typeAcquisitionDeclaration .ElementOptions , jsonOptions , basePath , & typeAcquisitionParser {options })
790
+ return options , errors
791
+ }
792
+
770
793
func parseOwnConfigOfJson (
771
794
json * collections.OrderedMap [string , any ],
772
795
host ParseConfigHost ,
@@ -778,8 +801,8 @@ func parseOwnConfigOfJson(
778
801
errors = append (errors , ast .NewCompilerDiagnostic (diagnostics .Unknown_option_excludes_Did_you_mean_exclude ))
779
802
}
780
803
options , err := convertCompilerOptionsFromJsonWorker (json .GetOrZero ("compilerOptions" ), basePath , configFileName )
781
- errors = append ( errors , err ... )
782
- // typeAcquisition := convertTypeAcquisitionFromJsonWorker(json.typeAcquisition, basePath, errors, configFileName )
804
+ typeAcquisition , err2 := convertTypeAcquisitionFromJsonWorker ( json . GetOrZero ( "typeAcquisition" ), basePath , configFileName )
805
+ errors = append ( append ( errors , err ... ), err2 ... )
783
806
// watchOptions := convertWatchOptionsFromJsonWorker(json.watchOptions, basePath, errors)
784
807
// json.compileOnSave = convertCompileOnSaveOptionFromJson(json, basePath, errors)
785
808
var extendedConfigPath []string
@@ -790,6 +813,7 @@ func parseOwnConfigOfJson(
790
813
parsedConfig := & parsedTsconfig {
791
814
raw : json ,
792
815
options : options ,
816
+ typeAcquisition : typeAcquisition ,
793
817
extendedConfigPath : extendedConfigPath ,
794
818
}
795
819
return parsedConfig , errors
@@ -1176,7 +1200,9 @@ func parseJsonConfigFileContentWorker(
1176
1200
1177
1201
return & ParsedCommandLine {
1178
1202
ParsedConfig : & core.ParsedOptions {
1179
- CompilerOptions : parsedConfig .options ,
1203
+ CompilerOptions : parsedConfig .options ,
1204
+ TypeAcquisition : parsedConfig .typeAcquisition ,
1205
+ // WatchOptions: nil,
1180
1206
FileNames : getFileNames (basePathForFileNames ),
1181
1207
ProjectReferences : getProjectReferences (basePathForFileNames ),
1182
1208
},
@@ -1321,43 +1347,43 @@ func substituteStringArrayWithConfigDirTemplate(list []string, basePath string)
1321
1347
}
1322
1348
}
1323
1349
1324
- func handleOptionConfigDirTemplateSubstitution (options * core.CompilerOptions , basePath string ) {
1325
- if options == nil {
1350
+ func handleOptionConfigDirTemplateSubstitution (compilerOptions * core.CompilerOptions , basePath string ) {
1351
+ if compilerOptions == nil {
1326
1352
return
1327
1353
}
1328
1354
1329
1355
// !!! don't hardcode this; use options declarations?
1330
1356
1331
- for v := range options .Paths .Values () {
1357
+ for v := range compilerOptions .Paths .Values () {
1332
1358
substituteStringArrayWithConfigDirTemplate (v , basePath )
1333
1359
}
1334
1360
1335
- substituteStringArrayWithConfigDirTemplate (options .RootDirs , basePath )
1336
- substituteStringArrayWithConfigDirTemplate (options .TypeRoots , basePath )
1361
+ substituteStringArrayWithConfigDirTemplate (compilerOptions .RootDirs , basePath )
1362
+ substituteStringArrayWithConfigDirTemplate (compilerOptions .TypeRoots , basePath )
1337
1363
1338
- if startsWithConfigDirTemplate (options .GenerateCpuProfile ) {
1339
- options .GenerateCpuProfile = getSubstitutedPathWithConfigDirTemplate (options .GenerateCpuProfile , basePath )
1364
+ if startsWithConfigDirTemplate (compilerOptions .GenerateCpuProfile ) {
1365
+ compilerOptions .GenerateCpuProfile = getSubstitutedPathWithConfigDirTemplate (compilerOptions .GenerateCpuProfile , basePath )
1340
1366
}
1341
- if startsWithConfigDirTemplate (options .GenerateTrace ) {
1342
- options .GenerateTrace = getSubstitutedPathWithConfigDirTemplate (options .GenerateTrace , basePath )
1367
+ if startsWithConfigDirTemplate (compilerOptions .GenerateTrace ) {
1368
+ compilerOptions .GenerateTrace = getSubstitutedPathWithConfigDirTemplate (compilerOptions .GenerateTrace , basePath )
1343
1369
}
1344
- if startsWithConfigDirTemplate (options .OutFile ) {
1345
- options .OutFile = getSubstitutedPathWithConfigDirTemplate (options .OutFile , basePath )
1370
+ if startsWithConfigDirTemplate (compilerOptions .OutFile ) {
1371
+ compilerOptions .OutFile = getSubstitutedPathWithConfigDirTemplate (compilerOptions .OutFile , basePath )
1346
1372
}
1347
- if startsWithConfigDirTemplate (options .OutDir ) {
1348
- options .OutDir = getSubstitutedPathWithConfigDirTemplate (options .OutDir , basePath )
1373
+ if startsWithConfigDirTemplate (compilerOptions .OutDir ) {
1374
+ compilerOptions .OutDir = getSubstitutedPathWithConfigDirTemplate (compilerOptions .OutDir , basePath )
1349
1375
}
1350
- if startsWithConfigDirTemplate (options .RootDir ) {
1351
- options .RootDir = getSubstitutedPathWithConfigDirTemplate (options .RootDir , basePath )
1376
+ if startsWithConfigDirTemplate (compilerOptions .RootDir ) {
1377
+ compilerOptions .RootDir = getSubstitutedPathWithConfigDirTemplate (compilerOptions .RootDir , basePath )
1352
1378
}
1353
- if startsWithConfigDirTemplate (options .TsBuildInfoFile ) {
1354
- options .TsBuildInfoFile = getSubstitutedPathWithConfigDirTemplate (options .TsBuildInfoFile , basePath )
1379
+ if startsWithConfigDirTemplate (compilerOptions .TsBuildInfoFile ) {
1380
+ compilerOptions .TsBuildInfoFile = getSubstitutedPathWithConfigDirTemplate (compilerOptions .TsBuildInfoFile , basePath )
1355
1381
}
1356
- if startsWithConfigDirTemplate (options .BaseUrl ) {
1357
- options .BaseUrl = getSubstitutedPathWithConfigDirTemplate (options .BaseUrl , basePath )
1382
+ if startsWithConfigDirTemplate (compilerOptions .BaseUrl ) {
1383
+ compilerOptions .BaseUrl = getSubstitutedPathWithConfigDirTemplate (compilerOptions .BaseUrl , basePath )
1358
1384
}
1359
- if startsWithConfigDirTemplate (options .DeclarationDir ) {
1360
- options .DeclarationDir = getSubstitutedPathWithConfigDirTemplate (options .DeclarationDir , basePath )
1385
+ if startsWithConfigDirTemplate (compilerOptions .DeclarationDir ) {
1386
+ compilerOptions .DeclarationDir = getSubstitutedPathWithConfigDirTemplate (compilerOptions .DeclarationDir , basePath )
1361
1387
}
1362
1388
}
1363
1389
@@ -1517,8 +1543,8 @@ func getFileNamesFromConfigSpecs(
1517
1543
return files
1518
1544
}
1519
1545
1520
- func GetSupportedExtensions (options * core.CompilerOptions , extraFileExtensions []fileExtensionInfo ) [][]string {
1521
- needJSExtensions := options .GetAllowJS ()
1546
+ func GetSupportedExtensions (compilerOptions * core.CompilerOptions , extraFileExtensions []fileExtensionInfo ) [][]string {
1547
+ needJSExtensions := compilerOptions .GetAllowJS ()
1522
1548
if len (extraFileExtensions ) == 0 {
1523
1549
if needJSExtensions {
1524
1550
return tspath .AllSupportedExtensions
@@ -1543,8 +1569,8 @@ func GetSupportedExtensions(options *core.CompilerOptions, extraFileExtensions [
1543
1569
return extensions
1544
1570
}
1545
1571
1546
- func GetSupportedExtensionsWithJsonIfResolveJsonModule (options * core.CompilerOptions , supportedExtensions [][]string ) [][]string {
1547
- if options == nil || ! options .GetResolveJsonModule () {
1572
+ func GetSupportedExtensionsWithJsonIfResolveJsonModule (compilerOptions * core.CompilerOptions , supportedExtensions [][]string ) [][]string {
1573
+ if compilerOptions == nil || ! compilerOptions .GetResolveJsonModule () {
1548
1574
return supportedExtensions
1549
1575
}
1550
1576
if core .Same (supportedExtensions , tspath .AllSupportedExtensions ) {
0 commit comments