@@ -531,7 +531,7 @@ namespace ts {
531531 includeSpecs = [ "**/*" ] ;
532532 }
533533
534- return expandFiles ( fileNames , includeSpecs , excludeSpecs , basePath , options , host , errors ) ;
534+ return matchFileNames ( fileNames , includeSpecs , excludeSpecs , basePath , options , host , errors ) ;
535535 }
536536 }
537537
@@ -589,14 +589,14 @@ namespace ts {
589589 * Expands an array of file specifications.
590590 *
591591 * @param fileNames The literal file names to include.
592- * @param includeSpecs The file specifications to expand .
593- * @param excludeSpecs The file specifications to exclude.
592+ * @param include The wildcard file specifications to include .
593+ * @param exclude The wildcard file specifications to exclude.
594594 * @param basePath The base path for any relative file specifications.
595595 * @param options Compiler options.
596596 * @param host The host used to resolve files and directories.
597597 * @param errors An array for diagnostic reporting.
598598 */
599- export function expandFiles ( fileNames : string [ ] , includeSpecs : string [ ] , excludeSpecs : string [ ] , basePath : string , options : CompilerOptions , host : ParseConfigHost , errors ? : Diagnostic [ ] ) : ExpandResult {
599+ function matchFileNames ( fileNames : string [ ] , include : string [ ] , exclude : string [ ] , basePath : string , options : CompilerOptions , host : ParseConfigHost , errors : Diagnostic [ ] ) : ExpandResult {
600600 basePath = normalizePath ( basePath ) ;
601601 basePath = removeTrailingDirectorySeparator ( basePath ) ;
602602
@@ -615,11 +615,19 @@ namespace ts {
615615 // via wildcard, and to handle extension priority.
616616 const wildcardFileMap : Map < string > = { } ;
617617
618+ if ( include ) {
619+ include = validateSpecs ( include , errors , /*allowTrailingRecursion*/ false ) ;
620+ }
621+
622+ if ( exclude ) {
623+ exclude = validateSpecs ( exclude , errors , /*allowTrailingRecursion*/ true ) ;
624+ }
625+
618626 // Wildcard directories (provided as part of a wildcard path) are stored in a
619627 // file map that marks whether it was a regular wildcard match (with a `*` or `?` token),
620628 // or a recursive directory. This information is used by filesystem watchers to monitor for
621629 // new entries in these paths.
622- const wildcardDirectories : Map < WatchDirectoryFlags > = getWildcardDirectories ( includeSpecs , basePath , host . useCaseSensitiveFileNames ) ;
630+ const wildcardDirectories : Map < WatchDirectoryFlags > = getWildcardDirectories ( include , exclude , basePath , host . useCaseSensitiveFileNames ) ;
623631
624632 // Rather than requery this for each file and filespec, we query the supported extensions
625633 // once and store it on the expansion context.
@@ -634,13 +642,8 @@ namespace ts {
634642 }
635643 }
636644
637- if ( includeSpecs ) {
638- includeSpecs = validateSpecs ( includeSpecs , errors , /*allowTrailingRecursion*/ false ) ;
639- if ( excludeSpecs ) {
640- excludeSpecs = validateSpecs ( excludeSpecs , errors , /*allowTrailingRecursion*/ true ) ;
641- }
642-
643- for ( const file of host . readDirectory ( basePath , supportedExtensions , excludeSpecs , includeSpecs ) ) {
645+ if ( include && include . length > 0 ) {
646+ for ( const file of host . readDirectory ( basePath , supportedExtensions , exclude , include ) ) {
644647 // If we have already included a literal or wildcard path with a
645648 // higher priority extension, we should skip this file.
646649 //
@@ -677,10 +680,10 @@ namespace ts {
677680 const validSpecs : string [ ] = [ ] ;
678681 for ( const spec of specs ) {
679682 if ( ! allowTrailingRecursion && invalidTrailingRecursionPattern . test ( spec ) ) {
680- errors . push ( createCompilerDiagnostic ( Diagnostics . File_specification_cannot_contain_multiple_recursive_directory_wildcards_Asterisk_Asterisk_Colon_0 , spec ) ) ;
683+ errors . push ( createCompilerDiagnostic ( Diagnostics . File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0 , spec ) ) ;
681684 }
682685 else if ( invalidMultipleRecursionPatterns . test ( spec ) ) {
683- errors . push ( createCompilerDiagnostic ( Diagnostics . File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0 , spec ) ) ;
686+ errors . push ( createCompilerDiagnostic ( Diagnostics . File_specification_cannot_contain_multiple_recursive_directory_wildcards_Asterisk_Asterisk_Colon_0 , spec ) ) ;
684687 }
685688 else {
686689 validSpecs . push ( spec ) ;
@@ -696,7 +699,7 @@ namespace ts {
696699 /**
697700 * Gets directories in a set of include patterns that should be watched for changes.
698701 */
699- function getWildcardDirectories ( includes : string [ ] , path : string , useCaseSensitiveFileNames : boolean ) {
702+ function getWildcardDirectories ( include : string [ ] , exclude : string [ ] , path : string , useCaseSensitiveFileNames : boolean ) {
700703 // We watch a directory recursively if it contains a wildcard anywhere in a directory segment
701704 // of the pattern:
702705 //
@@ -708,11 +711,16 @@ namespace ts {
708711 //
709712 // /a/b/* - Watch /a/b directly to catch any new file
710713 // /a/b/a?z - Watch /a/b directly to catch any new file matching a?z
714+ const excludeRegExp = getRegularExpressionForWildcard ( exclude , path , "exclude" , useCaseSensitiveFileNames ) ;
711715 const wildcardDirectories : Map < WatchDirectoryFlags > = { } ;
712- if ( includes !== undefined ) {
716+ if ( include !== undefined ) {
713717 const recursiveKeys : string [ ] = [ ] ;
714- for ( const include of includes ) {
715- const name = combinePaths ( path , include ) ;
718+ for ( const file of include ) {
719+ const name = combinePaths ( path , file ) ;
720+ if ( excludeRegExp && excludeRegExp . test ( name ) ) {
721+ continue ;
722+ }
723+
716724 const match = wildcardDirectoryPattern . exec ( name ) ;
717725 if ( match ) {
718726 const key = useCaseSensitiveFileNames ? match [ 0 ] : match [ 0 ] . toLowerCase ( ) ;
0 commit comments