{"record":{"id":"5b7417748f5b0777","repo":"swc-project/swc","slug":"failed-to-set-property","errorCode":null,"errorMessage":"failed to set property","messagePattern":"failed to set property","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_base/src/helpers/generated/_set.rs","lineNumber":44,"sourceCode":"            desc = Object.getOwnPropertyDescriptor(receiver, property);\n            if (desc) {\n                if (!desc.writable) return false;\n                desc.value = value;\n                Object.defineProperty(receiver, property, desc);\n            } else {\n                _define_property(receiver, property, value);\n            }\n\n            return true;\n        };\n    }\n\n    return set(target, property, value, receiver);\n}\n\nfunction _set(target, property, value, receiver, isStrict) {\n    var s = set(target, property, value, receiver || target);\n    if (!s && isStrict) throw new Error(\"failed to set property\");\n\n    return value;\n}\n\"#,\n    #[cfg(feature = \"inline-helpers\")]\n    deps: super::HelperBitmap::from_bits(0x00000000000210000008400000000000),\n};\n\n#[cfg(feature = \"inline-helpers\")]\npub fn stmts() -> &'static [swc_ecma_ast::Stmt] {\n    static STMTS: once_cell::sync::Lazy<Vec<swc_ecma_ast::Stmt>> =\n        once_cell::sync::Lazy::new(|| super::super::parse(DEF.source, DEF.import_path));\n    &STMTS\n}\n","sourceCodeStart":26,"sourceCodeEnd":59,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_base/src/helpers/generated/_set.rs#L26-L59","documentation":"The `_set` helper implements `super.prop = value` for targets without native classes. It walks the prototype chain looking for a setter (or a writable data property via `Object.defineProperty` semantics); if no receiver accepts the assignment and the code is strict (ESM always is), it throws `Error(\"failed to set property\")`.","triggerScenarios":"Compiled `super.x = v` where every superclass in the chain declares `x` as a getter-only accessor, a non-writable/non-configurable data property, or a Proxy whose `set` trap returns `false` — in strict-mode output.","commonSituations":"Extending framework base classes that expose read-only computed properties (custom elements, ORM entities) and trying to assign through `super.`; migrating sloppy-mode scripts to ESM where the failed assignment used to be silent; overriding a property that the parent deliberately froze.","solutions":["Define a setter for the property on the parent class (or override the accessor in the subclass) so the chain contains an accepting setter.","Store the value on the instance with a different own-property name instead of assigning through `super`.","Replace the assignment with an explicit method call on the parent (`this.setParentValue(v)`).","Before assigning, walk the prototype chain and verify a setter exists (see validation below)."],"exampleFix":"// before\nclass Base { get mode() { return 'read-only'; } }\nclass Child extends Base {\n  set mode(v) { super.mode = v; } // Error: failed to set property\n}\n\n// after\nclass Base {\n  #mode = 'default';\n  get mode() { return this.#mode; }\n  set mode(v) { this.#mode = v; }\n}\nclass Child extends Base {\n  set mode(v) { super.mode = v; } // parent now accepts the set\n}","handlingStrategy":"validation","validationCode":"// Verify a setter exists somewhere on the prototype chain before `super.x = v`.\nfunction chainHasSetter(obj, prop) {\n  for (let o = obj; o != null; o = Object.getPrototypeOf(o)) {\n    const d = Object.getOwnPropertyDescriptor(o, prop);\n    if (d) return d.writable === true || typeof d.set === 'function';\n  }\n  return false; // plain property addition will apply to the receiver\n}\nif (!chainHasSetter(Object.getPrototypeOf(this), 'mode')) {\n  throw new Error('parent does not accept super.mode assignment');\n}\nsuper.mode = value;","typeGuard":null,"tryCatchPattern":"try {\n  super.prop = value;\n} catch (err) {\n  if (err instanceof Error && err.message === 'failed to set property') {\n    // no accepting setter on the chain — store on the instance instead\n    Object.defineProperty(this, 'prop', { value, writable: true, configurable: true });\n  } else throw err;\n}","preventionTips":["Treat inherited properties as read-only unless the parent explicitly documents a setter.","When designing base classes others extend, provide setters for any property subclasses may need to push through `super`.","Remember ESM and class bodies are strict mode: failed assignments throw instead of being silently ignored."],"tags":["super","setter","prototype-chain","strict-mode","es2015"],"backgroundTag":"super-property-set-failed","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}