@@ -543,6 +543,7 @@ namespace ts {
543543 return {
544544 options,
545545 fileNames : getFileNames ( ) ,
546+ typingOptions : getTypingOptions ( ) ,
546547 errors
547548 } ;
548549
@@ -607,6 +608,35 @@ namespace ts {
607608 }
608609 return fileNames ;
609610 }
611+
612+ function getTypingOptions ( ) : TypingOptions {
613+ const options : TypingOptions = getBaseFileName ( configFileName ) === "jsconfig.json"
614+ ? { enableAutoDiscovery : true , include : [ ] , exclude : [ ] }
615+ : { enableAutoDiscovery : false , include : [ ] , exclude : [ ] } ;
616+ const jsonTypingOptions = json [ "typingOptions" ] ;
617+ if ( jsonTypingOptions ) {
618+ for ( const id in jsonTypingOptions ) {
619+ if ( id === "enableAutoDiscovery" ) {
620+ if ( typeof jsonTypingOptions [ id ] === "boolean" ) {
621+ options . enableAutoDiscovery = jsonTypingOptions [ id ] ;
622+ }
623+ else {
624+ errors . push ( createCompilerDiagnostic ( Diagnostics . Unknown_typing_option_0 , id ) ) ;
625+ }
626+ }
627+ else if ( id === "include" ) {
628+ options . include = convertJsonOptionToStringArray ( id , jsonTypingOptions [ id ] , errors ) ;
629+ }
630+ else if ( id === "exclude" ) {
631+ options . exclude = convertJsonOptionToStringArray ( id , jsonTypingOptions [ id ] , errors ) ;
632+ }
633+ else {
634+ errors . push ( createCompilerDiagnostic ( Diagnostics . Unknown_typing_option_0 , id ) ) ;
635+ }
636+ }
637+ }
638+ return options ;
639+ }
610640 }
611641
612642 export function convertCompilerOptionsFromJson ( jsonOptions : any , basePath : string , configFileName ?: string ) : { options : CompilerOptions , errors : Diagnostic [ ] } {
@@ -647,28 +677,7 @@ namespace ts {
647677 break ;
648678 case "object" :
649679 // "object" options with 'isFilePath' = true expected to be string arrays
650- let paths : string [ ] = [ ] ;
651- let invalidOptionType = false ;
652- if ( ! isArray ( value ) ) {
653- invalidOptionType = true ;
654- }
655- else {
656- for ( const element of < any [ ] > value ) {
657- if ( typeof element === "string" ) {
658- paths . push ( normalizePath ( combinePaths ( basePath , element ) ) ) ;
659- }
660- else {
661- invalidOptionType = true ;
662- break ;
663- }
664- }
665- }
666- if ( invalidOptionType ) {
667- errors . push ( createCompilerDiagnostic ( Diagnostics . Option_0_should_have_array_of_strings_as_a_value , opt . name ) ) ;
668- }
669- else {
670- value = paths ;
671- }
680+ value = convertJsonOptionToStringArray ( opt . name , value , errors , ( element ) => normalizePath ( combinePaths ( basePath , element ) ) ) ;
672681 break ;
673682 }
674683 if ( value === "" ) {
@@ -688,4 +697,28 @@ namespace ts {
688697
689698 return { options, errors } ;
690699 }
700+
701+ function convertJsonOptionToStringArray ( optionName : string , optionJson : any , errors : Diagnostic [ ] , func ?: ( element : string ) => string ) : string [ ] {
702+ const items : string [ ] = [ ] ;
703+ let invalidOptionType = false ;
704+ if ( ! isArray ( optionJson ) ) {
705+ invalidOptionType = true ;
706+ }
707+ else {
708+ for ( const element of < any [ ] > optionJson ) {
709+ if ( typeof element === "string" ) {
710+ const item = func ? func ( element ) : element ;
711+ items . push ( item ) ;
712+ }
713+ else {
714+ invalidOptionType = true ;
715+ break ;
716+ }
717+ }
718+ }
719+ if ( invalidOptionType ) {
720+ errors . push ( createCompilerDiagnostic ( Diagnostics . Option_0_should_have_array_of_strings_as_a_value , optionName ) ) ;
721+ }
722+ return items ;
723+ }
691724}
0 commit comments