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,8 @@ 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 ;
17+ use crate :: swc:: common:: sync:: Lrc ;
1718use crate :: swc:: ecma_visit:: visit_mut_pass;
1819use crate :: swc:: parser:: error:: SyntaxError ;
1920use crate :: swc:: transforms:: fixer;
@@ -39,7 +40,6 @@ use crate::ProgramRef;
3940use crate :: SourceMap ;
4041
4142use deno_error:: JsError ;
42- use std:: cell:: RefCell ;
4343
4444mod jsx_precompile;
4545mod transforms;
@@ -53,7 +53,7 @@ pub enum TranspileResult {
5353 ///
5454 /// This is a performance issue and you should strive to get an `Owned` result.
5555 Cloned ( EmittedSourceText ) ,
56- /// The emit occured consuming the `ParsedSource` without cloning.
56+ /// The emit occurred consuming the `ParsedSource` without cloning.
5757 Owned ( EmittedSourceText ) ,
5858}
5959
@@ -174,8 +174,8 @@ impl Default for TranspileOptions {
174174impl TranspileOptions {
175175 fn as_tsx_config ( & self ) -> typescript:: TsxConfig {
176176 typescript:: TsxConfig {
177- pragma : Some ( Rc :: new ( self . jsx_factory . clone ( ) ) ) ,
178- pragma_frag : Some ( Rc :: new ( self . jsx_fragment_factory . clone ( ) ) ) ,
177+ pragma : Some ( Lrc :: new ( self . jsx_factory . clone ( ) ) ) ,
178+ pragma_frag : Some ( Lrc :: new ( self . jsx_fragment_factory . clone ( ) ) ) ,
179179 }
180180 }
181181
@@ -196,7 +196,7 @@ impl TranspileOptions {
196196 } ,
197197 // no need for this to be false because we treat all files as modules
198198 no_empty_export : true ,
199- // we don't suport this, so leave it as-is so it errors in v8
199+ // we don't support this, so leave it as-is so it errors in v8
200200 import_export_assign_config :
201201 typescript:: TsImportExportAssignConfig :: Preserve ,
202202 // Do not opt into swc's optimization to inline enum member values
@@ -619,7 +619,7 @@ fn convert_script_module_to_swc_script(
619619
620620#[ derive( Default , Clone ) ]
621621struct DiagnosticCollector {
622- diagnostics_cell : Rc < RefCell < Vec < SwcDiagnostic > > > ,
622+ diagnostics : Lrc < Lock < Vec < SwcDiagnostic > > > ,
623623}
624624
625625impl DiagnosticCollector {
@@ -635,7 +635,8 @@ impl DiagnosticCollector {
635635impl crate :: swc:: common:: errors:: Emitter for DiagnosticCollector {
636636 fn emit ( & mut self , db : & crate :: swc:: common:: errors:: DiagnosticBuilder < ' _ > ) {
637637 use std:: ops:: Deref ;
638- self . diagnostics_cell . borrow_mut ( ) . push ( db. deref ( ) . clone ( ) ) ;
638+ let mut diagnostics = self . diagnostics . lock ( ) ;
639+ diagnostics. push ( db. deref ( ) . clone ( ) ) ;
639640 }
640641}
641642
@@ -720,8 +721,8 @@ pub fn fold_program<'a>(
720721 Some ( comments) ,
721722 #[ allow( deprecated) ]
722723 react:: Options {
723- pragma : Some ( Rc :: new ( options. jsx_factory . clone ( ) ) ) ,
724- pragma_frag : Some ( Rc :: new ( options. jsx_fragment_factory . clone ( ) ) ) ,
724+ pragma : Some ( Lrc :: new ( options. jsx_factory . clone ( ) ) ) ,
725+ pragma_frag : Some ( Lrc :: new ( options. jsx_fragment_factory . clone ( ) ) ) ,
725726 // This will use `Object.assign()` instead of the `_extends` helper
726727 // when spreading props (Note: this property is deprecated)
727728 use_builtins : Some ( true ) ,
@@ -755,7 +756,7 @@ pub fn fold_program<'a>(
755756 ) ;
756757
757758 let emitter = DiagnosticCollector :: default ( ) ;
758- let diagnostics_cell = emitter. diagnostics_cell . clone ( ) ;
759+ let diagnostics_cell = emitter. diagnostics . clone ( ) ;
759760 let handler = emitter. into_handler ( ) ;
760761 let result = crate :: swc:: common:: errors:: HANDLER . set ( & handler, || {
761762 helpers:: HELPERS
0 commit comments