{"record":{"id":"1e4f729f0a42f12a","repo":"swc-project/swc","slug":"cannot-transform-product-children-into-calcproduct","errorCode":null,"errorMessage":"Cannot transform product children into CalcProduct","messagePattern":"Cannot transform product children into CalcProduct","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_css_minifier/src/compressor/calc_sum.rs","lineNumber":997,"sourceCode":"                            CalcOperatorNode::Invert(calc_node) => {\n                                expr.push(CalcValueOrOperator::Operator(CalcOperator {\n                                    value: CalcOperatorType::Div,\n                                    span: Span::dummy_with_cmt(),\n                                }));\n                                expr.push(CalcValueOrOperator::Value(\n                                    serialize_calc_node_into_calc_value(calc_node),\n                                ));\n                            }\n                            CalcOperatorNode::Product(_) | CalcOperatorNode::Sum(_) => {\n                                expr.push(CalcValueOrOperator::Operator(CalcOperator {\n                                    value: CalcOperatorType::Mul,\n                                    span: Span::dummy_with_cmt(),\n                                }));\n                                expr.push(CalcValueOrOperator::Value(\n                                    serialize_calc_node_into_calc_value(calc_node),\n                                ));\n                            }\n                            _ => unreachable!(\"Cannot transform product children into CalcProduct\"),\n                        },\n                    }\n                }\n                CalcProductOrOperator::Product(CalcProduct {\n                    expressions: expr,\n                    span: Span::dummy_with_cmt(),\n                })\n            }\n            CalcOperatorNode::Sum(_) => CalcProductOrOperator::Product(CalcProduct {\n                expressions: vec![CalcValueOrOperator::Value(\n                    serialize_calc_node_into_calc_value(calc_node),\n                )],\n                span: Span::dummy_with_cmt(),\n            }),\n        },\n    }\n}\n","sourceCodeStart":979,"sourceCodeEnd":1015,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_minifier/src/compressor/calc_sum.rs#L979-L1015","documentation":"Companion guard to the CalcSum one in the same serializer: when re-serializing a CalcProduct's children into CalcValueOrOperator, only Value and operator nodes (Product/Sum get an explicit '*' inserted) are expected; any other child kind reaches unreachable!(). Like its sibling it marks a calc tree the minifier cannot round-trip — from a folding bug or hand-built AST.","triggerScenarios":"CSS minification where the product-level serialization encounters an unexpected CalcValueOrOperator child — deeply nested calc(), division/modulus combinations, or calc trees injected by custom transforms.","commonSituations":"Complex utility-CSS with chained calc(); minifier/parser version skew; plugins that rewrite calc subtrees.","solutions":["Update the swc_css_* crates together to one version","Reduce the failing stylesheet to a single calc() declaration, simplify the expression, and report the repro upstream","Normalize externally built calc ASTs through the parser before minifying"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Count calc() usages to route high-risk files to a no-minify path\nlet calc_heavy = css.matches(\"calc(\").count() > 8;\nlet mode = if calc_heavy { Minify::Off } else { Minify::On };","typeGuard":null,"tryCatchPattern":"match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| minify(&stylesheet))) {\n    Ok(v) => v,\n    Err(p) if panic_message(&p).contains(\"Cannot transform product children\") => stylesheet, // unminified fallback\n    Err(p) => std::panic::resume_unwind(p),\n}","preventionTips":["Update the swc_css_* crates together","Keep an unminified-output fallback for calc-heavy stylesheets","Add the failing calc() expression to your regression corpus once identified"],"tags":["swc","css","minifier","calc","invariant"],"backgroundTag":"calc-minification-unsupported","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"}