@@ -135,7 +135,7 @@ func parseOwnConfigOfJsonSourceFile(
135
135
// Ensure value is verified except for extends which is handled in its own way for error reporting
136
136
var propertySetErrors []* ast.Diagnostic
137
137
if option != nil && option != extendsOptionDeclaration {
138
- value , propertySetErrors = convertTsConfigJsonOption (option , value , basePath , propertyAssignment , propertyAssignment .Initializer , sourceFile )
138
+ value , propertySetErrors = convertJsonOption (option , value , basePath , propertyAssignment , propertyAssignment .Initializer , sourceFile )
139
139
}
140
140
if parentOption != nil && parentOption .Name != "undefined" && value != nil {
141
141
if option != nil && option .Name != "" {
@@ -317,7 +317,7 @@ func convertJsonOptionOfListType(
317
317
if valueExpression != nil {
318
318
expression = valueExpression .AsArrayLiteralExpression ().Elements .Nodes [index ]
319
319
}
320
- result , err := convertTsConfigJsonOption (option .Elements (), v , basePath , propertyAssignment , expression , sourceFile )
320
+ result , err := convertJsonOption (option .Elements (), v , basePath , propertyAssignment , expression , sourceFile )
321
321
errors = append (errors , err ... )
322
322
return result
323
323
})
@@ -355,7 +355,7 @@ func normalizeNonListOptionValue(option *CommandLineOption, basePath string, val
355
355
return value
356
356
}
357
357
358
- func convertTsConfigJsonOption (
358
+ func convertJsonOption (
359
359
opt * CommandLineOption ,
360
360
value any ,
361
361
basePath string ,
@@ -374,45 +374,27 @@ func convertTsConfigJsonOption(
374
374
return nil , []* ast.Diagnostic {createDiagnosticForNodeInSourceFileOrCompilerDiagnostic (sourceFile , nodeValue , diagnostics .Option_0_can_only_be_specified_on_command_line , opt .Name )}
375
375
}
376
376
}
377
- return convertJsonOption (opt , value , basePath , propertyAssignment , valueExpression , sourceFile )
378
- }
379
-
380
- func convertJsonOption (
381
- opt * CommandLineOption ,
382
- value any ,
383
- basePath string ,
384
- propertyAssignment * ast.PropertyAssignment ,
385
- valueExpression * ast.Expression ,
386
- sourceFile * ast.SourceFile ,
387
- ) (any , []* ast.Diagnostic ) {
388
- var errors []* ast.Diagnostic
389
377
if isCompilerOptionsValue (opt , value ) {
390
378
optType := opt .Kind
391
379
if optType == "list" {
392
- list , err := convertJsonOptionOfListType (opt , value , basePath , propertyAssignment , valueExpression , sourceFile ) // as ArrayLiteralExpression | undefined
393
- return list , append (errors , err ... )
380
+ return convertJsonOptionOfListType (opt , value , basePath , propertyAssignment , valueExpression , sourceFile ) // as ArrayLiteralExpression | undefined
394
381
} else if optType == "listOrElement" {
395
382
if reflect .TypeOf (value ).Kind () == reflect .Slice {
396
- listOrElement , err := convertJsonOptionOfListType (opt , value , basePath , propertyAssignment , valueExpression , sourceFile )
397
- errors = append (errors , err ... )
398
- return listOrElement , errors
383
+ return convertJsonOptionOfListType (opt , value , basePath , propertyAssignment , valueExpression , sourceFile )
399
384
} else {
400
- return convertTsConfigJsonOption (opt .Elements (), value , basePath , propertyAssignment , valueExpression , sourceFile )
385
+ return convertJsonOption (opt .Elements (), value , basePath , propertyAssignment , valueExpression , sourceFile )
401
386
}
402
387
} else if ! (reflect .TypeOf (optType ).Kind () == reflect .String ) {
403
- val , err := convertJsonOptionOfEnumType (opt , value .(string ), valueExpression , sourceFile )
404
- return val , append (errors , err ... )
388
+ return convertJsonOptionOfEnumType (opt , value .(string ), valueExpression , sourceFile )
405
389
}
406
- validatedValue , err := validateJsonOptionValue (opt , value , valueExpression , sourceFile )
407
- errors = append (errors , err ... )
408
- if err != nil {
390
+ validatedValue , errors := validateJsonOptionValue (opt , value , valueExpression , sourceFile )
391
+ if len (errors ) > 0 || validatedValue == nil {
409
392
return validatedValue , errors
410
393
} else {
411
394
return normalizeNonListOptionValue (opt , basePath , validatedValue ), errors
412
395
}
413
396
} else {
414
- errors = append (errors , createDiagnosticForNodeInSourceFileOrCompilerDiagnostic (sourceFile , valueExpression , diagnostics .Compiler_option_0_requires_a_value_of_type_1 , opt .Name , getCompilerOptionValueTypeString (opt )))
415
- return nil , errors
397
+ return nil , []* ast.Diagnostic {createDiagnosticForNodeInSourceFileOrCompilerDiagnostic (sourceFile , valueExpression , diagnostics .Compiler_option_0_requires_a_value_of_type_1 , opt .Name , getCompilerOptionValueTypeString (opt ))}
416
398
}
417
399
}
418
400
@@ -430,15 +412,15 @@ func getExtendsConfigPathOrArray(
430
412
if configFileName != "" {
431
413
newBase = directoryOfCombinedPath (configFileName , basePath )
432
414
}
433
-
434
- var errors []* ast.Diagnostic
435
415
if reflect .TypeOf (value ).Kind () == reflect .String {
436
416
val , err := getExtendsConfigPath (value .(string ), host , newBase , valueExpression , sourceFile )
437
417
if val != "" {
438
418
extendedConfigPathArray = append (extendedConfigPathArray , val )
439
419
}
440
- errors = append (errors , err ... )
441
- } else if reflect .TypeOf (value ).Kind () == reflect .Slice {
420
+ return extendedConfigPathArray , err
421
+ }
422
+ var errors []* ast.Diagnostic
423
+ if reflect .TypeOf (value ).Kind () == reflect .Slice {
442
424
for index , fileName := range value .([]any ) {
443
425
var expression * ast.Expression = nil
444
426
if valueExpression != nil {
@@ -451,13 +433,12 @@ func getExtendsConfigPathOrArray(
451
433
}
452
434
errors = append (errors , err ... )
453
435
} else {
454
- var err []* ast.Diagnostic
455
- _ , err = convertTsConfigJsonOption (extendsOptionDeclaration .Elements (), value , basePath , propertyAssignment , expression , sourceFile )
436
+ _ , err := convertJsonOption (extendsOptionDeclaration .Elements (), value , basePath , propertyAssignment , expression , sourceFile )
456
437
errors = append (errors , err ... )
457
438
}
458
439
}
459
440
} else {
460
- _ , errors = convertTsConfigJsonOption (extendsOptionDeclaration , value , basePath , propertyAssignment , valueExpression , sourceFile )
441
+ _ , errors = convertJsonOption (extendsOptionDeclaration , value , basePath , propertyAssignment , valueExpression , sourceFile )
461
442
}
462
443
return extendedConfigPathArray , errors
463
444
}
@@ -515,34 +496,41 @@ func commandLineOptionsToMap(options []*CommandLineOption) map[string]*CommandLi
515
496
516
497
var commandLineCompilerOptionsMap map [string ]* CommandLineOption = commandLineOptionsToMap (OptionsDeclarations )
517
498
499
+ func convertMapToOptions [O optionParser ](optionsNameMap map [string ]* CommandLineOption , options * collections.OrderedMap [string , any ], basePath string , result O ) O {
500
+ // this assumes any `key`, `value` pair in `options` will have `value` already be the correct type. this function should no error handling
501
+ for key , value := range options .Entries () {
502
+ result .ParseOption (key , value )
503
+ }
504
+ return result
505
+ }
506
+
518
507
func convertOptionsFromJson [O optionParser ](optionsNameMap map [string ]* CommandLineOption , jsonOptions any , basePath string , result O ) (O , []* ast.Diagnostic ) {
519
508
if jsonOptions == nil {
520
509
return result , nil
521
510
}
522
- convertOption := convertTsConfigJsonOption
523
- if result .CommandLine () {
524
- convertOption = convertJsonOption
511
+ jsonMap , ok := jsonOptions .(* collections.OrderedMap [string , any ])
512
+ if ! ok {
513
+ // !!! probably should be an error
514
+ return result , nil
525
515
}
526
516
var errors []* ast.Diagnostic
527
- if _ , ok := jsonOptions .(* collections.OrderedMap [string , any ]); ok {
528
- for key , value := range jsonOptions .(* collections.OrderedMap [string , any ]).Entries () {
529
- opt , ok := optionsNameMap [key ]
530
- commandLineOptionEnumMapVal := opt .EnumMap ()
531
- if commandLineOptionEnumMapVal != nil {
532
- val , ok := commandLineOptionEnumMapVal .Get (strings .ToLower (value .(string )))
533
- if ok {
534
- errors = result .ParseOption (key , val )
535
- }
536
- } else if ok {
537
- convertJson , err := convertOption (opt , value , basePath , nil , nil , nil )
538
- errors = append (errors , err ... )
539
- compilerOptionsErr := result .ParseOption (key , convertJson )
540
- errors = append (errors , compilerOptionsErr ... )
517
+ for key , value := range jsonMap .Entries () {
518
+ opt , ok := optionsNameMap [key ]
519
+ commandLineOptionEnumMapVal := opt .EnumMap ()
520
+ if commandLineOptionEnumMapVal != nil {
521
+ val , ok := commandLineOptionEnumMapVal .Get (strings .ToLower (value .(string )))
522
+ if ok {
523
+ errors = result .ParseOption (key , val )
541
524
}
542
- // else {
543
- // errors.push(createUnknownOptionError(id, diagnostics));
544
- // }
525
+ } else if ok {
526
+ convertJson , err := convertJsonOption (opt , value , basePath , nil , nil , nil )
527
+ errors = append (errors , err ... )
528
+ compilerOptionsErr := result .ParseOption (key , convertJson )
529
+ errors = append (errors , compilerOptionsErr ... )
545
530
}
531
+ // else {
532
+ // errors.push(createUnknownOptionError(id, diagnostics));
533
+ // }
546
534
}
547
535
return result , errors
548
536
}
@@ -773,7 +761,7 @@ func getDefaultCompilerOptions(configFileName string) *core.CompilerOptions {
773
761
774
762
func convertCompilerOptionsFromJsonWorker (jsonOptions any , basePath string , configFileName string ) (* core.CompilerOptions , []* ast.Diagnostic ) {
775
763
options := getDefaultCompilerOptions (configFileName )
776
- _ , errors := convertOptionsFromJson (commandLineCompilerOptionsMap , jsonOptions , basePath , & compilerOptionsParser {options , false /*commandLine*/ })
764
+ _ , errors := convertOptionsFromJson (commandLineCompilerOptionsMap , jsonOptions , basePath , & compilerOptionsParser {options })
777
765
if configFileName != "" {
778
766
options .ConfigFilePath = tspath .NormalizeSlashes (configFileName )
779
767
}
0 commit comments