swc-project/swc · error
#[ast_serde] on enum does not accept any argument
Error message
#[ast_serde] on enum does not accept any argument
What it means
Compile-time panic from the `ast_serde` proc-macro attribute in swc's ast_node crate. When `#[ast_serde]` is applied to an enum, the macro only generates `#[derive(Serialize, DeserializeEnum)] #[serde(untagged)]` and rejects any attribute arguments outright; arguments are only parsed (as `ast_node_macro::Args`) for structs. Passing anything on an enum aborts macro expansion.
Source
Thrown at crates/ast_node/src/lib.rs:106
///
/// so the deserializer can decide which variant to use.
///
///
/// `#[tag]` also supports wildcard like `#[tag("*")]`. You can use this if
/// there are two many variants.
#[proc_macro_attribute]
pub fn ast_serde(
args: proc_macro::TokenStream,
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let input: DeriveInput = parse(input).expect("failed to parse input as a DeriveInput");
// 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(..),View on GitHub (pinned to 5176682b65)
Solutions
- Remove all arguments and use a bare `#[ast_serde]` on the enum
- If you need custom serde behavior for the enum, write manual Serialize/Deserialize impls instead of the macro
- Keep struct-only arguments (e.g. field tags) on struct applications only
Example fix
// before
#[ast_serde(tag = "type")]
pub enum Expr {
Num(f64),
}
// after
#[ast_serde]
pub enum Expr {
Num(f64),
} Defensive patterns
Strategy: validation
Prevention
- Keep `#[ast_serde]` argument-free on enums; arguments are struct-only
- Run `cargo check` in CI so macro misuse fails fast at compile time
- Copy attribute usage from crates/ast_node tests rather than from struct invocations
When it happens
Trigger: Writing `#[ast_serde(some_arg)]` or any parenthesized/list argument on an enum item; the enum branch checks `!args.is_empty()` and panics before generating code.
Common situations: Copying a `#[ast_serde(...)]` invocation that was written for a struct onto a new enum; assuming enums and structs share the same argument grammar; upgrading swc_ast_node versions where accepted syntax shifted.
Related errors
- An element descriptor's .kind property must be either "metho
- An element descriptor's .placement property must be one of "
- A class descriptor's .kind property must be "class", but a d
- ${objectType} can't have a .${name} property.
- Expected '${name}' to be a function
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/d74077d7bd3ca772.
Report an issue: GitHub.