Merge pull request #27714 from Microsoft/okToSkipJsonOverrite

Skip writing json file if it is going to overwrite same location
This commit is contained in:
Sheetal Nandi
2018-10-11 15:48:28 -07:00
committed by GitHub
2 changed files with 3 additions and 21 deletions
+3 -1
View File
@@ -52,7 +52,9 @@ namespace ts {
else {
const ownOutputFilePath = getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
// If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it
const jsFilePath = options.emitDeclarationOnly ? undefined : ownOutputFilePath;
const isJsonEmittedToSameLocation = isJsonSourceFile(sourceFile) &&
comparePaths(sourceFile.fileName, ownOutputFilePath, host.getCurrentDirectory(), !host.useCaseSensitiveFileNames()) === Comparison.EqualTo;
const jsFilePath = options.emitDeclarationOnly || isJsonEmittedToSameLocation ? undefined : ownOutputFilePath;
const sourceMapFilePath = !jsFilePath || isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options);
// 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
const isJs = isSourceFileJS(sourceFile);
@@ -1,20 +0,0 @@
error TS5055: Cannot write file 'tests/cases/compiler/b.json' because it would overwrite input file.
Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
!!! error TS5055: Cannot write file 'tests/cases/compiler/b.json' because it would overwrite input file.
!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.
==== tests/cases/compiler/file1.ts (0 errors) ====
import b1 = require('./b.json');
let x = b1.a;
import b2 = require('./b.json');
if (x) {
let b = b2.b;
x = (b1.b === b);
}
==== tests/cases/compiler/b.json (0 errors) ====
{
"a": true,
"b": "hello"
}