@@ -1156,12 +1156,14 @@ namespace ts {
1156
1156
commandLine : readonly string [ ] ,
1157
1157
readFile ?: ( path : string ) => string | undefined ) {
1158
1158
const options = { } as OptionsBase ;
1159
+ let watchOptions : WatchOptions | undefined ;
1159
1160
const fileNames : string [ ] = [ ] ;
1160
1161
const errors : Diagnostic [ ] = [ ] ;
1161
1162
1162
1163
parseStrings ( commandLine ) ;
1163
1164
return {
1164
1165
options,
1166
+ watchOptions,
1165
1167
fileNames,
1166
1168
errors
1167
1169
} ;
@@ -1178,51 +1180,17 @@ namespace ts {
1178
1180
const inputOptionName = s . slice ( s . charCodeAt ( 1 ) === CharacterCodes . minus ? 2 : 1 ) ;
1179
1181
const opt = getOptionDeclarationFromName ( diagnostics . getOptionNameMap , inputOptionName , /*allowShort*/ true ) ;
1180
1182
if ( opt ) {
1181
- if ( opt . isTSConfigOnly ) {
1182
- errors . push ( createCompilerDiagnostic ( Diagnostics . Option_0_can_only_be_specified_in_tsconfig_json_file , opt . name ) ) ;
1183
+ i = parseOptionValue ( args , i , diagnostics , opt , options , errors ) ;
1184
+ }
1185
+ else {
1186
+ const watchOpt = getOptionDeclarationFromName ( watchOptionsDidYouMeanDiagnostics . getOptionNameMap , inputOptionName , /*allowShort*/ true ) ;
1187
+ if ( watchOpt ) {
1188
+ i = parseOptionValue ( args , i , watchOptionsDidYouMeanDiagnostics , watchOpt , watchOptions || ( watchOptions = { } ) , errors ) ;
1183
1189
}
1184
1190
else {
1185
- // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument).
1186
- if ( ! args [ i ] && opt . type !== "boolean" ) {
1187
- errors . push ( createCompilerDiagnostic ( diagnostics . optionTypeMismatchDiagnostic , opt . name ) ) ;
1188
- }
1189
-
1190
- switch ( opt . type ) {
1191
- case "number" :
1192
- options [ opt . name ] = parseInt ( args [ i ] ) ;
1193
- i ++ ;
1194
- break ;
1195
- case "boolean" :
1196
- // boolean flag has optional value true, false, others
1197
- const optValue = args [ i ] ;
1198
- options [ opt . name ] = optValue !== "false" ;
1199
- // consume next argument as boolean flag value
1200
- if ( optValue === "false" || optValue === "true" ) {
1201
- i ++ ;
1202
- }
1203
- break ;
1204
- case "string" :
1205
- options [ opt . name ] = args [ i ] || "" ;
1206
- i ++ ;
1207
- break ;
1208
- case "list" :
1209
- const result = parseListTypeOption ( opt , args [ i ] , errors ) ;
1210
- options [ opt . name ] = result || [ ] ;
1211
- if ( result ) {
1212
- i ++ ;
1213
- }
1214
- break ;
1215
- // If not a primitive, the possible types are specified in what is effectively a map of options.
1216
- default :
1217
- options [ opt . name ] = parseCustomTypeOption ( < CommandLineOptionOfCustomType > opt , args [ i ] , errors ) ;
1218
- i ++ ;
1219
- break ;
1220
- }
1191
+ errors . push ( createUnknownOptionError ( inputOptionName , diagnostics , createCompilerDiagnostic , s ) ) ;
1221
1192
}
1222
1193
}
1223
- else {
1224
- errors . push ( createUnknownOptionError ( inputOptionName , diagnostics , createCompilerDiagnostic , s ) ) ;
1225
- }
1226
1194
}
1227
1195
else {
1228
1196
fileNames . push ( s ) ;
@@ -1264,6 +1232,58 @@ namespace ts {
1264
1232
}
1265
1233
}
1266
1234
1235
+ function parseOptionValue (
1236
+ args : readonly string [ ] ,
1237
+ i : number ,
1238
+ diagnostics : ParseCommandLineWorkerDiagnostics ,
1239
+ opt : CommandLineOption ,
1240
+ options : OptionsBase ,
1241
+ errors : Diagnostic [ ]
1242
+ ) {
1243
+ if ( opt . isTSConfigOnly ) {
1244
+ errors . push ( createCompilerDiagnostic ( Diagnostics . Option_0_can_only_be_specified_in_tsconfig_json_file , opt . name ) ) ;
1245
+ }
1246
+ else {
1247
+ // Check to see if no argument was provided (e.g. "--locale" is the last command-line argument).
1248
+ if ( ! args [ i ] && opt . type !== "boolean" ) {
1249
+ errors . push ( createCompilerDiagnostic ( diagnostics . optionTypeMismatchDiagnostic , opt . name , getCompilerOptionValueTypeString ( opt ) ) ) ;
1250
+ }
1251
+
1252
+ switch ( opt . type ) {
1253
+ case "number" :
1254
+ options [ opt . name ] = parseInt ( args [ i ] ) ;
1255
+ i ++ ;
1256
+ break ;
1257
+ case "boolean" :
1258
+ // boolean flag has optional value true, false, others
1259
+ const optValue = args [ i ] ;
1260
+ options [ opt . name ] = optValue !== "false" ;
1261
+ // consume next argument as boolean flag value
1262
+ if ( optValue === "false" || optValue === "true" ) {
1263
+ i ++ ;
1264
+ }
1265
+ break ;
1266
+ case "string" :
1267
+ options [ opt . name ] = args [ i ] || "" ;
1268
+ i ++ ;
1269
+ break ;
1270
+ case "list" :
1271
+ const result = parseListTypeOption ( opt , args [ i ] , errors ) ;
1272
+ options [ opt . name ] = result || [ ] ;
1273
+ if ( result ) {
1274
+ i ++ ;
1275
+ }
1276
+ break ;
1277
+ // If not a primitive, the possible types are specified in what is effectively a map of options.
1278
+ default :
1279
+ options [ opt . name ] = parseCustomTypeOption ( < CommandLineOptionOfCustomType > opt , args [ i ] , errors ) ;
1280
+ i ++ ;
1281
+ break ;
1282
+ }
1283
+ }
1284
+ return i ;
1285
+ }
1286
+
1267
1287
const compilerOptionsDidYouMeanDiagnostics : ParseCommandLineWorkerDiagnostics = {
1268
1288
getOptionNameMap,
1269
1289
optionDeclarations,
@@ -1296,6 +1316,7 @@ namespace ts {
1296
1316
/*@internal */
1297
1317
export interface ParsedBuildCommand {
1298
1318
buildOptions : BuildOptions ;
1319
+ watchOptions : WatchOptions | undefined ;
1299
1320
projects : string [ ] ;
1300
1321
errors : Diagnostic [ ] ;
1301
1322
}
@@ -1315,7 +1336,7 @@ namespace ts {
1315
1336
1316
1337
/*@internal */
1317
1338
export function parseBuildCommand ( args : readonly string [ ] ) : ParsedBuildCommand {
1318
- const { options, fileNames : projects , errors } = parseCommandLineWorker (
1339
+ const { options, watchOptions , fileNames : projects , errors } = parseCommandLineWorker (
1319
1340
buildOptionsDidYouMeanDiagnostics ,
1320
1341
args
1321
1342
) ;
@@ -1340,7 +1361,7 @@ namespace ts {
1340
1361
errors . push ( createCompilerDiagnostic ( Diagnostics . Options_0_and_1_cannot_be_combined , "watch" , "dry" ) ) ;
1341
1362
}
1342
1363
1343
- return { buildOptions, projects, errors } ;
1364
+ return { buildOptions, watchOptions , projects, errors } ;
1344
1365
}
1345
1366
1346
1367
/* @internal */
@@ -1374,7 +1395,8 @@ namespace ts {
1374
1395
configFileName : string ,
1375
1396
optionsToExtend : CompilerOptions ,
1376
1397
host : ParseConfigFileHost ,
1377
- extendedConfigCache ?: Map < ExtendedConfigCacheEntry >
1398
+ extendedConfigCache ?: Map < ExtendedConfigCacheEntry > ,
1399
+ watchOptionsToExtend ?: WatchOptions
1378
1400
) : ParsedCommandLine | undefined {
1379
1401
let configFileText : string | undefined ;
1380
1402
try {
@@ -1404,7 +1426,8 @@ namespace ts {
1404
1426
getNormalizedAbsolutePath ( configFileName , cwd ) ,
1405
1427
/*resolutionStack*/ undefined ,
1406
1428
/*extraFileExtension*/ undefined ,
1407
- extendedConfigCache
1429
+ extendedConfigCache ,
1430
+ watchOptionsToExtend
1408
1431
) ;
1409
1432
}
1410
1433
@@ -1460,10 +1483,17 @@ namespace ts {
1460
1483
unknownDidYouMeanDiagnostic : Diagnostics . Unknown_type_acquisition_option_0_Did_you_mean_1 ,
1461
1484
} ;
1462
1485
1463
- const watchOptionsDidYouMeanDiagnostics : DidYouMeanOptionsDiagnostics = {
1486
+
1487
+ let watchOptionNameMapCache : OptionNameMap ;
1488
+ function getWatchOptionNameMap ( ) : OptionNameMap {
1489
+ return watchOptionNameMapCache || ( watchOptionNameMapCache = createOptionNameMap ( optionsForWatch ) ) ;
1490
+ }
1491
+ const watchOptionsDidYouMeanDiagnostics : ParseCommandLineWorkerDiagnostics = {
1492
+ getOptionNameMap : getWatchOptionNameMap ,
1464
1493
optionDeclarations : optionsForWatch ,
1465
1494
unknownOptionDiagnostic : Diagnostics . Unknown_watch_option_0 ,
1466
1495
unknownDidYouMeanDiagnostic : Diagnostics . Unknown_watch_option_0_Did_you_mean_1 ,
1496
+ optionTypeMismatchDiagnostic : Diagnostics . Watch_option_0_requires_a_value_of_type_1
1467
1497
} ;
1468
1498
1469
1499
let _tsconfigRootOptions : TsConfigOnlyOption ;
@@ -1826,7 +1856,7 @@ namespace ts {
1826
1856
)
1827
1857
) ,
1828
1858
f => getRelativePathFromFile ( getNormalizedAbsolutePath ( configFileName , host . getCurrentDirectory ( ) ) , getNormalizedAbsolutePath ( f , host . getCurrentDirectory ( ) ) , getCanonicalFileName )
1829
- ) ; //TODO
1859
+ ) ; // TODO
1830
1860
const optionMap = serializeCompilerOptions ( configParseResult . options , { configFilePath : getNormalizedAbsolutePath ( configFileName , host . getCurrentDirectory ( ) ) , useCaseSensitiveFileNames : host . useCaseSensitiveFileNames } ) ;
1831
1861
const config = {
1832
1862
compilerOptions : {
@@ -2089,8 +2119,8 @@ namespace ts {
2089
2119
* @param basePath A root directory to resolve relative path entries in the config
2090
2120
* file to. e.g. outDir
2091
2121
*/
2092
- export function parseJsonConfigFileContent ( json : any , host : ParseConfigHost , basePath : string , existingOptions ?: CompilerOptions , configFileName ?: string , resolutionStack ?: Path [ ] , extraFileExtensions ?: readonly FileExtensionInfo [ ] , extendedConfigCache ?: Map < ExtendedConfigCacheEntry > ) : ParsedCommandLine {
2093
- return parseJsonConfigFileContentWorker ( json , /*sourceFile*/ undefined , host , basePath , existingOptions , configFileName , resolutionStack , extraFileExtensions , extendedConfigCache ) ;
2122
+ export function parseJsonConfigFileContent ( json : any , host : ParseConfigHost , basePath : string , existingOptions ?: CompilerOptions , configFileName ?: string , resolutionStack ?: Path [ ] , extraFileExtensions ?: readonly FileExtensionInfo [ ] , extendedConfigCache ?: Map < ExtendedConfigCacheEntry > , existingWatchOptions ?: WatchOptions ) : ParsedCommandLine {
2123
+ return parseJsonConfigFileContentWorker ( json , /*sourceFile*/ undefined , host , basePath , existingOptions , existingWatchOptions , configFileName , resolutionStack , extraFileExtensions , extendedConfigCache ) ;
2094
2124
}
2095
2125
2096
2126
/**
@@ -2100,8 +2130,8 @@ namespace ts {
2100
2130
* @param basePath A root directory to resolve relative path entries in the config
2101
2131
* file to. e.g. outDir
2102
2132
*/
2103
- export function parseJsonSourceFileConfigFileContent ( sourceFile : TsConfigSourceFile , host : ParseConfigHost , basePath : string , existingOptions ?: CompilerOptions , configFileName ?: string , resolutionStack ?: Path [ ] , extraFileExtensions ?: readonly FileExtensionInfo [ ] , extendedConfigCache ?: Map < ExtendedConfigCacheEntry > ) : ParsedCommandLine {
2104
- return parseJsonConfigFileContentWorker ( /*json*/ undefined , sourceFile , host , basePath , existingOptions , configFileName , resolutionStack , extraFileExtensions , extendedConfigCache ) ;
2133
+ export function parseJsonSourceFileConfigFileContent ( sourceFile : TsConfigSourceFile , host : ParseConfigHost , basePath : string , existingOptions ?: CompilerOptions , configFileName ?: string , resolutionStack ?: Path [ ] , extraFileExtensions ?: readonly FileExtensionInfo [ ] , extendedConfigCache ?: Map < ExtendedConfigCacheEntry > , existingWatchOptions ?: WatchOptions ) : ParsedCommandLine {
2134
+ return parseJsonConfigFileContentWorker ( /*json*/ undefined , sourceFile , host , basePath , existingOptions , existingWatchOptions , configFileName , resolutionStack , extraFileExtensions , extendedConfigCache ) ;
2105
2135
}
2106
2136
2107
2137
/*@internal */
@@ -2136,24 +2166,29 @@ namespace ts {
2136
2166
host : ParseConfigHost ,
2137
2167
basePath : string ,
2138
2168
existingOptions : CompilerOptions = { } ,
2169
+ existingWatchOptions : WatchOptions | undefined ,
2139
2170
configFileName ?: string ,
2140
2171
resolutionStack : Path [ ] = [ ] ,
2141
2172
extraFileExtensions : readonly FileExtensionInfo [ ] = [ ] ,
2142
2173
extendedConfigCache ?: Map < ExtendedConfigCacheEntry >
2143
- ) : ParsedCommandLine { // TODO -- pass options to extend?
2174
+ ) : ParsedCommandLine {
2144
2175
Debug . assert ( ( json === undefined && sourceFile !== undefined ) || ( json !== undefined && sourceFile === undefined ) ) ;
2145
2176
const errors : Diagnostic [ ] = [ ] ;
2146
2177
2147
2178
const parsedConfig = parseConfig ( json , sourceFile , host , basePath , configFileName , resolutionStack , errors , extendedConfigCache ) ;
2148
2179
const { raw } = parsedConfig ;
2149
2180
const options = extend ( existingOptions , parsedConfig . options || { } ) ;
2181
+ const watchOptions = existingWatchOptions && parsedConfig . watchOptions ?
2182
+ extend ( existingWatchOptions , parsedConfig . watchOptions ) :
2183
+ parsedConfig . watchOptions || existingWatchOptions ;
2184
+
2150
2185
options . configFilePath = configFileName && normalizeSlashes ( configFileName ) ;
2151
2186
setConfigFileInOptions ( options , sourceFile ) ;
2152
2187
let projectReferences : ProjectReference [ ] | undefined ;
2153
2188
const { fileNames, wildcardDirectories, spec } = getFileNames ( ) ;
2154
2189
return {
2155
2190
options,
2156
- watchOptions : parsedConfig . watchOptions ,
2191
+ watchOptions,
2157
2192
fileNames,
2158
2193
projectReferences,
2159
2194
typeAcquisition : parsedConfig . typeAcquisition || getDefaultTypeAcquisition ( ) ,
0 commit comments