@@ -103,6 +103,7 @@ import {
103
103
returnTrue ,
104
104
ScriptTarget ,
105
105
startsWith ,
106
+ stringContains ,
106
107
StringLiteral ,
107
108
SyntaxKind ,
108
109
sys ,
@@ -1658,11 +1659,14 @@ export function parseCustomTypeOption(opt: CommandLineOptionOfCustomType, value:
1658
1659
}
1659
1660
1660
1661
/** @internal */
1661
- export function parseListTypeOption ( opt : CommandLineOptionOfListType , value = "" , errors : Push < Diagnostic > ) : ( string | number ) [ ] | undefined {
1662
+ export function parseListTypeOption ( opt : CommandLineOptionOfListType , value = "" , errors : Push < Diagnostic > ) : string | ( string | number ) [ ] | undefined {
1662
1663
value = trimString ( value ) ;
1663
1664
if ( startsWith ( value , "-" ) ) {
1664
1665
return undefined ;
1665
1666
}
1667
+ if ( opt . type === "string | list" && ! stringContains ( value , "," ) ) {
1668
+ return validateJsonOptionValue ( opt , value , errors ) ;
1669
+ }
1666
1670
if ( value === "" ) {
1667
1671
return [ ] ;
1668
1672
}
@@ -1672,6 +1676,10 @@ export function parseListTypeOption(opt: CommandLineOptionOfListType, value = ""
1672
1676
return mapDefined ( values , v => validateJsonOptionValue ( opt . element , parseInt ( v ) , errors ) ) ;
1673
1677
case "string" :
1674
1678
return mapDefined ( values , v => validateJsonOptionValue ( opt . element , v || "" , errors ) ) ;
1679
+ case "boolean" :
1680
+ case "object" :
1681
+ case "string | list" :
1682
+ return Debug . fail ( `List of ${ opt . element . type } is not yet supported.` ) ;
1675
1683
default :
1676
1684
return mapDefined ( values , v => parseCustomTypeOption ( opt . element as CommandLineOptionOfCustomType , v , errors ) ) ;
1677
1685
}
@@ -1843,6 +1851,7 @@ function parseOptionValue(
1843
1851
options [ opt . name ] = validateJsonOptionValue ( opt , args [ i ] || "" , errors ) ;
1844
1852
i ++ ;
1845
1853
break ;
1854
+ case "string | list" :
1846
1855
case "list" :
1847
1856
const result = parseListTypeOption ( opt , args [ i ] , errors ) ;
1848
1857
options [ opt . name ] = result || [ ] ;
@@ -2362,7 +2371,7 @@ export function convertToObjectWorker(
2362
2371
if ( ! isDoubleQuotedString ( valueExpression ) ) {
2363
2372
errors . push ( createDiagnosticForNodeInSourceFile ( sourceFile , valueExpression , Diagnostics . String_literal_with_double_quotes_expected ) ) ;
2364
2373
}
2365
- reportInvalidOptionValue ( option && isString ( option . type ) && option . type !== "string" && ( option . type !== "listOrElement" || ( isString ( option . element . type ) && option . element . type !== "string" ) ) ) ;
2374
+ reportInvalidOptionValue ( option && isString ( option . type ) && option . type !== "string" && ( option . type !== "listOrElement" || ( isString ( option . element . type ) && option . element . type !== "string" ) ) && option . type !== "string | list" ) ;
2366
2375
const text = ( valueExpression as StringLiteral ) . text ;
2367
2376
if ( option ) {
2368
2377
Debug . assert ( option . type !== "listOrElement" || option . element . type === "string" , "Only string or array of string is handled for now" ) ;
@@ -2394,7 +2403,7 @@ export function convertToObjectWorker(
2394
2403
return validateValue ( - Number ( ( ( valueExpression as PrefixUnaryExpression ) . operand as NumericLiteral ) . text ) ) ;
2395
2404
2396
2405
case SyntaxKind . ObjectLiteralExpression :
2397
- reportInvalidOptionValue ( option && option . type !== "object" && ( option . type !== "listOrElement" || option . element . type !== "object" ) ) ;
2406
+ reportInvalidOptionValue ( option && option . type !== "object" && ( option . type !== "listOrElement" || option . element . type !== "object" ) && option . type !== "string | list" ) ;
2398
2407
const objectLiteralExpression = valueExpression as ObjectLiteralExpression ;
2399
2408
2400
2409
// Currently having element option declaration in the tsconfig with type "object"
@@ -2472,6 +2481,9 @@ function isCompilerOptionsValue(option: CommandLineOption | undefined, value: an
2472
2481
if ( option . type === "listOrElement" ) {
2473
2482
return isArray ( value ) || isCompilerOptionsValue ( option . element , value ) ;
2474
2483
}
2484
+ if ( option . type === "string | list" ) {
2485
+ return typeof value === "string" || isArray ( value ) ;
2486
+ }
2475
2487
const expectedType = isString ( option . type ) ? option . type : "string" ;
2476
2488
return typeof value === expectedType ;
2477
2489
}
@@ -2576,15 +2588,29 @@ function matchesSpecs(path: string, includeSpecs: readonly string[] | undefined,
2576
2588
}
2577
2589
2578
2590
function getCustomTypeMapOfCommandLineOption ( optionDefinition : CommandLineOption ) : Map < string , string | number > | undefined {
2579
- if ( optionDefinition . type === "string" || optionDefinition . type === "number" || optionDefinition . type === "boolean" || optionDefinition . type === "object" ) {
2580
- // this is of a type CommandLineOptionOfPrimitiveType
2581
- return undefined ;
2582
- }
2583
- else if ( optionDefinition . type === "list" || optionDefinition . type === "listOrElement" ) {
2584
- return getCustomTypeMapOfCommandLineOption ( optionDefinition . element ) ;
2585
- }
2586
- else {
2587
- return optionDefinition . type ;
2591
+ // if (optionDefinition.type === "string" || optionDefinition.type === "number" || optionDefinition.type === "boolean" || optionDefinition.type === "object") {
2592
+ // // this is of a type CommandLineOptionOfPrimitiveType
2593
+ // return undefined;
2594
+ // }
2595
+ // else if (optionDefinition.type === "list" || optionDefinition.type === "listOrElement") {
2596
+ // return getCustomTypeMapOfCommandLineOption(optionDefinition.element);
2597
+ // }
2598
+ // else {
2599
+ // return optionDefinition.type;
2600
+ // }
2601
+ switch ( optionDefinition . type ) {
2602
+ case "string" :
2603
+ case "number" :
2604
+ case "boolean" :
2605
+ case "object" :
2606
+ case "string | list" :
2607
+ // this is of a type CommandLineOptionOfPrimitiveType
2608
+ return undefined ;
2609
+ case "list" :
2610
+ case "listOrElement" :
2611
+ return getCustomTypeMapOfCommandLineOption ( optionDefinition . element ) ;
2612
+ default :
2613
+ return optionDefinition . type ;
2588
2614
}
2589
2615
}
2590
2616
@@ -3495,15 +3521,15 @@ function convertOptionsFromJson(optionsNameMap: Map<string, CommandLineOption>,
3495
3521
export function convertJsonOption ( opt : CommandLineOption , value : any , basePath : string , errors : Push < Diagnostic > ) : CompilerOptionsValue {
3496
3522
if ( isCompilerOptionsValue ( opt , value ) ) {
3497
3523
const optType = opt . type ;
3498
- if ( optType === "list" && isArray ( value ) ) {
3524
+ if ( ( optType === "list" || opt . type === "string | list" ) && isArray ( value ) ) {
3499
3525
return convertJsonOptionOfListType ( opt , value , basePath , errors ) ;
3500
3526
}
3501
3527
else if ( optType === "listOrElement" ) {
3502
3528
return isArray ( value ) ?
3503
3529
convertJsonOptionOfListType ( opt , value , basePath , errors ) :
3504
3530
convertJsonOption ( opt . element , value , basePath , errors ) ;
3505
3531
}
3506
- else if ( ! isString ( optType ) ) {
3532
+ else if ( ! isString ( opt . type ) ) {
3507
3533
return convertJsonOptionOfCustomType ( opt as CommandLineOptionOfCustomType , value as string , errors ) ;
3508
3534
}
3509
3535
const validatedValue = validateJsonOptionValue ( opt , value , errors ) ;
@@ -3949,6 +3975,7 @@ function getOptionValueWithEmptyStrings(value: any, option: CommandLineOption):
3949
3975
if ( ! isArray ( value ) ) return getOptionValueWithEmptyStrings ( value , option . element ) ;
3950
3976
// fall through to list
3951
3977
case "list" :
3978
+ case "string | list" :
3952
3979
const elementType = option . element ;
3953
3980
return isArray ( value ) ? value . map ( v => getOptionValueWithEmptyStrings ( v , elementType ) ) : "" ;
3954
3981
default :
@@ -3968,6 +3995,7 @@ function getDefaultValueForOption(option: CommandLineOption): {} {
3968
3995
case "boolean" :
3969
3996
return true ;
3970
3997
case "string" :
3998
+ case "string | list" :
3971
3999
const defaultValue = option . defaultValueDescription ;
3972
4000
return option . isFilePath ? `./${ defaultValue && typeof defaultValue === "string" ? defaultValue : "" } ` : "" ;
3973
4001
case "list" :
0 commit comments