@@ -717,7 +717,7 @@ namespace ts {
717717 export function parseConfigFileTextToJson ( fileName : string , jsonText : string ) : { config ?: any ; error ?: Diagnostic } {
718718 const jsonSourceFile = parseJsonText ( fileName , jsonText ) ;
719719 return {
720- config : convertToJson ( jsonSourceFile , jsonSourceFile . parseDiagnostics ) ,
720+ config : convertToObject ( jsonSourceFile , jsonSourceFile . parseDiagnostics ) ,
721721 error : jsonSourceFile . parseDiagnostics . length ? jsonSourceFile . parseDiagnostics [ 0 ] : undefined
722722 } ;
723723 }
@@ -726,7 +726,7 @@ namespace ts {
726726 * Read tsconfig.json file
727727 * @param fileName The path to the config file
728728 */
729- export function readConfigFileToJsonSourceFile ( fileName : string , readFile : ( path : string ) => string ) : JsonSourceFile {
729+ export function readJsonConfigFile ( fileName : string , readFile : ( path : string ) => string ) : JsonSourceFile {
730730 let text = "" ;
731731 try {
732732 text = readFile ( fileName ) ;
@@ -737,66 +737,64 @@ namespace ts {
737737 return parseJsonText ( fileName , text ) ;
738738 }
739739
740- const tsconfigRootOptions : CommandLineOption [ ] = [
741- {
742- name : "compilerOptions" ,
743- type : "object" ,
744- optionDeclarations : optionDeclarations ,
745- extraKeyDiagnosticMessage : Diagnostics . Unknown_compiler_option_0
746- } ,
747- {
748- name : "typingOptions" ,
749- type : "object" ,
750- optionDeclarations : typeAcquisitionDeclarations ,
751- extraKeyDiagnosticMessage : Diagnostics . Unknown_type_acquisition_option_0
752- } ,
753- {
754- name : "typeAcquisition" ,
755- type : "object" ,
756- optionDeclarations : typeAcquisitionDeclarations ,
757- extraKeyDiagnosticMessage : Diagnostics . Unknown_type_acquisition_option_0
758- } ,
759- {
760- name : "extends" ,
761- type : "string"
762- } ,
763- {
764- name : "files" ,
765- type : "list" ,
766- element : {
767- name : "files" ,
768- type : "string"
769- }
770- } ,
771- {
772- name : "include" ,
773- type : "list" ,
774- element : {
775- name : "include" ,
776- type : "string"
777- }
778- } ,
779- {
780- name : "exclude" ,
781- type : "list" ,
782- element : {
783- name : "exclude" ,
784- type : "string"
785- }
786- } ,
787- compileOnSaveCommandLineOption
788- ] ;
789-
790740 function commandLineOptionsToMap ( options : CommandLineOption [ ] ) {
791741 return arrayToMap ( options , option => option . name ) ;
792742 }
793743
794- let _tsconfigRootOptionsMap : Map < CommandLineOption > ;
744+ let _tsconfigRootOptions : Map < CommandLineOption > ;
795745 function getTsconfigRootOptionsMap ( ) {
796- if ( _tsconfigRootOptionsMap === undefined ) {
797- _tsconfigRootOptionsMap = commandLineOptionsToMap ( tsconfigRootOptions ) ;
746+ if ( _tsconfigRootOptions === undefined ) {
747+ _tsconfigRootOptions = commandLineOptionsToMap ( [
748+ {
749+ name : "compilerOptions" ,
750+ type : "object" ,
751+ optionDeclarations : commandLineOptionsToMap ( optionDeclarations ) ,
752+ extraKeyDiagnosticMessage : Diagnostics . Unknown_compiler_option_0
753+ } ,
754+ {
755+ name : "typingOptions" ,
756+ type : "object" ,
757+ optionDeclarations : commandLineOptionsToMap ( typeAcquisitionDeclarations ) ,
758+ extraKeyDiagnosticMessage : Diagnostics . Unknown_type_acquisition_option_0
759+ } ,
760+ {
761+ name : "typeAcquisition" ,
762+ type : "object" ,
763+ optionDeclarations : commandLineOptionsToMap ( typeAcquisitionDeclarations ) ,
764+ extraKeyDiagnosticMessage : Diagnostics . Unknown_type_acquisition_option_0
765+ } ,
766+ {
767+ name : "extends" ,
768+ type : "string"
769+ } ,
770+ {
771+ name : "files" ,
772+ type : "list" ,
773+ element : {
774+ name : "files" ,
775+ type : "string"
776+ }
777+ } ,
778+ {
779+ name : "include" ,
780+ type : "list" ,
781+ element : {
782+ name : "include" ,
783+ type : "string"
784+ }
785+ } ,
786+ {
787+ name : "exclude" ,
788+ type : "list" ,
789+ element : {
790+ name : "exclude" ,
791+ type : "string"
792+ }
793+ } ,
794+ compileOnSaveCommandLineOption
795+ ] ) ;
798796 }
799- return _tsconfigRootOptionsMap ;
797+ return _tsconfigRootOptions ;
800798 }
801799
802800 interface JsonConversionNotifier {
@@ -811,16 +809,16 @@ namespace ts {
811809 * @param jsonNode
812810 * @param errors
813811 */
814- export function convertToJson ( sourceFile : JsonSourceFile , errors : Diagnostic [ ] ) : any {
815- return convertToJsonWorker ( sourceFile , errors ) ;
812+ export function convertToObject ( sourceFile : JsonSourceFile , errors : Diagnostic [ ] ) : any {
813+ return convertToObjectWorker ( sourceFile , errors ) ;
816814 }
817815
818816 /**
819817 * Convert the json syntax tree into the json value
820818 * @param jsonNode
821819 * @param errors
822820 */
823- function convertToJsonWorker ( sourceFile : JsonSourceFile , errors : Diagnostic [ ] , knownRootOptions ?: Map < CommandLineOption > , optionsIterator ?: JsonConversionNotifier ) : any {
821+ function convertToObjectWorker ( sourceFile : JsonSourceFile , errors : Diagnostic [ ] , knownRootOptions ?: Map < CommandLineOption > , optionsIterator ?: JsonConversionNotifier ) : any {
824822 if ( ! sourceFile . jsonObject ) {
825823 if ( sourceFile . endOfFileToken ) {
826824 return { } ;
@@ -830,7 +828,7 @@ namespace ts {
830828
831829 return convertObjectLiteralExpressionToJson ( sourceFile . jsonObject , knownRootOptions ) ;
832830
833- function convertObjectLiteralExpressionToJson ( node : ObjectLiteralExpression , options ? : Map < CommandLineOption > , extraKeyDiagnosticMessage ?: DiagnosticMessage , optionsObject ?: string ) : any {
831+ function convertObjectLiteralExpressionToJson ( node : ObjectLiteralExpression , knownOptions : Map < CommandLineOption > , extraKeyDiagnosticMessage ?: DiagnosticMessage , optionsObject ?: string ) : any {
834832 const result : any = { } ;
835833 for ( const element of node . properties ) {
836834 if ( element . kind !== SyntaxKind . PropertyAssignment ) {
@@ -846,21 +844,21 @@ namespace ts {
846844 }
847845
848846 const keyText = getTextOfPropertyName ( element . name ) ;
849- const option = options ? options . get ( keyText ) : undefined ;
847+ const option = knownOptions ? knownOptions . get ( keyText ) : undefined ;
850848 if ( extraKeyDiagnosticMessage && ! option ) {
851849 errors . push ( createDiagnosticForNodeInSourceFile ( sourceFile , element . name , extraKeyDiagnosticMessage , keyText ) ) ;
852850 }
853- const value = parseValue ( element . initializer , option ) ;
851+ const value = convertPropertyValueToJson ( element . initializer , option ) ;
854852 if ( typeof keyText !== undefined && typeof value !== undefined ) {
855853 result [ keyText ] = value ;
856854 // Notify key value set, if user asked for it
857855 if ( optionsIterator &&
858- ( optionsObject || options === knownRootOptions ) ) {
856+ ( optionsObject || knownOptions === knownRootOptions ) ) {
859857 const isValidOptionValue = isCompilerOptionsValue ( option , value ) ;
860858 if ( optionsObject && isValidOptionValue ) {
861859 optionsIterator . onSetOptionKeyValue ( optionsObject , option , value ) ;
862860 }
863- if ( options === knownRootOptions && ( isValidOptionValue || ! option ) ) {
861+ if ( knownOptions === knownRootOptions && ( isValidOptionValue || ! option ) ) {
864862 optionsIterator . onRootKeyValue ( keyText , element . name , value , element . initializer ) ;
865863 }
866864 }
@@ -873,12 +871,12 @@ namespace ts {
873871 function convertArrayLiteralExpressionToJson ( elements : NodeArray < Expression > , option ?: CommandLineOption ) : any [ ] {
874872 const result : any [ ] = [ ] ;
875873 for ( const element of elements ) {
876- result . push ( parseValue ( element , option ) ) ;
874+ result . push ( convertPropertyValueToJson ( element , option ) ) ;
877875 }
878876 return result ;
879877 }
880878
881- function parseValue ( node : Expression , option : CommandLineOption ) : any {
879+ function convertPropertyValueToJson ( node : Expression , option : CommandLineOption ) : any {
882880 switch ( node . kind ) {
883881 case SyntaxKind . TrueKeyword :
884882 reportInvalidOptionValue ( option && option . type !== "boolean" ) ;
@@ -919,7 +917,7 @@ namespace ts {
919917 case SyntaxKind . ObjectLiteralExpression :
920918 reportInvalidOptionValue ( option && option . type !== "object" ) ;
921919 const objectOption = < TsConfigOnlyOption > option ;
922- const optionDeclarations = option && objectOption . optionDeclarations ? commandLineOptionsToMap ( objectOption . optionDeclarations ) : undefined ;
920+ const optionDeclarations = option && objectOption . optionDeclarations ;
923921 return convertObjectLiteralExpressionToJson (
924922 < ObjectLiteralExpression > node ,
925923 optionDeclarations ,
@@ -934,10 +932,10 @@ namespace ts {
934932
935933 // Not in expected format
936934 if ( option ) {
937- reportInvalidOptionValue ( ! ! option ) ;
935+ reportInvalidOptionValue ( /*isError*/ true ) ;
938936 }
939937 else {
940- errors . push ( createDiagnosticForNodeInSourceFile ( sourceFile , node , Diagnostics . String_number_object_array_true_false_or_null_expected ) ) ;
938+ errors . push ( createDiagnosticForNodeInSourceFile ( sourceFile , node , Diagnostics . Property_value_can_only_be_string_literal_numeric_literal_true_false_null_object_literal_or_array_literal ) ) ;
941939 }
942940
943941 return undefined ;
@@ -1097,7 +1095,7 @@ namespace ts {
10971095 options : { } ,
10981096 fileNames : [ ] ,
10991097 typeAcquisition : { } ,
1100- raw : json || convertToJson ( sourceFile , errors ) ,
1098+ raw : json || convertToObject ( sourceFile , errors ) ,
11011099 errors : errors . concat ( createCompilerDiagnostic ( Diagnostics . Circularity_detected_while_resolving_configuration_Colon_0 , [ ...resolutionStack , resolvedPath ] . join ( " -> " ) ) ) ,
11021100 wildcardDirectories : { }
11031101 } ;
@@ -1154,7 +1152,7 @@ namespace ts {
11541152 }
11551153 }
11561154 } ;
1157- json = convertToJsonWorker ( sourceFile , errors , getTsconfigRootOptionsMap ( ) , optionsIterator ) ;
1155+ json = convertToObjectWorker ( sourceFile , errors , getTsconfigRootOptionsMap ( ) , optionsIterator ) ;
11581156 if ( ! typeAcquisition ) {
11591157 if ( typingOptionstypeAcquisition ) {
11601158 typeAcquisition = ( typingOptionstypeAcquisition . enableAutoDiscovery !== undefined ) ?
@@ -1235,7 +1233,7 @@ namespace ts {
12351233 extendedConfigPath = `${ extendedConfigPath } .json` as Path ;
12361234 }
12371235
1238- const extendedResult = readConfigFileToJsonSourceFile ( extendedConfigPath , path => host . readFile ( path ) ) ;
1236+ const extendedResult = readJsonConfigFile ( extendedConfigPath , path => host . readFile ( path ) ) ;
12391237 if ( extendedResult . parseDiagnostics . length ) {
12401238 errors . push ( ...extendedResult . parseDiagnostics ) ;
12411239 return ;
0 commit comments