Private method call in an update expression (`this.#m().n++`) compiles to field helper → `privateMap.get is not a function`
Describe the bug
When a private method call appears in the operand of an update expression (++/--), the class-properties transform compiles the private-name access through _class_private_field_update / _class_extract_field_descriptor(receiver, privateMap, "update") instead of _class_private_method_get. The brand for a private method is a WeakSet, so the helper's privateMap.get(receiver) throws at runtime:
TypeError: privateMap.get is not a function(minified: a.get is not a function). Static private methods fail the same way with ReferenceError: _s is not defined.
Only ++/-- are affected; +=, ??=, = etc. on the same chain compile correctly. Any receiver and any chain depth reproduces it: this.#m().n++, ++this.#m().n, other.#m().n++, this.#m().a.n++, this.#m().g().n++, this.#m()[0]++, (this.#m()).n++.
Targets es2015 to es2021 fail; es2022 (no downlevel) is fine. We hit this via Next.js 15.5 (its bundled SWC) in a production build. vitest/esbuild/next dev compile it correctly, so it only surfaced in the deployed bundle.
Input code
class A {
#m() { return (this.o ??= { n: 0 }) }
go() { this.#m().n++; return this.o.n }
}
console.log(new A().go())Config
{ "jsc": { "parser": { "syntax": "ecmascript" }, "target": "es2019" } }Expected behavior
Logs 1. this.#m() should compile via _class_private_method_get(this, _m, m) and the ++ should apply to the returned object's n property.
Actual behavior
Throws TypeError: privateMap.get is not a function. The output wraps the #m access in _class_private_field_update, which treats the method's WeakSet brand as a field WeakMap.
Version
@swc/core 1.16.2 (also the SWC bundled with next 15.5.24)
Additional context
Workaround: hoist the call to a local: const o = this.#m(); o.n++.
Source: swc-project/swc