Skip to content

Commit 2787a27

Browse files
committed
Skip writing json file if it is going to overwrite same location
Fixes #24715
1 parent 6365eb0 commit 2787a27

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

src/compiler/emitter.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ namespace ts {
5252
else {
5353
const ownOutputFilePath = getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
5454
// If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it
55-
const jsFilePath = options.emitDeclarationOnly ? undefined : ownOutputFilePath;
55+
const isJsonEmittedToSameLocation = isJsonSourceFile(sourceFile) &&
56+
comparePaths(sourceFile.fileName, ownOutputFilePath, host.getCurrentDirectory(), !host.useCaseSensitiveFileNames()) === Comparison.EqualTo;
57+
const jsFilePath = options.emitDeclarationOnly || isJsonEmittedToSameLocation ? undefined : ownOutputFilePath;
5658
const sourceMapFilePath = !jsFilePath || isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options);
5759
// For legacy reasons (ie, we have baselines capturing the behavior), js files don't report a .d.ts output path - this would only matter if `declaration` and `allowJs` were both on, which is currently an error
5860
const isJs = isSourceFileJS(sourceFile);

tests/baselines/reference/requireOfJsonFileWithoutOutDir.errors.txt

-20
This file was deleted.

0 commit comments

Comments
 (0)