swc-project/swc · error

right-associative binary expression

Error message

right-associative binary expression

What it means

This is a Rust todo!() panic in the ES2015 generator-lowering pass (swc_ecma_compat_es2015). While rewriting a function containing yield into a state machine, the transform special-cases binary expressions: left-associative operators are lowered via visit_left_associative_bin_expr, but the exponentiation operator ** is right-associative and its lowering logic has not been implemented yet, so hitting a ** expression inside a generator function aborts compilation with an 'internal error: entered unreachable code' style panic. The input at fault is any `a ** b` (or nested `a ** b ** c`) expression occurring within a generator function body that this compat pass is processing.

Source

Thrown at crates/swc_ecma_compat_es2015/src/generator.rs:506

                    let alt_span = node.cons.span();
                    node.alt.visit_mut_with(self);
                    self.emit_assignment(
                        result_local.clone().into(),
                        node.alt.take(),
                        Some(alt_span),
                    );

                    self.mark_label(result_label);

                    *e = result_local.into();
                } else {
                    node.visit_mut_with(self);
                }
            }

            Expr::Bin(node) => {
                if node.op == op!("**") {
                    todo!("right-associative binary expression")
                } else {
                    let new = self.visit_left_associative_bin_expr(node);
                    if let Some(new) = new {
                        *e = new;
                    }
                }
            }

            Expr::Seq(node) => {
                //     // flattened version of `visitCommaExpression`
                let mut pending_expressions = Vec::new();

                for mut elem in node.exprs.take() {
                    if let Expr::Seq(mut elem) = *elem {
                        elem.visit_mut_with(self);
                        pending_expressions.extend(elem.exprs.take());
                    } else {
                        if contains_yield(&elem) && !pending_expressions.is_empty() {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Rewrite the generator to compute the exponentiation with Math.pow(a, b) instead of the ** operator, so the transform never encounters a right-associative BinExpr
  2. Move the ** expression out of the generator function into a separate (non-generator) helper that is called from the generator
  3. Run the swc_exponentiation_operator (ES2016) transform before the ES2015 generator pass so ** is already rewritten to Math.pow by the time generator lowering runs
  4. If you control the compiler configuration, ensure the correct ordering of compat passes (exponentiation before generators) in the SWC pass pipeline
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/swc_ecma_compat_es2015/src/generator.rs:506 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/ab2a710bdeba7582. Report an issue: GitHub.