swc-project/swc · error
failed to parse input as an item
Error message
failed to parse input as an item
What it means
The #[node_impl] proc-macro in swc_ecma_codegen_macros requires its input to be an impl block; this fires when syn cannot parse the attached item as an ItemImpl — e.g. the attribute is applied to a non-impl item (fn, struct, mod) or the impl block is syntactically malformed, during codegen macro expansion.
Source
Thrown at crates/swc_ecma_codegen_macros/src/lib.rs:39
/// ParamOrTsParamProp::TsParamProp(n) => emit!(n),
/// }
/// }
/// }
/// ```
///
///
/// ## `emit!()`.
///
/// `emit!()` macro in `#[node_impl]` functions are special.
///
/// Those are replaced with `emit_with` and `adjust_span` methods, depending on
/// the context.
#[proc_macro_attribute]
pub fn node_impl(
_attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let item: ItemImpl = syn::parse(item).expect("failed to parse input as an item");
let mut output = TokenStream::new();
for i in item.items {
match i {
ImplItem::Fn(i) => {
let item = expand_node_impl_method(&item.self_ty, i);
output.extend(item.to_token_stream());
}
_ => {
panic!("Unexpected item: {i:?}");
}
}
}
output.into()View on GitHub (pinned to 5176682b65)
Solutions
- Apply #[node_impl] only to `impl` blocks
- Ensure the impl block is complete and syntactically valid
- If another macro generates the impl, verify the generated tokens form a valid ItemImpl
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_ecma_codegen_macros/src/lib.rs:39 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/d6f8a5ba9634b759.
Report an issue: GitHub.