mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39: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,34 +379,39 @@ window.compilerMain = function compilerMain(): void {
|
|||
|
||||
const options = host.getCompilationSettings();
|
||||
const program = ts.createProgram(rootNames, options, host);
|
||||
|
||||
const preEmitDiagnostics = ts.getPreEmitDiagnostics(program).filter(
|
||||
({ code }): boolean => {
|
||||
// TS2691: An import path cannot end with a '.ts' extension. Consider
|
||||
// importing 'bad-module' instead.
|
||||
if (code === 2691) return false;
|
||||
// TS5009: Cannot find the common subdirectory path for the input files.
|
||||
if (code === 5009) return false;
|
||||
// TS5055: Cannot write file
|
||||
// 'http://localhost:4545/tests/subdir/mt_application_x_javascript.j4.js'
|
||||
// because it would overwrite input file.
|
||||
if (code === 5055) return false;
|
||||
// TypeScript is overly opinionated that only CommonJS modules kinds can
|
||||
// support JSON imports. Allegedly this was fixed in
|
||||
// Microsoft/TypeScript#26825 but that doesn't seem to be working here,
|
||||
// so we will ignore complaints about this compiler setting.
|
||||
if (code === 5070) return false;
|
||||
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 = ts
|
||||
.getPreEmitDiagnostics(program)
|
||||
.concat(emitResult.diagnostics)
|
||||
.filter(
|
||||
({ code }): boolean => {
|
||||
// TS2691: An import path cannot end with a '.ts' extension. Consider
|
||||
// importing 'bad-module' instead.
|
||||
if (code === 2691) return false;
|
||||
// TS5009: Cannot find the common subdirectory path for the input files.
|
||||
if (code === 5009) return false;
|
||||
// TS5055: Cannot write file
|
||||
// 'http://localhost:4545/tests/subdir/mt_application_x_javascript.j4.js'
|
||||
// because it would overwrite input file.
|
||||
if (code === 5055) return false;
|
||||
// TypeScript is overly opinionated that only CommonJS modules kinds can
|
||||
// support JSON imports. Allegedly this was fixed in
|
||||
// Microsoft/TypeScript#26825 but that doesn't seem to be working here,
|
||||
// so we will ignore complaints about this compiler setting.
|
||||
if (code === 5070) return false;
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
const { diagnostics } = emitResult;
|
||||
if (diagnostics.length > 0) {
|
||||
host._logDiagnostics(diagnostics);
|
||||
// The above _logDiagnostics calls os.exit(). The return is here just for
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue