swc-project/swc · error
ToCode for {}
Error message
ToCode for {} What it means
A todo!() stub generated by the fail_todo! macro in swc_ecma_quote_macros (ast/mod.rs:11). For AST node types the quote-strings-to-code machinery has not implemented yet, the macro installs a ToCode impl that panics with 'ToCode for <Type>' when that node is quoted. It fires whenever a quoted expression contains an AST node kind lacking a real ToCode implementation; the node type named in the message is the gap.
Source
Thrown at crates/swc_ecma_quote_macros/src/ast/mod.rs:11
use swc_common::{Span, SyntaxContext};
use swc_ecma_ast::*;
use syn::{parse_quote, ExprBlock};
use crate::ctxt::Ctx;
macro_rules! fail_todo {
($T:ty) => {
impl crate::ast::ToCode for $T {
fn to_code(&self, _: &crate::ctxt::Ctx) -> syn::Expr {
todo!("ToCode for {}", stringify!($T))
}
}
};
}
macro_rules! impl_enum_body {
($E:ident, $s:expr, $cx:expr,[ $($v:ident),* ]) => {
match $s {
$(
$E::$v(inner) => {
let val = crate::ast::ToCode::to_code(inner, $cx);
syn::parse_quote!(
swc_core::ecma::ast::$E::$v(#val)
)
},
)*
#[cfg(swc_ast_unknown)]
_ => panic!("unable to access unknown nodes"),View on GitHub (pinned to 5176682b65)
Solutions
- Implement ToCode for the node type named in the panic message and contribute it upstream
- Avoid quoting that node kind inside the quote macros until support exists
- Check swc release notes — the missing ToCode impl may have been added in a newer version
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at crates/swc_ecma_quote_macros/src/ast/mod.rs:11 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/3ec767715c6761d5.
Report an issue: GitHub.