swc-project/swc · error

Unknown suffix

Error message

Unknown suffix `{}`

What it means

Internal panic inside the #[parallel] proc macro's node_type() helper, which maps a method suffix to the AST node type it traverses. Only "module_items" (-> ModuleItem) and "stmts" (-> Stmt) are mapped; the expand() function itself only ever generates those two, so end users cannot trigger this through normal attribute usage.

Solutions

  1. If extending the macro, add a match arm mapping the new suffix to its node type, e.g. `"exprs" => parse_quote!(Expr)`
  2. Downstream users hitting this should pin/upgrade to an unmodified release of swc_ecma_transforms_macros
  3. Check the macro invocation only uses supported entry points (module_items/stmts methods)

Example fix

// before (crates/swc_ecma_transforms_macros/src/parallel.rs)
fn node_type(suffix: &str) -> Type {
    match suffix {
        "module_items" => parse_quote!(ModuleItem),
        "stmts" => parse_quote!(Stmt),
        _ => unimplemented!("Unknown suffix `{}`", suffix),
    }
}

// after
fn node_type(suffix: &str) -> Type {
    match suffix {
        "module_items" => parse_quote!(ModuleItem),
        "stmts" => parse_quote!(Stmt),
        "exprs" => parse_quote!(Expr),
        _ => unimplemented!("Unknown suffix `{}`", suffix),
    }
}
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Only reachable by modifying swc_ecma_transforms_macros itself: adding a make_par_visit_method call with a new suffix (e.g. "exprs") without extending node_type()'s match arms.

Common situations: Contributing a new parallel traversal method to the swc macro crate and forgetting to register the suffix-to-type mapping in node_type().

Related errors


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

Appendix: source

Thrown at crates/swc_ecma_transforms_macros/src/parallel.rs:45

        .unwrap_or(false);

    item.items.push(ImplItem::Fn(make_par_visit_method(
        mode,
        "module_items",
        explode,
    )));
    item.items
        .push(ImplItem::Fn(make_par_visit_method(mode, "stmts", explode)));

    item
}

fn node_type(suffix: &str) -> Type {
    match suffix {
        "module_items" => parse_quote!(ModuleItem),
        "stmts" => parse_quote!(Stmt),
        _ => {
            unimplemented!("Unknown suffix `{}`", suffix)
        }
    }
}

fn post_visit_hook(mode: Mode, suffix: &str) -> Option<Expr> {
    match suffix {
        "module_items" => Some(match mode {
            Mode::Fold => parse_quote!(
                swc_ecma_transforms_base::perf::Parallel::after_module_items(self, &mut nodes)
            ),

            Mode::VisitMut => parse_quote!(
                swc_ecma_transforms_base::perf::Parallel::after_module_items(self, nodes)
            ),
        }),
        "stmts" => Some(match mode {
            Mode::Fold => parse_quote!(swc_ecma_transforms_base::perf::Parallel::after_stmts(
                self, &mut nodes

View on GitHub (pinned to 5176682b65)