Port #7106 to master

This commit is contained in:
Mohamed Hegazy 2016-02-16 22:01:28 -08:00
parent bde20c4ec7
commit eed65a0334
7 changed files with 31 additions and 26 deletions

View File

@ -389,7 +389,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
return {
emitSkipped,
diagnostics: emitterDiagnostics.getDiagnostics(),
declarationDiagnostics: emitterDiagnostics.getDiagnostics(),
sourceMaps: sourceMapDataList
};

View File

@ -953,13 +953,27 @@ namespace ts {
}
function emitWorker(program: Program, sourceFile: SourceFile, writeFileCallback: WriteFileCallback, cancellationToken: CancellationToken): EmitResult {
let declarationDiagnostics: Diagnostic[] = [];
if (options.noEmit) {
return { declarationDiagnostics, sourceMaps: undefined, emitSkipped: true };
}
// If the noEmitOnError flag is set, then check if we have any errors so far. If so,
// immediately bail out. Note that we pass 'undefined' for 'sourceFile' so that we
// get any preEmit diagnostics, not just the ones
if (options.noEmitOnError) {
const preEmitDiagnostics = getPreEmitDiagnostics(program, /*sourceFile:*/ undefined, cancellationToken);
if (preEmitDiagnostics.length > 0) {
return { diagnostics: preEmitDiagnostics, sourceMaps: undefined, emitSkipped: true };
let diagnostics = program.getOptionsDiagnostics(cancellationToken).concat(
program.getSyntacticDiagnostics(sourceFile, cancellationToken),
program.getGlobalDiagnostics(cancellationToken),
program.getSemanticDiagnostics(sourceFile, cancellationToken));
if (diagnostics.length === 0 && program.getCompilerOptions().declaration) {
declarationDiagnostics = program.getDeclarationDiagnostics(/*sourceFile*/ undefined, cancellationToken);
}
if (diagnostics.length > 0 || declarationDiagnostics.length > 0) {
return { declarationDiagnostics, sourceMaps: undefined, emitSkipped: true };
}
}

View File

@ -590,30 +590,21 @@ namespace ts {
}
}
reportDiagnostics(diagnostics, compilerHost);
// If the user doesn't want us to emit, then we're done at this point.
if (compilerOptions.noEmit) {
return diagnostics.length
? ExitStatus.DiagnosticsPresent_OutputsSkipped
: ExitStatus.Success;
}
// Otherwise, emit and report any errors we ran into.
const emitOutput = program.emit();
reportDiagnostics(emitOutput.diagnostics, compilerHost);
diagnostics = diagnostics.concat(emitOutput.declarationDiagnostics);
// If the emitter didn't emit anything, then pass that value along.
if (emitOutput.emitSkipped) {
reportDiagnostics(sortAndDeduplicateDiagnostics(diagnostics), compilerHost);
if (emitOutput.emitSkipped && diagnostics.length > 0) {
// If the emitter didn't emit anything, then pass that value along.
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
}
// The emitter emitted something, inform the caller if that happened in the presence
// of diagnostics or not.
if (diagnostics.length > 0 || emitOutput.diagnostics.length > 0) {
else if (diagnostics.length > 0) {
// The emitter emitted something, inform the caller if that happened in the presence
// of diagnostics or not.
return ExitStatus.DiagnosticsPresent_OutputsGenerated;
}
return ExitStatus.Success;
}
}

View File

@ -1680,7 +1680,7 @@ namespace ts {
export interface EmitResult {
emitSkipped: boolean;
diagnostics: Diagnostic[];
/* @internal */ declarationDiagnostics: Diagnostic[];
/* @internal */ sourceMaps: SourceMapData[]; // Array of sourceMapData if compiler emitted sourcemaps
}

View File

@ -127,7 +127,7 @@ class ProjectRunner extends RunnerBase {
let errors = ts.getPreEmitDiagnostics(program);
const emitResult = program.emit();
errors = ts.concatenate(errors, emitResult.diagnostics);
errors = ts.concatenate(errors, emitResult.declarationDiagnostics);
const sourceMapData = emitResult.sourceMaps;
// Clean up source map data that will be used in baselining

View File

@ -16,7 +16,7 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
var program = ts.createProgram(fileNames, options);
var emitResult = program.emit();
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
var allDiagnostics = ts.getPreEmitDiagnostics(program);
allDiagnostics.forEach(diagnostic => {
var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
@ -45,7 +45,7 @@ var ts = require("typescript");
function compile(fileNames, options) {
var program = ts.createProgram(fileNames, options);
var emitResult = program.emit();
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
var allDiagnostics = ts.getPreEmitDiagnostics(program);
allDiagnostics.forEach(function (diagnostic) {
var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character;
var message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');

View File

@ -18,7 +18,7 @@ export function compile(fileNames: string[], options: ts.CompilerOptions): void
var program = ts.createProgram(fileNames, options);
var emitResult = program.emit();
var allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
var allDiagnostics = ts.getPreEmitDiagnostics(program);
allDiagnostics.forEach(diagnostic => {
var { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);