{"record":{"id":"b4baf577e82af1ba","repo":"swc-project/swc","slug":"illegal-conversion-cannot-convert-to-assignm","errorCode":null,"errorMessage":"illegal conversion: Cannot convert {:?} to AssignmentPatternLeft","messagePattern":"illegal conversion: Cannot convert (.+?) to AssignmentPatternLeft","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_estree_compat/src/babelify/pat.rs","lineNumber":107,"sourceCode":"            PatOutput::Id(i) => PatternLike::Id(i),\n            PatOutput::Array(a) => PatternLike::ArrayPat(a),\n            PatOutput::Rest(r) => PatternLike::RestEl(r),\n            PatOutput::Object(o) => PatternLike::ObjectPat(o),\n            PatOutput::Assign(a) => PatternLike::AssignmentPat(a),\n            PatOutput::Expr(_) => panic!(\"illegal conversion: Cannot convert {:?} to LVal\", &pat),\n        }\n    }\n}\n\nimpl From<PatOutput> for AssignmentPatternLeft {\n    fn from(pat: PatOutput) -> Self {\n        match pat {\n            PatOutput::Id(i) => AssignmentPatternLeft::Id(i),\n            PatOutput::Array(a) => AssignmentPatternLeft::Array(a),\n            PatOutput::Object(o) => AssignmentPatternLeft::Object(o),\n            PatOutput::Expr(expr) => match *expr {\n                Expression::Member(e) => AssignmentPatternLeft::Member(e),\n                _ => panic!(\n                    \"illegal conversion: Cannot convert {:?} to AssignmentPatternLeft\",\n                    &expr\n                ),\n            },\n            PatOutput::Rest(_) => panic!(\n                \"illegal conversion: Cannot convert {:?} to AssignmentPatternLeft\",\n                &pat\n            ),\n            PatOutput::Assign(_) => panic!(\n                \"illegal conversion: Cannot convert {:?} to AssignmentPatternLeft\",\n                &pat\n            ),\n        }\n    }\n}\n\nimpl From<PatOutput> for Param {\n    fn from(pat: PatOutput) -> Self {","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_estree_compat/src/babelify/pat.rs#L89-L125","documentation":"The left side of a default value (`AssignPat`, e.g. `a = 1` inside destructuring) maps to Babel's AssignmentPatternLeft, which accepts Id/Array/Object/Member only. A `PatOutput::Expr` that is not a member expression — e.g. `(a || b) = init` — has no legal ESTree shape, so this branch of the inner match panics.","triggerScenarios":"Recovered or synthetic destructuring where an expression pattern wraps a non-member expression in a default-value slot: `[(a + b) = 2] = xs`, `({ x: (f()) = 0 } = o)`; converted via `left: self.left.babelify(ctx).into()` at pat.rs:235.","commonSituations":"Error-recovered parses of typo'd defaults; codemods generating defaults programmatically; ASTs hand-built for tests.","solutions":["Validate that AssignPat.left, when it is Pat::Expr, wraps a MemberExpr before babelify","Fix the malformed default-value syntax in the source","In transforms, only attach defaults to Id/Array/Object/Member targets","Return a diagnostic instead of converting when validation fails"],"exampleFix":"// before\nlet estree = module.babelify(); // panics on `[(a + b) = 2] = xs`\n\n// after\nif module.has_invalid_default_targets() {\n    return Err(anyhow!(\"invalid default-value target\"));\n}\nlet estree = module.babelify();","handlingStrategy":"type-guard","validationCode":"use swc_ecma_ast::{AssignPat, Expr, Pat};\n\nfn default_target_ok(left: &Pat) -> bool {\n    match left {\n        Pat::Ident(_) | Pat::Array(_) | Pat::Object(_) => true,\n        Pat::Expr(e) => matches!(&**e, Expr::Member(_)),\n        _ => false,\n    }\n}\n\nfn defaults_ok(p: &AssignPat) -> bool { default_target_ok(&p.left) }","typeGuard":"fn assign_pat_left_ok(p: &AssignPat) -> bool {\n    match &*p.left {\n        Pat::Ident(_) | Pat::Array(_) | Pat::Object(_) => true,\n        Pat::Expr(e) => matches!(&**e, Expr::Member(_)),\n        _ => false,\n    }\n}","tryCatchPattern":"use std::panic::{catch_unwind, AssertUnwindSafe};\n\ncatch_unwind(AssertUnwindSafe(|| program.babelify()))\n    .map_err(|_| anyhow!(\"invalid default-value target\"))?;","preventionTips":["Attach defaults only to Id/Array/Object/Member targets in generated ASTs","Validate nested destructuring before conversion when input came from recovery","Add tests with `[(a + b) = 2] = xs` to confirm your tool rejects it"],"tags":["rust","swc","babelify","destructuring","default-value","parser-error-recovery","panic"],"backgroundTag":"unsupported-ast-conversion","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}