Repository: swc-project/swc (rust)

Issue:
module umd not working on m1 mac
### Describe the bug

Error when tried `transform` or `parse` to `module.type` => **umd** on MacBook Air (M1, 2020) mac.

### Input code

```typescript
import { parseSync, printSync, transform } from '@swc/core'
const code = `
console.log('test')
`

transform(code, {
  jsc: {
    parser: {
      syntax: 'ecmascript',
    },
    target: 'es3',
  },
  module: {
    type: 'umd',
  },
  minify: true,
  isModule: true,
}).then((d) => {
  console.log(d)
})
```

### Expected behavior

Should compile **UMD** it any supported platform

### Actual behavior

crash:

```
thread '<unnamed>' panicked at 'not implemented: determine_export_name(Anon)', /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/swc_ecma_transforms_module-0.153.22/src/umd/config.rs:85:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

(node:4140) UnhandledPromiseRejectionWarning: Error: failed to handle: not implemented: determine_export_name(Anon)
```

### Version

1.3.11 - but I tried also previous version.

Pull request description:
fix(es/module): Do not determine module name for modules without exports in UMD
**Description:**


**Related issue:**

 - Closes #6263.

Patch:
diff --git a/crates/swc_ecma_transforms_module/src/umd.rs b/crates/swc_ecma_transforms_module/src/umd.rs
index 8bd9f1b213..0c46840c27 100644
--- a/crates/swc_ecma_transforms_module/src/umd.rs
+++ b/crates/swc_ecma_transforms_module/src/umd.rs
@@ -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);
@@ -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,
@@ -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 {
@@ -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![];
@@ -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(


Test patch:
diff --git a/node-swc/__tests__/module_test.js b/node-swc/__tests__/module_test.js
index 00fec97c31..1c3ecefb30 100644
--- a/node-swc/__tests__/module_test.js
+++ b/node-swc/__tests__/module_test.js
@@ -47,3 +47,20 @@ it("should work with amd and external helpers", () => {
     expect(out.code).toContain(`_class_call_check._(this, Foo);`);
     expect(out.code).toContain(`_inherits._(Bar, Foo);`);
 });
+
+it('should not require filename if no exports in umd', () => {
+    const code = `console.log('test')`;
+
+    const out = swc.transformSync(code, {
+        jsc: {
+            parser: {
+                syntax: 'ecmascript',
+            },
+        },
+        module: {
+            type: 'umd',
+        },
+        isModule: true,
+    });
+    expect(out.code).toContain(`function(global`);
+});