swc-project/swc · error
Type of node parameter should be reference but got {}
Error message
Type of node parameter should be reference but got {} What it means
A compile-time macro validation panic in `expand` of swc_xml_codegen_macros (lib.rs:40). The #[emitter] macro requires its annotated method's second parameter (the node) to be a reference type; the macro strips the `&` and checks the remaining type. This panic fires when that parameter is not a `Type::Reference`, i.e. the user declared the emit_ method taking the node by value or with some other non-reference type. The offending parameter type in the macro input is the input at fault.
Source
Thrown at crates/swc_xml_codegen_macros/src/lib.rs:40
format!("{}", i.sig.ident).starts_with("emit_"),
"#[emitter] methods should start with `emit_`"
);
let block = {
let node_type = {
i.sig
.inputs
.clone()
.into_iter()
.nth(1)
.and_then(|arg| match arg {
FnArg::Typed(ty) => Some(ty.ty),
_ => None,
})
.map(|ty| {
// &Ident -> Ident
match *ty {
Type::Reference(TypeReference { elem, .. }) => *elem,
_ => panic!(
"Type of node parameter should be reference but got {}",
ty.into_token_stream()
),
}
})
.expect(
"#[emitter] methods should have signature of
fn (&mut self, node: Node) -> Result;
",
)
};
let block = &i.block;
parse_quote!({
impl<W> crate::Emit<#node_type> for crate::CodeGenerator<'_, W>
where W: crate::writer::XmlWriter,
{
fn emit(&mut self, n: &#node_type) -> crate::Result {View on GitHub (pinned to 5176682b65)
Solutions
- Change the #[emitter] method signature so the node parameter is a reference, e.g. `fn emit_ident(&mut self, node: &Ident)`
- Add a clearer compile_error! that names the offending method and the expected signature
- Document the required parameter shape near the #[emitter] macro definition
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_xml_codegen_macros/src/lib.rs:40 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/3cda1a8ab93aef9c.
Report an issue: GitHub.