summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/doc/parser.rs2
-rw-r--r--cli/op_error.rs21
-rw-r--r--cli/swc_util.rs2
-rw-r--r--cli/tests/compiler_api_test.ts28
-rw-r--r--cli/tsc.rs2
5 files changed, 50 insertions, 5 deletions
diff --git a/cli/doc/parser.rs b/cli/doc/parser.rs
index 59fa2b734..14e921237 100644
--- a/cli/doc/parser.rs
+++ b/cli/doc/parser.rs
@@ -51,7 +51,7 @@ impl DocParser {
pub fn new(loader: Box<dyn DocFileLoader>, private: bool) -> Self {
DocParser {
loader,
- ast_parser: AstParser::new(),
+ ast_parser: AstParser::default(),
private,
}
}
diff --git a/cli/op_error.rs b/cli/op_error.rs
index 73f7640a8..3cbe27a06 100644
--- a/cli/op_error.rs
+++ b/cli/op_error.rs
@@ -15,6 +15,7 @@
//! exceptions.
use crate::import_map::ImportMapError;
+use crate::swc_util::SwcDiagnosticBuffer;
use deno_core::ErrBox;
use deno_core::ModuleResolutionError;
use rustyline::error::ReadlineError;
@@ -382,6 +383,21 @@ impl From<&notify::Error> for OpError {
}
}
+impl From<SwcDiagnosticBuffer> for OpError {
+ fn from(error: SwcDiagnosticBuffer) -> Self {
+ OpError::from(&error)
+ }
+}
+
+impl From<&SwcDiagnosticBuffer> for OpError {
+ fn from(error: &SwcDiagnosticBuffer) -> Self {
+ Self {
+ kind: ErrorKind::Other,
+ msg: error.diagnostics.join(", "),
+ }
+ }
+}
+
impl From<ErrBox> for OpError {
fn from(error: ErrBox) -> Self {
#[cfg(unix)]
@@ -418,6 +434,11 @@ impl From<ErrBox> for OpError {
})
.or_else(|| error.downcast_ref::<dlopen::Error>().map(|e| e.into()))
.or_else(|| error.downcast_ref::<notify::Error>().map(|e| e.into()))
+ .or_else(|| {
+ error
+ .downcast_ref::<SwcDiagnosticBuffer>()
+ .map(|e| e.into())
+ })
.or_else(|| unix_error_kind(&error))
.unwrap_or_else(|| {
panic!("Can't downcast {:?} to OpError", error);
diff --git a/cli/swc_util.rs b/cli/swc_util.rs
index 906d9f9bd..8203c4c3a 100644
--- a/cli/swc_util.rs
+++ b/cli/swc_util.rs
@@ -141,7 +141,7 @@ pub struct AstParser {
}
impl AstParser {
- pub fn new() -> Self {
+ pub fn default() -> Self {
let buffered_error = SwcErrorBuffer::default();
let handler = Handler::with_emitter_and_flags(
diff --git a/cli/tests/compiler_api_test.ts b/cli/tests/compiler_api_test.ts
index 7ff9ebc2b..311dae8fd 100644
--- a/cli/tests/compiler_api_test.ts
+++ b/cli/tests/compiler_api_test.ts
@@ -1,5 +1,9 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { assert, assertEquals } from "../../std/testing/asserts.ts";
+import {
+ assert,
+ assertEquals,
+ assertThrowsAsync,
+} from "../../std/testing/asserts.ts";
Deno.test({
name: "Deno.compile() - sources provided",
@@ -33,7 +37,7 @@ Deno.test({
});
Deno.test({
- name: "Deno.compile() - compiler options effects imit",
+ name: "Deno.compile() - compiler options effects emit",
async fn() {
const [diagnostics, actual] = await Deno.compile(
"/foo.ts",
@@ -199,3 +203,23 @@ Deno.test({
assert(diagnostics.length === 1);
},
});
+
+// See https://github.com/denoland/deno/issues/6908
+Deno.test({
+ name: "Deno.compile() - SWC diagnostics",
+ async fn() {
+ await assertThrowsAsync(async () => {
+ await Deno.compile("main.js", {
+ "main.js": `
+ export class Foo {
+ constructor() {
+ console.log("foo");
+ }
+ export get() {
+ console.log("bar");
+ }
+ }`,
+ });
+ });
+ },
+});
diff --git a/cli/tsc.rs b/cli/tsc.rs
index b42e23e10..b3d8aebd9 100644
--- a/cli/tsc.rs
+++ b/cli/tsc.rs
@@ -1411,7 +1411,7 @@ pub fn pre_process_file(
source_code: &str,
analyze_dynamic_imports: bool,
) -> Result<(Vec<ImportDesc>, Vec<TsReferenceDesc>), SwcDiagnosticBuffer> {
- let parser = AstParser::new();
+ let parser = AstParser::default();
parser.parse_module(file_name, media_type, source_code, |parse_result| {
let module = parse_result?;
let mut collector = DependencyVisitor {