Skip to content

Commit 2c6501d

Browse files
authored
Allow multiple star-star globs in one pattern (#20639)
* Allow multiple starglobs in one pattern * Add extra test case
1 parent f6603cd commit 2c6501d

File tree

4 files changed

+67
-39
lines changed

4 files changed

+67
-39
lines changed

src/compiler/commandLineParser.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,21 +1906,6 @@ namespace ts {
19061906
*/
19071907
const invalidTrailingRecursionPattern = /(^|\/)\*\*\/?$/;
19081908

1909-
/**
1910-
* Tests for a path with multiple recursive directory wildcards.
1911-
* Matches **\** and **\a\**, but not **\a**b.
1912-
*
1913-
* NOTE: used \ in place of / above to avoid issues with multiline comments.
1914-
*
1915-
* Breakdown:
1916-
* (^|\/) # matches either the beginning of the string or a directory separator.
1917-
* \*\*\/ # matches a recursive directory wildcard "**" followed by a directory separator.
1918-
* (.*\/)? # optionally matches any number of characters followed by a directory separator.
1919-
* \*\* # matches a recursive directory wildcard "**"
1920-
* ($|\/) # matches either the end of the string or a directory separator.
1921-
*/
1922-
const invalidMultipleRecursionPatterns = /(^|\/)\*\*\/(.*\/)?\*\*($|\/)/;
1923-
19241909
/**
19251910
* Tests for a path where .. appears after a recursive directory wildcard.
19261911
* Matches **\..\*, **\a\..\*, and **\.., but not ..\**\*
@@ -2115,9 +2100,6 @@ namespace ts {
21152100
if (!allowTrailingRecursion && invalidTrailingRecursionPattern.test(spec)) {
21162101
return Diagnostics.File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0;
21172102
}
2118-
else if (invalidMultipleRecursionPatterns.test(spec)) {
2119-
return Diagnostics.File_specification_cannot_contain_multiple_recursive_directory_wildcards_Asterisk_Asterisk_Colon_0;
2120-
}
21212103
else if (invalidDotDotAfterRecursiveWildcardPattern.test(spec)) {
21222104
return Diagnostics.File_specification_cannot_contain_a_parent_directory_that_appears_after_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0;
21232105
}

src/compiler/core.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,7 +2376,6 @@ namespace ts {
23762376

23772377
function getSubPatternFromSpec(spec: string, basePath: string, usage: "files" | "directories" | "exclude", { singleAsteriskRegexFragment, doubleAsteriskRegexFragment, replaceWildcardCharacter }: WildcardMatcher): string | undefined {
23782378
let subpattern = "";
2379-
let hasRecursiveDirectoryWildcard = false;
23802379
let hasWrittenComponent = false;
23812380
const components = getNormalizedPathComponents(spec, basePath);
23822381
const lastComponent = lastOrUndefined(components);
@@ -2395,12 +2394,7 @@ namespace ts {
23952394
let optionalCount = 0;
23962395
for (let component of components) {
23972396
if (component === "**") {
2398-
if (hasRecursiveDirectoryWildcard) {
2399-
return undefined;
2400-
}
2401-
24022397
subpattern += doubleAsteriskRegexFragment;
2403-
hasRecursiveDirectoryWildcard = true;
24042398
}
24052399
else {
24062400
if (usage === "directories") {

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,10 +2623,6 @@
26232623
"category": "Error",
26242624
"code": 5010
26252625
},
2626-
"File specification cannot contain multiple recursive directory wildcards ('**'): '{0}'.": {
2627-
"category": "Error",
2628-
"code": 5011
2629-
},
26302626
"Cannot read file '{0}': {1}.": {
26312627
"category": "Error",
26322628
"code": 5012

src/harness/unittests/matchFiles.ts

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace ts {
5050
"/dev/x/b.ts",
5151
"/dev/x/y/a.ts",
5252
"/dev/x/y/b.ts",
53+
"/dev/q/a/c/b/d.ts",
5354
"/dev/js/a.js",
5455
"/dev/js/b.js",
5556
]);
@@ -1171,13 +1172,17 @@ namespace ts {
11711172
};
11721173
const expected: ts.ParsedCommandLine = {
11731174
options: {},
1174-
errors: [
1175-
createDiagnosticForConfigFile(json, 12, 11, ts.Diagnostics.File_specification_cannot_contain_multiple_recursive_directory_wildcards_Asterisk_Asterisk_Colon_0, "**/x/**/*"),
1176-
ts.createCompilerDiagnostic(ts.Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2,
1177-
caseInsensitiveTsconfigPath, JSON.stringify(json.include), "[]")
1175+
errors: [],
1176+
fileNames: [
1177+
"c:/dev/x/a.ts",
1178+
"c:/dev/x/aa.ts",
1179+
"c:/dev/x/b.ts",
1180+
"c:/dev/x/y/a.ts",
1181+
"c:/dev/x/y/b.ts",
11781182
],
1179-
fileNames: [],
1180-
wildcardDirectories: {}
1183+
wildcardDirectories: {
1184+
"c:/dev": ts.WatchDirectoryFlags.Recursive
1185+
}
11811186
};
11821187
validateMatches(expected, json, caseInsensitiveHost, caseInsensitiveBasePath, /*existingOptions*/ undefined, caseInsensitiveTsconfigPath);
11831188
});
@@ -1192,13 +1197,9 @@ namespace ts {
11921197
};
11931198
const expected: ts.ParsedCommandLine = {
11941199
options: {},
1195-
errors: [
1196-
createDiagnosticForConfigFile(json, 34, 9, ts.Diagnostics.File_specification_cannot_contain_multiple_recursive_directory_wildcards_Asterisk_Asterisk_Colon_0, "**/x/**")
1197-
],
1200+
errors: [],
11981201
fileNames: [
11991202
"c:/dev/a.ts",
1200-
"c:/dev/x/a.ts",
1201-
"c:/dev/x/y/a.ts",
12021203
"c:/dev/z/a.ts"
12031204
],
12041205
wildcardDirectories: {
@@ -1426,5 +1427,60 @@ namespace ts {
14261427
});
14271428
});
14281429
});
1430+
1431+
describe("exclude or include patterns which start with **", () => {
1432+
it("can exclude dirs whose pattern starts with **", () => {
1433+
const json = {
1434+
exclude: [
1435+
"**/x"
1436+
]
1437+
};
1438+
const expected: ts.ParsedCommandLine = {
1439+
options: {},
1440+
errors: [],
1441+
fileNames: [
1442+
"/dev/A.ts",
1443+
"/dev/B.ts",
1444+
"/dev/a.ts",
1445+
"/dev/b.ts",
1446+
"/dev/c.d.ts",
1447+
"/dev/q/a/c/b/d.ts",
1448+
"/dev/z/a.ts",
1449+
"/dev/z/aba.ts",
1450+
"/dev/z/abz.ts",
1451+
"/dev/z/b.ts",
1452+
"/dev/z/bba.ts",
1453+
"/dev/z/bbz.ts",
1454+
],
1455+
wildcardDirectories: {
1456+
"/dev": ts.WatchDirectoryFlags.Recursive
1457+
}
1458+
};
1459+
validateMatches(expected, json, caseSensitiveHost, caseSensitiveBasePath);
1460+
});
1461+
it("can include dirs whose pattern starts with **", () => {
1462+
const json = {
1463+
include: [
1464+
"**/x",
1465+
"**/a/**/b"
1466+
]
1467+
};
1468+
const expected: ts.ParsedCommandLine = {
1469+
options: {},
1470+
errors: [],
1471+
fileNames: [
1472+
"/dev/x/a.ts",
1473+
"/dev/x/b.ts",
1474+
"/dev/x/y/a.ts",
1475+
"/dev/x/y/b.ts",
1476+
"/dev/q/a/c/b/d.ts",
1477+
],
1478+
wildcardDirectories: {
1479+
"/dev": ts.WatchDirectoryFlags.Recursive
1480+
}
1481+
};
1482+
validateMatches(expected, json, caseSensitiveHost, caseSensitiveBasePath);
1483+
});
1484+
});
14291485
});
14301486
}

0 commit comments

Comments
 (0)