2020-08-03 19:33:23 +03:00
|
|
|
use std::sync::RwLock;
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2020-08-03 19:33:23 +03:00
|
|
|
use swc_common::{
|
|
|
|
errors::{Diagnostic, DiagnosticBuilder, Emitter, Handler, HandlerFlags, SourceMapperDyn},
|
|
|
|
sync::Lrc,
|
2019-11-17 12:36:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Creates a new handler for testing.
|
2020-03-09 15:18:41 +03:00
|
|
|
pub(crate) fn new_handler(
|
2020-08-03 19:33:23 +03:00
|
|
|
_: Lrc<SourceMapperDyn>,
|
2020-03-09 15:18:41 +03:00
|
|
|
treat_err_as_bug: bool,
|
|
|
|
) -> (Handler, BufferedError) {
|
2019-11-17 12:36:47 +03:00
|
|
|
let e = BufferedError::default();
|
|
|
|
|
|
|
|
let handler = Handler::with_emitter_and_flags(
|
2020-07-23 20:18:22 +03:00
|
|
|
Box::new(e.clone()),
|
2019-11-17 12:36:47 +03:00
|
|
|
HandlerFlags {
|
2020-03-09 15:18:41 +03:00
|
|
|
treat_err_as_bug,
|
2019-11-17 12:36:47 +03:00
|
|
|
can_emit_warnings: true,
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
(handler, e)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Default)]
|
2020-08-03 19:33:23 +03:00
|
|
|
pub(crate) struct BufferedError(Lrc<RwLock<Vec<Diagnostic>>>);
|
2019-11-17 12:36:47 +03:00
|
|
|
|
|
|
|
impl Emitter for BufferedError {
|
|
|
|
fn emit(&mut self, db: &DiagnosticBuilder) {
|
|
|
|
self.0.write().unwrap().push((**db).clone());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<BufferedError> for Vec<Diagnostic> {
|
|
|
|
fn from(buf: BufferedError) -> Self {
|
|
|
|
let s = buf.0.read().unwrap();
|
|
|
|
|
|
|
|
s.clone()
|
|
|
|
}
|
|
|
|
}
|