swc-project/swc · error

failed to parse args of #[ast_serde]

Error message

failed to parse args of #[ast_serde]

What it means

The attribute arguments of #[ast_serde] on a struct (the non-enum arm) failed to parse into ast_node_macro::Args. This fires when the payload inside #[ast_serde(...)] does not match the expected argument grammar — typically a stray, unknown, or malformed option — while enums accept no arguments at all.

Source

Thrown at crates/ast_node/src/lib.rs:119

    // we should use call_site
    let mut item = TokenStream::new();
    match input.data {
        Data::Enum(..) => {
            if !args.is_empty() {
                panic!("#[ast_serde] on enum does not accept any argument")
            }

            item.extend(quote!(
                #[derive(::serde::Serialize, ::swc_common::DeserializeEnum)]
                #[serde(untagged)]
                #input
            ));
        }
        _ => {
            let args: Option<ast_node_macro::Args> = if args.is_empty() {
                None
            } else {
                Some(parse(args).expect("failed to parse args of #[ast_serde]"))
            };

            let serde_tag = match input.data {
                Data::Struct(DataStruct {
                    fields: Fields::Named(..),
                    ..
                }) => {
                    if args.is_some() {
                        Some(quote!(#[serde(tag = "type")]))
                    } else {
                        None
                    }
                }
                _ => None,
            };

            let serde_rename = args.as_ref().map(|args| {
                let name = &args.ty;

View on GitHub (pinned to 5176682b65)

Solutions

  1. Keep only arguments accepted by ast_node_macro::Args inside #[ast_serde(...)]
  2. On enums, remove all arguments entirely — the enum arm rejects any argument
  3. Consult the ast_node crate docs for the supported attribute argument forms
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/ast_node/src/lib.rs:119 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


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