{"record":{"id":"96d75868fc46cc22","repo":"swc-project/swc","slug":"illegal-conversion-cannot-convert-to-objectk","errorCode":null,"errorMessage":"illegal conversion: Cannot convert {:?} to ObjectKey - babel has no equivalent","messagePattern":"illegal conversion: Cannot convert (.+?) to ObjectKey - babel has no equivalent","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_estree_compat/src/babelify/expr.rs","lineNumber":210,"sourceCode":"impl From<ExprOutput> for BinaryExprLeft {\n    fn from(o: ExprOutput) -> Self {\n        match o {\n            ExprOutput::Expr(e) => BinaryExprLeft::Expr(e),\n            ExprOutput::Private(p) => BinaryExprLeft::Private(p),\n        }\n    }\n}\n\nimpl From<ExprOutput> for ObjectKey {\n    fn from(o: ExprOutput) -> Self {\n        match o {\n            ExprOutput::Expr(e) => match *e {\n                Expression::Id(i) => ObjectKey::Id(i),\n                Expression::Literal(Literal::String(s)) => ObjectKey::String(s),\n                Expression::Literal(Literal::Numeric(n)) => ObjectKey::Numeric(n),\n                _ => ObjectKey::Expr(e),\n            },\n            ExprOutput::Private(_) => panic!(\n                \"illegal conversion: Cannot convert {:?} to ObjectKey - babel has no equivalent\",\n                &o\n            ),\n        }\n    }\n}\n\nimpl From<ExprOutput> for MemberExprProp {\n    fn from(o: ExprOutput) -> Self {\n        match o {\n            ExprOutput::Private(p) => MemberExprProp::PrivateName(p),\n            ExprOutput::Expr(e) => match *e {\n                Expression::Id(i) => MemberExprProp::Id(i),\n                _ => MemberExprProp::Expr(e),\n            },\n        }\n    }\n}","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_estree_compat/src/babelify/expr.rs#L192-L228","documentation":"When an expression babelify result is converted into an object key (From<ExprOutput> for ObjectKey, expr.rs:193-206), a PrivateName result panics: Babel's ObjectMember key types (Id/String/Numeric/Expression) have no PrivateName form. Object keys are exactly where a `#x` computed-key misuse surfaces.","triggerScenarios":"Babelifying an AST where a PrivateName was used as an object key — e.g. `{ [#x]: 1 }` from a permissive parser or plugin-built AST (the SWC parser rejects private names there).","commonSituations":"Plugins copying class member names into object literals; AST fixtures for private members.","solutions":["Use a plain identifier or string for the object key instead of a private name.","Fix the producer that placed a PrivateName into a key position.","Add a pre-scan for PrivateName nodes reaching key conversions."],"exampleFix":"// before\n{ [#x]: 1 }\n\n// after\n{ [\"#x\"]: 1 } // or a normal identifier key","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn has_private_object_key(program: &Program) -> bool {\n    struct Scan(bool);\n    impl Visit for Scan {\n        fn visit_prop(&mut self, p: &Prop) {\n            if let Prop::KeyValue(kv) = p {\n                if let PropName::Computed(c) = &kv.key {\n                    if matches!(&*c.expr, Expr::PrivateName(_)) { self.0 = true; }\n                }\n            }\n            p.visit_children_with(self);\n        }\n    }\n    let mut s = Scan(false);\n    program.visit_with(&mut s);\n    s.0\n}","tryCatchPattern":null,"preventionTips":["Never use `#x` as an object key; use a plain identifier or string.","Codemods copying class member names into objects must stringify private names.","Include private-class-member fixtures in converter tests."],"tags":["swc","estree","babelify","private-name","object-literal","panic"],"backgroundTag":"ast-conversion-unsupported-node","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}