Files
YT 8432de6b27 fix(transformer/class-properties): apply a compound assignment to a static private field once (#28606)
If the target is `es2021` or lower, a compound assignment to a static
private field applies the operator twice, unless the left side of
`.#prop` is the class name. For example, `this.#count += k` is affected,
but `Counter.#count += k` is not.

```js
class Counter {
  static #count = 10;
  static add(k) {
    this.#count += k;
    return this.#count;
  }
}
console.log(Counter.add(1)); // 11
```

The transformed code prints `21`, because it keeps `+=` and also adds
the old value on the right side:

```js
// before
_count._ += _assertClassBrand(Counter, this, _assertClassBrand(Counter, this, _count)._ + k);

// after
_count._ = _assertClassBrand(Counter, this, _assertClassBrand(Counter, this, _count)._ + k);
```

`Counter.#count += k` uses a separate branch that sets the operator to
`=`. The branch for `this.#count += k` did not set the operator. This PR
adds that line.

The new fixture `oxc/private-static-compound-assignment` covers `this`,
an object from a function call, and an object without the private field.
Its `exec.js` fails on main with `expected 21 to be 11`.

---

AI assistance was used for this change. I reviewed and tested it.
2026-11-04 09:52:54 +08:00
..