swc-project/swc · error

failed to parse #[tag] attribute

Error message

failed to parse #[tag] attribute

What it means

Compile-time panic in the ast_node enum-deserialize derive: a #[tag(...)] attribute on a variant could not be parsed into a VariantAttr (malformed token stream in the attribute meta), so derive expansion aborts with this expect.

Source

Thrown at crates/ast_node/src/enum_deserialize.rs:68

                    }
                    _ => {
                        unreachable!("#[ast_node] enum cannot contain named fields or unit variant")
                    }
                };
                let tags = variant
                    .attrs
                    .iter()
                    .filter_map(|attr| -> Option<VariantAttr> {
                        if !is_attr_name(attr, "tag") {
                            return None;
                        }
                        let tokens = match &attr.meta {
                            Meta::List(meta) => meta.tokens.clone(),
                            _ => {
                                panic!("#[tag] attribute must be in form of #[tag(..)]")
                            }
                        };
                        let tags = parse2(tokens).expect("failed to parse #[tag] attribute");

                        Some(tags)
                    })
                    .flat_map(|v| v.tags)
                    .collect::<Punctuated<_, token::Comma>>();

                assert!(
                    !tags.is_empty(),
                    "All #[ast_node] enum variants have one or more tag"
                );

                // TODO: Clean up this code
                if tags.len() == 1
                    && match tags.first() {
                        Some(Lit::Str(s)) => &*s.value() == "*",
                        _ => false,
                    }
                {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Write the #[tag] attribute in the exact form the derive expects (e.g. #[tag("Name")])
  2. Remove the malformed attribute
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/ast_node/src/enum_deserialize.rs:68 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/87763c6a24180229. Report an issue: GitHub.