Skip to content

Commit

Permalink
fix(es/module): Do not determine filename if no exports
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Jul 27, 2023
1 parent 9daa0e2 commit 75e8214
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/swc_ecma_transforms_module/src/umd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ where
fn visit_mut_module(&mut self, module: &mut Module) {
let import_interop = self.config.config.import_interop();

let filename = self.cm.span_to_filename(module.span);
let exported_name = self.config.determine_export_name(filename);

let module_items = &mut module.body;

let mut strip = ModuleDeclStrip::new(self.const_var_kind);
Expand Down Expand Up @@ -170,7 +167,7 @@ where
// Emit
// ====================

let (adapter_fn_expr, factory_params) = self.adapter(exported_name, is_export_assign);
let (adapter_fn_expr, factory_params) = self.adapter(module.span, is_export_assign);

let factory_fn_expr: Expr = Function {
params: factory_params,
Expand Down Expand Up @@ -341,7 +338,7 @@ where
/// });
/// ```
/// Return: adapter expr and factory params
fn adapter(&mut self, exported_name: Ident, is_export_assign: bool) -> (FnExpr, Vec<Param>) {
fn adapter(&mut self, module_span: Span, is_export_assign: bool) -> (FnExpr, Vec<Param>) {
macro_rules! js_typeof {
($test:expr =>! $type:expr) => {
Expr::Unary(UnaryExpr {
Expand Down Expand Up @@ -375,7 +372,6 @@ where
let factory = private_ident!("factory");

let module_exports = module.clone().make_member(quote_ident!("exports"));
let global_lib = global.clone().make_member(exported_name);
let define_amd = define.clone().make_member(quote_ident!("amd"));

let mut cjs_args = vec![];
Expand All @@ -385,6 +381,10 @@ where
let mut factory_params = vec![];

if !is_export_assign && self.exports.is_some() {
let filename = self.cm.span_to_filename(module_span);
let exported_name = self.config.determine_export_name(filename);
let global_lib = global.clone().make_member(exported_name);

cjs_args.push(quote_ident!("exports").as_arg());
amd_dep_list.push(Some(quote_str!("exports").as_arg()));
browser_args.push(
Expand Down

0 comments on commit 75e8214

Please sign in to comment.