1
1
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
2
2
3
3
use std:: borrow:: Cow ;
4
- use std:: rc:: Rc ;
5
4
use std:: sync:: Arc ;
6
5
7
6
use deno_media_type:: MediaType ;
@@ -14,6 +13,7 @@ use crate::emit;
14
13
use crate :: swc:: ast:: Program ;
15
14
use crate :: swc:: common:: comments:: SingleThreadedComments ;
16
15
use crate :: swc:: common:: errors:: Diagnostic as SwcDiagnostic ;
16
+ use crate :: swc:: common:: sync:: { Lock , Lrc } ;
17
17
use crate :: swc:: ecma_visit:: visit_mut_pass;
18
18
use crate :: swc:: parser:: error:: SyntaxError ;
19
19
use crate :: swc:: transforms:: fixer;
@@ -39,7 +39,6 @@ use crate::ProgramRef;
39
39
use crate :: SourceMap ;
40
40
41
41
use deno_error:: JsError ;
42
- use std:: cell:: RefCell ;
43
42
44
43
mod jsx_precompile;
45
44
mod transforms;
@@ -53,7 +52,7 @@ pub enum TranspileResult {
53
52
///
54
53
/// This is a performance issue and you should strive to get an `Owned` result.
55
54
Cloned ( EmittedSourceText ) ,
56
- /// The emit occured consuming the `ParsedSource` without cloning.
55
+ /// The emit occurred consuming the `ParsedSource` without cloning.
57
56
Owned ( EmittedSourceText ) ,
58
57
}
59
58
@@ -174,8 +173,8 @@ impl Default for TranspileOptions {
174
173
impl TranspileOptions {
175
174
fn as_tsx_config ( & self ) -> typescript:: TsxConfig {
176
175
typescript:: TsxConfig {
177
- pragma : Some ( Rc :: new ( self . jsx_factory . clone ( ) ) ) ,
178
- pragma_frag : Some ( Rc :: new ( self . jsx_fragment_factory . clone ( ) ) ) ,
176
+ pragma : Some ( Lrc :: new ( self . jsx_factory . clone ( ) ) ) ,
177
+ pragma_frag : Some ( Lrc :: new ( self . jsx_fragment_factory . clone ( ) ) ) ,
179
178
}
180
179
}
181
180
@@ -196,7 +195,7 @@ impl TranspileOptions {
196
195
} ,
197
196
// no need for this to be false because we treat all files as modules
198
197
no_empty_export : true ,
199
- // we don't suport this, so leave it as-is so it errors in v8
198
+ // we don't support this, so leave it as-is so it errors in v8
200
199
import_export_assign_config :
201
200
typescript:: TsImportExportAssignConfig :: Preserve ,
202
201
// Do not opt into swc's optimization to inline enum member values
@@ -619,7 +618,7 @@ fn convert_script_module_to_swc_script(
619
618
620
619
#[ derive( Default , Clone ) ]
621
620
struct DiagnosticCollector {
622
- diagnostics_cell : Rc < RefCell < Vec < SwcDiagnostic > > > ,
621
+ diagnostics : Lrc < Lock < Vec < SwcDiagnostic > > > ,
623
622
}
624
623
625
624
impl DiagnosticCollector {
@@ -635,7 +634,8 @@ impl DiagnosticCollector {
635
634
impl crate :: swc:: common:: errors:: Emitter for DiagnosticCollector {
636
635
fn emit ( & mut self , db : & crate :: swc:: common:: errors:: DiagnosticBuilder < ' _ > ) {
637
636
use std:: ops:: Deref ;
638
- self . diagnostics_cell . borrow_mut ( ) . push ( db. deref ( ) . clone ( ) ) ;
637
+ let mut diagnostics = self . diagnostics . lock ( ) ;
638
+ diagnostics. push ( db. deref ( ) . clone ( ) ) ;
639
639
}
640
640
}
641
641
@@ -720,8 +720,8 @@ pub fn fold_program<'a>(
720
720
Some ( comments) ,
721
721
#[ allow( deprecated) ]
722
722
react:: Options {
723
- pragma : Some ( Rc :: new ( options. jsx_factory . clone ( ) ) ) ,
724
- pragma_frag : Some ( Rc :: new ( options. jsx_fragment_factory . clone ( ) ) ) ,
723
+ pragma : Some ( Lrc :: new ( options. jsx_factory . clone ( ) ) ) ,
724
+ pragma_frag : Some ( Lrc :: new ( options. jsx_fragment_factory . clone ( ) ) ) ,
725
725
// This will use `Object.assign()` instead of the `_extends` helper
726
726
// when spreading props (Note: this property is deprecated)
727
727
use_builtins : Some ( true ) ,
@@ -755,7 +755,7 @@ pub fn fold_program<'a>(
755
755
) ;
756
756
757
757
let emitter = DiagnosticCollector :: default ( ) ;
758
- let diagnostics_cell = emitter. diagnostics_cell . clone ( ) ;
758
+ let diagnostics_cell = emitter. diagnostics . clone ( ) ;
759
759
let handler = emitter. into_handler ( ) ;
760
760
let result = crate :: swc:: common:: errors:: HANDLER . set ( & handler, || {
761
761
helpers:: HELPERS
0 commit comments