@@ -1164,11 +1164,13 @@ namespace ts {
1164
1164
}
1165
1165
}
1166
1166
1167
- interface OptionsBase {
1167
+ /*@internal */
1168
+ export interface OptionsBase {
1168
1169
[ option : string ] : CompilerOptionsValue | TsConfigSourceFile | undefined ;
1169
1170
}
1170
1171
1171
- interface ParseCommandLineWorkerDiagnostics extends DidYouMeanOptionsDiagnostics {
1172
+ /*@internal */
1173
+ export interface ParseCommandLineWorkerDiagnostics extends DidYouMeanOptionsDiagnostics {
1172
1174
getOptionsNameMap : ( ) => OptionsNameMap ;
1173
1175
optionTypeMismatchDiagnostic : DiagnosticMessage ;
1174
1176
}
@@ -1189,7 +1191,8 @@ namespace ts {
1189
1191
createDiagnostics ( diagnostics . unknownOptionDiagnostic , unknownOptionErrorText || unknownOption ) ;
1190
1192
}
1191
1193
1192
- function parseCommandLineWorker (
1194
+ /*@internal */
1195
+ export function parseCommandLineWorker (
1193
1196
diagnostics : ParseCommandLineWorkerDiagnostics ,
1194
1197
commandLine : readonly string [ ] ,
1195
1198
readFile ?: ( path : string ) => string | undefined ) {
@@ -1279,50 +1282,75 @@ namespace ts {
1279
1282
errors : Diagnostic [ ]
1280
1283
) {
1281
1284
if ( opt . isTSConfigOnly ) {
1282
- errors . push ( createCompilerDiagnostic ( Diagnostics . Option_0_can_only_be_specified_in_tsconfig_json_file , opt . name ) ) ;
1285
+ const optValue = args [ i ] ;
1286
+ if ( optValue === "null" ) {
1287
+ options [ opt . name ] = undefined ;
1288
+ i ++ ;
1289
+ }
1290
+ else if ( opt . type === "boolean" ) {
1291
+ if ( optValue === "false" ) {
1292
+ options [ opt . name ] = false ;
1293
+ i ++ ;
1294
+ }
1295
+ else {
1296
+ if ( optValue === "true" ) i ++ ;
1297
+ errors . push ( createCompilerDiagnostic ( Diagnostics . Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_false_or_null_on_command_line , opt . name ) ) ;
1298
+ }
1299
+ }
1300
+ else {
1301
+ errors . push ( createCompilerDiagnostic ( Diagnostics . Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_null_on_command_line , opt . name ) ) ;
1302
+ if ( optValue && ! startsWith ( optValue , "-" ) ) i ++ ;
1303
+ }
1283
1304
}
1284
1305
else {
1285
1306
// Check to see if no argument was provided (e.g. "--locale" is the last command-line argument).
1286
1307
if ( ! args [ i ] && opt . type !== "boolean" ) {
1287
1308
errors . push ( createCompilerDiagnostic ( diagnostics . optionTypeMismatchDiagnostic , opt . name , getCompilerOptionValueTypeString ( opt ) ) ) ;
1288
1309
}
1289
1310
1290
- switch ( opt . type ) {
1291
- case "number" :
1292
- options [ opt . name ] = parseInt ( args [ i ] ) ;
1293
- i ++ ;
1294
- break ;
1295
- case "boolean" :
1296
- // boolean flag has optional value true, false, others
1297
- const optValue = args [ i ] ;
1298
- options [ opt . name ] = optValue !== "false" ;
1299
- // consume next argument as boolean flag value
1300
- if ( optValue === "false" || optValue === "true" ) {
1311
+ if ( args [ i ] !== "null" ) {
1312
+ switch ( opt . type ) {
1313
+ case "number" :
1314
+ options [ opt . name ] = parseInt ( args [ i ] ) ;
1301
1315
i ++ ;
1302
- }
1303
- break ;
1304
- case "string" :
1305
- options [ opt . name ] = args [ i ] || "" ;
1306
- i ++ ;
1307
- break ;
1308
- case "list" :
1309
- const result = parseListTypeOption ( opt , args [ i ] , errors ) ;
1310
- options [ opt . name ] = result || [ ] ;
1311
- if ( result ) {
1316
+ break ;
1317
+ case "boolean" :
1318
+ // boolean flag has optional value true, false, others
1319
+ const optValue = args [ i ] ;
1320
+ options [ opt . name ] = optValue !== "false" ;
1321
+ // consume next argument as boolean flag value
1322
+ if ( optValue === "false" || optValue === "true" ) {
1323
+ i ++ ;
1324
+ }
1325
+ break ;
1326
+ case "string" :
1327
+ options [ opt . name ] = args [ i ] || "" ;
1312
1328
i ++ ;
1313
- }
1314
- break ;
1315
- // If not a primitive, the possible types are specified in what is effectively a map of options.
1316
- default :
1317
- options [ opt . name ] = parseCustomTypeOption ( < CommandLineOptionOfCustomType > opt , args [ i ] , errors ) ;
1318
- i ++ ;
1319
- break ;
1329
+ break ;
1330
+ case "list" :
1331
+ const result = parseListTypeOption ( opt , args [ i ] , errors ) ;
1332
+ options [ opt . name ] = result || [ ] ;
1333
+ if ( result ) {
1334
+ i ++ ;
1335
+ }
1336
+ break ;
1337
+ // If not a primitive, the possible types are specified in what is effectively a map of options.
1338
+ default :
1339
+ options [ opt . name ] = parseCustomTypeOption ( < CommandLineOptionOfCustomType > opt , args [ i ] , errors ) ;
1340
+ i ++ ;
1341
+ break ;
1342
+ }
1343
+ }
1344
+ else {
1345
+ options [ opt . name ] = undefined ;
1346
+ i ++ ;
1320
1347
}
1321
1348
}
1322
1349
return i ;
1323
1350
}
1324
1351
1325
- const compilerOptionsDidYouMeanDiagnostics : ParseCommandLineWorkerDiagnostics = {
1352
+ /*@internal */
1353
+ export const compilerOptionsDidYouMeanDiagnostics : ParseCommandLineWorkerDiagnostics = {
1326
1354
getOptionsNameMap,
1327
1355
optionDeclarations,
1328
1356
unknownOptionDiagnostic : Diagnostics . Unknown_compiler_option_0 ,
@@ -2170,7 +2198,7 @@ namespace ts {
2170
2198
}
2171
2199
2172
2200
function convertToOptionValueWithAbsolutePaths ( option : CommandLineOption | undefined , value : CompilerOptionsValue , toAbsolutePath : ( path : string ) => string ) {
2173
- if ( option ) {
2201
+ if ( option && ! isNullOrUndefined ( value ) ) {
2174
2202
if ( option . type === "list" ) {
2175
2203
const values = value as readonly ( string | number ) [ ] ;
2176
2204
if ( option . element . isFilePath && values . length ) {
0 commit comments