Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge

return {
emitSkipped,
diagnostics: emitterDiagnostics.getDiagnostics(),
declarationDiagnostics: emitterDiagnostics.getDiagnostics(),
sourceMaps: sourceMapDataList
};

Expand Down
20 changes: 17 additions & 3 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
const 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 };
}
}

Expand Down
25 changes: 8 additions & 17 deletions src/compiler/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/harness/projectsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/APISample_compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/compiler/APISample_compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down