{"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/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_module/src/umd/config.rs#L69-L91","documentation":"When building UMD output, swc_ecma_transforms_module derives the global/export identifier from the input FileName: real paths use the file stem, FileName::Custom uses the string directly. Every other FileName variant (anonymous stdin input, internal buffers, command-line pseudo files) has no defined mapping and panics with unimplemented!.","triggerScenarios":"Running the UMD module transform on a source whose FileName is not Real or Custom — typically FileName::Anon created via SourceMap::anon / new_source_file with an anonymous name when transforming an in-memory string or stdin without setting a filename.","commonSituations":"Using the swc Compiler/API to transform an in-memory string or stdin buffer with jsc.parser/module UMD settings; test harnesses that build SourceFiles without names.","solutions":["Give the input a real file name before transforming, e.g. FileName::Custom(\"index\".into()) or a real PathBuf","When using the swc crate's Compiler, pass the source through a named file or set the filename on the transform task instead of feeding an anonymous SourceFile","Avoid `module.type = \"umd\"` for anonymous/eval-compiled inputs, or pre-map them to a custom name"],"exampleFix":"// before\nlet fm = cm.new_source_file(FileName::Anon.into(), src);\n\n// after\nlet fm = cm.new_source_file(FileName::Custom(\"index\".into()).into(), src);","handlingStrategy":"validation","validationCode":"// Rust: check the FileName variant before running the UMD transform\nuse swc_common::FileName;\nfn umd_safe_filename(f: &FileName) -> bool {\n    matches!(f, FileName::Real(_) | FileName::Custom(_))\n}\nassert!(umd_safe_filename(&*source_file.name), \"UMD transform requires a Real or Custom file name\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always assign a concrete filename when creating SourceFiles for programmatic transforms (FileName::Custom as fallback)","Never rely on FileName::Anon/stdin inputs when module.type is umd","Add an integration test that transforms an in-memory string to catch anonymous-filename paths early"],"tags":["swc","umd","filename","source-map","config"],"backgroundTag":"unsupported-filename-kind","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}