swc-project/swc · error
unknown binary operator: {:?}
Error message
unknown binary operator: {:?} What it means
perform_arithmetic_op in the simplifier constant-folds bitwise/modulo arithmetic once both sides are Known values. It matches exactly `&`, `|`, `^`, `%`; any other operator reaching the final match trips this unreachable!. Like its shift sibling, the guard upstream is supposed to only route those four operators here.
Source
Thrown at crates/swc_ecma_transforms_optimization/src/simplify/expr/mod.rs:1580
let result: f64 = js_lv.pow(js_rv).into();
return try_replace(lv, rv, result);
}
return Unknown;
}
_ => {}
}
let (lv, rv) = match (lv, rv) {
(Known(lv), Known(rv)) => (lv, rv),
_ => return Unknown,
};
match op {
op!("&") => try_replace_i32(lv, rv, to_int32(lv) & to_int32(rv)),
op!("|") => try_replace_i32(lv, rv, to_int32(lv) | to_int32(rv)),
op!("^") => try_replace_i32(lv, rv, to_int32(lv) ^ to_int32(rv)),
op!("%") => try_replace(lv, rv, lv % rv),
_ => unreachable!("unknown binary operator: {:?}", op),
}
}
/// This actually performs `<`.
///
/// https://tc39.github.io/ecma262/#sec-abstract-relational-comparison
fn perform_abstract_rel_cmp(
expr_ctx: ExprCtx,
left: &Expr,
right: &Expr,
will_negate: bool,
) -> Value<bool> {
match (left, right) {
// Special case: `x < x` is always false.
(
&Expr::Ident(
Ident {
sym: ref li,View on GitHub (pinned to 5176682b65)
Solutions
- Align swc crates on one swc_core version and update — the routing guards and matches are versioned together.
- In forks, keep the caller's operator filter consistent with this match.
- File an swc issue with the expression if stock swc reproduces it.
Defensive patterns
Strategy: validation
Validate before calling
fn is_arithmetic_fold_op(op: BinaryOp) -> bool {
matches!(op, op!("&") | op!("|") | op!("^") | op!("%"))
} Prevention
- Route only &, |, ^, % into arithmetic folding in patched forks.
- Reproduce simplifier panics on the latest swc_core before investigating locally.
- Treat unreachable! in the optimizer as an upstream bug report, not a config problem.
When it happens
Trigger: An swc internal bug where the simplifier routes an unsupported binary operator into perform_arithmetic_op, or a fork calling this internal function with an arbitrary op.
Common situations: Forked/patched simplifiers; version skew inside swc crates; not reachable through public config on released versions.
Related errors
- Unknown bit operator {:?}
- unknown compound assignment operator
- getter/setter property be compiled as CompiledProp::Accessor
- jsonify: Expr {:?} cannot be converted to json
- multiple constructor?
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/5802af23a664df6f.
Report an issue: GitHub.