swc-project/swc · error
failed to parse #[ast_node]
Error message
failed to parse #[ast_node]
What it means
The #[ast_node] proc-macro attribute was applied to a token stream that syn could not parse as a DeriveInput. It fires when the attribute is placed on a non-item (function, module, statement) or on syntactically broken code, since #[ast_node] is only defined for struct/enum type definitions.
Source
Thrown at crates/ast_node/src/lib.rs:174
/// Structs derive `PartialEq` by default. Pass `no_partial_eq` after the node
/// tag when the type provides a manual implementation:
/// `#[ast_node("CustomNode", no_partial_eq)]`.
#[proc_macro_attribute]
pub fn ast_node(
args: proc_macro::TokenStream,
input: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let mut 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(data) => {
use syn::parse::Parser;
let attrs = <syn::punctuated::Punctuated<syn::Ident, syn::Token![,]>>::parse_terminated
.parse(args)
.expect("failed to parse #[ast_node]");
let mut has_no_clone = false;
let mut has_no_unknown = false;
for attr in &attrs {
if attr == "no_clone" {
has_no_clone = true;
} else if attr == "no_unknown" {
has_no_unknown = true;
} else {
panic!("unknown attribute: {attr:?}")
}
}
let clone = if !has_no_clone {
Some(quote!(#[derive(Clone)]))
} else {
None
};View on GitHub (pinned to 5176682b65)
Solutions
- Attach #[ast_node("Tag")] only to struct or enum definitions
- Ensure the annotated item is complete and syntactically valid before expansion
- If another macro emits this item, confirm the emitted tokens form a valid DeriveInput
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/ast_node/src/lib.rs:174 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/03a074bd033c0fdd.
Report an issue: GitHub.