Skip to content

Fix file matching with tsx and dts of same name are included by include patterns #55690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3849,7 +3849,10 @@ function hasFileWithHigherPriorityExtension(file: string, literalFiles: Map<stri
return false;
}
for (const ext of extensionGroup) {
if (fileExtensionIs(file, ext)) {
// 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
// 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
// So dont match .d.ts files with .ts extension
if (fileExtensionIs(file, ext) && (ext !== Extension.Ts || !fileExtensionIs(file, Extension.Dts))) {
return false;
}
const higherPriorityPath = keyMapper(changeExtension(file, ext));
Expand Down
65 changes: 65 additions & 0 deletions src/testRunner/unittests/config/matchFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ const caseSensitiveOrderingDiffersWithCaseHost = new fakes.ParseConfigHost(
}),
);

const caseInsensitiveHostWithSameFileNamesWithDifferentExtensions = new fakes.ParseConfigHost(
new vfs.FileSystem(/*ignoreCase*/ true, {
cwd: caseInsensitiveBasePath,
files: {
"c:/dev/a.tsx": "",
"c:/dev/a.d.ts": "",
"c:/dev/b.tsx": "",
"c:/dev/b.ts": "",
"c:/dev/c.tsx": "",
"c:/dev/m.ts": "",
"c:/dev/m.d.ts": "",
"c:/dev/n.tsx": "",
"c:/dev/n.ts": "",
"c:/dev/n.d.ts": "",
"c:/dev/o.ts": "",
"c:/dev/x.d.ts": "",
},
}),
);

function baselineMatches(subScenario: string, json: any, host: fakes.ParseConfigHost, basePath: string) {
const jsonText = JSON.stringify(json, undefined, " ");
baselineParseConfig({
Expand Down Expand Up @@ -839,6 +859,51 @@ describe("unittests:: config:: matchFiles", () => {
caseInsensitiveBasePath,
);
});

describe("sameNamedDeclarations", () => {
baselineMatches(
"same named declarations with include ts",
{ include: ["*.ts"] },
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
caseInsensitiveBasePath,
);
baselineMatches(
"same named declarations with include ts dts",
{ include: ["*.ts", "*.d.ts"] },
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
caseInsensitiveBasePath,
);
baselineMatches(
"same named declarations with include tsx",
{ include: ["*.tsx"] },
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
caseInsensitiveBasePath,
);
baselineMatches(
"same named declarations with include tsx ts",
{ include: ["*.tsx", "*.ts"] },
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
caseInsensitiveBasePath,
);
baselineMatches(
"same named declarations with include ts tsx",
{ include: ["*.tsx", "*.ts"] },
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
caseInsensitiveBasePath,
);
baselineMatches(
"same named declarations with include tsx dts",
{ include: ["*.tsx", "*.d.ts"] },
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
caseInsensitiveBasePath,
);
baselineMatches(
"same named declarations with include dts tsx",
{ include: ["*.tsx", "*.d.ts"] },
caseInsensitiveHostWithSameFileNamesWithDifferentExtensions,
caseInsensitiveBasePath,
);
});
});

describe("with files or folders that begin with a .", () => {
Expand Down
28 changes: 27 additions & 1 deletion src/testRunner/unittests/tsbuild/clean.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {
noop,
} from "../../_namespaces/ts";
import {
noChangeRun,
verifyTsc,
} from "../helpers/tsc";
import {
loadProjectFromFiles,
} from "../helpers/vfs";

describe("unittests:: tsbuild - clean", () => {
describe("unittests:: tsbuild - clean::", () => {
verifyTsc({
scenario: "clean",
subScenario: `file name and output name clashing`,
Expand All @@ -19,4 +23,26 @@ describe("unittests:: tsbuild - clean", () => {
}),
}),
});

verifyTsc({
scenario: "clean",
subScenario: "tsx with dts emit",
fs: () =>
loadProjectFromFiles({
"/src/project/src/main.tsx": "export const x = 10;",
"/src/project/tsconfig.json": JSON.stringify({
compilerOptions: { declaration: true },
include: ["src/**/*.tsx", "src/**/*.ts"],
}),
}),
commandLineArgs: ["--b", "src/project", "-v", "--explainFiles"],
edits: [
noChangeRun,
{
caption: "clean build",
edit: noop,
commandLineArgs: ["-b", "/src/project", "--clean"],
},
],
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
config:
{
"include": [
"*.tsx",
"*.d.ts"
]
}
Fs::
//// [c:/dev/a.d.ts]


//// [c:/dev/a.tsx]


//// [c:/dev/b.ts]


//// [c:/dev/b.tsx]


//// [c:/dev/c.tsx]


//// [c:/dev/m.d.ts]


//// [c:/dev/m.ts]


//// [c:/dev/n.d.ts]


//// [c:/dev/n.ts]


//// [c:/dev/n.tsx]


//// [c:/dev/o.ts]


//// [c:/dev/x.d.ts]



configFileName:: c:/dev/tsconfig.json
Result
{
"options": {
"configFilePath": "c:/dev/tsconfig.json"
},
"fileNames": [
"c:/dev/a.tsx",
"c:/dev/b.tsx",
"c:/dev/c.tsx",
"c:/dev/n.tsx",
"c:/dev/m.d.ts",
"c:/dev/x.d.ts"
],
"typeAcquisition": {
"enable": false,
"include": [],
"exclude": []
},
"raw": {
"include": [
"*.tsx",
"*.d.ts"
],
"compileOnSave": false
},
"wildcardDirectories": {
"c:/dev": "WatchDirectoryFlags.None"
},
"compileOnSave": false
}
Errors::

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
config:
{
"include": [
"*.tsx",
"*.d.ts"
]
}
Fs::
//// [c:/dev/a.d.ts]


//// [c:/dev/a.tsx]


//// [c:/dev/b.ts]


//// [c:/dev/b.tsx]


//// [c:/dev/c.tsx]


//// [c:/dev/m.d.ts]


//// [c:/dev/m.ts]


//// [c:/dev/n.d.ts]


//// [c:/dev/n.ts]


//// [c:/dev/n.tsx]


//// [c:/dev/o.ts]


//// [c:/dev/x.d.ts]



configFileName:: c:/dev/tsconfig.json
Result
{
"options": {
"configFilePath": "c:/dev/tsconfig.json"
},
"fileNames": [
"c:/dev/a.tsx",
"c:/dev/b.tsx",
"c:/dev/c.tsx",
"c:/dev/n.tsx",
"c:/dev/m.d.ts",
"c:/dev/x.d.ts"
],
"typeAcquisition": {
"enable": false,
"include": [],
"exclude": []
},
"raw": {
"include": [
"*.tsx",
"*.d.ts"
]
},
"wildcardDirectories": {
"c:/dev": "WatchDirectoryFlags.None"
},
"compileOnSave": false
}
Errors::

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
config:
{
"include": [
"*.ts",
"*.d.ts"
]
}
Fs::
//// [c:/dev/a.d.ts]


//// [c:/dev/a.tsx]


//// [c:/dev/b.ts]


//// [c:/dev/b.tsx]


//// [c:/dev/c.tsx]


//// [c:/dev/m.d.ts]


//// [c:/dev/m.ts]


//// [c:/dev/n.d.ts]


//// [c:/dev/n.ts]


//// [c:/dev/n.tsx]


//// [c:/dev/o.ts]


//// [c:/dev/x.d.ts]



configFileName:: c:/dev/tsconfig.json
Result
{
"options": {
"configFilePath": "c:/dev/tsconfig.json"
},
"fileNames": [
"c:/dev/a.d.ts",
"c:/dev/b.ts",
"c:/dev/m.ts",
"c:/dev/n.ts",
"c:/dev/o.ts",
"c:/dev/x.d.ts"
],
"typeAcquisition": {
"enable": false,
"include": [],
"exclude": []
},
"raw": {
"include": [
"*.ts",
"*.d.ts"
],
"compileOnSave": false
},
"wildcardDirectories": {
"c:/dev": "WatchDirectoryFlags.None"
},
"compileOnSave": false
}
Errors::

Loading