11// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
22
33use std:: borrow:: Cow ;
4- use std:: rc:: Rc ;
54use std:: sync:: Arc ;
65
76use deno_media_type:: MediaType ;
@@ -14,6 +13,7 @@ use crate::emit;
1413use crate :: swc:: ast:: Program ;
1514use crate :: swc:: common:: comments:: SingleThreadedComments ;
1615use crate :: swc:: common:: errors:: Diagnostic as SwcDiagnostic ;
16+ use crate :: swc:: common:: sync:: { Lock , Lrc } ;
1717use crate :: swc:: ecma_visit:: visit_mut_pass;
1818use crate :: swc:: parser:: error:: SyntaxError ;
1919use crate :: swc:: transforms:: fixer;
@@ -39,7 +39,6 @@ use crate::ProgramRef;
3939use crate :: SourceMap ;
4040
4141use deno_error:: JsError ;
42- use std:: cell:: RefCell ;
4342
4443mod jsx_precompile;
4544mod transforms;
@@ -53,7 +52,7 @@ pub enum TranspileResult {
5352 ///
5453 /// This is a performance issue and you should strive to get an `Owned` result.
5554 Cloned ( EmittedSourceText ) ,
56- /// The emit occured consuming the `ParsedSource` without cloning.
55+ /// The emit occurred consuming the `ParsedSource` without cloning.
5756 Owned ( EmittedSourceText ) ,
5857}
5958
@@ -174,8 +173,8 @@ impl Default for TranspileOptions {
174173impl TranspileOptions {
175174 fn as_tsx_config ( & self ) -> typescript:: TsxConfig {
176175 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 ( ) ) ) ,
179178 }
180179 }
181180
@@ -196,7 +195,7 @@ impl TranspileOptions {
196195 } ,
197196 // no need for this to be false because we treat all files as modules
198197 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
200199 import_export_assign_config :
201200 typescript:: TsImportExportAssignConfig :: Preserve ,
202201 // Do not opt into swc's optimization to inline enum member values
@@ -619,7 +618,7 @@ fn convert_script_module_to_swc_script(
619618
620619#[ derive( Default , Clone ) ]
621620struct DiagnosticCollector {
622- diagnostics_cell : Rc < RefCell < Vec < SwcDiagnostic > > > ,
621+ diagnostics : Lrc < Lock < Vec < SwcDiagnostic > > > ,
623622}
624623
625624impl DiagnosticCollector {
@@ -635,7 +634,8 @@ impl DiagnosticCollector {
635634impl crate :: swc:: common:: errors:: Emitter for DiagnosticCollector {
636635 fn emit ( & mut self , db : & crate :: swc:: common:: errors:: DiagnosticBuilder < ' _ > ) {
637636 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 ( ) ) ;
639639 }
640640}
641641
@@ -720,8 +720,8 @@ pub fn fold_program<'a>(
720720 Some ( comments) ,
721721 #[ allow( deprecated) ]
722722 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 ( ) ) ) ,
725725 // This will use `Object.assign()` instead of the `_extends` helper
726726 // when spreading props (Note: this property is deprecated)
727727 use_builtins : Some ( true ) ,
@@ -755,7 +755,7 @@ pub fn fold_program<'a>(
755755 ) ;
756756
757757 let emitter = DiagnosticCollector :: default ( ) ;
758- let diagnostics_cell = emitter. diagnostics_cell . clone ( ) ;
758+ let diagnostics_cell = emitter. diagnostics . clone ( ) ;
759759 let handler = emitter. into_handler ( ) ;
760760 let result = crate :: swc:: common:: errors:: HANDLER . set ( & handler, || {
761761 helpers:: HELPERS
0 commit comments