Do not emit files if noEmit is specified

Handles #5799
This commit is contained in:
Sheetal Nandi 2015-11-30 12:46:53 -08:00
parent 78ba4b2e9e
commit acedf3c247
4 changed files with 3 additions and 28 deletions

View File

@ -1675,7 +1675,7 @@ namespace ts {
/* @internal */
export function writeDeclarationFile(declarationFilePath: string, sourceFiles: SourceFile[], isBundledEmit: boolean, host: EmitHost, resolver: EmitResolver, emitterDiagnostics: DiagnosticCollection) {
const emitDeclarationResult = emitDeclarations(host, resolver, emitterDiagnostics, declarationFilePath, sourceFiles, isBundledEmit);
const emitSkipped = emitDeclarationResult.reportedDeclarationError || host.isEmitBlocked(declarationFilePath);
const emitSkipped = emitDeclarationResult.reportedDeclarationError || host.isEmitBlocked(declarationFilePath) || host.getCompilerOptions().noEmit;
if (!emitSkipped) {
const declarationOutput = emitDeclarationResult.referencePathsOutput
+ getDeclarationOutput(emitDeclarationResult.synchronousDeclarationOutput, emitDeclarationResult.moduleElementDeclarationEmitInfo);

View File

@ -8221,7 +8221,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
function emitFile({ jsFilePath, sourceMapFilePath, declarationFilePath}: { jsFilePath: string, sourceMapFilePath: string, declarationFilePath: string },
sourceFiles: SourceFile[], isBundledEmit: boolean) {
// Make sure not to write js File and source map file if any of them cannot be written
if (!host.isEmitBlocked(jsFilePath)) {
if (!host.isEmitBlocked(jsFilePath) && !compilerOptions.noEmit) {
emitJavaScript(jsFilePath, sourceMapFilePath, sourceFiles, isBundledEmit);
}
else {

View File

@ -142,7 +142,7 @@ class CompilerBaselineRunner extends RunnerBase {
it("Correct JS output for " + fileName, () => {
if (hasNonDtsFiles && this.emit) {
if (result.files.length === 0 && result.errors.length === 0) {
if (!options.noEmit && result.files.length === 0 && result.errors.length === 0) {
throw new Error("Expected at least one js file to be emitted or at least one error to be created.");
}

View File

@ -1,25 +0,0 @@
//// [a.js]
let C = "sss";
let C = 0; // Error: Cannot redeclare block-scoped variable 'C'.
function f() {
return;
return; // Error: Unreachable code detected.
}
function b() {
"use strict";
var arguments = 0; // Error: Invalid use of 'arguments' in strict mode.
}
//// [a.js]
var C = "sss";
var C = 0; // Error: Cannot redeclare block-scoped variable 'C'.
function f() {
return;
return; // Error: Unreachable code detected.
}
function b() {
"use strict";
var arguments = 0; // Error: Invalid use of 'arguments' in strict mode.
}