{"record":{"id":"3c920cdd6328aa72","repo":"swc-project/swc","slug":"internal-error-entered-unreachable-code-3c920c","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_css_codegen/src/lib.rs","lineNumber":1237,"sourceCode":"\n            write_str!(self, n.span, &minified);\n        } else if let Some(raw) = &n.raw {\n            write_str!(self, n.span, raw);\n        } else {\n            let value = serialize_string(&n.value);\n\n            write_str!(self, n.span, &value);\n        }\n    }\n\n    #[emitter]\n    fn emit_simple_block(&mut self, n: &SimpleBlock) -> Result {\n        let (starting, ending) = match n.name.token {\n            Token::LBracket => (\"[\", \"]\"),\n            Token::LParen => (\"(\", \")\"),\n            Token::LBrace => (\"{\", \"}\"),\n            _ => {\n                unreachable!();\n            }\n        };\n\n        write_raw!(self, lo_span_offset!(n.span, 1), starting);\n\n        let len = n.value.len();\n\n        for (idx, node) in n.value.iter().enumerate() {\n            match node {\n                ComponentValue::ListOfComponentValues(_) | ComponentValue::Declaration(_) => {\n                    if idx == 0 {\n                        formatting_newline!(self);\n                    }\n\n                    increase_indent!(self);\n                }\n                ComponentValue::AtRule(_)\n                | ComponentValue::QualifiedRule(_)","sourceCodeStart":1219,"sourceCodeEnd":1255,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_codegen/src/lib.rs#L1219-L1255","documentation":"emit_simple_block prints the delimiters of a CSS simple block by matching the opening token against '[', '(' and '{'. Any other token reaches unreachable!(), i.e. the AST holds a SimpleBlock whose name is not a bracket token. The standard swc_css_parser cannot produce such a node, so this indicates a programmatically built or mutated AST, or a parser/codegen version mismatch.","triggerScenarios":"Passing swc_css_ast SimpleBlock nodes constructed or altered by external code (deserializers, linters, plugins) whose name token is not LBracket/LParen/LBrace into swc_css_codegen; mixing swc_css_parser and swc_css_codegen from different releases.","commonSituations":"Postcss-style CSS tooling in Rust that constructs or edits AST nodes; deserializing CSS ASTs from JSON without validating token kinds; partial crate upgrades.","solutions":["If you build or mutate CSS AST yourself, normalize SimpleBlock.name.token to one of LBracket/LParen/LBrace before emitting","Align all swc_css_* crates to the same version","Dump the offending stylesheet/AST node, isolate it, and report to swc if it came from the parser"],"exampleFix":"// before (hand-built AST)\nlet block = SimpleBlock { name: ComponentValue::Ident(ident(\"foo\")), ..Default::default() };\n\n// after\nlet block = SimpleBlock { name: ComponentValue::Token(Token { span, token: Token::LBrace }), ..Default::default() };","handlingStrategy":"validation","validationCode":"// Validate every SimpleBlock you construct/mutate before emitting\nfn block_delims_ok(b: &SimpleBlock) -> bool {\n    matches!(\n        b.name.token,\n        Token::LBracket | Token::LParen | Token::LBrace\n    )\n}\n\nblocks.iter().all(block_delims_ok)","typeGuard":"fn is_emittable_block(b: &SimpleBlock) -> bool {\n    matches!(b.name.token, Token::LBracket | Token::LParen | Token::LBrace)\n}","tryCatchPattern":"let css = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {\n    let mut c = Codegen::new(); c.build(&stylesheet); c.get()\n}));\nmatch css {\n    Ok(s) => s,\n    Err(p) if panic_message(&p).contains(\"unreachable\") => {\n        // fallback: re-serialize via the parser (parse -> emit) to normalize the AST\n    }\n    Err(p) => std::panic::resume_unwind(p),\n}","preventionTips":["Keep swc_css_parser/codegen/ast on the same version","Validate tokens of programmatically built SimpleBlock nodes before emitting","Round-trip mutated AST through the parser once to normalize it"],"tags":["swc","css","codegen","ast","simple-block"],"backgroundTag":"css-ast-invalid-node","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"}