@@ -911,7 +911,7 @@ namespace ts {
911911 const reservedCharacterPattern = / [ ^ \w \s \/ ] / g;
912912 const wildcardCharCodes = [ CharacterCodes . asterisk , CharacterCodes . question ] ;
913913
914- export function getRegularExpressionForWildcard ( specs : string [ ] , basePath : string , usage : "files" | "directories" | "exclude" , useCaseSensitiveFileNames : boolean ) {
914+ export function getRegularExpressionForWildcard ( specs : string [ ] , basePath : string , usage : "files" | "directories" | "exclude" ) {
915915 if ( specs === undefined || specs . length === 0 ) {
916916 return undefined ;
917917 }
@@ -978,7 +978,7 @@ namespace ts {
978978 return undefined ;
979979 }
980980
981- return new RegExp ( "^(" + pattern + ( usage === "exclude" ? ")($|/)" : ")$" ) , useCaseSensitiveFileNames ? "" : "i ") ;
981+ return "^(" + pattern + ( usage === "exclude" ? ")($|/)" : ")$" ) ;
982982 }
983983
984984 function replaceWildcardCharacter ( match : string ) {
@@ -990,15 +990,39 @@ namespace ts {
990990 directories : string [ ] ;
991991 }
992992
993- export function matchFiles ( path : string , extensions : string [ ] , excludes : string [ ] , includes : string [ ] , useCaseSensitiveFileNames : boolean , currentDirectory : string , getFileSystemEntries : ( path : string ) => FileSystemEntries ) : string [ ] {
993+ interface FileMatcherPatterns {
994+ includeFilePattern : string ;
995+ includeDirectoryPattern : string ;
996+ excludePattern : string ;
997+ basePaths : string [ ] ;
998+ }
999+
1000+ export function getFileMatcherPatterns ( path : string , extensions : string [ ] , excludes : string [ ] , includes : string [ ] , useCaseSensitiveFileNames : boolean , currentDirectory : string ) : FileMatcherPatterns {
9941001 path = normalizePath ( path ) ;
9951002 currentDirectory = normalizePath ( currentDirectory ) ;
9961003 const absolutePath = combinePaths ( currentDirectory , path ) ;
997- const includeFileRegex = getRegularExpressionForWildcard ( includes , absolutePath , "files" , useCaseSensitiveFileNames ) ;
998- const includeDirectoryRegex = getRegularExpressionForWildcard ( includes , absolutePath , "directories" , useCaseSensitiveFileNames ) ;
999- const excludeRegex = getRegularExpressionForWildcard ( excludes , absolutePath , "exclude" , useCaseSensitiveFileNames ) ;
1004+
1005+ return {
1006+ includeFilePattern : getRegularExpressionForWildcard ( includes , absolutePath , "files" ) ,
1007+ includeDirectoryPattern : getRegularExpressionForWildcard ( includes , absolutePath , "directories" ) ,
1008+ excludePattern : getRegularExpressionForWildcard ( excludes , absolutePath , "exclude" ) ,
1009+ basePaths : getBasePaths ( path , includes , useCaseSensitiveFileNames )
1010+ } ;
1011+ }
1012+
1013+ export function matchFiles ( path : string , extensions : string [ ] , excludes : string [ ] , includes : string [ ] , useCaseSensitiveFileNames : boolean , currentDirectory : string , getFileSystemEntries : ( path : string ) => FileSystemEntries ) : string [ ] {
1014+ path = normalizePath ( path ) ;
1015+ currentDirectory = normalizePath ( currentDirectory ) ;
1016+
1017+ const patterns = getFileMatcherPatterns ( path , extensions , excludes , includes , useCaseSensitiveFileNames , currentDirectory ) ;
1018+
1019+ const regexFlag = useCaseSensitiveFileNames ? "" : "i" ;
1020+ const includeFileRegex = patterns . includeFilePattern && new RegExp ( patterns . includeFilePattern , regexFlag ) ;
1021+ const includeDirectoryRegex = patterns . includeDirectoryPattern && new RegExp ( patterns . includeDirectoryPattern , regexFlag ) ;
1022+ const excludeRegex = patterns . excludePattern && new RegExp ( patterns . excludePattern , regexFlag ) ;
1023+
10001024 const result : string [ ] = [ ] ;
1001- for ( const basePath of getBasePaths ( path , includes , useCaseSensitiveFileNames ) ) {
1025+ for ( const basePath of patterns . basePaths ) {
10021026 visitDirectory ( basePath , combinePaths ( currentDirectory , basePath ) ) ;
10031027 }
10041028 return result ;
0 commit comments