@@ -117,7 +117,7 @@ type parsedTsconfig struct {
117
117
}
118
118
119
119
func parseOwnConfigOfJsonSourceFile (
120
- sourceFile * TsConfigSourceFile ,
120
+ sourceFile * ast. SourceFile ,
121
121
host ParseConfigHost ,
122
122
basePath string ,
123
123
configFileName string ,
@@ -165,7 +165,7 @@ func parseOwnConfigOfJsonSourceFile(
165
165
propertySetErrors = append (propertySetErrors , err ... )
166
166
} else if option == nil {
167
167
if keyText == "excludes" {
168
- propertySetErrors = append (propertySetErrors , createDiagnosticForNodeInSourceFileOrCompilerDiagnostic (sourceFile . SourceFile , propertyAssignment .Name (), diagnostics .Unknown_option_excludes_Did_you_mean_exclude ))
168
+ propertySetErrors = append (propertySetErrors , createDiagnosticForNodeInSourceFileOrCompilerDiagnostic (sourceFile , propertyAssignment .Name (), diagnostics .Unknown_option_excludes_Did_you_mean_exclude ))
169
169
}
170
170
if core .Find (optionsDeclarations , func (option * CommandLineOption ) bool { return option .Name == keyText }) != nil {
171
171
rootCompilerOptions = append (rootCompilerOptions , propertyAssignment .Name ())
@@ -176,7 +176,7 @@ func parseOwnConfigOfJsonSourceFile(
176
176
}
177
177
178
178
json , err := convertConfigFileToObject (
179
- sourceFile . SourceFile ,
179
+ sourceFile ,
180
180
& jsonConversionNotifier {
181
181
tsconfigRootOptionsMap ,
182
182
onPropertySet ,
@@ -200,6 +200,14 @@ type TsConfigSourceFile struct {
200
200
configFileSpecs * configFileSpecs
201
201
SourceFile * ast.SourceFile
202
202
}
203
+
204
+ func tsconfigToSourceFile (tsconfigSourceFile * TsConfigSourceFile ) * ast.SourceFile {
205
+ if tsconfigSourceFile == nil {
206
+ return nil
207
+ }
208
+ return tsconfigSourceFile .SourceFile
209
+ }
210
+
203
211
type jsonConversionNotifier struct {
204
212
rootOptions * CommandLineOption
205
213
onPropertySet func (keyText string , value any , propertyAssignment * ast.PropertyAssignment , parentOption * CommandLineOption , option * CommandLineOption ) (any , []* ast.Diagnostic )
@@ -272,7 +280,7 @@ func validateJsonOptionValue(
272
280
opt * CommandLineOption ,
273
281
val any ,
274
282
valueExpression * ast.Expression ,
275
- sourceFile * TsConfigSourceFile ,
283
+ sourceFile * ast. SourceFile ,
276
284
) (any , []* ast.Diagnostic ) {
277
285
if val == nil || val == "" {
278
286
return nil , nil
@@ -284,7 +292,7 @@ func validateJsonOptionValue(
284
292
if result == nil {
285
293
return val , nil
286
294
}
287
- errors = append (errors , createDiagnosticForNodeInSourceFileOrCompilerDiagnostic (sourceFile . SourceFile , valueExpression , err ))
295
+ errors = append (errors , createDiagnosticForNodeInSourceFileOrCompilerDiagnostic (sourceFile , valueExpression , err ))
288
296
} else {
289
297
return val , nil
290
298
}
@@ -297,7 +305,7 @@ func convertJsonOptionOfListType(
297
305
basePath string ,
298
306
propertyAssignment * ast.PropertyAssignment ,
299
307
valueExpression * ast.Node ,
300
- sourceFile * TsConfigSourceFile ,
308
+ sourceFile * ast. SourceFile ,
301
309
) ([]any , []* ast.Diagnostic ) {
302
310
var expression * ast.Node
303
311
var errors []* ast.Diagnostic
@@ -350,7 +358,7 @@ func convertJsonOption(
350
358
basePath string ,
351
359
propertyAssignment * ast.PropertyAssignment ,
352
360
valueExpression * ast.Expression ,
353
- sourceFile * TsConfigSourceFile ,
361
+ sourceFile * ast. SourceFile ,
354
362
) (any , []* ast.Diagnostic ) {
355
363
var errors []* ast.Diagnostic
356
364
if opt .isCommandLineOnly {
@@ -361,7 +369,7 @@ func convertJsonOption(
361
369
if sourceFile == nil && nodeValue == nil {
362
370
errors = append (errors , ast .NewCompilerDiagnostic (diagnostics .Option_0_can_only_be_specified_on_command_line , opt .Name ))
363
371
} else {
364
- errors = append (errors , createDiagnosticForNodeInSourceFileOrCompilerDiagnostic (sourceFile . SourceFile , nodeValue , diagnostics .Option_0_can_only_be_specified_on_command_line , opt .Name ))
372
+ errors = append (errors , createDiagnosticForNodeInSourceFileOrCompilerDiagnostic (sourceFile , nodeValue , diagnostics .Option_0_can_only_be_specified_on_command_line , opt .Name ))
365
373
}
366
374
return nil , errors
367
375
}
@@ -390,7 +398,7 @@ func convertJsonOption(
390
398
return normalizeNonListOptionValue (opt , basePath , validatedValue ), errors
391
399
}
392
400
} else {
393
- errors = append (errors , createDiagnosticForNodeInSourceFileOrCompilerDiagnostic (sourceFile . SourceFile , valueExpression , diagnostics .Compiler_option_0_requires_a_value_of_type_1 , opt .Name , getCompilerOptionValueTypeString (opt )))
401
+ errors = append (errors , createDiagnosticForNodeInSourceFileOrCompilerDiagnostic (sourceFile , valueExpression , diagnostics .Compiler_option_0_requires_a_value_of_type_1 , opt .Name , getCompilerOptionValueTypeString (opt )))
394
402
return nil , errors
395
403
}
396
404
}
@@ -402,7 +410,7 @@ func getExtendsConfigPathOrArray(
402
410
configFileName string ,
403
411
propertyAssignment * ast.PropertyAssignment ,
404
412
valueExpression * ast.Expression ,
405
- sourceFile * TsConfigSourceFile ,
413
+ sourceFile * ast. SourceFile ,
406
414
) ([]string , []* ast.Diagnostic ) {
407
415
var extendedConfigPathArray []string
408
416
newBase := basePath
@@ -446,13 +454,13 @@ func getExtendsConfigPath(
446
454
host ParseConfigHost ,
447
455
basePath string ,
448
456
valueExpression * ast.Expression ,
449
- sourceFile * TsConfigSourceFile ,
457
+ sourceFile * ast. SourceFile ,
450
458
) (string , []* ast.Diagnostic ) {
451
459
extendedConfig = tspath .NormalizeSlashes (extendedConfig )
452
460
var errors []* ast.Diagnostic
453
461
var errorFile * ast.SourceFile
454
462
if sourceFile != nil {
455
- errorFile = sourceFile . SourceFile
463
+ errorFile = sourceFile
456
464
}
457
465
if tspath .IsRootedDiskPath (extendedConfig ) || strings .HasPrefix (extendedConfig , "./" ) || strings .HasPrefix (extendedConfig , "../" ) {
458
466
extendedConfigPath := tspath .GetNormalizedAbsolutePath (extendedConfig , basePath )
@@ -579,7 +587,7 @@ type resolverHost struct {
579
587
580
588
func (r * resolverHost ) Trace (msg string ) {}
581
589
582
- func ParseJsonSourceFileConfigFileContent (sourceFile * TsConfigSourceFile , host ParseConfigHost , basePath string , existingOptions * core.CompilerOptions , configFileName string , resolutionStack []tspath.Path , extraFileExtensions []fileExtensionInfo , extendedConfigCache map [string ]* extendedConfigCacheEntry ) ParsedCommandLine {
590
+ func ParseJsonSourceFileConfigFileContent (sourceFile * TsConfigSourceFile , host ParseConfigHost , basePath string , existingOptions * core.CompilerOptions , configFileName string , resolutionStack []tspath.Path , extraFileExtensions []fileExtensionInfo , extendedConfigCache map [string ]* extendedConfigCacheEntry ) * ParsedCommandLine {
583
591
// tracing?.push(tracing.Phase.Parse, "parseJsonSourceFileConfigFileContent", { path: sourceFile.fileName });
584
592
result := parseJsonConfigFileContentWorker (nil /*json*/ , sourceFile , host , basePath , existingOptions , configFileName , resolutionStack , extraFileExtensions , extendedConfigCache )
585
593
// tracing?.pop();
@@ -719,7 +727,7 @@ func convertPropertyValueToJson(sourceFile *ast.SourceFile, valueExpression *ast
719
727
// jsonNode: The contents of the config file to parse
720
728
// host: Instance of ParseConfigHost used to enumerate files in folder.
721
729
// basePath: A root directory to resolve relative path entries in the config file to. e.g. outDir
722
- func ParseJsonConfigFileContent (json any , host ParseConfigHost , basePath string , existingOptions * core.CompilerOptions , configFileName string , resolutionStack []tspath.Path , extraFileExtensions []fileExtensionInfo , extendedConfigCache map [string ]* extendedConfigCacheEntry ) ParsedCommandLine {
730
+ func ParseJsonConfigFileContent (json any , host ParseConfigHost , basePath string , existingOptions * core.CompilerOptions , configFileName string , resolutionStack []tspath.Path , extraFileExtensions []fileExtensionInfo , extendedConfigCache map [string ]* extendedConfigCacheEntry ) * ParsedCommandLine {
723
731
result := parseJsonConfigFileContentWorker (parseJsonToStringKey (json ), nil /*sourceFile*/ , host , basePath , existingOptions , configFileName , resolutionStack , extraFileExtensions , extendedConfigCache )
724
732
return result
725
733
}
@@ -883,7 +891,7 @@ func parseConfig(
883
891
if json != nil {
884
892
ownConfig , err = parseOwnConfigOfJson (json , host , basePath , configFileName )
885
893
} else {
886
- ownConfig , err = parseOwnConfigOfJsonSourceFile (sourceFile , host , basePath , configFileName )
894
+ ownConfig , err = parseOwnConfigOfJsonSourceFile (tsconfigToSourceFile ( sourceFile ) , host , basePath , configFileName )
887
895
}
888
896
errors = append (errors , err ... )
889
897
if ownConfig .options != nil && ownConfig .options .Paths != nil {
@@ -1004,7 +1012,7 @@ func parseJsonConfigFileContentWorker(
1004
1012
resolutionStack []tspath.Path ,
1005
1013
extraFileExtensions []fileExtensionInfo ,
1006
1014
extendedConfigCache map [string ]* extendedConfigCacheEntry ,
1007
- ) ParsedCommandLine {
1015
+ ) * ParsedCommandLine {
1008
1016
// Debug.assert((json === undefined && sourceFile !== undefined) || (json !== undefined && sourceFile === undefined));
1009
1017
var errors []* ast.Diagnostic
1010
1018
resolutionStackString := []string {}
@@ -1060,7 +1068,7 @@ func parseJsonConfigFileContentWorker(
1060
1068
fileName = "tsconfig.json"
1061
1069
}
1062
1070
diagnosticMessage := diagnostics .The_files_list_in_config_file_0_is_empty
1063
- nodeValue := forEachTsConfigPropArray (sourceFile , "files" , func (property * ast.PropertyAssignment ) * ast.Node { return property .Initializer })
1071
+ nodeValue := forEachTsConfigPropArray (sourceFile . SourceFile , "files" , func (property * ast.PropertyAssignment ) * ast.Node { return property .Initializer })
1064
1072
errors = append (errors , ast .NewDiagnostic (sourceFile .SourceFile , core .NewTextRange (scanner .SkipTrivia (sourceFile .SourceFile .Text , nodeValue .Pos ()), nodeValue .End ()), diagnosticMessage , fileName ))
1065
1073
} else {
1066
1074
errors = append (errors , ast .NewCompilerDiagnostic (diagnostics .The_files_list_in_config_file_0_is_empty , configFileName ))
@@ -1099,7 +1107,7 @@ func parseJsonConfigFileContentWorker(
1099
1107
// file system.
1100
1108
if includeSpecs .sliceValue != nil {
1101
1109
var err []* ast.Diagnostic
1102
- validatedIncludeSpecsBeforeSubstitution , err = validateSpecs (includeSpecs .sliceValue , true /*disallowTrailingRecursion*/ , sourceFile , "include" )
1110
+ validatedIncludeSpecsBeforeSubstitution , err = validateSpecs (includeSpecs .sliceValue , true /*disallowTrailingRecursion*/ , tsconfigToSourceFile ( sourceFile ) , "include" )
1103
1111
errors = append (errors , err ... )
1104
1112
validatedIncludeSpecs = getSubstitutedStringArrayWithConfigDirTemplate (
1105
1113
validatedIncludeSpecsBeforeSubstitution ,
@@ -1111,7 +1119,7 @@ func parseJsonConfigFileContentWorker(
1111
1119
}
1112
1120
if excludeSpecs .sliceValue != nil {
1113
1121
var err []* ast.Diagnostic
1114
- validatedExcludeSpecsBeforeSubstitution , err = validateSpecs (excludeSpecs .sliceValue , false /*disallowTrailingRecursion*/ , sourceFile , "exclude" )
1122
+ validatedExcludeSpecsBeforeSubstitution , err = validateSpecs (excludeSpecs .sliceValue , false /*disallowTrailingRecursion*/ , tsconfigToSourceFile ( sourceFile ) , "exclude" )
1115
1123
errors = append (errors , err ... )
1116
1124
validatedExcludeSpecs = getSubstitutedStringArrayWithConfigDirTemplate (
1117
1125
validatedExcludeSpecsBeforeSubstitution ,
@@ -1193,7 +1201,7 @@ func parseJsonConfigFileContentWorker(
1193
1201
return projectReferences
1194
1202
}
1195
1203
1196
- return ParsedCommandLine {
1204
+ return & ParsedCommandLine {
1197
1205
ParsedConfig : & core.ParsedOptions {
1198
1206
CompilerOptions : parsedConfig .options ,
1199
1207
FileNames : getFileNames (basePathForFileNames ),
@@ -1214,10 +1222,10 @@ func shouldReportNoInputFiles(fileNames []string, canJsonReportNoInutFiles bool,
1214
1222
return len (fileNames ) == 0 && canJsonReportNoInutFiles && len (resolutionStack ) == 0
1215
1223
}
1216
1224
1217
- func validateSpecs (specs any , disallowTrailingRecursion bool , jsonSourceFile * TsConfigSourceFile , specKey string ) ([]string , []* ast.Diagnostic ) {
1225
+ func validateSpecs (specs any , disallowTrailingRecursion bool , jsonSourceFile * ast. SourceFile , specKey string ) ([]string , []* ast.Diagnostic ) {
1218
1226
createDiagnostic := func (message * diagnostics.Message , spec string ) * ast.Diagnostic {
1219
1227
element := getTsConfigPropArrayElementValue (jsonSourceFile , specKey , spec )
1220
- return createDiagnosticForNodeInSourceFileOrCompilerDiagnostic (jsonSourceFile . SourceFile , element .AsNode (), message , spec )
1228
+ return createDiagnosticForNodeInSourceFileOrCompilerDiagnostic (jsonSourceFile , element .AsNode (), message , spec )
1221
1229
}
1222
1230
var errors []* ast.Diagnostic
1223
1231
var finalSpecs []string
@@ -1282,7 +1290,7 @@ func invalidDotDotAfterRecursiveWildcard(s string) bool {
1282
1290
// \/?$ # matches an optional trailing directory separator at the end of the string.
1283
1291
const invalidTrailingRecursionPattern = `(?:^|\/)\*\*\/?$`
1284
1292
1285
- func getTsConfigPropArrayElementValue (tsConfigSourceFile * TsConfigSourceFile , propKey string , elementValue string ) * ast.StringLiteral {
1293
+ func getTsConfigPropArrayElementValue (tsConfigSourceFile * ast. SourceFile , propKey string , elementValue string ) * ast.StringLiteral {
1286
1294
return forEachTsConfigPropArray (tsConfigSourceFile , propKey , func (property * ast.PropertyAssignment ) * ast.StringLiteral {
1287
1295
if ast .IsArrayLiteralExpression (property .Initializer ) {
1288
1296
value := core .Find (property .Initializer .AsArrayLiteralExpression ().Elements .Nodes , func (element * ast.Node ) bool {
@@ -1296,7 +1304,7 @@ func getTsConfigPropArrayElementValue(tsConfigSourceFile *TsConfigSourceFile, pr
1296
1304
})
1297
1305
}
1298
1306
1299
- func forEachTsConfigPropArray [T any ](tsConfigSourceFile * TsConfigSourceFile , propKey string , callback func (property * ast.PropertyAssignment ) * T ) * T {
1307
+ func forEachTsConfigPropArray [T any ](tsConfigSourceFile * ast. SourceFile , propKey string , callback func (property * ast.PropertyAssignment ) * T ) * T {
1300
1308
if tsConfigSourceFile != nil {
1301
1309
return forEachPropertyAssignment (getTsConfigObjectLiteralExpression (tsConfigSourceFile ), propKey , callback )
1302
1310
}
@@ -1319,9 +1327,9 @@ func forEachPropertyAssignment[T any](objectLiteral *ast.ObjectLiteralExpression
1319
1327
return * new (T )
1320
1328
}
1321
1329
1322
- func getTsConfigObjectLiteralExpression (tsConfigSourceFile * TsConfigSourceFile ) * ast.ObjectLiteralExpression {
1323
- if tsConfigSourceFile != nil && tsConfigSourceFile .SourceFile . Statements != nil && len (tsConfigSourceFile . SourceFile .Statements .Nodes ) > 0 {
1324
- expression := tsConfigSourceFile .SourceFile . Statements .Nodes [0 ].AsExpressionStatement ().Expression
1330
+ func getTsConfigObjectLiteralExpression (tsConfigSourceFile * ast. SourceFile ) * ast.ObjectLiteralExpression {
1331
+ if tsConfigSourceFile != nil && tsConfigSourceFile .Statements != nil && len (tsConfigSourceFile .Statements .Nodes ) > 0 {
1332
+ expression := tsConfigSourceFile .Statements .Nodes [0 ].AsExpressionStatement ().Expression
1325
1333
return expression .AsObjectLiteralExpression ()
1326
1334
}
1327
1335
return nil
0 commit comments