Skip to content

Commit 3ade502

Browse files
authored
Fix file matching with tsx and dts of same name are included by include patterns (#55690)
1 parent 3bc4178 commit 3ade502

18 files changed

+1254
-2
lines changed

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3849,7 +3849,10 @@ function hasFileWithHigherPriorityExtension(file: string, literalFiles: Map<stri
38493849
return false;
38503850
}
38513851
for (const ext of extensionGroup) {
3852-
if (fileExtensionIs(file, ext)) {
3852+
// d.ts files match with .ts extension and with case sensitive sorting the file order for same files with ts tsx and dts extension is
3853+
// d.ts, .ts, .tsx in that order so we need to handle tsx and dts of same same name case here and in remove files with same extensions
3854+
// So dont match .d.ts files with .ts extension
3855+
if (fileExtensionIs(file, ext) && (ext !== Extension.Ts || !fileExtensionIs(file, Extension.Dts))) {
38533856
return false;
38543857
}
38553858
const higherPriorityPath = keyMapper(changeExtension(file, ext));

src/testRunner/unittests/config/matchFiles.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ const caseSensitiveOrderingDiffersWithCaseHost = new fakes.ParseConfigHost(
141141
}),
142142
);
143143

144+
const caseInsensitiveHostWithSameFileNamesWithDifferentExtensions = new fakes.ParseConfigHost(
145+
new vfs.FileSystem(/*ignoreCase*/ true, {
146+
cwd: caseInsensitiveBasePath,
147+
files: {
148+
"c:/dev/a.tsx": "",
149+
"c:/dev/a.d.ts": "",
150+
"c:/dev/b.tsx": "",
151+
"c:/dev/b.ts": "",
152+
"c:/dev/c.tsx": "",
153+
"c:/dev/m.ts": "",
154+
"c:/dev/m.d.ts": "",
155+
"c:/dev/n.tsx": "",
156+
"c:/dev/n.ts": "",
157+
"c:/dev/n.d.ts": "",
158+
"c:/dev/o.ts": "",
159+
"c:/dev/x.d.ts": "",
160+
},
161+
}),
162+
);
163+
144164
function baselineMatches(subScenario: string, json: any, host: fakes.ParseConfigHost, basePath: string) {
145165
const jsonText = JSON.stringify(json, undefined, " ");
146166
baselineParseConfig({
@@ -839,6 +859,51 @@ describe("unittests:: config:: matchFiles", () => {
839859
caseInsensitiveBasePath,
840860
);
841861
});
862+
863+
describe("sameNamedDeclarations", () => {
864+
baselineMatches(
865+
"same named declarations with include ts",
866+
{ include: ["*.ts"] },
867+
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
868+
caseInsensitiveBasePath,
869+
);
870+
baselineMatches(
871+
"same named declarations with include ts dts",
872+
{ include: ["*.ts", "*.d.ts"] },
873+
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
874+
caseInsensitiveBasePath,
875+
);
876+
baselineMatches(
877+
"same named declarations with include tsx",
878+
{ include: ["*.tsx"] },
879+
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
880+
caseInsensitiveBasePath,
881+
);
882+
baselineMatches(
883+
"same named declarations with include tsx ts",
884+
{ include: ["*.tsx", "*.ts"] },
885+
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
886+
caseInsensitiveBasePath,
887+
);
888+
baselineMatches(
889+
"same named declarations with include ts tsx",
890+
{ include: ["*.tsx", "*.ts"] },
891+
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
892+
caseInsensitiveBasePath,
893+
);
894+
baselineMatches(
895+
"same named declarations with include tsx dts",
896+
{ include: ["*.tsx", "*.d.ts"] },
897+
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
898+
caseInsensitiveBasePath,
899+
);
900+
baselineMatches(
901+
"same named declarations with include dts tsx",
902+
{ include: ["*.tsx", "*.d.ts"] },
903+
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
904+
caseInsensitiveBasePath,
905+
);
906+
});
842907
});
843908

844909
describe("with files or folders that begin with a .", () => {

src/testRunner/unittests/tsbuild/clean.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import {
2+
noop,
3+
} from "../../_namespaces/ts";
4+
import {
5+
noChangeRun,
26
verifyTsc,
37
} from "../helpers/tsc";
48
import {
59
loadProjectFromFiles,
610
} from "../helpers/vfs";
711

8-
describe("unittests:: tsbuild - clean", () => {
12+
describe("unittests:: tsbuild - clean::", () => {
913
verifyTsc({
1014
scenario: "clean",
1115
subScenario: `file name and output name clashing`,
@@ -19,4 +23,26 @@ describe("unittests:: tsbuild - clean", () => {
1923
}),
2024
}),
2125
});
26+
27+
verifyTsc({
28+
scenario: "clean",
29+
subScenario: "tsx with dts emit",
30+
fs: () =>
31+
loadProjectFromFiles({
32+
"/src/project/src/main.tsx": "export const x = 10;",
33+
"/src/project/tsconfig.json": JSON.stringify({
34+
compilerOptions: { declaration: true },
35+
include: ["src/**/*.tsx", "src/**/*.ts"],
36+
}),
37+
}),
38+
commandLineArgs: ["--b", "src/project", "-v", "--explainFiles"],
39+
edits: [
40+
noChangeRun,
41+
{
42+
caption: "clean build",
43+
edit: noop,
44+
commandLineArgs: ["-b", "/src/project", "--clean"],
45+
},
46+
],
47+
});
2248
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
config:
2+
{
3+
"include": [
4+
"*.tsx",
5+
"*.d.ts"
6+
]
7+
}
8+
Fs::
9+
//// [c:/dev/a.d.ts]
10+
11+
12+
//// [c:/dev/a.tsx]
13+
14+
15+
//// [c:/dev/b.ts]
16+
17+
18+
//// [c:/dev/b.tsx]
19+
20+
21+
//// [c:/dev/c.tsx]
22+
23+
24+
//// [c:/dev/m.d.ts]
25+
26+
27+
//// [c:/dev/m.ts]
28+
29+
30+
//// [c:/dev/n.d.ts]
31+
32+
33+
//// [c:/dev/n.ts]
34+
35+
36+
//// [c:/dev/n.tsx]
37+
38+
39+
//// [c:/dev/o.ts]
40+
41+
42+
//// [c:/dev/x.d.ts]
43+
44+
45+
46+
configFileName:: c:/dev/tsconfig.json
47+
Result
48+
{
49+
"options": {
50+
"configFilePath": "c:/dev/tsconfig.json"
51+
},
52+
"fileNames": [
53+
"c:/dev/a.tsx",
54+
"c:/dev/b.tsx",
55+
"c:/dev/c.tsx",
56+
"c:/dev/n.tsx",
57+
"c:/dev/m.d.ts",
58+
"c:/dev/x.d.ts"
59+
],
60+
"typeAcquisition": {
61+
"enable": false,
62+
"include": [],
63+
"exclude": []
64+
},
65+
"raw": {
66+
"include": [
67+
"*.tsx",
68+
"*.d.ts"
69+
],
70+
"compileOnSave": false
71+
},
72+
"wildcardDirectories": {
73+
"c:/dev": "WatchDirectoryFlags.None"
74+
},
75+
"compileOnSave": false
76+
}
77+
Errors::
78+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
config:
2+
{
3+
"include": [
4+
"*.tsx",
5+
"*.d.ts"
6+
]
7+
}
8+
Fs::
9+
//// [c:/dev/a.d.ts]
10+
11+
12+
//// [c:/dev/a.tsx]
13+
14+
15+
//// [c:/dev/b.ts]
16+
17+
18+
//// [c:/dev/b.tsx]
19+
20+
21+
//// [c:/dev/c.tsx]
22+
23+
24+
//// [c:/dev/m.d.ts]
25+
26+
27+
//// [c:/dev/m.ts]
28+
29+
30+
//// [c:/dev/n.d.ts]
31+
32+
33+
//// [c:/dev/n.ts]
34+
35+
36+
//// [c:/dev/n.tsx]
37+
38+
39+
//// [c:/dev/o.ts]
40+
41+
42+
//// [c:/dev/x.d.ts]
43+
44+
45+
46+
configFileName:: c:/dev/tsconfig.json
47+
Result
48+
{
49+
"options": {
50+
"configFilePath": "c:/dev/tsconfig.json"
51+
},
52+
"fileNames": [
53+
"c:/dev/a.tsx",
54+
"c:/dev/b.tsx",
55+
"c:/dev/c.tsx",
56+
"c:/dev/n.tsx",
57+
"c:/dev/m.d.ts",
58+
"c:/dev/x.d.ts"
59+
],
60+
"typeAcquisition": {
61+
"enable": false,
62+
"include": [],
63+
"exclude": []
64+
},
65+
"raw": {
66+
"include": [
67+
"*.tsx",
68+
"*.d.ts"
69+
]
70+
},
71+
"wildcardDirectories": {
72+
"c:/dev": "WatchDirectoryFlags.None"
73+
},
74+
"compileOnSave": false
75+
}
76+
Errors::
77+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
config:
2+
{
3+
"include": [
4+
"*.ts",
5+
"*.d.ts"
6+
]
7+
}
8+
Fs::
9+
//// [c:/dev/a.d.ts]
10+
11+
12+
//// [c:/dev/a.tsx]
13+
14+
15+
//// [c:/dev/b.ts]
16+
17+
18+
//// [c:/dev/b.tsx]
19+
20+
21+
//// [c:/dev/c.tsx]
22+
23+
24+
//// [c:/dev/m.d.ts]
25+
26+
27+
//// [c:/dev/m.ts]
28+
29+
30+
//// [c:/dev/n.d.ts]
31+
32+
33+
//// [c:/dev/n.ts]
34+
35+
36+
//// [c:/dev/n.tsx]
37+
38+
39+
//// [c:/dev/o.ts]
40+
41+
42+
//// [c:/dev/x.d.ts]
43+
44+
45+
46+
configFileName:: c:/dev/tsconfig.json
47+
Result
48+
{
49+
"options": {
50+
"configFilePath": "c:/dev/tsconfig.json"
51+
},
52+
"fileNames": [
53+
"c:/dev/a.d.ts",
54+
"c:/dev/b.ts",
55+
"c:/dev/m.ts",
56+
"c:/dev/n.ts",
57+
"c:/dev/o.ts",
58+
"c:/dev/x.d.ts"
59+
],
60+
"typeAcquisition": {
61+
"enable": false,
62+
"include": [],
63+
"exclude": []
64+
},
65+
"raw": {
66+
"include": [
67+
"*.ts",
68+
"*.d.ts"
69+
],
70+
"compileOnSave": false
71+
},
72+
"wildcardDirectories": {
73+
"c:/dev": "WatchDirectoryFlags.None"
74+
},
75+
"compileOnSave": false
76+
}
77+
Errors::
78+

0 commit comments

Comments
 (0)