{"record":{"id":"887f97b649b5538c","repo":"swc-project/swc","slug":"assignment-property-be-removed-before-generator-pa","errorCode":null,"errorMessage":"assignment property be removed before generator pass","messagePattern":"assignment property be removed before generator pass","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_compat_es2015/src/generator.rs","lineNumber":1326,"sourceCode":"                    }\n                    .into(),\n                    right: p.into(),\n                }\n                .into(),\n                Prop::KeyValue(p) => AssignExpr {\n                    span: DUMMY_SP,\n                    op: op!(\"=\"),\n                    left: MemberExpr {\n                        span: DUMMY_SP,\n                        obj: temp.clone().into(),\n                        prop: p.key.into(),\n                    }\n                    .into(),\n                    right: p.value,\n                }\n                .into(),\n                Prop::Assign(_) => {\n                    unreachable!(\"assignment property be removed before generator pass\")\n                }\n                Prop::Getter(_) | Prop::Setter(_) => {\n                    unreachable!(\"getter/setter property be compiled as CompiledProp::Accessor\")\n                }\n                Prop::Method(p) => AssignExpr {\n                    span: DUMMY_SP,\n                    op: op!(\"=\"),\n                    left: MemberExpr {\n                        span: DUMMY_SP,\n                        obj: temp.clone().into(),\n                        prop: p.key.into(),\n                    }\n                    .into(),\n                    right: p.function.into(),\n                }\n                .into(),\n                #[cfg(swc_ast_unknown)]\n                _ => panic!(\"unable to access unknown nodes\"),","sourceCodeStart":1308,"sourceCodeEnd":1344,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_compat_es2015/src/generator.rs#L1308-L1344","documentation":"While emitting assignments for object-literal properties inside a converted generator, the generator pass handles KeyValue and Method props but treats Prop::Assign as impossible. Prop::Assign (`{a}` shorthand-assign / `{a = 1}` cover grammar) only exists in destructuring patterns; in a plain object literal expression it is invalid JavaScript, and the destructuring pass is expected to have normalized any pattern context away before the generator pass.","triggerScenarios":"Feeding the generator transform an object expression containing Prop::Assign nodes — i.e. an invalid AST produced by a custom transform/codemod that reused pattern nodes as object literals, or a pipeline where the es2015 destructuring normalization did not run.","commonSituations":"Codemods converting destructuring patterns into object expressions; hand-built ASTs in tests or FFI; lenient/older parsers emitting cover-grammar nodes in expression position.","solutions":["Fix the producer of the AST: rewrite Prop::Assign into Prop::KeyValue (and shorthand `{a}` into `{a: a}`) before generator lowering.","If the input is source text, it is invalid JS (`({a = 1})` as an expression) — correct the source or run the standard compat chain which destructures patterns first.","Report an swc bug if plain parsed source reproduces it."],"exampleFix":"// before: pattern cover-grammar node in expression position (invalid)\n// ast: ObjectLit { props: [Prop::Assign { key: a, value: Some(1) }] }\n\n// after: normalized key/value property\n// ast: ObjectLit { props: [Prop::KeyValue { key: a, value: 1 }] }\n// source equivalent: ({ a: 1 })","handlingStrategy":"validation","validationCode":"// Object literals in expression position must not contain Prop::Assign\nuse swc_ecma_ast::*; use swc_ecma_visit::{Visit, VisitWith};\nstruct AssignPropScan(bool); impl Visit for AssignPropScan {\n    fn visit_prop(&mut self, p: &Prop) {\n        self.0 |= matches!(p, Prop::Assign(_));\n        p.visit_children_with(self);\n    }\n}\n// scan program; if true, normalize Prop::Assign -> Prop::KeyValue first","typeGuard":"fn is_valid_object_expr(o: &ObjectLit) -> bool {\n    o.props.iter().all(|p| !matches!(p, PropOrSpread::Prop(p) if matches!(**p, Prop::Assign(_))))\n}","tryCatchPattern":null,"preventionTips":["When converting patterns to object literals, always emit KeyValue props.","Remember `{a = 1}` is only valid inside destructuring patterns.","Validate foreign ASTs before feeding them to compat passes."],"tags":["swc","compat-es2015","generator","prop-assign","cover-grammar","invalid-ast","panic"],"backgroundTag":"invalid-syntax-ast","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}