1- use std:: cell :: RefCell ;
1+ use std:: sync :: { Arc , Mutex } ;
22
33use swc_core:: common:: errors:: { DiagnosticBuilder , Emitter } ;
44
55pub struct ErrorReporter {
6- pub errors : RefCell < Vec < String > > ,
7- pub warnings : RefCell < Vec < String > > ,
6+ pub errors : Arc < Mutex < Vec < String > > > ,
7+ pub warnings : Arc < Mutex < Vec < String > > > ,
88}
99
1010impl ErrorReporter {
11- pub fn new ( errors : RefCell < Vec < String > > , warnings : RefCell < Vec < String > > ) -> Self {
11+ pub fn new ( errors : Arc < Mutex < Vec < String > > > , warnings : Arc < Mutex < Vec < String > > > ) -> Self {
1212 ErrorReporter { errors, warnings }
1313 }
1414}
1515
1616impl Default for ErrorReporter {
1717 fn default ( ) -> Self {
1818 ErrorReporter {
19- errors : RefCell :: new ( Vec :: new ( ) ) ,
20- warnings : RefCell :: new ( Vec :: new ( ) ) ,
19+ errors : Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ,
20+ warnings : Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ,
2121 }
2222 }
2323}
@@ -29,14 +29,16 @@ impl Emitter for ErrorReporter {
2929 | swc_core:: common:: errors:: Level :: Fatal
3030 | swc_core:: common:: errors:: Level :: PhaseFatal
3131 | swc_core:: common:: errors:: Level :: Error => {
32- self . errors . borrow_mut ( ) . push ( diagnostic. message ( ) ) ;
32+ let mut errors = self . errors . lock ( ) . unwrap ( ) ;
33+ errors. push ( diagnostic. message ( ) ) ;
3334 }
3435 swc_core:: common:: errors:: Level :: Warning
3536 | swc_core:: common:: errors:: Level :: Note
3637 | swc_core:: common:: errors:: Level :: Help
3738 | swc_core:: common:: errors:: Level :: Cancelled
3839 | swc_core:: common:: errors:: Level :: FailureNote => {
39- self . warnings . borrow_mut ( ) . push ( diagnostic. message ( ) ) ;
40+ let mut warnings = self . warnings . lock ( ) . unwrap ( ) ;
41+ warnings. push ( diagnostic. message ( ) ) ;
4042 }
4143 }
4244 }
0 commit comments