Skip to content

Commit 574851f

Browse files
committed
More PR feedback
1 parent fd2caf6 commit 574851f

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/compiler/core.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -922,20 +922,22 @@ namespace ts {
922922
const reservedCharacterPattern = /[^\w\s\/]/g;
923923
const wildcardCharCodes = [CharacterCodes.asterisk, CharacterCodes.question];
924924

925+
/**
926+
* Matches any single directory segment unless it is the last segment and a .min.js file
927+
* Breakdown:
928+
* [^./] # matches everything up to the first . character (excluding directory seperators)
929+
* (\\.(?!min\\.js$))? # matches . characters but not if they are part of the .min.js file extension
930+
*/
931+
const singleAsteriskRegexFragmentFiles = "([^./]*(\\.(?!min\\.js$))?)*";
932+
const singleAsteriskRegexFragmentOther = "[^/]*";
933+
925934
export function getRegularExpressionForWildcard(specs: string[], basePath: string, usage: "files" | "directories" | "exclude") {
926935
if (specs === undefined || specs.length === 0) {
927936
return undefined;
928937
}
929938

930-
/**
931-
* Regex for the * wildcard. Matches all characters except for directory seperators. When
932-
* used for including files, also does not match the file extension .min.js
933-
*
934-
* Breakdown for the "files" version:
935-
* [^./] # matches everything up to the first . character (excluding directory seperators)
936-
* (\\.(?!min\\.js$))? # matches . characters but not if they are part of the .min.js file extension
937-
*/
938-
const singleAsteriskRegexFragment = usage === "files" ? "([^./]*(\\.(?!min\\.js$))?)*" : "[^/]*";
939+
const replaceWildcardCharacter = usage === "files" ? replaceWildCardCharacterFiles : replaceWildCardCharacterOther;
940+
const singleAsteriskRegexFragment = usage === "files" ? singleAsteriskRegexFragmentFiles : singleAsteriskRegexFragmentOther;
939941

940942
/**
941943
* Regex for the ** wildcard. Matches any number of subdirectories. When used for including
@@ -997,7 +999,7 @@ namespace ts {
997999
}
9981000
}
9991001

1000-
subpattern += replaceWildcardCharacters(component, singleAsteriskRegexFragment);
1002+
subpattern += component.replace(reservedCharacterPattern, replaceWildcardCharacter);
10011003
hasWrittenComponent = true;
10021004
}
10031005
}
@@ -1022,12 +1024,16 @@ namespace ts {
10221024
return "^(" + pattern + (usage === "exclude" ? ")($|/)" : ")$");
10231025
}
10241026

1025-
function replaceWildcardCharacters(component: string, singleAsteriskRegexFragment: string) {
1026-
return component.replace(reservedCharacterPattern, replaceWildcardCharacter);
1027+
function replaceWildCardCharacterFiles(match: string) {
1028+
return replaceWildcardCharacter(match, singleAsteriskRegexFragmentFiles);
1029+
}
10271030

1028-
function replaceWildcardCharacter(match: string) {
1029-
return match === "*" ? singleAsteriskRegexFragment : match === "?" ? "[^/]" : "\\" + match;
1030-
}
1031+
function replaceWildCardCharacterOther(match: string) {
1032+
return replaceWildcardCharacter(match, singleAsteriskRegexFragmentOther);
1033+
}
1034+
1035+
function replaceWildcardCharacter(match: string, singleAsteriskRegexFragment: string) {
1036+
return match === "*" ? singleAsteriskRegexFragment : match === "?" ? "[^/]" : "\\" + match;
10311037
}
10321038

10331039
export interface FileSystemEntries {

0 commit comments

Comments
 (0)