swc-project/swc · error

Babel doesn't support this right now.

Error message

Babel doesn't support this right now.

What it means

When converting SWC AST to Babel/ESTree AST (babelify), Expr::TsInstantiation — a TypeScript 4.7 instantiation expression like `const g = fn<number>;` — has no counterpart modeled in the swc_estree_ast version used here, so the conversion panics with `unimplemented!("Babel doesn't support this right now.")`.

Source

Thrown at crates/swc_estree_compat/src/babelify/expr.rs:142

                ExprOutput::Expr(Box::alloc().init(Expression::Await(a.babelify(ctx))))
            }
            Expr::Paren(p) => {
                ExprOutput::Expr(Box::alloc().init(Expression::Parenthesized(p.babelify(ctx))))
            }
            Expr::JSXElement(e) => {
                ExprOutput::Expr(Box::alloc().init(Expression::JSXElement(e.babelify(ctx))))
            }
            Expr::JSXFragment(f) => {
                ExprOutput::Expr(Box::alloc().init(Expression::JSXFragment(f.babelify(ctx))))
            }
            Expr::TsTypeAssertion(a) => {
                ExprOutput::Expr(Box::alloc().init(Expression::TSTypeAssertion(a.babelify(ctx))))
            }
            Expr::TsNonNull(n) => {
                ExprOutput::Expr(Box::alloc().init(Expression::TSNonNull(n.babelify(ctx))))
            }
            Expr::TsAs(a) => ExprOutput::Expr(Box::alloc().init(Expression::TSAs(a.babelify(ctx)))),
            Expr::TsInstantiation(..) => unimplemented!("Babel doesn't support this right now."),
            Expr::PrivateName(p) => ExprOutput::Private(p.babelify(ctx)),

            // TODO(dwoznicki): how does babel handle these?
            Expr::JSXMember(_) => panic!(
                "illegal conversion: Cannot convert {:?} to ExprOutput - babel has no equivalent",
                &self
            ),
            Expr::JSXNamespacedName(_) => panic!(
                "illegal conversion: Cannot convert {:?} to ExprOutput - babel has no equivalent",
                &self
            ),
            Expr::JSXEmpty(_) => panic!(
                "illegal conversion: Cannot convert {:?} to ExprOutput - babel has no equivalent",
                &self
            ),
            Expr::TsConstAssertion(_) => panic!(
                "illegal conversion: Cannot convert {:?} to ExprOutput - babel has no equivalent",
                &self

View on GitHub (pinned to 5176682b65)

Solutions

  1. Run the TypeScript strip/transform pass (e.g. swc's typescript pass or resolver-mode strip) before babelify so instantiation expressions are erased
  2. Upgrade swc_estree_compat / swc_estree_ast where a TSTypeInstantiation node may exist
  3. Preprocess source to remove instantiation expressions if you control the input

Example fix

// before (input reaching babelify)
const g = Array<number>;

// after (run TS strip first, or write input without instantiation)
const g = Array;
Defensive patterns

Strategy: validation

Validate before calling

// Rust: reject ASTs containing instantiation expressions before babelify
use swc_ecma_visit::{Visit, VisitWith};
struct HasTsInstantiation;
impl Visit for HasTsInstantiation {
    fn visit_ts_instantiation(&mut self, n: &swc_ecma_ast::TsInstantiation) {
        panic!("TsInstantiation at {:?} not babelifiable", n.span);
    }
}

Type guard

// Walk check before conversion
fn babelifiable(program: &swc_ecma_ast::Program) -> bool {
    // after a full typescript-strip pass, no TsInstantiation nodes remain
    !contains_ts_type_nodes(program)
}

Prevention

When it happens

Trigger: Calling babelify on SWC AST that still contains type instantiation expressions, i.e. source using TS instantiation expressions (`const g = Array<number>;`) was parsed and not stripped before the ESTree conversion.

Common situations: Toolchains that parse TypeScript with SWC then hand the AST to Babel-based consumers (codemods, jscodeshift-like tools, babel plugins) without first running the TS-stripping transform; TS 4.7+ codebases.

Related errors


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/8dc74d447b7f265e. Report an issue: GitHub.