Merge pull request #840 from Microsoft/getEmitOutputExternalModule

Get emit output external module
This commit is contained in:
Yui
2014-10-07 13:42:49 -07:00
7 changed files with 87 additions and 35 deletions
+14 -8
View File
@@ -3231,21 +3231,27 @@ module ts {
}
if (targetSourceFile === undefined) {
// No targetSourceFile is specified (e.g. calling emitter from batch compiler)
forEach(program.getSourceFiles(), sourceFile => {
if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
var jsFilePath = getOwnEmitOutputFilePath(sourceFile, ".js");
emitFile(jsFilePath, sourceFile);
}
});
}
else {
// Emit only one file specified in targetFilename. This is mainly used in compilerOnSave feature
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js");
emitFile(jsFilePath, targetSourceFile);
}
if (compilerOptions.out) {
emitFile(compilerOptions.out);
if (compilerOptions.out) {
emitFile(compilerOptions.out);
}
} else {
// targetSourceFile is specified (e.g calling emitter from language service)
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
// If shouldEmitToOwnFile is true or targetSourceFile is an external module file, then emit targetSourceFile in its own output file
var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js");
emitFile(jsFilePath, targetSourceFile);
} else {
// If shouldEmitToOwnFile is false, then emit all, non-external-module file, into one single output file
emitFile(compilerOptions.out);
}
}
// Sort and make the unique list of diagnostics
+4 -3
View File
@@ -3882,7 +3882,8 @@ module ts {
filename = TypeScript.switchToForwardSlashes(filename);
var compilerOptions = program.getCompilerOptions();
var targetSourceFile = program.getSourceFile(filename); // Current selected file to be output
var emitToSingleFile = ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions);
// If --out flag is not specified, shouldEmitToOwnFile is true. Otherwise shouldEmitToOwnFile is false.
var shouldEmitToOwnFile = ts.shouldEmitToOwnFile(targetSourceFile, compilerOptions);
var emitDeclaration = compilerOptions.declaration;
var emitOutput: EmitOutput = {
outputFiles: [],
@@ -3903,7 +3904,7 @@ module ts {
var syntacticDiagnostics: Diagnostic[] = [];
var containSyntacticErrors = false;
if (emitToSingleFile) {
if (shouldEmitToOwnFile) {
// Check only the file we want to emit
containSyntacticErrors = containErrors(program.getDiagnostics(targetSourceFile));
} else {
@@ -3930,7 +3931,7 @@ module ts {
// Perform semantic and force a type check before emit to ensure that all symbols are updated
// EmitFiles will report if there is an error from TypeChecker and Emitter
// Depend whether we will have to emit into a single file or not either emit only selected file in the project, emit all files into a single file
var emitFilesResult = emitToSingleFile ? getFullTypeCheckChecker().emitFiles(targetSourceFile) : getFullTypeCheckChecker().emitFiles();
var emitFilesResult = getFullTypeCheckChecker().emitFiles(targetSourceFile);
emitOutput.emitOutputStatus = emitFilesResult.emitResultStatus;
// Reset writer back to undefined to make sure that we produce an error message if CompilerHost.writeFile method is called when we are not in getEmitOutput
@@ -0,0 +1,9 @@
EmitOutputStatus : Succeeded
Filename : declSingleFile.js
var x = 5;
var Bar = (function () {
function Bar() {
}
return Bar;
})();
@@ -0,0 +1,15 @@
EmitOutputStatus : JSGeneratedWithSemanticErrors
Filename : declSingleFile.js
var x = 5;
var Bar = (function () {
function Bar() {
}
return Bar;
})();
var x = "world";
var Bar2 = (function () {
function Bar2() {
}
return Bar2;
})();
@@ -5,28 +5,4 @@ exports.bar = "hello world";
Filename : tests/cases/fourslash/inputFile3.d.ts
export declare var foo: number;
export declare var bar: string;
Filename : declSingleFile.js
var x = 5;
var Bar = (function () {
function Bar() {
}
return Bar;
})();
var x1 = "hello world";
var Foo = (function () {
function Foo() {
}
return Foo;
})();
Filename : declSingleFile.d.ts
declare var x: number;
declare class Bar {
x: string;
y: number;
}
declare var x1: string;
declare class Foo {
x: string;
y: number;
}
@@ -0,0 +1,19 @@
/// <reference path="fourslash.ts" />
// @BaselineFile: getEmitOutputExternalModule.baseline
// @out: declSingleFile.js
// @Filename: inputFile1.ts
// @emitThisFile: true
//// var x: number = 5;
//// class Bar {
//// x : string;
//// y : number
//// }
// @Filename: inputFile2.ts
//// export module M {
//// class C {c}
//// }
verify.baselineGetEmitOutput();
@@ -0,0 +1,26 @@
/// <reference path="fourslash.ts" />
// @BaselineFile: getEmitOutputExternalModule2.baseline
// @out: declSingleFile.js
// @Filename: inputFile1.ts
//// var x: number = 5;
//// class Bar {
//// x : string;
//// y : number
//// }
// @Filename: inputFile2.ts
// @emitThisFile: true
//// var x: string = "world";
//// class Bar2 {
//// x : string;
//// y : number
//// }
// @Filename: inputFile3.ts
//// export module M {
//// class C {c}
//// }
verify.baselineGetEmitOutput();