Skip to content

fix(transformer/class-properties): preserve private accessor assignment receivers - #28790

Merged
graphite-app[bot] merged 1 commit into
mainfrom
codex/fix-private-accessor-assignment-receiver
Nov 4, 2026
Merged

graphite-app[bot] merged 1 commit into
mainfrom
codex/fix-private-accessor-assignment-receiver

Conversation

@Dunqing

@Dunqing Dunqing commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

When targeting ES2021 or earlier, a logical assignment to a private accessor can use the wrong receiver if the getter reassigns the variable on the left:

let receiver;

class Counter {
  get #value() {
    receiver = {};
    return 1;
  }

  set #value(value) {
    console.log("set", value);
  }

  run(rhs) {
    return (receiver.#value &&= rhs());
  }
}

receiver = new Counter();
console.log(receiver.run(() => {
  console.log("rhs");
  return 2;
}));

Before this change, the getter and setter each read receiver. The getter changes it to {}, so preparing the setter throws TypeError before the RHS runs. Nothing is logged.

The relevant generated code changes as follows:

// Before
return _get_value.call(babelHelpers.assertClassBrand(_Counter_brand, receiver)) &&
  (babelHelpers.toSetter(
    _set_value.bind(babelHelpers.assertClassBrand(_Counter_brand, receiver))
  )._ = rhs());

// After
var _receiver;
return _get_value.call(babelHelpers.assertClassBrand(_Counter_brand, _receiver = receiver)) &&
  (babelHelpers.toSetter(
    _set_value.bind(babelHelpers.assertClassBrand(_Counter_brand, _receiver))
  )._ = rhs());

After this change, the receiver is saved before calling the getter and reused for the setter. The example prints:

rhs
set 2
2

The same fix applies to ||= and ??=. For assignments inside default parameters, the transform also places the temporary inside an arrow IIFE. Each invocation gets its own temporary, so a recursive getter cannot overwrite the outer assignment's receiver.

Regression tests cover static and instance accessors, all three logical operators, short-circuiting, failed brand checks, and recursive default parameters.

Validation:

  • 39 Rust tests and 53 Node binding tests passed, along with Clippy and Rust formatting checks.
  • The new fixture passed natively and after transformation at ES2021, ES2020, and ES2015.
  • Transform conformance and transformer coverage have no new failures.

AI assistance was used to implement and test this change.

@github-actions github-actions Bot added the A-transformer Area - JS/TS transforms and downleveling, oxc_transformer label Nov 4, 2026
@codspeed

codspeed Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 77 untouched benchmarks
⏩ 19 skipped benchmarks1


Comparing codex/fix-private-accessor-assignment-receiver (2484931) with main (98b65d8)

Open in CodSpeed

Footnotes

  1. 19 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@Dunqing
Dunqing marked this pull request as ready for review November 4, 2026 09:02
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Nov 4, 2026

Dunqing commented Nov 4, 2026 •

Copy link
Copy Markdown
Member Author

Merge activity

  • Nov 4, 9:04 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Nov 4, 9:04 AM UTC: Dunqing added this pull request to the Graphite merge queue.
  • Nov 4, 9:07 AM UTC: The Graphite merge queue couldn't merge this PR because it was not satisfying all requirements (Failed CI: 'Conformance').
  • Nov 4, 1:51 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Nov 4, 1:55 PM UTC: Dunqing added this pull request to the Graphite merge queue.
  • Nov 4, 1:59 PM UTC: Merged by the Graphite merge queue.

graphite-app Bot pushed a commit that referenced this pull request Nov 4, 2026
…nt receivers (#28790)

When targeting ES2021 or earlier, a logical assignment to a private accessor can use the wrong receiver if the getter reassigns the variable on the left:

```js
let receiver;

class Counter {
  get #value() {
    receiver = {};
    return 1;
  }

  set #value(value) {
    console.log("set", value);
  }

  run(rhs) {
    return (receiver.#value &&= rhs());
  }
}

receiver = new Counter();
console.log(receiver.run(() => {
  console.log("rhs");
  return 2;
}));
```

Before this change, the getter and setter each read `receiver`. The getter changes it to `{}`, so preparing the setter throws `TypeError` before the RHS runs. Nothing is logged.

The relevant generated code changes as follows:

```js
// Before
return _get_value.call(babelHelpers.assertClassBrand(_Counter_brand, receiver)) &&
  (babelHelpers.toSetter(
    _set_value.bind(babelHelpers.assertClassBrand(_Counter_brand, receiver))
  )._ = rhs());

// After
var _receiver;
return _get_value.call(babelHelpers.assertClassBrand(_Counter_brand, _receiver = receiver)) &&
  (babelHelpers.toSetter(
    _set_value.bind(babelHelpers.assertClassBrand(_Counter_brand, _receiver))
  )._ = rhs());
```

After this change, the receiver is saved before calling the getter and reused for the setter. The example prints:

```text
rhs
set 2
2
```

The same fix applies to `||=` and `??=`. For assignments inside default parameters, the transform also places the temporary inside an arrow IIFE. Each invocation gets its own temporary, so a recursive getter cannot overwrite the outer assignment's receiver.

Regression tests cover static and instance accessors, all three logical operators, short-circuiting, failed brand checks, and recursive default parameters.

Validation:

- 39 Rust tests and 53 Node binding tests passed, along with Clippy and Rust formatting checks.
- The new fixture passed natively and after transformation at ES2021, ES2020, and ES2015.
- Transform conformance and transformer coverage have no new failures.

AI assistance was used to implement and test this change.
@graphite-app
graphite-app Bot force-pushed the codex/fix-private-accessor-assignment-receiver branch from 7de3092 to 340b081 Compare November 4, 2026 09:04
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Nov 4, 2026
Dunqing added a commit that referenced this pull request Nov 4, 2026
…nt receivers (#28790)

When targeting ES2021 or earlier, a logical assignment to a private accessor can use the wrong receiver if the getter reassigns the variable on the left:

```js
let receiver;

class Counter {
  get #value() {
    receiver = {};
    return 1;
  }

  set #value(value) {
    console.log("set", value);
  }

  run(rhs) {
    return (receiver.#value &&= rhs());
  }
}

receiver = new Counter();
console.log(receiver.run(() => {
  console.log("rhs");
  return 2;
}));
```

Before this change, the getter and setter each read `receiver`. The getter changes it to `{}`, so preparing the setter throws `TypeError` before the RHS runs. Nothing is logged.

The relevant generated code changes as follows:

```js
// Before
return _get_value.call(babelHelpers.assertClassBrand(_Counter_brand, receiver)) &&
  (babelHelpers.toSetter(
    _set_value.bind(babelHelpers.assertClassBrand(_Counter_brand, receiver))
  )._ = rhs());

// After
var _receiver;
return _get_value.call(babelHelpers.assertClassBrand(_Counter_brand, _receiver = receiver)) &&
  (babelHelpers.toSetter(
    _set_value.bind(babelHelpers.assertClassBrand(_Counter_brand, _receiver))
  )._ = rhs());
```

After this change, the receiver is saved before calling the getter and reused for the setter. The example prints:

```text
rhs
set 2
2
```

The same fix applies to `||=` and `??=`. For assignments inside default parameters, the transform also places the temporary inside an arrow IIFE. Each invocation gets its own temporary, so a recursive getter cannot overwrite the outer assignment's receiver.

Regression tests cover static and instance accessors, all three logical operators, short-circuiting, failed brand checks, and recursive default parameters.

Validation:

- 39 Rust tests and 53 Node binding tests passed, along with Clippy and Rust formatting checks.
- The new fixture passed natively and after transformation at ES2021, ES2020, and ES2015.
- Transform conformance and transformer coverage have no new failures.

AI assistance was used to implement and test this change.
@Dunqing
Dunqing force-pushed the codex/fix-private-accessor-assignment-receiver branch from f74d856 to 2484931 Compare November 4, 2026 13:51
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Nov 4, 2026
…nt receivers (#28790)

When targeting ES2021 or earlier, a logical assignment to a private accessor can use the wrong receiver if the getter reassigns the variable on the left:

```js
let receiver;

class Counter {
  get #value() {
    receiver = {};
    return 1;
  }

  set #value(value) {
    console.log("set", value);
  }

  run(rhs) {
    return (receiver.#value &&= rhs());
  }
}

receiver = new Counter();
console.log(receiver.run(() => {
  console.log("rhs");
  return 2;
}));
```

Before this change, the getter and setter each read `receiver`. The getter changes it to `{}`, so preparing the setter throws `TypeError` before the RHS runs. Nothing is logged.

The relevant generated code changes as follows:

```js
// Before
return _get_value.call(babelHelpers.assertClassBrand(_Counter_brand, receiver)) &&
  (babelHelpers.toSetter(
    _set_value.bind(babelHelpers.assertClassBrand(_Counter_brand, receiver))
  )._ = rhs());

// After
var _receiver;
return _get_value.call(babelHelpers.assertClassBrand(_Counter_brand, _receiver = receiver)) &&
  (babelHelpers.toSetter(
    _set_value.bind(babelHelpers.assertClassBrand(_Counter_brand, _receiver))
  )._ = rhs());
```

After this change, the receiver is saved before calling the getter and reused for the setter. The example prints:

```text
rhs
set 2
2
```

The same fix applies to `||=` and `??=`. For assignments inside default parameters, the transform also places the temporary inside an arrow IIFE. Each invocation gets its own temporary, so a recursive getter cannot overwrite the outer assignment's receiver.

Regression tests cover static and instance accessors, all three logical operators, short-circuiting, failed brand checks, and recursive default parameters.

Validation:

- 39 Rust tests and 53 Node binding tests passed, along with Clippy and Rust formatting checks.
- The new fixture passed natively and after transformation at ES2021, ES2020, and ES2015.
- Transform conformance and transformer coverage have no new failures.

AI assistance was used to implement and test this change.
@graphite-app
graphite-app Bot force-pushed the codex/fix-private-accessor-assignment-receiver branch from 2484931 to 28a44b7 Compare November 4, 2026 13:56
@graphite-app
graphite-app Bot merged commit 28a44b7 into main Nov 4, 2026
33 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Nov 4, 2026
@graphite-app
graphite-app Bot deleted the codex/fix-private-accessor-assignment-receiver branch November 4, 2026 13:59
graphite-app Bot pushed a commit that referenced this pull request Nov 9, 2026
### 🐛 Bug Fixes

- de6ac92 isolated-declarations: Preserve object accessor mutability (#29039) (camc314)
- 3729ce1 transformer/typescript: Merge exported enums across namespace blocks (#28999) (camc314)
- 7243594 minifier: Preserve throwing ArrayBuffer and URI calls (#29012) (camc314)
- 67ac6be isolated-declarations: Evaluate enum template literal initializers (#28997) (camc314)
- f05b30e isolated-declarations: Infer auto-accessor initializer types (#29038) (camc314)
- 030d410 isolated-declarations: Preserve computed ambient enum members (#29040) (camc314)
- 6303df1 jsdoc: Preserve param tags after unmatched description delimiters (#28923) (Vishal Punjabi)
- 99e67d3 transformer: Preserve static private brands with shadowed class names (#28894) (Dunqing)
- 595f3c2 minifier: Preserve left-hand side effects in instanceof checks (#29011) (camc314)
- a791a5b cfg: Resolve continues through stacked loop labels (#29016) (camc314)
- 9e3b3d1 ecmascript: Reject signs after nondecimal prefixes (#29034) (camc314)
- 43c5273 ecmascript: Round nondecimal strings to numbers once (#29026) (camc314)
- b71234f cfg: Skip labeled contexts for unlabeled jumps (#29001) (camc314)
- fd51bff jsdoc: Handle every line terminators as newline (#28902) (leaysgur)
- c00dc61 codegen: Keep one source map mapping per generated position (#28844) (YT)
- 52f3e3d jsdoc: Do not treat `@word` containing `/` as tag (#28834) (leaysgur)
- 0b48483 minifier: Preserve UTF-16 boundaries in empty-search replaceAll folding (#28807) (huuya)
- 1e57a4e codegen: Print infinite numeric literals as `1e400` instead of `Infinity` (#28812) (Dominic Elm)
- 28a44b7 transformer/class-properties: Preserve private accessor assignment receivers (#28790) (Dunqing)
- ea76490 transformer/class-properties: Preserve private method values in assignments (#28788) (Dunqing)
- 8432de6 transformer/class-properties: Apply a compound assignment to a static private field once (#28606) (YT)
- 3dbf140 parser: Treat escaped contextual keywords as names, not modifiers (#28748) (Dominic Elm)
- e3b1bb4 transformer/class-properties: Keep the value of a private accessor assignment (#28716) (YT)
- ae7474e minifier: Keep array concat chain reads before later side effects (#28261) (Dunqing)
- ec327aa semantic: Keep block type bindings separate from hoisted vars (#28601) (YT)
- 3fd78d7 codegen: Preserve names in duplicate source mappings (#26051) (camc314)

### ⚡ Performance

- 7761a39 codegen: Remove redundant sourcemap buffer shrinks (#28893) (Dunqing)
- bee25de regular_expression: Check only the latest group per name in duplicate prescan (#29083) (Yuji Sugiura)
- 4da1752 codegen: Use SWAR scanning and shared column tables (#28939) (Dunqing)
- cc84126 mangler: Inline candidate checks during slot assignment (#28881) (Dunqing)
- 6611cf9 parser: Specialize quoted string value access (#28965) (Boshen)
- 5038ba6 parser: Avoid repeated await-using lookahead (#28960) (Boshen)
- ecc807b parser: Skip discarded arrow diagnostics (#28940) (Boshen)
- c880368 parser: Fast-path absent TypeScript type lists (#28959) (Boshen)
- dee6cf4 parser: Skip repeated optional call lookahead (#28876) (Boshen)
- a524e17 parser: Reuse successful parenthesized arrow heads (#28862) (Boshen)
- 296b12a parser: Accelerate line comment scanning (#28878) (Boshen)
- c4fc21e parser: Accelerate escaped string scanning (#28907) (Boshen)
- f7726b6 parser: Accelerate regex literal scanning (#28911) (Boshen)
- a8aff38 parser: Scan whitespace in runs (#28953) (Boshen)
- b1c137c parser: Avoid lookahead for TypeScript keyword types (#28954) (Boshen)
- 6a8a2a7 parser: Fast-path plain identifiers (#28955) (Boshen)
- 00deb87 parser: Initialize declaration lists with their first item (#28956) (Boshen)
- 71dd877 parser: Specialize binary operator associativity (#28957) (Boshen)
- 732a8e4 codegen: Skip repeated word scans for sourcemap tails (#28869) (Dunqing)
- 6972243 codegen: Accelerate sourcemap line scanning (#28400) (codspeed)
- 027eb7e parser: Combine async arrow lookahead (#28431) (Boshen)
- 7b933d5 lexer: Directly dispatch common punctuation (#28792) (Boshen)
- 45d86c3 lexer: Combine per-token annotation resets (#28492) (Boshen)
- d497fbf lexer: Match keywords with byte patterns (#28494) (Boshen)

### 📚 Documentation

- 844c28c syntax: Correct crate capabilities and module records (#29075) (camc314)
- 8d30d9b traverse: Clarify ancestor access during traversal (#29074) (camc314)
- a74b7cd ecmascript: Clarify test locations (#29072) (camc314)
- 7acaa4e mangler: Correct naming strategy and pipeline order (#29073) (camc314)
- ed28291 ast: Clarify which AST nodes use arena allocation (#29070) (camc314)
- d5832ab oxc: Correct README APIs and feature requirements (#29068) (camc314)
- 261c4a2 allocator: Clarify arena storage and memory reclamation (#29066) (camc314)
- 6448a54 napi/parser: Correct parser options and usage guidance (#29065) (camc314)
- 157fc5a napi/minify: Correct minifier capabilities and caveats (#29064) (camc314)
- 6989796 parser: Update TS-ESTree import differences (#29061) (camc314)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - JS/TS transforms and downleveling, oxc_transformer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant