mirror of
https://github.com/denoland/deno.git
synced 2024-12-27 09:39:08 -05:00
fix: downcast from SwcDiagnosticBuffer to OpError (#6909)
This commit is contained in:
parent
b7942bf0f6
commit
315efbc0e8
5 changed files with 50 additions and 5 deletions
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<¬ify::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);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}`,
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue