swc-project/swc · error
failed to parse input as a DeriveInput
Error message
failed to parse input as a DeriveInput
What it means
The #[ast_serde] proc-macro attribute received a token stream that syn could not parse as a DeriveInput. It fires at macro-expansion time when the attribute is applied to something that is not a struct, enum, or union definition (e.g. a fn, mod, or free statement), or when the item's tokens are otherwise malformed, so the macro cannot inspect the type's data to emit serde impls.
Source
Thrown at crates/ast_node/src/lib.rs:99
/// enum Expr {
/// #[tag("StringLiteral")]
/// #[tag("NumericLiteral")]
/// #[tag("BooleanLiteral")]
/// Lit(Lit),
/// }
/// ```
///
/// 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() {
NoneView on GitHub (pinned to 5176682b65)
Solutions
- Apply #[ast_serde] only to struct, enum, or union definitions
- Check that the annotated item is complete and syntactically valid
- If the item is generated by another macro, verify the generated tokens form a valid DeriveInput
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/ast_node/src/lib.rs:99 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/ed277823fbfe7bd4.
Report an issue: GitHub.