@@ -2012,6 +2012,16 @@ namespace ts {
20122012 return emitOutputFilePathWithoutExtension + extension ;
20132013 }
20142014
2015+ export function getDeclarationEmitOutputFilePath ( sourceFile : SourceFile , host : EmitHost ) {
2016+ const options = host . getCompilerOptions ( ) ;
2017+ const outputDir = options . declarationDir || options . outDir ; // Prefer declaration folder if specified
2018+ return options . declaration ? removeFileExtension (
2019+ outputDir
2020+ ? getSourceFilePathInNewDir ( sourceFile , host , outputDir )
2021+ : sourceFile . fileName
2022+ ) + ".d.ts" : undefined ;
2023+ }
2024+
20152025 export function getEmitScriptTarget ( compilerOptions : CompilerOptions ) {
20162026 return compilerOptions . target || ScriptTarget . ES3 ;
20172027 }
@@ -2065,23 +2075,23 @@ namespace ts {
20652075 const emitFileNames : EmitFileNames = {
20662076 jsFilePath,
20672077 sourceMapFilePath : getSourceMapFilePath ( jsFilePath , options ) ,
2068- declarationFilePath : ! isSourceFileJavaScript ( sourceFile ) ? getDeclarationEmitFilePath ( jsFilePath , options ) : undefined
2078+ declarationFilePath : ! isSourceFileJavaScript ( sourceFile ) ? getDeclarationEmitOutputFilePath ( sourceFile , host ) : undefined
20692079 } ;
20702080 action ( emitFileNames , [ sourceFile ] , /*isBundledEmit*/ false ) ;
20712081 }
20722082
20732083 function onBundledEmit ( host : EmitHost ) {
20742084 // Can emit only sources that are not declaration file and are either non module code or module with --module or --target es6 specified
2075- const bundledSources = filter ( host . getSourceFiles ( ) ,
2076- sourceFile => ! isDeclarationFile ( sourceFile ) && // Not a declaration file
2077- ( ! isExternalModule ( sourceFile ) || // non module file
2078- ( getEmitModuleKind ( options ) && isExternalModule ( sourceFile ) ) ) ) ; // module that can emit - note falsy value from getEmitModuleKind means the module kind that shouldn't be emitted
2085+ const bundledSources = filter ( host . getSourceFiles ( ) , sourceFile =>
2086+ ! isDeclarationFile ( sourceFile ) // Not a declaration file
2087+ && ( ! isExternalModule ( sourceFile ) || ! ! getEmitModuleKind ( options ) ) ) ; // and not a module, unless module emit enabled
2088+
20792089 if ( bundledSources . length ) {
20802090 const jsFilePath = options . outFile || options . out ;
20812091 const emitFileNames : EmitFileNames = {
20822092 jsFilePath,
20832093 sourceMapFilePath : getSourceMapFilePath ( jsFilePath , options ) ,
2084- declarationFilePath : getDeclarationEmitFilePath ( jsFilePath , options )
2094+ declarationFilePath : options . declaration ? removeFileExtension ( jsFilePath ) + ".d.ts" : undefined
20852095 } ;
20862096 action ( emitFileNames , bundledSources , /*isBundledEmit*/ true ) ;
20872097 }
@@ -2090,10 +2100,6 @@ namespace ts {
20902100 function getSourceMapFilePath ( jsFilePath : string , options : CompilerOptions ) {
20912101 return options . sourceMap ? jsFilePath + ".map" : undefined ;
20922102 }
2093-
2094- function getDeclarationEmitFilePath ( jsFilePath : string , options : CompilerOptions ) {
2095- return options . declaration ? removeFileExtension ( jsFilePath ) + ".d.ts" : undefined ;
2096- }
20972103 }
20982104
20992105 export function getSourceFilePathInNewDir ( sourceFile : SourceFile , host : EmitHost , newDirPath : string ) {
0 commit comments