Skip to content

Commit 451f92b

Browse files
author
Yui T
committed
Expose function shouldEmitToOwnFile to be called in services.ts
1 parent 2acd98e commit 451f92b

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/compiler/emitter.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ module ts {
2525
return indentStrings[1].length;
2626
}
2727

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+
2836
export function emitFiles(resolver: EmitResolver): EmitResult {
2937
var program = resolver.getProgram();
3038
var compilerHost = program.getCompilerHost();
@@ -34,19 +42,11 @@ module ts {
3442
var newLine = program.getCompilerHost().getNewLine();
3543

3644
function getSourceFilePathInNewDir(newDirPath: string, sourceFile: SourceFile) {
37-
var sourceFilePath = getNormalizedPathFromPathCompoments(getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory));
45+
var sourceFilePath = getNormalizedPathFromPathComponents(getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory));
3846
sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), "");
3947
return combinePaths(newDirPath, sourceFilePath);
4048
}
4149

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-
5050
function getOwnEmitOutputFilePath(sourceFile: SourceFile, extension: string) {
5151
if (program.getCompilerOptions().outDir) {
5252
var emitOutputFilePathWithoutExtension = getModuleNameFromFilename(getSourceFilePathInNewDir(program.getCompilerOptions().outDir, sourceFile));
@@ -3082,7 +3082,7 @@ module ts {
30823082
function writeReferencePath(referencedFile: SourceFile) {
30833083
var declFileName = referencedFile.flags & NodeFlags.DeclarationFile
30843084
? referencedFile.filename // Declaration file, use declaration file name
3085-
: shouldEmitToOwnFile(referencedFile)
3085+
: shouldEmitToOwnFile(referencedFile, compilerOptions)
30863086
? getOwnEmitOutputFilePath(referencedFile, ".d.ts") // Own output file so get the .d.ts file
30873087
: getModuleNameFromFilename(compilerOptions.out) + ".d.ts";// Global out file
30883088

@@ -3170,7 +3170,7 @@ module ts {
31703170
}
31713171

31723172
forEach(program.getSourceFiles(), sourceFile => {
3173-
if (shouldEmitToOwnFile(sourceFile)) {
3173+
if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
31743174
var jsFilePath = getOwnEmitOutputFilePath(sourceFile, ".js");
31753175
emitFile(jsFilePath, sourceFile);
31763176
}

src/services/services.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,8 +2849,10 @@ module ts {
28492849
function getEmitOutput(filename: string): EmitOutput {
28502850
synchronizeHostData();
28512851
filename = TypeScript.switchToForwardSlashes(filename);
2852-
var emitToSingleFile = program.getCompilerOptions().out;
2853-
var emitDeclaration = program.getCompilerOptions().declaration;
2852+
var sourceFile = getSourceFile(filename);
2853+
var compilerOptions = program.getCompilerOptions();
2854+
var emitToSingleFile = ts.shouldEmitToOwnFile(program.getSourceFile(filename), compilerOptions);
2855+
var emitDeclaration = compilerOptions.declaration;
28542856
var emitResult: EmitOutput = {
28552857
outputFiles: [],
28562858
emitOutputResult: undefined,
@@ -2867,7 +2869,7 @@ module ts {
28672869
}
28682870

28692871
var syntacticDiagnostics = emitToSingleFile
2870-
? program.getDiagnostics(getSourceFile(filename).getSourceFile())
2872+
? program.getDiagnostics(sourceFile)
28712873
: program.getDiagnostics();
28722874
program.getGlobalDiagnostics();
28732875

0 commit comments

Comments
 (0)