@@ -41,20 +41,23 @@ namespace ts {
4141 export function getOutputPathsFor ( sourceFile : SourceFile | Bundle , host : EmitHost , forceDtsPaths : boolean ) : EmitFileNames {
4242 const options = host . getCompilerOptions ( ) ;
4343 if ( sourceFile . kind === SyntaxKind . Bundle ) {
44- const jsFilePath = options . outFile || options . out ! ;
45- const sourceMapFilePath = getSourceMapFilePath ( jsFilePath , options ) ;
46- const declarationFilePath = ( forceDtsPaths || getEmitDeclarations ( options ) ) ? removeFileExtension ( jsFilePath ) + Extension . Dts : undefined ;
47- const declarationMapPath = getAreDeclarationMapsEnabled ( options ) ? declarationFilePath + ".map" : undefined ;
44+ const outPath = options . outFile || options . out ! ;
45+ const jsFilePath = options . emitDeclarationOnly ? undefined : outPath ;
46+ const sourceMapFilePath = jsFilePath && getSourceMapFilePath ( jsFilePath , options ) ;
47+ const declarationFilePath = ( forceDtsPaths || getEmitDeclarations ( options ) ) ? removeFileExtension ( outPath ) + Extension . Dts : undefined ;
48+ const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled ( options ) ? declarationFilePath + ".map" : undefined ;
4849 const bundleInfoPath = options . references && jsFilePath ? ( removeFileExtension ( jsFilePath ) + infoExtension ) : undefined ;
4950 return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath } ;
5051 }
5152 else {
52- const jsFilePath = getOwnEmitOutputFilePath ( sourceFile . fileName , host , getOutputExtension ( sourceFile , options ) ) ;
53- const sourceMapFilePath = isJsonSourceFile ( sourceFile ) ? undefined : getSourceMapFilePath ( jsFilePath , options ) ;
53+ const ownOutputFilePath = getOwnEmitOutputFilePath ( sourceFile . fileName , host , getOutputExtension ( sourceFile , options ) ) ;
54+ // If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it
55+ const jsFilePath = options . emitDeclarationOnly ? undefined : ownOutputFilePath ;
56+ const sourceMapFilePath = ! jsFilePath || isJsonSourceFile ( sourceFile ) ? undefined : getSourceMapFilePath ( jsFilePath , options ) ;
5457 // 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
5558 const isJs = isSourceFileJS ( sourceFile ) ;
5659 const declarationFilePath = ( ( forceDtsPaths || getEmitDeclarations ( options ) ) && ! isJs ) ? getDeclarationEmitOutputFilePath ( sourceFile . fileName , host ) : undefined ;
57- const declarationMapPath = getAreDeclarationMapsEnabled ( options ) ? declarationFilePath + ".map" : undefined ;
60+ const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled ( options ) ? declarationFilePath + ".map" : undefined ;
5861 return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath : undefined } ;
5962 }
6063 }
@@ -135,27 +138,33 @@ namespace ts {
135138
136139 if ( ! emitSkipped && emittedFilesList ) {
137140 if ( ! emitOnlyDtsFiles ) {
138- emittedFilesList . push ( jsFilePath ) ;
139- }
140- if ( sourceMapFilePath ) {
141- emittedFilesList . push ( sourceMapFilePath ) ;
141+ if ( jsFilePath ) {
142+ emittedFilesList . push ( jsFilePath ) ;
143+ }
144+ if ( sourceMapFilePath ) {
145+ emittedFilesList . push ( sourceMapFilePath ) ;
146+ }
147+ if ( bundleInfoPath ) {
148+ emittedFilesList . push ( bundleInfoPath ) ;
149+ }
142150 }
143151 if ( declarationFilePath ) {
144152 emittedFilesList . push ( declarationFilePath ) ;
145153 }
146- if ( bundleInfoPath ) {
147- emittedFilesList . push ( bundleInfoPath ) ;
154+ if ( declarationMapPath ) {
155+ emittedFilesList . push ( declarationMapPath ) ;
148156 }
149157 }
150158 }
151159
152- function emitJsFileOrBundle ( sourceFileOrBundle : SourceFile | Bundle , jsFilePath : string , sourceMapFilePath : string | undefined , bundleInfoPath : string | undefined ) {
153- // Make sure not to write js file and source map file if any of them cannot be written
154- if ( host . isEmitBlocked ( jsFilePath ) || compilerOptions . noEmit || compilerOptions . emitDeclarationOnly ) {
155- emitSkipped = true ;
160+ function emitJsFileOrBundle ( sourceFileOrBundle : SourceFile | Bundle , jsFilePath : string | undefined , sourceMapFilePath : string | undefined , bundleInfoPath : string | undefined ) {
161+ if ( emitOnlyDtsFiles || ! jsFilePath ) {
156162 return ;
157163 }
158- if ( emitOnlyDtsFiles ) {
164+
165+ // Make sure not to write js file and source map file if any of them cannot be written
166+ if ( ( jsFilePath && host . isEmitBlocked ( jsFilePath ) ) || compilerOptions . noEmit ) {
167+ emitSkipped = true ;
159168 return ;
160169 }
161170 // Transform the source files
0 commit comments