@@ -93,7 +93,6 @@ import {
93
93
filter ,
94
94
find ,
95
95
findIndex ,
96
- firstDefined ,
97
96
firstDefinedIterator ,
98
97
flatMap ,
99
98
flatten ,
@@ -104,7 +103,9 @@ import {
104
103
forEachEmittedFile ,
105
104
forEachEntry ,
106
105
forEachKey ,
106
+ forEachPropertyAssignment ,
107
107
forEachResolvedProjectReference as ts_forEachResolvedProjectReference ,
108
+ forEachTsConfigPropArray ,
108
109
FunctionLikeDeclaration ,
109
110
getAllowJSCompilerOption ,
110
111
getAutomaticTypeDirectiveNames ,
@@ -138,7 +139,6 @@ import {
138
139
getPathFromPathComponents ,
139
140
getPositionOfLineAndCharacter ,
140
141
getPropertyArrayElementValue ,
141
- getPropertyAssignment ,
142
142
getResolvedModule ,
143
143
getResolveJsonModule ,
144
144
getRootLength ,
@@ -152,7 +152,6 @@ import {
152
152
getTransformers ,
153
153
getTsBuildInfoEmitOutputFilePath ,
154
154
getTsConfigObjectLiteralExpression ,
155
- getTsConfigPropArray ,
156
155
getTsConfigPropArrayElementValue ,
157
156
HasChangedAutomaticTypeDirectiveNames ,
158
157
hasChangesInResolutions ,
@@ -263,6 +262,7 @@ import {
263
262
ProjectReference ,
264
263
ProjectReferenceFile ,
265
264
projectReferenceIsEqualTo ,
265
+ PropertyAssignment ,
266
266
PropertyDeclaration ,
267
267
ReferencedFile ,
268
268
removeFileExtension ,
@@ -4535,7 +4535,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
4535
4535
) ;
4536
4536
if ( ! referenceInfo ) return undefined ;
4537
4537
const { sourceFile, index } = referenceInfo ;
4538
- const referencesSyntax = firstDefined ( getTsConfigPropArray ( sourceFile as TsConfigSourceFile , "references" ) ,
4538
+ const referencesSyntax = forEachTsConfigPropArray ( sourceFile as TsConfigSourceFile , "references" ,
4539
4539
property => isArrayLiteralExpression ( property . initializer ) ? property . initializer : undefined ) ;
4540
4540
return referencesSyntax && referencesSyntax . elements . length > index ?
4541
4541
createDiagnosticForNodeInSourceFile (
@@ -4610,52 +4610,47 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
4610
4610
4611
4611
function createDiagnosticForOptionPathKeyValue ( key : string , valueIndex : number , message : DiagnosticMessage , ...args : DiagnosticArguments ) {
4612
4612
let needCompilerDiagnostic = true ;
4613
- const pathsSyntax = getOptionPathsSyntax ( ) ;
4614
- for ( const pathProp of pathsSyntax ) {
4613
+ forEachOptionPathsSyntax ( pathProp => {
4615
4614
if ( isObjectLiteralExpression ( pathProp . initializer ) ) {
4616
- for ( const keyProps of getPropertyAssignment ( pathProp . initializer , key ) ) {
4615
+ forEachPropertyAssignment ( pathProp . initializer , key , keyProps => {
4617
4616
const initializer = keyProps . initializer ;
4618
4617
if ( isArrayLiteralExpression ( initializer ) && initializer . elements . length > valueIndex ) {
4619
4618
programDiagnostics . add ( createDiagnosticForNodeInSourceFile ( options . configFile ! , initializer . elements [ valueIndex ] , message , ...args ) ) ;
4620
4619
needCompilerDiagnostic = false ;
4621
4620
}
4622
- }
4621
+ } ) ;
4623
4622
}
4624
- }
4625
-
4623
+ } ) ;
4626
4624
if ( needCompilerDiagnostic ) {
4627
4625
programDiagnostics . add ( createCompilerDiagnostic ( message , ...args ) ) ;
4628
4626
}
4629
4627
}
4630
4628
4631
4629
function createDiagnosticForOptionPaths ( onKey : boolean , key : string , message : DiagnosticMessage , ...args : DiagnosticArguments ) {
4632
4630
let needCompilerDiagnostic = true ;
4633
- const pathsSyntax = getOptionPathsSyntax ( ) ;
4634
- for ( const pathProp of pathsSyntax ) {
4631
+ forEachOptionPathsSyntax ( pathProp => {
4635
4632
if ( isObjectLiteralExpression ( pathProp . initializer ) &&
4636
4633
createOptionDiagnosticInObjectLiteralSyntax (
4637
4634
pathProp . initializer , onKey , key , /*key2*/ undefined ,
4638
4635
message , ...args ) ) {
4639
4636
needCompilerDiagnostic = false ;
4640
4637
}
4641
- }
4638
+ } ) ;
4642
4639
if ( needCompilerDiagnostic ) {
4643
4640
programDiagnostics . add ( createCompilerDiagnostic ( message , ...args ) ) ;
4644
4641
}
4645
4642
}
4646
4643
4647
- function getOptionsSyntaxByName ( name : string ) {
4648
- const compilerOptionsObjectLiteralSyntax = getCompilerOptionsObjectLiteralSyntax ( ) ;
4649
- return compilerOptionsObjectLiteralSyntax && getPropertyAssignment ( compilerOptionsObjectLiteralSyntax , name ) ;
4644
+ function forEachOptionsSyntaxByName < T > ( name : string , callback : ( prop : PropertyAssignment ) => T | undefined ) : T | undefined {
4645
+ return forEachPropertyAssignment ( getCompilerOptionsObjectLiteralSyntax ( ) , name , callback ) ;
4650
4646
}
4651
4647
4652
- function getOptionPathsSyntax ( ) {
4653
- return getOptionsSyntaxByName ( "paths" ) || emptyArray ;
4648
+ function forEachOptionPathsSyntax < T > ( callback : ( prop : PropertyAssignment ) => T | undefined ) {
4649
+ return forEachOptionsSyntaxByName ( "paths" , callback ) ;
4654
4650
}
4655
4651
4656
4652
function getOptionsSyntaxByValue ( name : string , value : string ) {
4657
- const syntaxByName = getOptionsSyntaxByName ( name ) ;
4658
- return syntaxByName && firstDefined ( syntaxByName , property => isStringLiteral ( property . initializer ) && property . initializer . text === value ? property . initializer : undefined ) ;
4653
+ return forEachOptionsSyntaxByName ( name , property => isStringLiteral ( property . initializer ) && property . initializer . text === value ? property . initializer : undefined ) ;
4659
4654
}
4660
4655
4661
4656
function getOptionsSyntaxByArrayElementValue ( name : string , value : string ) {
@@ -4673,7 +4668,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
4673
4668
}
4674
4669
4675
4670
function createDiagnosticForReference ( sourceFile : JsonSourceFile | undefined , index : number , message : DiagnosticMessage , ...args : DiagnosticArguments ) {
4676
- const referencesSyntax = firstDefined ( getTsConfigPropArray ( sourceFile || options . configFile , "references" ) ,
4671
+ const referencesSyntax = forEachTsConfigPropArray ( sourceFile || options . configFile , "references" ,
4677
4672
property => isArrayLiteralExpression ( property . initializer ) ? property . initializer : undefined ) ;
4678
4673
if ( referencesSyntax && referencesSyntax . elements . length > index ) {
4679
4674
programDiagnostics . add ( createDiagnosticForNodeInSourceFile ( sourceFile || options . configFile ! , referencesSyntax . elements [ index ] , message , ...args ) ) ;
@@ -4703,16 +4698,11 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
4703
4698
4704
4699
function getCompilerOptionsObjectLiteralSyntax ( ) {
4705
4700
if ( _compilerOptionsObjectLiteralSyntax === undefined ) {
4706
- _compilerOptionsObjectLiteralSyntax = false ;
4707
- const jsonObjectLiteral = getTsConfigObjectLiteralExpression ( options . configFile ) ;
4708
- if ( jsonObjectLiteral ) {
4709
- for ( const prop of getPropertyAssignment ( jsonObjectLiteral , "compilerOptions" ) ) {
4710
- if ( isObjectLiteralExpression ( prop . initializer ) ) {
4711
- _compilerOptionsObjectLiteralSyntax = prop . initializer ;
4712
- break ;
4713
- }
4714
- }
4715
- }
4701
+ _compilerOptionsObjectLiteralSyntax = forEachPropertyAssignment (
4702
+ getTsConfigObjectLiteralExpression ( options . configFile ) ,
4703
+ "compilerOptions" ,
4704
+ prop => isObjectLiteralExpression ( prop . initializer ) ? prop . initializer : undefined
4705
+ ) || false ;
4716
4706
}
4717
4707
return _compilerOptionsObjectLiteralSyntax || undefined ;
4718
4708
}
@@ -4721,17 +4711,18 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
4721
4711
function createOptionDiagnosticInObjectLiteralSyntax ( objectLiteral : ObjectLiteralExpression , onKey : boolean , key1 : string , key2 : string | undefined , message : DiagnosticMessage , ...args : DiagnosticArguments ) : boolean ;
4722
4712
function createOptionDiagnosticInObjectLiteralSyntax ( objectLiteral : ObjectLiteralExpression , onKey : boolean , key1 : string , key2 : string | undefined , message : DiagnosticMessage | DiagnosticMessageChain , ...args : DiagnosticArguments ) : boolean ;
4723
4713
function createOptionDiagnosticInObjectLiteralSyntax ( objectLiteral : ObjectLiteralExpression , onKey : boolean , key1 : string , key2 : string | undefined , message : DiagnosticMessage | DiagnosticMessageChain , ...args : DiagnosticArguments ) : boolean {
4724
- const props = getPropertyAssignment ( objectLiteral , key1 , key2 ) ;
4725
- for ( const prop of props ) {
4714
+ let needsCompilerDiagnostic = false ;
4715
+ forEachPropertyAssignment ( objectLiteral , key1 , prop => {
4726
4716
// eslint-disable-next-line local/no-in-operator
4727
4717
if ( "messageText" in message ) {
4728
4718
programDiagnostics . add ( createDiagnosticForNodeFromMessageChain ( options . configFile ! , onKey ? prop . name : prop . initializer , message ) ) ;
4729
4719
}
4730
4720
else {
4731
4721
programDiagnostics . add ( createDiagnosticForNodeInSourceFile ( options . configFile ! , onKey ? prop . name : prop . initializer , message , ...args ) ) ;
4732
4722
}
4733
- }
4734
- return ! ! props . length ;
4723
+ needsCompilerDiagnostic = true ;
4724
+ } , key2 ) ;
4725
+ return needsCompilerDiagnostic ;
4735
4726
}
4736
4727
4737
4728
/**
0 commit comments