@@ -25,6 +25,14 @@ module ts {
25
25
return indentStrings [ 1 ] . length ;
26
26
}
27
27
28
+ export function shouldEmitToOwnFile ( sourceFile : SourceFile , compilerOptions : CompilerOptions ) {
29
+ if ( ! ( sourceFile . flags & NodeFlags . DeclarationFile ) ) {
30
+ if ( ( isExternalModule ( sourceFile ) || ! compilerOptions . out ) && ! fileExtensionIs ( sourceFile . filename , ".js" ) ) {
31
+ return true ;
32
+ }
33
+ }
34
+ }
35
+
28
36
export function emitFiles ( resolver : EmitResolver ) : EmitResult {
29
37
var program = resolver . getProgram ( ) ;
30
38
var compilerHost = program . getCompilerHost ( ) ;
@@ -34,19 +42,11 @@ module ts {
34
42
var newLine = program . getCompilerHost ( ) . getNewLine ( ) ;
35
43
36
44
function getSourceFilePathInNewDir ( newDirPath : string , sourceFile : SourceFile ) {
37
- var sourceFilePath = getNormalizedPathFromPathCompoments ( getNormalizedPathComponents ( sourceFile . filename , compilerHost . getCurrentDirectory ) ) ;
45
+ var sourceFilePath = getNormalizedPathFromPathComponents ( getNormalizedPathComponents ( sourceFile . filename , compilerHost . getCurrentDirectory ) ) ;
38
46
sourceFilePath = sourceFilePath . replace ( program . getCommonSourceDirectory ( ) , "" ) ;
39
47
return combinePaths ( newDirPath , sourceFilePath ) ;
40
48
}
41
49
42
- function shouldEmitToOwnFile ( sourceFile : SourceFile ) {
43
- if ( ! ( sourceFile . flags & NodeFlags . DeclarationFile ) ) {
44
- if ( ( isExternalModule ( sourceFile ) || ! compilerOptions . out ) && ! fileExtensionIs ( sourceFile . filename , ".js" ) ) {
45
- return true ;
46
- }
47
- }
48
- }
49
-
50
50
function getOwnEmitOutputFilePath ( sourceFile : SourceFile , extension : string ) {
51
51
if ( program . getCompilerOptions ( ) . outDir ) {
52
52
var emitOutputFilePathWithoutExtension = getModuleNameFromFilename ( getSourceFilePathInNewDir ( program . getCompilerOptions ( ) . outDir , sourceFile ) ) ;
@@ -3082,7 +3082,7 @@ module ts {
3082
3082
function writeReferencePath ( referencedFile : SourceFile ) {
3083
3083
var declFileName = referencedFile . flags & NodeFlags . DeclarationFile
3084
3084
? referencedFile . filename // Declaration file, use declaration file name
3085
- : shouldEmitToOwnFile ( referencedFile )
3085
+ : shouldEmitToOwnFile ( referencedFile , compilerOptions )
3086
3086
? getOwnEmitOutputFilePath ( referencedFile , ".d.ts" ) // Own output file so get the .d.ts file
3087
3087
: getModuleNameFromFilename ( compilerOptions . out ) + ".d.ts" ; // Global out file
3088
3088
@@ -3170,7 +3170,7 @@ module ts {
3170
3170
}
3171
3171
3172
3172
forEach ( program . getSourceFiles ( ) , sourceFile => {
3173
- if ( shouldEmitToOwnFile ( sourceFile ) ) {
3173
+ if ( shouldEmitToOwnFile ( sourceFile , compilerOptions ) ) {
3174
3174
var jsFilePath = getOwnEmitOutputFilePath ( sourceFile , ".js" ) ;
3175
3175
emitFile ( jsFilePath , sourceFile ) ;
3176
3176
}
0 commit comments