@@ -1164,11 +1164,13 @@ namespace ts {
11641164 }
11651165 }
11661166
1167- interface OptionsBase {
1167+ /*@internal */
1168+ export interface OptionsBase {
11681169 [ option : string ] : CompilerOptionsValue | TsConfigSourceFile | undefined ;
11691170 }
11701171
1171- interface ParseCommandLineWorkerDiagnostics extends DidYouMeanOptionsDiagnostics {
1172+ /*@internal */
1173+ export interface ParseCommandLineWorkerDiagnostics extends DidYouMeanOptionsDiagnostics {
11721174 getOptionsNameMap : ( ) => OptionsNameMap ;
11731175 optionTypeMismatchDiagnostic : DiagnosticMessage ;
11741176 }
@@ -1189,7 +1191,8 @@ namespace ts {
11891191 createDiagnostics ( diagnostics . unknownOptionDiagnostic , unknownOptionErrorText || unknownOption ) ;
11901192 }
11911193
1192- function parseCommandLineWorker (
1194+ /*@internal */
1195+ export function parseCommandLineWorker (
11931196 diagnostics : ParseCommandLineWorkerDiagnostics ,
11941197 commandLine : readonly string [ ] ,
11951198 readFile ?: ( path : string ) => string | undefined ) {
@@ -1279,50 +1282,75 @@ namespace ts {
12791282 errors : Diagnostic [ ]
12801283 ) {
12811284 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+ }
12831304 }
12841305 else {
12851306 // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument).
12861307 if ( ! args [ i ] && opt . type !== "boolean" ) {
12871308 errors . push ( createCompilerDiagnostic ( diagnostics . optionTypeMismatchDiagnostic , opt . name , getCompilerOptionValueTypeString ( opt ) ) ) ;
12881309 }
12891310
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 ] ) ;
13011315 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 ] || "" ;
13121328 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 ++ ;
13201347 }
13211348 }
13221349 return i ;
13231350 }
13241351
1325- const compilerOptionsDidYouMeanDiagnostics : ParseCommandLineWorkerDiagnostics = {
1352+ /*@internal */
1353+ export const compilerOptionsDidYouMeanDiagnostics : ParseCommandLineWorkerDiagnostics = {
13261354 getOptionsNameMap,
13271355 optionDeclarations,
13281356 unknownOptionDiagnostic : Diagnostics . Unknown_compiler_option_0 ,
@@ -2170,7 +2198,7 @@ namespace ts {
21702198 }
21712199
21722200 function convertToOptionValueWithAbsolutePaths ( option : CommandLineOption | undefined , value : CompilerOptionsValue , toAbsolutePath : ( path : string ) => string ) {
2173- if ( option ) {
2201+ if ( option && ! isNullOrUndefined ( value ) ) {
21742202 if ( option . type === "list" ) {
21752203 const values = value as readonly ( string | number ) [ ] ;
21762204 if ( option . element . isFilePath && values . length ) {
0 commit comments