Skip to content

Commit

Permalink
Skip writing json file if it is going to overwrite same location
Browse files Browse the repository at this point in the history
Fixes #24715
  • Loading branch information
sheetalkamat committed Oct 11, 2018
1 parent b2bae85 commit f48a4ca
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 28 deletions.
17 changes: 11 additions & 6 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ namespace ts {
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath };
}
else {
const jsFilePath = getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
const sourceMapFilePath = isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options);
const ownOutputFilePath = getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
// If json file emits to the same location skip writing it
const jsFilePath = isJsonSourceFile(sourceFile) &&
comparePaths(sourceFile.fileName, ownOutputFilePath, host.getCurrentDirectory(), !host.useCaseSensitiveFileNames()) === Comparison.EqualTo ?
undefined :
ownOutputFilePath;
const sourceMapFilePath = 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);
const declarationFilePath = ((forceDtsPaths || getEmitDeclarations(options)) && !isJs) ? getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined;
Expand Down Expand Up @@ -134,7 +139,7 @@ namespace ts {
emitDeclarationFileOrBundle(sourceFileOrBundle, declarationFilePath, declarationMapPath);

if (!emitSkipped && emittedFilesList) {
if (!emitOnlyDtsFiles) {
if (!emitOnlyDtsFiles && jsFilePath) {
emittedFilesList.push(jsFilePath);
}
if (sourceMapFilePath) {
Expand All @@ -149,13 +154,13 @@ namespace ts {
}
}

function emitJsFileOrBundle(sourceFileOrBundle: SourceFile | Bundle, jsFilePath: string, sourceMapFilePath: string | undefined, bundleInfoPath: string | undefined) {
function emitJsFileOrBundle(sourceFileOrBundle: SourceFile | Bundle, jsFilePath: string | undefined, sourceMapFilePath: string | undefined, bundleInfoPath: string | undefined) {
// Make sure not to write js file and source map file if any of them cannot be written
if (host.isEmitBlocked(jsFilePath) || compilerOptions.noEmit || compilerOptions.emitDeclarationOnly) {
if ((jsFilePath && host.isEmitBlocked(jsFilePath)) || compilerOptions.noEmit || compilerOptions.emitDeclarationOnly) {
emitSkipped = true;
return;
}
if (emitOnlyDtsFiles) {
if (emitOnlyDtsFiles || !jsFilePath) {
return;
}
// Transform the source files
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ namespace ts {
else {
if (isBundledEmit && contains((node as Bundle).sourceFiles, file)) return; // Omit references to files which are being merged
const paths = getOutputPathsFor(file, host, /*forceDtsPaths*/ true);
declFileName = paths.declarationFilePath || paths.jsFilePath;
declFileName = paths.declarationFilePath || paths.jsFilePath || file.fileName;
}

if (declFileName) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3245,7 +3245,7 @@ namespace ts {
}

export interface EmitFileNames {
jsFilePath: string;
jsFilePath: string | undefined;
sourceMapFilePath: string | undefined;
declarationFilePath: string | undefined;
declarationMapPath: string | undefined;
Expand Down

This file was deleted.

0 comments on commit f48a4ca

Please sign in to comment.