mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 12:49:10 +00:00
Compiler exit before emit if preEmitDiagnostics found (#2441)
This commit is contained in:
parent
43c6c1a9f5
commit
60d4522641
2 changed files with 35 additions and 23 deletions
|
@ -379,15 +379,8 @@ window.compilerMain = function compilerMain(): void {
|
||||||
|
|
||||||
const options = host.getCompilationSettings();
|
const options = host.getCompilationSettings();
|
||||||
const program = ts.createProgram(rootNames, options, host);
|
const program = ts.createProgram(rootNames, options, host);
|
||||||
const emitResult = program!.emit();
|
|
||||||
|
|
||||||
// TODO(ry) Print diagnostics in Rust.
|
const preEmitDiagnostics = ts.getPreEmitDiagnostics(program).filter(
|
||||||
// https://github.com/denoland/deno/pull/2310
|
|
||||||
|
|
||||||
const diagnostics = ts
|
|
||||||
.getPreEmitDiagnostics(program)
|
|
||||||
.concat(emitResult.diagnostics)
|
|
||||||
.filter(
|
|
||||||
({ code }): boolean => {
|
({ code }): boolean => {
|
||||||
// TS2691: An import path cannot end with a '.ts' extension. Consider
|
// TS2691: An import path cannot end with a '.ts' extension. Consider
|
||||||
// importing 'bad-module' instead.
|
// importing 'bad-module' instead.
|
||||||
|
@ -406,7 +399,19 @@ window.compilerMain = function compilerMain(): void {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
if (preEmitDiagnostics.length > 0) {
|
||||||
|
host._logDiagnostics(preEmitDiagnostics);
|
||||||
|
// The above _logDiagnostics calls os.exit(). The return is here just for
|
||||||
|
// clarity.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const emitResult = program!.emit();
|
||||||
|
|
||||||
|
// TODO(ry) Print diagnostics in Rust.
|
||||||
|
// https://github.com/denoland/deno/pull/2310
|
||||||
|
|
||||||
|
const { diagnostics } = emitResult;
|
||||||
if (diagnostics.length > 0) {
|
if (diagnostics.length > 0) {
|
||||||
host._logDiagnostics(diagnostics);
|
host._logDiagnostics(diagnostics);
|
||||||
// The above _logDiagnostics calls os.exit(). The return is here just for
|
// The above _logDiagnostics calls os.exit(). The return is here just for
|
||||||
|
|
7
tests/error_003_typescript2.test
Normal file
7
tests/error_003_typescript2.test
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# Supposing that we've already attempted to run error_003_typescript.ts
|
||||||
|
# we want to make sure that JS wasn't emitted. Running again without reload flag
|
||||||
|
# should result in the same output.
|
||||||
|
# https://github.com/denoland/deno/issues/2436
|
||||||
|
args: run tests/error_003_typescript.ts
|
||||||
|
exit_code: 1
|
||||||
|
output: tests/error_003_typescript.ts.out
|
Loading…
Add table
Add a link
Reference in a new issue