@@ -41,20 +41,23 @@ namespace ts {
41
41
export function getOutputPathsFor ( sourceFile : SourceFile | Bundle , host : EmitHost , forceDtsPaths : boolean ) : EmitFileNames {
42
42
const options = host . getCompilerOptions ( ) ;
43
43
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 ;
48
49
const bundleInfoPath = options . references && jsFilePath ? ( removeFileExtension ( jsFilePath ) + infoExtension ) : undefined ;
49
50
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath } ;
50
51
}
51
52
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 ) ;
54
57
// 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
55
58
const isJs = isSourceFileJS ( sourceFile ) ;
56
59
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 ;
58
61
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, bundleInfoPath : undefined } ;
59
62
}
60
63
}
@@ -135,27 +138,33 @@ namespace ts {
135
138
136
139
if ( ! emitSkipped && emittedFilesList ) {
137
140
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
+ }
142
150
}
143
151
if ( declarationFilePath ) {
144
152
emittedFilesList . push ( declarationFilePath ) ;
145
153
}
146
- if ( bundleInfoPath ) {
147
- emittedFilesList . push ( bundleInfoPath ) ;
154
+ if ( declarationMapPath ) {
155
+ emittedFilesList . push ( declarationMapPath ) ;
148
156
}
149
157
}
150
158
}
151
159
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 ) {
156
162
return ;
157
163
}
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 ;
159
168
return ;
160
169
}
161
170
// Transform the source files
0 commit comments