{"record":{"id":"682b922382ae1b06","repo":"swc-project/swc","slug":"name-is-write-only","errorCode":null,"errorMessage":"\"${name}\" is write-only","messagePattern":"\"(.+?)\" is write-only","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_base/src/helpers/generated/_write_only_error.rs","lineNumber":11,"sourceCode":"// This file is generated by `cargo codegen helpers`. DO NOT MODIFY.\n\nuse super::{HelperDef, HelperName};\n\npub const DEF: HelperDef = HelperDef {\n    name: HelperName::write_only_error,\n    local: \"_write_only_error\",\n    import_path: \"@swc/helpers/_/_write_only_error\",\n    #[cfg(feature = \"inline-helpers\")]\n    source: r#\"function _write_only_error(name) {\n    throw new TypeError(\"\\\"\" + name + \"\\\" is write-only\");\n}\n\"#,\n    #[cfg(feature = \"inline-helpers\")]\n    deps: super::HelperBitmap::from_bits(0x00000200000000000000000000000000),\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":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_base/src/helpers/generated/_write_only_error.rs#L1-L24","documentation":"The ES2022 private-field transform emits `_write_only_error(\"#x\")` (crates/swc_ecma_compat_es2022/src/class_properties/private_field.rs:728) when compiled code reads a private accessor that declares only a setter. At runtime the helper throws `TypeError: \"#x\" is write-only`, mirroring the engine error for reading a set-only private accessor.","triggerScenarios":"`class A { set #x(v) { this._v = v; } read() { return this.#x; } }` — any read of a setter-only private accessor (`this.#x` in an expression, template literal, or log) in downleveled output.","commonSituations":"Write-only private setters used for validation with an accidental read added later (logging, debug serialization); refactors that move reads into the class without adding a getter; code generators that reference every declared private name.","solutions":["Add a getter paired with the setter: `get #x() { return this._v; }`.","Move state into a plain private field `#x` and keep an accessor pair or expose reads via a normal method.","Remove the read; if the value is write-only by design, return the assigned value from the API instead."],"exampleFix":"// before\nclass Socket {\n  set #buf(v) { this._buf = Buffer.from(v); }\n  flush() { console.log(this.#buf); } // TypeError: \"#buf\" is write-only\n}\n\n// after\nclass Socket {\n  #buf;\n  set buf(v) { this.#buf = Buffer.from(v); }\n  flush() { console.log(this.#buf); }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Setter-only private accessors cannot be probed, so guard the read site.\ntry {\n  debug(this.#buf);\n} catch (err) {\n  if (err instanceof TypeError && /is write-only/.test(err.message)) {\n    debug(this.readBuf()); // use the read API instead\n  } else throw err;\n}","preventionTips":["Declare accessor pairs (`get #x` + `set #x`) together, or store state in a plain private field `#x` with explicit methods.","Keep serialization/logging away from private accessors — expose a `snapshot()`/`toString()` method instead of reading internals.","Review every private-accessor declaration for a matching counterpart as part of code review."],"tags":["private-field","accessor","write-only","es2022","class-properties"],"backgroundTag":"read-from-write-only-property","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"}