Skip to content

Commit ca029c7

Browse files
committed
Allow multiple starglobs in one pattern
1 parent d01f4d1 commit ca029c7

5 files changed

Lines changed: 64 additions & 40 deletions

File tree

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
@@ -2374,7 +2374,6 @@ namespace ts {
23742374

23752375
function getSubPatternFromSpec(spec: string, basePath: string, usage: "files" | "directories" | "exclude", { singleAsteriskRegexFragment, doubleAsteriskRegexFragment, replaceWildcardCharacter }: WildcardMatcher): string | undefined {
23762376
let subpattern = "";
2377-
let hasRecursiveDirectoryWildcard = false;
23782377
let hasWrittenComponent = false;
23792378
const components = getNormalizedPathComponents(spec, basePath);
23802379
const lastComponent = lastOrUndefined(components);
@@ -2393,12 +2392,7 @@ namespace ts {
23932392
let optionalCount = 0;
23942393
for (let component of components) {
23952394
if (component === "**") {
2396-
if (hasRecursiveDirectoryWildcard) {
2397-
return undefined;
2398-
}
2399-
24002395
subpattern += doubleAsteriskRegexFragment;
2401-
hasRecursiveDirectoryWildcard = true;
24022396
}
24032397
else {
24042398
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: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,13 +1171,17 @@ namespace ts {
11711171
};
11721172
const expected: ts.ParsedCommandLine = {
11731173
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), "[]")
1174+
errors: [],
1175+
fileNames: [
1176+
"c:/dev/x/a.ts",
1177+
"c:/dev/x/aa.ts",
1178+
"c:/dev/x/b.ts",
1179+
"c:/dev/x/y/a.ts",
1180+
"c:/dev/x/y/b.ts",
11781181
],
1179-
fileNames: [],
1180-
wildcardDirectories: {}
1182+
wildcardDirectories: {
1183+
"c:/dev": ts.WatchDirectoryFlags.Recursive
1184+
}
11811185
};
11821186
validateMatches(expected, json, caseInsensitiveHost, caseInsensitiveBasePath, /*existingOptions*/ undefined, caseInsensitiveTsconfigPath);
11831187
});
@@ -1192,13 +1196,9 @@ namespace ts {
11921196
};
11931197
const expected: ts.ParsedCommandLine = {
11941198
options: {},
1195-
errors: [
1196-
createDiagnosticForConfigFile(json, 34, 9, ts.Diagnostics.File_specification_cannot_contain_multiple_recursive_directory_wildcards_Asterisk_Asterisk_Colon_0, "**/x/**")
1197-
],
1199+
errors: [],
11981200
fileNames: [
11991201
"c:/dev/a.ts",
1200-
"c:/dev/x/a.ts",
1201-
"c:/dev/x/y/a.ts",
12021202
"c:/dev/z/a.ts"
12031203
],
12041204
wildcardDirectories: {
@@ -1426,5 +1426,57 @@ namespace ts {
14261426
});
14271427
});
14281428
});
1429+
1430+
describe("exclude or include patterns which start with **", () => {
1431+
it("can exclude dirs whose pattern starts with **", () => {
1432+
const json = {
1433+
exclude: [
1434+
"**/x"
1435+
]
1436+
};
1437+
const expected: ts.ParsedCommandLine = {
1438+
options: {},
1439+
errors: [],
1440+
fileNames: [
1441+
"/dev/A.ts",
1442+
"/dev/B.ts",
1443+
"/dev/a.ts",
1444+
"/dev/b.ts",
1445+
"/dev/c.d.ts",
1446+
"/dev/z/a.ts",
1447+
"/dev/z/aba.ts",
1448+
"/dev/z/abz.ts",
1449+
"/dev/z/b.ts",
1450+
"/dev/z/bba.ts",
1451+
"/dev/z/bbz.ts",
1452+
],
1453+
wildcardDirectories: {
1454+
"/dev": ts.WatchDirectoryFlags.Recursive
1455+
}
1456+
};
1457+
validateMatches(expected, json, caseSensitiveHost, caseSensitiveBasePath);
1458+
});
1459+
it("can include dirs whose pattern starts with **", () => {
1460+
const json = {
1461+
include: [
1462+
"**/x"
1463+
]
1464+
};
1465+
const expected: ts.ParsedCommandLine = {
1466+
options: {},
1467+
errors: [],
1468+
fileNames: [
1469+
"/dev/x/a.ts",
1470+
"/dev/x/b.ts",
1471+
"/dev/x/y/a.ts",
1472+
"/dev/x/y/b.ts",
1473+
],
1474+
wildcardDirectories: {
1475+
"/dev": ts.WatchDirectoryFlags.Recursive
1476+
}
1477+
};
1478+
validateMatches(expected, json, caseSensitiveHost, caseSensitiveBasePath);
1479+
});
1480+
});
14291481
});
14301482
}

0 commit comments

Comments
 (0)