diff --git a/crates/oxc_diagnostics/src/lib.rs b/crates/oxc_diagnostics/src/lib.rs index d172665f4..7c5776f1f 100644 --- a/crates/oxc_diagnostics/src/lib.rs +++ b/crates/oxc_diagnostics/src/lib.rs @@ -4,7 +4,7 @@ mod graphic_reporter; mod graphical_theme; -use std::{cell::RefCell, ops::Deref, path::PathBuf, rc::Rc}; +use std::path::PathBuf; pub use graphic_reporter::GraphicalReportHandler; pub use miette; @@ -19,25 +19,6 @@ pub type Report = miette::Report; pub type Result = std::result::Result; -#[derive(Debug, Default, Clone)] -pub struct Diagnostics(Rc>>); - -impl Deref for Diagnostics { - type Target = Rc>>; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl Diagnostics { - /// # Panics - #[must_use] - pub fn into_inner(self) -> Vec { - Rc::try_unwrap(self.0).unwrap().into_inner() - } -} - #[derive(Debug, Error, Diagnostic)] #[error("Identifier `{0}` has already been declared")] #[diagnostic()] diff --git a/crates/oxc_wasm/src/driver.rs b/crates/oxc_wasm/src/driver.rs index 153d8d409..9de2ad3e6 100644 --- a/crates/oxc_wasm/src/driver.rs +++ b/crates/oxc_wasm/src/driver.rs @@ -3,7 +3,6 @@ use std::{rc::Rc, sync::Arc}; use miette::NamedSource; use oxc_allocator::Allocator; use oxc_ast::SourceType; -use oxc_diagnostics::Diagnostics; use oxc_linter::Linter; use oxc_parser::Parser; use oxc_semantic::SemanticBuilder; @@ -30,24 +29,21 @@ impl Driver { .allow_return_outside_function(true) .parse(); + let mut diagnostics = ret.errors; + let program = self.allocator.alloc(ret.program); - let diagnostics = Diagnostics::default(); let semantic_ret = SemanticBuilder::new(source_text, source_type, &ret.trivias).build(program); - let mut diagnostics = diagnostics.into_inner(); + diagnostics.extend(semantic_ret.errors); let source = Arc::new(NamedSource::new(path, source_text.to_string())); - diagnostics.extend( - Linter::from_json_str(eslintrc) - .with_fix(false) - .run(&Rc::new(semantic_ret.semantic)) - .into_iter() - .map(|m| m.error.with_source_code(Arc::clone(&source))) - .chain(ret.errors) - .chain(semantic_ret.errors), - ); + let messages = + Linter::from_json_str(eslintrc).with_fix(false).run(&Rc::new(semantic_ret.semantic)); + + diagnostics + .extend(messages.into_iter().map(|m| m.error.with_source_code(Arc::clone(&source)))); if diagnostics.is_empty() { if let Ok(ast) = JsValue::from_serde(program) { @@ -55,11 +51,12 @@ impl Driver { } } - let result = diagnostics + let diagnostics = diagnostics .into_iter() .map(|error| format!("{error:?}")) .collect::>() .join("\n"); - JsValue::from_str(&result) + + JsValue::from_str(&diagnostics) } }