swc-project/swc · error

codegen of `export default from 'foo';`

Error message

codegen of `export default from 'foo';`

What it means

The code generator hit ExportSpecifier::Default, the AST node produced by non-standard `export default from '...'` syntax, and deliberately panics via unimplemented! because no JS output is implemented for that variant. It fires whenever such a specifier reaches emit — the input reached the parser but the codegen pass has no lowering for it.

Solutions

  1. Guard against ExportSpecifier::Default before emitting and lower it to a form codegen supports (e.g. a named re-export of the default binding)
  2. Avoid source syntax that produces `export default from ...` until codegen support lands
  3. Implement the emit arm for ExportSpecifier::Default in swc_ecma_codegen
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/swc_ecma_codegen/src/module_decls.rs:263 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/b0dceeeaa11de852. Report an issue: GitHub.

Appendix: source

Thrown at crates/swc_ecma_codegen/src/module_decls.rs:263

            space!(emitter);
            keyword!(emitter, "as");
            space!(emitter);
        }

        emit!(self.local);

        srcmap!(emitter, self, false);

        Ok(())
    }
}

#[node_impl]
impl MacroNode for ExportSpecifier {
    fn emit(&mut self, emitter: &mut Macro) -> Result {
        match self {
            ExportSpecifier::Default(..) => {
                unimplemented!("codegen of `export default from 'foo';`")
            }
            ExportSpecifier::Namespace(ref node) => emit!(node),
            ExportSpecifier::Named(ref node) => emit!(node),
            #[cfg(swc_ast_unknown)]
            _ => return Err(unknown_error()),
        }

        Ok(())
    }
}

#[node_impl]
impl MacroNode for ExportNamespaceSpecifier {
    fn emit(&mut self, emitter: &mut Macro) -> Result {
        emitter.emit_leading_comments_of_span(self.span(), false)?;

        srcmap!(emitter, self, true);

View on GitHub (pinned to 5176682b65)