{"record":{"id":"03a074bd033c0fdd","repo":"swc-project/swc","slug":"failed-to-parse-ast-node","errorCode":null,"errorMessage":"failed to parse #[ast_node]","messagePattern":"failed to parse #\\[ast_node\\]","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ast_node/src/lib.rs","lineNumber":174,"sourceCode":"/// Structs derive `PartialEq` by default. Pass `no_partial_eq` after the node\n/// tag when the type provides a manual implementation:\n/// `#[ast_node(\"CustomNode\", no_partial_eq)]`.\n#[proc_macro_attribute]\npub fn ast_node(\n    args: proc_macro::TokenStream,\n    input: proc_macro::TokenStream,\n) -> proc_macro::TokenStream {\n    let mut input: DeriveInput = parse(input).expect(\"failed to parse input as a DeriveInput\");\n\n    // we should use call_site\n    let mut item = TokenStream::new();\n    match &input.data {\n        Data::Enum(data) => {\n            use syn::parse::Parser;\n\n            let attrs = <syn::punctuated::Punctuated<syn::Ident, syn::Token![,]>>::parse_terminated\n                .parse(args)\n                .expect(\"failed to parse #[ast_node]\");\n\n            let mut has_no_clone = false;\n            let mut has_no_unknown = false;\n            for attr in &attrs {\n                if attr == \"no_clone\" {\n                    has_no_clone = true;\n                } else if attr == \"no_unknown\" {\n                    has_no_unknown = true;\n                } else {\n                    panic!(\"unknown attribute: {attr:?}\")\n                }\n            }\n\n            let clone = if !has_no_clone {\n                Some(quote!(#[derive(Clone)]))\n            } else {\n                None\n            };","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/ast_node/src/lib.rs#L156-L192","documentation":"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.","triggerScenarios":"Thrown at crates/ast_node/src/lib.rs:174 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}