{"record":{"id":"60fb012f9661fc6e","repo":"swc-project/swc","slug":"illegal-conversion-cannot-convert-to-objectk-60fb01","errorCode":null,"errorMessage":"illegal conversion: Cannot convert {:?} to ObjectKey","messagePattern":"illegal conversion: Cannot convert (.+?) to ObjectKey","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_estree_compat/src/babelify/prop.rs","lineNumber":129,"sourceCode":"\nimpl Babelify for MethodProp {\n    type Output = ObjectMethod;\n\n    fn babelify(self, ctx: &Context) -> Self::Output {\n        babelify_object_method(self.key, self.function, ObjectMethodKind::Method, ctx)\n    }\n}\n\nimpl Babelify for PropName {\n    type Output = ObjectKey;\n\n    fn babelify(self, ctx: &Context) -> Self::Output {\n        match self {\n            PropName::Ident(i) => ObjectKey::Id(i.babelify(ctx)),\n            PropName::Str(s) => ObjectKey::String(s.babelify(ctx)),\n            PropName::Num(n) => ObjectKey::Numeric(n.babelify(ctx)),\n            PropName::Computed(e) => ObjectKey::Expr(Box::alloc().init(e.babelify(ctx))),\n            _ => panic!(\n                \"illegal conversion: Cannot convert {:?} to ObjectKey\",\n                &self\n            ),\n        }\n    }\n}\n\nimpl Babelify for ComputedPropName {\n    type Output = Expression;\n\n    fn babelify(self, ctx: &Context) -> Self::Output {\n        self.expr.babelify(ctx).into()\n    }\n}\n","sourceCodeStart":111,"sourceCodeEnd":144,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_estree_compat/src/babelify/prop.rs#L111-L144","documentation":"babelify maps PropName to Babel ObjectKey for Ident, Str, Num and Computed — but `PropName::BigInt` has no arm, so an object literal with a BigInt property key panics. This is reachable with plain, valid JavaScript (`({ 100n: 1 })`); Babel itself represents such keys as string keys. The `_` also catches unknown variants under `swc_ast_unknown` builds.","triggerScenarios":"Babelify source containing a BigInt literal in property-key position: `({ 100n: 1 })`, `{ 0b1101n: v }`, `{ 0x1fn: v }` — no special feature flags or error recovery needed.","commonSituations":"Codebases using BigInt keys for bitmask/hash tables; snapshot or AST-viewer tools that babelify arbitrary fixture corpora; upgrading swc without checking estree-compat coverage for newer syntax.","solutions":["Upgrade swc_estree_compat; check the changelog for a BigInt PropName -> ObjectKey mapping and pick a release that includes it","Preprocess: rewrite `PropName::BigInt` into a string or computed key with a VisitMut pass before babelify","Reject inputs containing BigInt property keys until your swc version covers them","Patch prop.rs to map PropName::BigInt to a StringLiteral key the way Babel does, and upstream it"],"exampleFix":"// before (crates/swc_estree_compat/src/babelify/prop.rs)\nPropName::Computed(e) => ObjectKey::Expr(Box::alloc().init(e.babelify(ctx))),\n_ => panic!(\"illegal conversion: Cannot convert {:?} to ObjectKey\", &self),\n\n// after - map BigInt keys like Babel (string key)\nPropName::BigInt(b) => ObjectKey::String(Str {\n    span: b.span,\n    value: b.value.to_string().into(),\n    raw: None,\n}.babelify(ctx)),","handlingStrategy":"validation","validationCode":"use swc_ecma_ast::{Module, PropName};\nuse swc_ecma_visit::{Visit, VisitWith};\n\n#[derive(Default)]\nstruct BigIntKeys(Vec<swc_common::Span>);\n\nimpl Visit for BigIntKeys {\n    fn visit_prop_name(&mut self, n: &PropName) {\n        if let PropName::BigInt(b) = n { self.0.push(b.span); }\n        n.visit_children_with(self);\n    }\n}\n\nfn has_bigint_keys(m: &Module) -> bool {\n    let mut v = BigIntKeys::default();\n    m.visit_with(&mut v);\n    !v.0.is_empty()\n}","typeGuard":"fn prop_name_convertible(n: &PropName) -> bool {\n    !matches!(n, PropName::BigInt(_))\n}","tryCatchPattern":"use std::panic::{catch_unwind, AssertUnwindSafe};\n\ncatch_unwind(AssertUnwindSafe(|| program.babelify()))\n    .map_err(|_| anyhow!(\"BigInt property key is not mapped by this swc_estree_compat version\"))?;","preventionTips":["Grep inputs for BigInt keys (`/[0-9][0-9a-fx]*n\\s*:/`) or scan the AST before babelify on affected versions","Upgrade swc_estree_compat together with swc_ecma_ast on every bump","Include BigInt-keyed objects in your fixture corpus so coverage gaps surface in CI","Watch swc changelogs for estree-compat fixes before adopting new syntax"],"tags":["rust","swc","babelify","bigint","object-literal","property-key","panic"],"backgroundTag":"unsupported-ast-conversion","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}