@@ -462,7 +462,7 @@ namespace ts {
462
462
] ;
463
463
464
464
/* @internal */
465
- export let typeAcquisitionDeclarations : CommandLineOption [ ] = [
465
+ export const typeAcquisitionDeclarations : CommandLineOption [ ] = [
466
466
{
467
467
/* @deprecated typingOptions.enableAutoDiscovery
468
468
* Use typeAcquisition.enable instead.
@@ -723,24 +723,24 @@ namespace ts {
723
723
* @param jsonText The text of the config file
724
724
*/
725
725
export function parseConfigFileTextToJson ( fileName : string , jsonText : string ) : { config ?: any ; error ?: Diagnostic } {
726
- const { node , errors } = parseJsonText ( fileName , jsonText ) ;
726
+ const jsonSourceFile = parseJsonText ( fileName , jsonText ) ;
727
727
return {
728
- config : convertToJson ( node , errors ) ,
729
- error : errors . length ? errors [ 0 ] : undefined
728
+ config : convertToJson ( jsonSourceFile , jsonSourceFile . parseDiagnostics ) ,
729
+ error : jsonSourceFile . parseDiagnostics . length ? jsonSourceFile . parseDiagnostics [ 0 ] : undefined
730
730
} ;
731
731
}
732
732
733
733
/**
734
734
* Read tsconfig.json file
735
735
* @param fileName The path to the config file
736
736
*/
737
- export function readConfigFileToJsonNode ( fileName : string , readFile : ( path : string ) => string ) : ParsedNodeResults < JsonNode > {
737
+ export function readConfigFileToJsonSourceFile ( fileName : string , readFile : ( path : string ) => string ) : JsonSourceFile {
738
738
let text = "" ;
739
739
try {
740
740
text = readFile ( fileName ) ;
741
741
}
742
742
catch ( e ) {
743
- return { errors : [ createCompilerDiagnostic ( Diagnostics . Cannot_read_file_0_Colon_1 , fileName , e . message ) ] } ;
743
+ return < JsonSourceFile > { parseDiagnostics : [ createCompilerDiagnostic ( Diagnostics . Cannot_read_file_0_Colon_1 , fileName , e . message ) ] } ;
744
744
}
745
745
return parseJsonText ( fileName , text ) ;
746
746
}
@@ -819,26 +819,24 @@ namespace ts {
819
819
* @param jsonNode
820
820
* @param errors
821
821
*/
822
- export function convertToJson ( jsonNode : JsonNode , errors : Diagnostic [ ] ) : any {
823
- return convertToJsonWorker ( jsonNode , errors ) ;
822
+ export function convertToJson ( sourceFile : JsonSourceFile , errors : Diagnostic [ ] ) : any {
823
+ return convertToJsonWorker ( sourceFile , errors ) ;
824
824
}
825
825
826
826
/**
827
827
* Convert the json syntax tree into the json value
828
828
* @param jsonNode
829
829
* @param errors
830
830
*/
831
- function convertToJsonWorker ( jsonNode : JsonNode , errors : Diagnostic [ ] , knownRootOptions ?: Map < CommandLineOption > , optionsIterator ?: JsonConversionNotifier ) : any {
832
- if ( ! jsonNode ) {
831
+ function convertToJsonWorker ( sourceFile : JsonSourceFile , errors : Diagnostic [ ] , knownRootOptions ?: Map < CommandLineOption > , optionsIterator ?: JsonConversionNotifier ) : any {
832
+ if ( ! sourceFile . jsonObject ) {
833
+ if ( sourceFile . endOfFileToken ) {
834
+ return { } ;
835
+ }
833
836
return undefined ;
834
837
}
835
838
836
- if ( jsonNode . kind === SyntaxKind . EndOfFileToken ) {
837
- return { } ;
838
- }
839
-
840
- const sourceFile = < SourceFile > jsonNode . parent ;
841
- return convertObjectLiteralExpressionToJson ( jsonNode , knownRootOptions ) ;
839
+ return convertObjectLiteralExpressionToJson ( sourceFile . jsonObject , knownRootOptions ) ;
842
840
843
841
function convertObjectLiteralExpressionToJson ( node : ObjectLiteralExpression , options ?: Map < CommandLineOption > , extraKeyDiagnosticMessage ?: DiagnosticMessage , optionsObject ?: string ) : any {
844
842
const result : any = { } ;
@@ -1076,7 +1074,7 @@ namespace ts {
1076
1074
* file to. e.g. outDir
1077
1075
*/
1078
1076
export function parseJsonConfigFileContent ( json : any , host : ParseConfigHost , basePath : string , existingOptions ?: CompilerOptions , configFileName ?: string , resolutionStack ?: Path [ ] ) : ParsedCommandLine {
1079
- return parseJsonConfigFileContentWorker ( json , /*jsonNode */ undefined , host , basePath , existingOptions , configFileName , resolutionStack ) ;
1077
+ return parseJsonConfigFileContentWorker ( json , /*sourceFile */ undefined , host , basePath , existingOptions , configFileName , resolutionStack ) ;
1080
1078
}
1081
1079
1082
1080
/**
@@ -1086,8 +1084,8 @@ namespace ts {
1086
1084
* @param basePath A root directory to resolve relative path entries in the config
1087
1085
* file to. e.g. outDir
1088
1086
*/
1089
- export function parseJsonNodeConfigFileContent ( jsonNode : JsonNode , host : ParseConfigHost , basePath : string , existingOptions ?: CompilerOptions , configFileName ?: string , resolutionStack ?: Path [ ] ) : ParsedCommandLine {
1090
- return parseJsonConfigFileContentWorker ( /*json*/ undefined , jsonNode , host , basePath , existingOptions , configFileName , resolutionStack ) ;
1087
+ export function parseJsonSourceFileConfigFileContent ( sourceFile : JsonSourceFile , host : ParseConfigHost , basePath : string , existingOptions ?: CompilerOptions , configFileName ?: string , resolutionStack ?: Path [ ] ) : ParsedCommandLine {
1088
+ return parseJsonConfigFileContentWorker ( /*json*/ undefined , sourceFile , host , basePath , existingOptions , configFileName , resolutionStack ) ;
1091
1089
}
1092
1090
1093
1091
/**
@@ -1097,8 +1095,8 @@ namespace ts {
1097
1095
* @param basePath A root directory to resolve relative path entries in the config
1098
1096
* file to. e.g. outDir
1099
1097
*/
1100
- function parseJsonConfigFileContentWorker ( json : any , jsonNode : JsonNode , host : ParseConfigHost , basePath : string , existingOptions : CompilerOptions = { } , configFileName ?: string , resolutionStack : Path [ ] = [ ] ) : ParsedCommandLine {
1101
- Debug . assert ( ( json === undefined && jsonNode !== undefined ) || ( json !== undefined && jsonNode === undefined ) ) ;
1098
+ function parseJsonConfigFileContentWorker ( json : any , sourceFile : JsonSourceFile , host : ParseConfigHost , basePath : string , existingOptions : CompilerOptions = { } , configFileName ?: string , resolutionStack : Path [ ] = [ ] ) : ParsedCommandLine {
1099
+ Debug . assert ( ( json === undefined && sourceFile !== undefined ) || ( json !== undefined && sourceFile === undefined ) ) ;
1102
1100
const errors : Diagnostic [ ] = [ ] ;
1103
1101
const getCanonicalFileName = createGetCanonicalFileName ( host . useCaseSensitiveFileNames ) ;
1104
1102
const resolvedPath = toPath ( configFileName || "" , basePath , getCanonicalFileName ) ;
@@ -1107,7 +1105,7 @@ namespace ts {
1107
1105
options : { } ,
1108
1106
fileNames : [ ] ,
1109
1107
typeAcquisition : { } ,
1110
- raw : json || convertToJson ( jsonNode , errors ) ,
1108
+ raw : json || convertToJson ( sourceFile , errors ) ,
1111
1109
errors : errors . concat ( createCompilerDiagnostic ( Diagnostics . Circularity_detected_while_resolving_configuration_Colon_0 , [ ...resolutionStack , resolvedPath ] . join ( " -> " ) ) ) ,
1112
1110
wildcardDirectories : { }
1113
1111
} ;
@@ -1141,7 +1139,7 @@ namespace ts {
1141
1139
switch ( key ) {
1142
1140
case "extends" :
1143
1141
const extendsDiagnostic = getExtendsConfigPath ( < string > value , ( message , arg0 ) =>
1144
- createDiagnosticForNodeInSourceFile ( < SourceFile > jsonNode . parent , node , message , arg0 ) ) ;
1142
+ createDiagnosticForNodeInSourceFile ( sourceFile , node , message , arg0 ) ) ;
1145
1143
if ( ( < Diagnostic > extendsDiagnostic ) . messageText ) {
1146
1144
errors . push ( < Diagnostic > extendsDiagnostic ) ;
1147
1145
hasExtendsError = true ;
@@ -1151,11 +1149,11 @@ namespace ts {
1151
1149
}
1152
1150
return ;
1153
1151
case "excludes" :
1154
- errors . push ( createDiagnosticForNodeInSourceFile ( < SourceFile > jsonNode . parent , propertyName , Diagnostics . Unknown_option_excludes_Did_you_mean_exclude ) ) ;
1152
+ errors . push ( createDiagnosticForNodeInSourceFile ( sourceFile , propertyName , Diagnostics . Unknown_option_excludes_Did_you_mean_exclude ) ) ;
1155
1153
return ;
1156
1154
case "files" :
1157
1155
if ( ( < string [ ] > value ) . length === 0 ) {
1158
- errors . push ( createDiagnosticForNodeInSourceFile ( < SourceFile > jsonNode . parent , node , Diagnostics . The_files_list_in_config_file_0_is_empty , configFileName || "tsconfig.json" ) ) ;
1156
+ errors . push ( createDiagnosticForNodeInSourceFile ( sourceFile , node , Diagnostics . The_files_list_in_config_file_0_is_empty , configFileName || "tsconfig.json" ) ) ;
1159
1157
}
1160
1158
return ;
1161
1159
case "compileOnSave" :
@@ -1164,7 +1162,7 @@ namespace ts {
1164
1162
}
1165
1163
}
1166
1164
} ;
1167
- json = convertToJsonWorker ( jsonNode , errors , getTsconfigRootOptionsMap ( ) , optionsIterator ) ;
1165
+ json = convertToJsonWorker ( sourceFile , errors , getTsconfigRootOptionsMap ( ) , optionsIterator ) ;
1168
1166
if ( ! typeAcquisition ) {
1169
1167
if ( typingOptionstypeAcquisition ) {
1170
1168
typeAcquisition = ( typingOptionstypeAcquisition . enableAutoDiscovery !== undefined ) ?
@@ -1244,16 +1242,16 @@ namespace ts {
1244
1242
extendedConfigPath = `${ extendedConfigPath } .json` as Path ;
1245
1243
}
1246
1244
1247
- const extendedResult = readConfigFileToJsonNode ( extendedConfigPath , path => host . readFile ( path ) ) ;
1248
- if ( extendedResult . errors . length ) {
1249
- errors . push ( ...extendedResult . errors ) ;
1245
+ const extendedResult = readConfigFileToJsonSourceFile ( extendedConfigPath , path => host . readFile ( path ) ) ;
1246
+ if ( extendedResult . parseDiagnostics . length ) {
1247
+ errors . push ( ...extendedResult . parseDiagnostics ) ;
1250
1248
return ;
1251
1249
}
1252
1250
const extendedDirname = getDirectoryPath ( extendedConfigPath ) ;
1253
1251
const relativeDifference = convertToRelativePath ( extendedDirname , basePath , getCanonicalFileName ) ;
1254
1252
const updatePath : ( path : string ) => string = path => isRootedDiskPath ( path ) ? path : combinePaths ( relativeDifference , path ) ;
1255
1253
// Merge configs (copy the resolution stack so it is never reused between branches in potential diamond-problem scenarios)
1256
- const result = parseJsonNodeConfigFileContent ( extendedResult . node , host , extendedDirname , /*existingOptions*/ undefined , getBaseFileName ( extendedConfigPath ) , resolutionStack . concat ( [ resolvedPath ] ) ) ;
1254
+ const result = parseJsonSourceFileConfigFileContent ( extendedResult , host , extendedDirname , /*existingOptions*/ undefined , getBaseFileName ( extendedConfigPath ) , resolutionStack . concat ( [ resolvedPath ] ) ) ;
1257
1255
errors . push ( ...result . errors ) ;
1258
1256
const [ include , exclude , files ] = map ( [ "include" , "exclude" , "files" ] , key => {
1259
1257
if ( ! json [ key ] && result . raw [ key ] ) {
@@ -1313,7 +1311,7 @@ namespace ts {
1313
1311
includeSpecs = [ "**/*" ] ;
1314
1312
}
1315
1313
1316
- const result = matchFileNames ( fileNames , includeSpecs , excludeSpecs , basePath , options , host , errors , jsonNode ) ;
1314
+ const result = matchFileNames ( fileNames , includeSpecs , excludeSpecs , basePath , options , host , errors , sourceFile ) ;
1317
1315
1318
1316
if ( result . fileNames . length === 0 && ! hasProperty ( json , "files" ) && resolutionStack . length === 0 ) {
1319
1317
errors . push (
@@ -1328,7 +1326,7 @@ namespace ts {
1328
1326
}
1329
1327
1330
1328
function createCompilerDiagnosticForJson ( message : DiagnosticMessage , arg0 ?: string , arg1 ?: string ) {
1331
- if ( ! jsonNode ) {
1329
+ if ( ! sourceFile ) {
1332
1330
errors . push ( createCompilerDiagnostic ( message , arg0 , arg1 ) ) ;
1333
1331
}
1334
1332
}
@@ -1548,7 +1546,7 @@ namespace ts {
1548
1546
* @param host The host used to resolve files and directories.
1549
1547
* @param errors An array for diagnostic reporting.
1550
1548
*/
1551
- function matchFileNames ( fileNames : string [ ] , include : string [ ] , exclude : string [ ] , basePath : string , options : CompilerOptions , host : ParseConfigHost , errors : Diagnostic [ ] , jsonNode : JsonNode ) : ExpandResult {
1549
+ function matchFileNames ( fileNames : string [ ] , include : string [ ] , exclude : string [ ] , basePath : string , options : CompilerOptions , host : ParseConfigHost , errors : Diagnostic [ ] , jsonSourceFile : JsonSourceFile ) : ExpandResult {
1552
1550
basePath = normalizePath ( basePath ) ;
1553
1551
1554
1552
// The exclude spec list is converted into a regular expression, which allows us to quickly
@@ -1567,11 +1565,11 @@ namespace ts {
1567
1565
const wildcardFileMap = createMap < string > ( ) ;
1568
1566
1569
1567
if ( include ) {
1570
- include = validateSpecs ( include , errors , /*allowTrailingRecursion*/ false , jsonNode , "include" ) ;
1568
+ include = validateSpecs ( include , errors , /*allowTrailingRecursion*/ false , jsonSourceFile , "include" ) ;
1571
1569
}
1572
1570
1573
1571
if ( exclude ) {
1574
- exclude = validateSpecs ( exclude , errors , /*allowTrailingRecursion*/ true , jsonNode , "exclude" ) ;
1572
+ exclude = validateSpecs ( exclude , errors , /*allowTrailingRecursion*/ true , jsonSourceFile , "exclude" ) ;
1575
1573
}
1576
1574
1577
1575
// Wildcard directories (provided as part of a wildcard path) are stored in a
@@ -1627,7 +1625,7 @@ namespace ts {
1627
1625
} ;
1628
1626
}
1629
1627
1630
- function validateSpecs ( specs : string [ ] , errors : Diagnostic [ ] , allowTrailingRecursion : boolean , jsonNode : JsonNode , specKey : string ) {
1628
+ function validateSpecs ( specs : string [ ] , errors : Diagnostic [ ] , allowTrailingRecursion : boolean , jsonSourceFile : JsonSourceFile , specKey : string ) {
1631
1629
const validSpecs : string [ ] = [ ] ;
1632
1630
for ( const spec of specs ) {
1633
1631
if ( ! allowTrailingRecursion && invalidTrailingRecursionPattern . test ( spec ) ) {
@@ -1647,13 +1645,13 @@ namespace ts {
1647
1645
return validSpecs ;
1648
1646
1649
1647
function createDiagnostic ( message : DiagnosticMessage , spec : string ) : Diagnostic {
1650
- if ( jsonNode && jsonNode . kind === SyntaxKind . ObjectLiteralExpression ) {
1651
- for ( const property of jsonNode . properties ) {
1648
+ if ( jsonSourceFile && jsonSourceFile . jsonObject ) {
1649
+ for ( const property of jsonSourceFile . jsonObject . properties ) {
1652
1650
if ( property . kind === SyntaxKind . PropertyAssignment && getTextOfPropertyName ( property . name ) === specKey ) {
1653
1651
const specsNode = < ArrayLiteralExpression > property . initializer ;
1654
1652
for ( const element of specsNode . elements ) {
1655
1653
if ( element . kind === SyntaxKind . StringLiteral && ( < StringLiteral > element ) . text === spec ) {
1656
- return createDiagnosticForNodeInSourceFile ( < SourceFile > jsonNode . parent , element , message , spec ) ;
1654
+ return createDiagnosticForNodeInSourceFile ( jsonSourceFile , element , message , spec ) ;
1657
1655
}
1658
1656
}
1659
1657
}
0 commit comments