swc-project/swc · error

failed to convert `AssignmentExpression` of babel: Unknown a

Error message

failed to convert `AssignmentExpression` of babel: Unknown assignment operator {}

What it means

Raised in `Swcify for AssignmentExpression` (swcify/expr.rs:107). The Babel AST stores the assignment operator as a string; the code parses it into swc's AssignOp. If the operator string is not one that swc_ecma_ast recognizes (a malformed, exotic, or future operator token), the parse fails and the closure panics. The operator string itself is the faulty input.

Source

Thrown at crates/swc_estree_compat/src/swcify/expr.rs:107

impl Swcify for ArrayExpression {
    type Output = ArrayLit;

    fn swcify(self, ctx: &Context) -> Self::Output {
        ArrayLit {
            span: ctx.span(&self.base),
            elems: self.elements.swcify(ctx),
        }
    }
}

impl Swcify for AssignmentExpression {
    type Output = AssignExpr;

    fn swcify(self, ctx: &Context) -> Self::Output {
        AssignExpr {
            span: ctx.span(&self.base),
            op: self.operator.parse().unwrap_or_else(|_| {
                panic!(
                    "failed to convert `AssignmentExpression` of babel: Unknown assignment \
                     operator {}",
                    self.operator,
                )
            }),
            left: self.left.swcify(ctx).try_into().unwrap(),
            right: self.right.swcify(ctx),
        }
    }
}

impl Swcify for BinaryExpression {
    type Output = BinExpr;

    fn swcify(self, ctx: &Context) -> Self::Output {
        BinExpr {
            span: ctx.span(&self.base),
            op: self.operator.swcify(ctx),

View on GitHub (pinned to 5176682b65)

Solutions

  1. Inspect the failing operator string (include it in the panic message) and either extend the parse mapping in swc to accept it or normalize it before swcify
  2. Validate the Babel AST before conversion: verify each AssignmentExpression.operator is a known operator
  3. Fall back to a plain `=` assignment or reject the file with a proper error instead of panicking
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/swc_estree_compat/src/swcify/expr.rs:107 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/612fd4bbc8cc9034. Report an issue: GitHub.