diff --git a/crates/mako/src/visitors/dynamic_import.rs b/crates/mako/src/visitors/dynamic_import.rs index 77cfd0e73..9af78bc09 100644 --- a/crates/mako/src/visitors/dynamic_import.rs +++ b/crates/mako/src/visitors/dynamic_import.rs @@ -9,9 +9,7 @@ use swc_core::ecma::utils::{ }; use swc_core::ecma::visit::{VisitMut, VisitMutWith}; -use crate::ast::utils::{ - id, is_dynamic_import, member_call, member_prop, promise_all, require_ensure, -}; +use crate::ast::utils::{is_dynamic_import, promise_all, require_ensure}; use crate::compiler::Context; use crate::generate::chunk::ChunkId; use crate::visitors::dep_replacer::DependenciesToReplace; @@ -133,45 +131,28 @@ impl<'a> VisitMut for DynamicImport<'a> { .collect::>(); let load_promise = promise_all(ExprOrSpread { spread: None, - expr: Box::new(Expr::Array(ArrayLit { + expr: ArrayLit { span: DUMMY_SP, elems: to_ensure_elems, - })), + } + .into(), }); - let require_call = member_call( - Expr::Ident(id("__mako_require__")), - member_prop("bind"), - vec![ - ExprOrSpread { - spread: None, - expr: Box::new(Expr::Ident(id("__mako_require__"))), - }, - ExprOrSpread { - spread: None, - expr: Box::new(Expr::Lit(Lit::Str(resolved_source.into()))), - }, - ], - ); + let lazy_require_call = member_expr!(DUMMY_SP, __mako_require__.bind) + .as_call( + DUMMY_SP, + vec![ + quote_ident!("__mako_require__").as_arg(), + quote_str!(resolved_source.clone()).as_arg(), + ], + ); let dr_call = member_expr!(DUMMY_SP, __mako_require__.dr).as_call( DUMMY_SP, - vec![ - self.interop.clone().as_arg(), - ExprOrSpread { - spread: None, - expr: Box::new(require_call), - }, - ], + vec![self.interop.clone().as_arg(), lazy_require_call.as_arg()], ); - member_call( - load_promise, - member_prop("then"), - vec![ExprOrSpread { - spread: None, - expr: dr_call.into(), - }], - ) + member_expr!(@EXT, DUMMY_SP, load_promise.into(), then) + .as_call(call_expr.span, vec![dr_call.as_arg()]) }; } }