mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 12:51:57 +00:00
Fix class properties transform to create a temp var for class when it's required.
Input:
```js
class C {
static getSelf = () => this;
}
const C2 = C;
C = 123;
assert(C2.getSelf() === C);
```
Output:
```js
var _C;
class C {}
_C = C;
_defineProperty(C, "getSelf", () => _C);
const C2 = C;
C = 123;
assert(C2.getSelf() === C);
```
Previously, temp var wasn't used so code was `_defineProperty(C, "getSelf", () => C);`. `C` is altered later by `C = 123`, so `C2.getSelf()` returned `123`, instead of reference to the class.
The logic around when a temp var is required and when it's not, and when/where it's referenced is ridiculously complicated. So add some debug assert mechanisms to double-check the logic.
|
||
|---|---|---|
| .. | ||
| babel-plugin-transform-object-rest-spread/test/fixtures | ||
| babel-plugin-transform-optional-chaining/test/fixtures | ||
| babel.snap.md | ||
| babel_exec.snap.md | ||
| oxc.snap.md | ||
| oxc_exec.snap.md | ||