@@ -13,6 +13,7 @@ mod hoist;
1313mod lazy_loading_transformer;
1414mod magic_comments;
1515mod node_replacer;
16+ mod react_async_import_lift;
1617mod react_hooks_remover;
1718mod static_prevaluator;
1819mod sync_dynamic_import;
@@ -56,6 +57,7 @@ use magic_comments::MagicCommentsVisitor;
5657use node_replacer:: NodeReplacer ;
5758use path_slash:: PathExt ;
5859use pathdiff:: diff_paths;
60+ use react_async_import_lift:: ReactAsyncImportLift ;
5961use react_hooks_remover:: ReactHooksRemover ;
6062use serde:: Deserialize ;
6163use serde:: Serialize ;
@@ -159,15 +161,18 @@ pub struct Config {
159161 pub hmr_improvements : bool ,
160162 pub magic_comments : bool ,
161163 pub exports_rebinding_optimisation : bool ,
162- pub sync_dynamic_import_config : Option < SyncDynamicImportConfig > ,
163164 pub nested_promise_import_fix : bool ,
164165 pub global_aliasing_config : Option < HashMap < String , String > > ,
165166 pub enable_lazy_loading : bool ,
166167 pub enable_ssr_typeof_replacement : bool ,
167168 pub enable_react_hooks_removal : bool ,
169+ pub enable_react_async_import_lift : bool ,
170+ pub react_async_lift_by_default : bool ,
171+ pub react_async_lift_report_level : String ,
168172 pub enable_static_prevaluation : bool ,
169173 pub enable_dead_returns_removal : bool ,
170174 pub enable_unused_bindings_removal : bool ,
175+ pub sync_dynamic_import_config : Option < SyncDynamicImportConfig > ,
171176}
172177
173178#[ derive( Serialize , Debug , Default ) ]
@@ -420,6 +425,20 @@ pub fn transform(
420425 ) ) ;
421426 }
422427
428+ let module = module. apply ( (
429+ Optional :: new (
430+ visit_mut_pass ( ReactAsyncImportLift :: new ( global_mark, config. react_async_lift_by_default , config. react_async_lift_report_level . clone ( ) ) ) ,
431+ config. enable_react_async_import_lift && ReactAsyncImportLift :: should_transform ( code)
432+ ) ,
433+ Optional :: new (
434+ visit_mut_pass (
435+ SyncDynamicImport :: new ( Path :: new ( & config. filename ) ,
436+ unresolved_mark,
437+ & config. sync_dynamic_import_config ,
438+ ) ) ,
439+ config. sync_dynamic_import_config . is_some ( ) ) ,
440+ ) ) ;
441+
423442 let mut module = {
424443 let mut passes = (
425444 Optional :: new (
@@ -440,13 +459,6 @@ pub fn transform(
440459 } ) ,
441460 config. source_type != SourceType :: Script
442461 ) ,
443- Optional :: new (
444- visit_mut_pass (
445- SyncDynamicImport :: new ( Path :: new ( & config. filename ) ,
446- unresolved_mark,
447- & config. sync_dynamic_import_config ,
448- ) ) ,
449- config. sync_dynamic_import_config . is_some ( ) ) ,
450462 Optional :: new (
451463 visit_mut_pass ( GlobalAliaser :: with_config ( unresolved_mark, & config. global_aliasing_config ) ) ,
452464 config. global_aliasing_config . is_some ( )
0 commit comments