-
Notifications
You must be signed in to change notification settings - Fork 718
Fix parsing of enum options #593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
353028c
ea674fa
b0b2760
3411451
e7871d6
46beccf
a91c709
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,15 +139,7 @@ func parseOwnConfigOfJsonSourceFile( | |
} | ||
if parentOption != nil && parentOption.Name != "undefined" && value != nil { | ||
if option != nil && option.Name != "" { | ||
commandLineOptionEnumMapVal := option.EnumMap() | ||
if commandLineOptionEnumMapVal != nil { | ||
val, ok := commandLineOptionEnumMapVal.Get(strings.ToLower(value.(string))) | ||
if ok { | ||
propertySetErrors = append(propertySetErrors, ParseCompilerOptions(option.Name, val, options)...) | ||
} | ||
} else { | ||
propertySetErrors = append(propertySetErrors, ParseCompilerOptions(option.Name, value, options)...) | ||
} | ||
propertySetErrors = append(propertySetErrors, ParseCompilerOptions(option.Name, value, options)...) | ||
} else if keyText != "" { | ||
if parentOption.ElementOptions != nil { | ||
// !!! TODO: support suggestion | ||
|
@@ -276,8 +268,7 @@ func isCompilerOptionsValue(option *CommandLineOption, value any) bool { | |
return reflect.TypeOf(value) == orderedMapType | ||
} | ||
if option.Kind == "enum" && reflect.TypeOf(value).Kind() == reflect.String { | ||
_, ok := option.EnumMap().Get(strings.ToLower(value.(string))) | ||
return ok || (option.DeprecatedKeys() != nil && option.DeprecatedKeys().Has(strings.ToLower(value.(string)))) | ||
return true | ||
} | ||
} | ||
return false | ||
|
@@ -376,18 +367,19 @@ func convertJsonOption( | |
} | ||
} | ||
if isCompilerOptionsValue(opt, value) { | ||
optType := opt.Kind | ||
if optType == "list" { | ||
switch opt.Kind { | ||
case CommandLineOptionTypeList: | ||
return convertJsonOptionOfListType(opt, value, basePath, propertyAssignment, valueExpression, sourceFile) // as ArrayLiteralExpression | undefined | ||
} else if optType == "listOrElement" { | ||
case CommandLineOptionTypeListOrElement: | ||
if reflect.TypeOf(value).Kind() == reflect.Slice { | ||
return convertJsonOptionOfListType(opt, value, basePath, propertyAssignment, valueExpression, sourceFile) | ||
} else { | ||
return convertJsonOption(opt.Elements(), value, basePath, propertyAssignment, valueExpression, sourceFile) | ||
} | ||
} else if !(reflect.TypeOf(optType).Kind() == reflect.String) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the bug you referred to in another comment. 🤔 @jakebailey |
||
case CommandLineOptionTypeEnum: | ||
return convertJsonOptionOfEnumType(opt, value.(string), valueExpression, sourceFile) | ||
} | ||
|
||
validatedValue, errors := validateJsonOptionValue(opt, value, valueExpression, sourceFile) | ||
if len(errors) > 0 || validatedValue == nil { | ||
return validatedValue, errors | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Fs:: | ||
//// [/app.ts] | ||
|
||
|
||
//// [/tsconfig.json] | ||
{ | ||
"compilerOptions": { | ||
"target": "invalid value", | ||
"removeComments": "should be a boolean", | ||
"moduleResolution": "invalid value" | ||
} | ||
} | ||
|
||
|
||
configFileName:: tsconfig.json | ||
CompilerOptions:: | ||
{ | ||
"configFilePath": "/tsconfig.json" | ||
} | ||
|
||
FileNames:: | ||
/app.ts | ||
Errors:: | ||
[91merror[0m[90m TS5024: [0mCompiler option 'removeComments' requires a value of type boolean. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Fs:: | ||
//// [/app.ts] | ||
|
||
|
||
//// [/tsconfig.json] | ||
{ | ||
"compilerOptions": { | ||
"target": "invalid value", | ||
"removeComments": "should be a boolean", | ||
"moduleResolution": "invalid value" | ||
} | ||
} | ||
|
||
|
||
configFileName:: tsconfig.json | ||
CompilerOptions:: | ||
{ | ||
"configFilePath": "/tsconfig.json" | ||
} | ||
|
||
FileNames:: | ||
/app.ts | ||
Errors:: | ||
[96mtsconfig.json[0m:[93m3[0m:[93m15[0m - [91merror[0m[90m TS6046: [0mArgument for '--target' option must be: 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext'. | ||
|
||
[7m3[0m "target": "invalid value", | ||
[7m [0m [91m ~~~~~~~~~~~~~~~[0m | ||
|
||
[96mtsconfig.json[0m:[93m4[0m:[93m23[0m - [91merror[0m[90m TS5024: [0mCompiler option 'removeComments' requires a value of type boolean. | ||
|
||
[7m4[0m "removeComments": "should be a boolean", | ||
[7m [0m [91m ~~~~~~~~~~~~~~~~~~~~~[0m | ||
|
||
[96mtsconfig.json[0m:[93m5[0m:[93m25[0m - [91merror[0m[90m TS6046: [0mArgument for '--moduleResolution' option must be: 'node16', 'nodenext', 'bundler'. | ||
|
||
[7m5[0m "moduleResolution": "invalid value" | ||
[7m [0m [91m ~~~~~~~~~~~~~~~[0m | ||
|
Uh oh!
There was an error while loading. Please reload this page.