swc-project/swc · error

swc does not support throw expressions

Error message

swc does not support throw expressions

What it means

Raised in `Swcify for UnaryExprOp` (swcify/expr.rs:595). Babel's AST can represent the stage-1 `throw` expression via a UnaryExpr operator, but swc's UnaryOp has no `throw` variant because the proposal was abandoned and never shipped in ECMAScript. Converting such a UnaryExpr to swc is therefore impossible, and the code panics when it encounters UnaryExprOp::Throw. The unsupported Throw operator is the input at fault.

Source

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

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

impl Swcify for UnaryExprOp {
    type Output = UnaryOp;

    fn swcify(self, _: &Context) -> Self::Output {
        match self {
            UnaryExprOp::Void => {
                op!("void")
            }
            UnaryExprOp::Throw => {
                panic!("swc does not support throw expressions")
            }
            UnaryExprOp::Delete => {
                op!("delete")
            }
            UnaryExprOp::LogicalNot => {
                op!("!")
            }
            UnaryExprOp::Plus => {
                op!(unary, "+")
            }
            UnaryExprOp::Negation => {
                op!(unary, "-")
            }
            UnaryExprOp::BitwiseNot => {
                op!("~")
            }
            UnaryExprOp::Typeof => {
                op!("typeof")

View on GitHub (pinned to 5176682b65)

Solutions

  1. Reject inputs containing throw expressions before conversion with an explicit 'throw expressions are not supported' error
  2. Strip or transform throw expressions in a preprocessing pass if the surrounding tooling can tolerate dropping them
  3. Do not feed Babel ASTs produced with throw-expression syntax enabled into the swcify path
Defensive patterns

Strategy: fallback

When it happens

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