{"record":{"id":"ca0825bd0076a43f","repo":"swc-project/swc","slug":"internal-error-entered-unreachable-code-ca0825","errorCode":null,"errorMessage":"internal error: entered unreachable code","messagePattern":"internal error: entered unreachable code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_bundler/src/bundler/finalize.rs","lineNumber":196,"sourceCode":"\n                        ModuleDecl::ExportDecl(export) => {\n                            match &export.decl {\n                                Decl::Class(ClassDecl { ident, .. })\n                                | Decl::Fn(FnDecl { ident, .. }) => {\n                                    props.push(PropOrSpread::Prop(Box::new(Prop::Shorthand(\n                                        ident.clone(),\n                                    ))));\n                                }\n                                Decl::Var(decl) => {\n                                    let ids: Vec<Ident> = find_pat_ids(decl);\n                                    props.extend(\n                                        ids.into_iter()\n                                            .map(Prop::Shorthand)\n                                            .map(Box::new)\n                                            .map(PropOrSpread::Prop),\n                                    );\n                                }\n                                _ => unreachable!(),\n                            }\n\n                            Some(export.decl.into())\n                        }\n\n                        ModuleDecl::ExportNamed(NamedExport {\n                            specifiers,\n                            src: None,\n                            ..\n                        }) => {\n                            for s in specifiers {\n                                match s {\n                                    ExportSpecifier::Namespace(..) => {\n                                        // unreachable\n                                    }\n                                    ExportSpecifier::Default(s) => {\n                                        props.push(PropOrSpread::Prop(Box::new(Prop::KeyValue(\n                                            KeyValueProp {","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_bundler/src/bundler/finalize.rs#L178-L214","documentation":"When swc_bundler finalizes a bundle whose output format is IIFE, may_wrap_with_iife rewrites `export <decl>` statements into properties on the returned object. It converts Class, Fn and Var declarations; any other Decl — TsEnum, TsInterface, TsTypeAlias, TsModule, i.e. TypeScript-only syntax that should have been stripped — hits unreachable!().","triggerScenarios":"Bundling with ModuleType::Iife where an entry still contains TypeScript exports such as `export enum E {}`, `export interface I {}`, `export type T = ...`, or `export namespace N {}` because the TypeScript strip pass never ran (or ran after the bundler).","commonSituations":"Custom swc pipelines invoking the bundler on raw TypeScript; a pass chain where typescript::strip was accidentally omitted or ordered after bundling; plugins re-inserting TS nodes into the graph.","solutions":["Run the TypeScript strip/compile pass before the bundler so only plain ESM reaches finalize","Verify pass ordering in your pipeline: typescript::strip must precede bundling","If TypeScript was already stripped, capture the failing module and report it to swc as a bundler gap"],"exampleFix":"// before (raw TS fed to bundler)\nexport enum Flag { A, B }\n\n// after (pre-stripped by typescript::strip before bundling)\nexport var Flag;\n(function (Flag) {\n  Flag[Flag[\"A\"] = 0] = \"A\";\n  Flag[Flag[\"B\"] = 1] = \"B\";\n})(Flag || (Flag = {}));","handlingStrategy":"validation","validationCode":"// Detect TS-only exported declarations before bundling with IIFE output\nlet ts_export = regex::Regex::new(\n    r#\"(?m)^\\s*export\\s+(?:enum|interface|type|namespace|module|declare)\\b\"#,\n).unwrap();\nfor (path, src) in &sources {\n    if ts_export.is_match(src) {\n        return Err(format!(\"{} still contains TypeScript exports; strip first\", path));\n    }\n}","typeGuard":null,"tryCatchPattern":"match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| bundler.bundle(&entries))) {\n    Ok(v) => v?,\n    Err(p) => {\n        if panic_message(&p).contains(\"entered unreachable code\") && cfg_module_iife {\n            // retry after inserting typescript::strip at the front of the pipeline\n        } else { std::panic::resume_unwind(p); }\n    }\n}","preventionTips":["Order the pipeline: typescript::strip -> bundler (never the reverse)","When output ModuleType is IIFE, run fixture tests over TS-heavy entry files","Keep a lint rule forbidding `export enum/interface/type/namespace` in bundler inputs"],"tags":["swc","bundler","typescript","iife","finalize"],"backgroundTag":"typescript-strip-before-bundle","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}