swc-project/swc · error

flow

Error message

flow

What it means

swcify for the estree DeclareClass node (Flow ambient `declare class C { ... }` statements) is declared but unimplemented — it panics with `unimplemented!("flow")`. SWC has no Flow declaration nodes; ambient declarations would need hand-translation into TS declaration syntax, which this crate never implemented.

Solutions

  1. Strip Flow declarations before conversion (flow-strip-types drops declare statements in implementation mode)
  2. Filter out DeclareClass nodes in a pre-pass if the declarations are not needed for output
  3. Parse with TypeScript mode if the source is actually TS ambient declarations

Example fix

// before
declare class Point { x: number; y: number; }

// after (after flow-strip-types with declarations dropped, or hand-translated)
// (declaration removed from implementation output)
Defensive patterns

Strategy: validation

Validate before calling

// Node: reject Flow declare nodes before swcify
const FLOW_DECLARE = new Set(['DeclareClass','DeclareFunction','DeclareInterface','DeclareModule','DeclareModuleExports','DeclareTypeAlias','DeclareVariable','DeclareExportDeclaration']);
function containsFlowDeclares(node) {
  return FLOW_DECLARE.has(node.type)
    || Object.values(node).some(v => v && typeof v === 'object' && containsFlowDeclares(v));
}

Type guard

function isFlowDeclareNode(node) {
  return node.type.startsWith('Declare');
}

Prevention

When it happens

Trigger: Converting a Babel AST parsed in Flow mode that contains `declare class Foo { ... }` ambient class declarations (typical in .js.flow library files) via swc_estree_compat's swcify.

Common situations: Migrating Flow-typed libraries or React Native 0.x sources to SWC-based pipelines; consuming .flow definition files through Babel interop.

Related errors


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

Appendix: source

Thrown at crates/swc_estree_compat/src/swcify/stmt.rs:730

    }
}

impl Swcify for ImportNamespaceSpecifier {
    type Output = ImportStarAsSpecifier;

    fn swcify(self, ctx: &Context) -> Self::Output {
        ImportStarAsSpecifier {
            span: ctx.span(&self.base),
            local: self.local.swcify(ctx).into(),
        }
    }
}

impl Swcify for DeclareClass {
    type Output = ClassDecl;

    fn swcify(self, _: &Context) -> Self::Output {
        unimplemented!("flow")
    }
}

impl Swcify for DeclareFunction {
    type Output = FnDecl;

    fn swcify(self, _: &Context) -> Self::Output {
        unimplemented!("flow")
    }
}

impl Swcify for DeclareInterface {
    type Output = TsInterfaceDecl;

    fn swcify(self, _: &Context) -> Self::Output {
        unimplemented!("flow")
    }
}

View on GitHub (pinned to 5176682b65)