{"record":{"id":"48b8fdca8131767f","repo":"swc-project/swc","slug":"determine-export-name","errorCode":null,"errorMessage":"determine_export_name({:?})","messagePattern":"determine_export_name\\((.+?)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_module/src/umd/config.rs","lineNumber":87,"sourceCode":"\n        src.split('/').next_back().unwrap().to_camel_case().into()\n    }\n\n    pub fn determine_export_name(&self, filename: Lrc<FileName>) -> Ident {\n        match &*filename {\n            FileName::Real(ref path) => {\n                let s = match path.file_stem() {\n                    Some(stem) => self.global_name(&stem.to_string_lossy()),\n                    None => self.global_name(&path.display().to_string()),\n                };\n\n                quote_ident!(s).into()\n            }\n            FileName::Custom(s) => {\n                let s = self.global_name(s);\n                quote_ident!(s).into()\n            }\n            _ => unimplemented!(\"determine_export_name({:?})\", filename),\n        }\n    }\n}\n","sourceCodeStart":69,"sourceCodeEnd":91,"githubUrl":"https://github.com/swc-project/swc/blob/d7d74346665e36e692aa07e13d4ee3ee692ee35c/crates/swc_ecma_transforms_module/src/umd/config.rs#L69-L91","documentation":"The UMD transform derives the global export name from the module's file name. Only `FileName::Real` and `FileName::Custom` carry a name `global_name` can use; `Anon`, `Url`, `Internal`, `Macros` and other variants hit `unimplemented!(\"determine_export_name(...)\")` because no identifier can be derived.","triggerScenarios":"Run the UMD pass on a module whose SourceMap file was created with `FileName::Anon` — the common default in tests and ad-hoc tools (`cm.new_source_file(FileName::Anon.into(), code)`) — or with Url/Internal names.","commonSituations":"Tests and one-off compilers that never set a real filename; pipelines feeding virtual modules; plugins creating source files with generated internal names.","solutions":["Create the source file with `FileName::Custom(\"myLib\".into())` or a real path before running the UMD transform","Prefer `FileName::Custom` for virtual modules so the derived global name is deterministic (camelCased from the string)","If you use the high-level Compiler API, always pass a real `filename` in the compile options"],"exampleFix":"// before\nlet fm = cm.new_source_file(FileName::Anon.into(), code.to_string());\n\n// after\nlet fm = cm.new_source_file(FileName::Custom(\"myLib\".into()).into(), code.to_string());","handlingStrategy":"validation","validationCode":"// Rust: guard the filename before running the UMD transform\nfn usable_for_umd(f: &FileName) -> bool {\n    matches!(f, FileName::Real(_) | FileName::Custom(_))\n}\nassert!(usable_for_umd(&fm.name), \"UMD requires a Real or Custom FileName\");","typeGuard":"fn has_export_name_source(f: &FileName) -> bool {\n    matches!(f, FileName::Real(_) | FileName::Custom(_))\n}","tryCatchPattern":null,"preventionTips":["Never build source files with `FileName::Anon` in pipelines that run module-format transforms","Use `FileName::Custom(\"libName\")` for virtual modules so the UMD global name is deterministic"],"tags":["umd","module-transforms","filename","config"],"backgroundTag":null,"analyzedSha":"d7d74346665e36e692aa07e13d4ee3ee692ee35c","analyzedAt":"2026-08-16T12:41:13.160Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}