{"record":{"id":"c2c7874ffd129386","repo":"swc-project/swc","slug":"unknown-bit-operator","errorCode":null,"errorMessage":"Unknown bit operator {:?}","messagePattern":"Unknown bit operator (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs","lineNumber":1233,"sourceCode":"        // Bit shift operations\n        op!(\"<<\") | op!(\">>\") | op!(\">>>\") => {\n            fn try_fold_shift(ctx: ExprCtx, op: BinaryOp, left: &Expr, right: &Expr) -> Value<f64> {\n                if !left.is_number() || !right.is_number() {\n                    return Unknown;\n                }\n\n                let (lv, rv) = match (left.as_pure_number(ctx), right.as_pure_number(ctx)) {\n                    (Known(lv), Known(rv)) => (lv, rv),\n                    _ => unreachable!(),\n                };\n                let (lv, rv) = (JsNumber::from(lv), JsNumber::from(rv));\n\n                Known(match op {\n                    op!(\"<<\") => *(lv << rv),\n                    op!(\">>\") => *(lv >> rv),\n                    op!(\">>>\") => *(lv.unsigned_shr(rv)),\n\n                    _ => unreachable!(\"Unknown bit operator {:?}\", op),\n                })\n            }\n            try_replace!(number, try_fold_shift(expr_ctx, op, left, right))\n        }\n\n        // These needs one more check.\n        //\n        // (a * 1) * 2 --> a * (1 * 2) --> a * 2\n        op!(\"*\") | op!(\"&\") | op!(\"|\") | op!(\"^\") => {\n            try_replace!(number, perform_arithmetic_op(expr_ctx, op, left, right));\n\n            // Try left.rhs * right\n            if let Expr::Bin(BinExpr {\n                span: _,\n                left: left_lhs,\n                op: left_op,\n                right: left_rhs,\n            }) = &mut **left","sourceCodeStart":1215,"sourceCodeEnd":1251,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs#L1215-L1251","documentation":"In the expression simplifier, try_fold_shift constant-folds shift operations once both operands are known pure numbers (lv << rv etc.). The function is only invoked for the `<<`, `>>`, `>>>` operators and the match lists exactly those three; the `_ => unreachable!` arm can only fire if the caller set and the match set desynchronize — an internal invariant, not a user-input condition.","triggerScenarios":"Internal simplifier bug where the guard selecting try_fold_shift admits an operator outside {<<, >>, >>>}; or calling the private helper directly with another operator in a fork/patch of swc.","commonSituations":"Forks of swc modifying the simplifier; swc_core version regressions after operator-set changes; essentially never from ordinary config or source input.","solutions":["Update to a matching swc_core release (simplifier guards and matches ship together).","If you maintain a fork, keep the operator guard that routes to try_fold_shift in sync with its match arms.","Report with a minimal expression if plain parsed input reproduces it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Only route shift operators if you invoke folding logic yourself\nfn is_shift_op(op: BinaryOp) -> bool { matches!(op, op!(\"<<\") | op!(\">>\") | op!(\">>>\")) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In forks, keep operator guards and match arms in the simplifier in sync.","Don't call private folding helpers directly; go through the public simplify pass.","Update swc_core before assuming a simplifier crash is your bug."],"tags":["swc","optimizer","simplifier","constant-folding","shift-operators","ast-invariant","panic"],"backgroundTag":"compiler-internal-panic","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"}