@@ -2308,10 +2308,26 @@ namespace ts {
2308
2308
} ;
2309
2309
2310
2310
function getFileNames ( ) : ExpandResult {
2311
- const filesSpecs = getSpecs ( "files" ) ?. specs ;
2311
+ const referencesOfRaw = getPropFromRaw < ProjectReference > ( "references" , element => typeof element === "object" , "object" ) ;
2312
+ if ( isArray ( referencesOfRaw ) ) {
2313
+ for ( const ref of referencesOfRaw ) {
2314
+ if ( typeof ref . path !== "string" ) {
2315
+ createCompilerDiagnosticOnlyIfJson ( Diagnostics . Compiler_option_0_requires_a_value_of_type_1 , "reference.path" , "string" ) ;
2316
+ }
2317
+ else {
2318
+ ( projectReferences || ( projectReferences = [ ] ) ) . push ( {
2319
+ path : getNormalizedAbsolutePath ( ref . path , basePath ) ,
2320
+ originalPath : ref . path ,
2321
+ prepend : ref . prepend ,
2322
+ circular : ref . circular
2323
+ } ) ;
2324
+ }
2325
+ }
2326
+ }
2327
+
2328
+ const filesSpecs = toPropValue ( getSpecsFromRaw ( "files" ) ) ;
2312
2329
if ( filesSpecs ) {
2313
- const hasReferences = hasProperty ( raw , "references" ) && ! isNullOrUndefined ( raw . references ) ;
2314
- const hasZeroOrNoReferences = ! hasReferences || raw . references . length === 0 ;
2330
+ const hasZeroOrNoReferences = referencesOfRaw === "no-prop" || isArray ( referencesOfRaw ) && referencesOfRaw . length === 0 ;
2315
2331
const hasExtends = hasProperty ( raw , "extends" ) ;
2316
2332
if ( filesSpecs . length === 0 && hasZeroOrNoReferences && ! hasExtends ) {
2317
2333
if ( sourceFile ) {
@@ -2329,11 +2345,11 @@ namespace ts {
2329
2345
}
2330
2346
}
2331
2347
2332
- let includeSpecs = getSpecs ( "include" ) ?. specs ;
2348
+ let includeSpecs = toPropValue ( getSpecsFromRaw ( "include" ) ) ;
2333
2349
2334
- const excludeSpecResult = getSpecs ( "exclude" ) ;
2335
- let excludeSpecs = excludeSpecResult ?. specs ;
2336
- if ( ! excludeSpecResult && raw . compilerOptions ) {
2350
+ const excludeOfRaw = getSpecsFromRaw ( "exclude" ) ;
2351
+ let excludeSpecs = toPropValue ( excludeOfRaw ) ;
2352
+ if ( excludeOfRaw === "no-prop" && raw . compilerOptions ) {
2337
2353
const outDir = raw . compilerOptions . outDir ;
2338
2354
const declarationDir = raw . compilerOptions . declarationDir ;
2339
2355
@@ -2351,44 +2367,33 @@ namespace ts {
2351
2367
errors . push ( getErrorForNoInputFiles ( result . spec , configFileName ) ) ;
2352
2368
}
2353
2369
2354
- if ( hasProperty ( raw , "references" ) && ! isNullOrUndefined ( raw . references ) ) {
2355
- if ( isArray ( raw . references ) ) {
2356
- for ( const ref of raw . references ) {
2357
- if ( typeof ref . path !== "string" ) {
2358
- createCompilerDiagnosticOnlyIfJson ( Diagnostics . Compiler_option_0_requires_a_value_of_type_1 , "reference.path" , "string" ) ;
2359
- }
2360
- else {
2361
- ( projectReferences || ( projectReferences = [ ] ) ) . push ( {
2362
- path : getNormalizedAbsolutePath ( ref . path , basePath ) ,
2363
- originalPath : ref . path ,
2364
- prepend : ref . prepend ,
2365
- circular : ref . circular
2366
- } ) ;
2367
- }
2368
- }
2369
- }
2370
- else {
2371
- createCompilerDiagnosticOnlyIfJson ( Diagnostics . Compiler_option_0_requires_a_value_of_type_1 , "references" , "Array" ) ;
2372
- }
2373
- }
2374
-
2375
2370
return result ;
2376
2371
}
2377
2372
2378
- function getSpecs ( prop : "files" | "include" | "exclude" ) {
2373
+ type PropOfRaw < T > = readonly T [ ] | "not-array" | "no-prop" ;
2374
+ function toPropValue < T > ( specResult : PropOfRaw < T > ) {
2375
+ return isArray ( specResult ) ? specResult : undefined ;
2376
+ }
2377
+
2378
+ function getSpecsFromRaw ( prop : "files" | "include" | "exclude" ) : PropOfRaw < string > {
2379
+ return getPropFromRaw ( prop , isString , "string" ) ;
2380
+ }
2381
+
2382
+ function getPropFromRaw < T > ( prop : "files" | "include" | "exclude" | "references" , validateElement : ( value : unknown ) => boolean , elementTypeName : string ) : PropOfRaw < T > {
2379
2383
if ( hasProperty ( raw , prop ) && ! isNullOrUndefined ( raw [ prop ] ) ) {
2380
- let specs : readonly string [ ] | undefined ;
2381
2384
if ( isArray ( raw [ prop ] ) ) {
2382
- specs = < readonly string [ ] > raw [ prop ] ;
2383
- if ( ! sourceFile && ! every ( specs , isString ) ) {
2384
- errors . push ( createCompilerDiagnostic ( Diagnostics . Compiler_option_0_requires_a_value_of_type_1 , prop , "string" ) ) ;
2385
+ const result = raw [ prop ] ;
2386
+ if ( ! sourceFile && ! every ( result , validateElement ) ) {
2387
+ errors . push ( createCompilerDiagnostic ( Diagnostics . Compiler_option_0_requires_a_value_of_type_1 , prop , elementTypeName ) ) ;
2385
2388
}
2389
+ return result ;
2386
2390
}
2387
2391
else {
2388
2392
createCompilerDiagnosticOnlyIfJson ( Diagnostics . Compiler_option_0_requires_a_value_of_type_1 , prop , "Array" ) ;
2393
+ return "not-array" ;
2389
2394
}
2390
- return { specs } ;
2391
2395
}
2396
+ return "no-prop" ;
2392
2397
}
2393
2398
2394
2399
function createCompilerDiagnosticOnlyIfJson ( message : DiagnosticMessage , arg0 ?: string , arg1 ?: string ) {
0 commit comments