mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
116c8b8303
Private methods lowered from a class expression inside a concise arrow
were inserted next to the arrow's outer statement, while private field
storage remained inside the arrow. Starting with Oxc 0.143, this could
leave the generated helper unable to resolve the private field and throw
a `ReferenceError` at runtime.
Concise arrow bodies have no statement list where the helper declaration
can be inserted. In that context, the helper is now emitted as an
assignment in the class-expression sequence, with its `var` binding
inside the expanded arrow body. Ordinary statement-backed class
expressions keep block-local function declarations so classes created by
repeated block evaluation retain their own captured values. The
generated symbol flags and scope parents match the emitted form in both
cases.
## Example
```js
const makeClass = () => class {
#field = 41;
#read() { return this.#field; }
run() { return this.#read() + 1; }
};
new (makeClass())().run();
```
Before Oxc emitted a helper outside `makeClass`, and the call threw
`ReferenceError: _field is not defined`. After this change it returns
`42`.
Verified with the private-method transform conformance suite, runtime
regressions for concise arrows and repeated block evaluation, `cargo
test -p oxc_transformer`, and transformer clippy.
Fixes the upstream cause of
[rolldown/rolldown#10818](https://github.com/rolldown/rolldown/issues/10818).
AI assistance: Cursor was used for the original patch; OpenAI Codex was
used for follow-up review, fixes, and testing.
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Dunqing <dengqing0821@gmail.com>
Transformation Conformance Test Runner
Execution
This test runner uses the transformation plugin test suite from the Babel repository.
Additional tests are in the tests directory.
The failing test cases are listed in:
To get started, run
cargo run -p oxc_transform_conformance
or watch for changes
just watch 'cargo run -p oxc_transform_conformance'
Options
--filter
To filter for a specific test case, apply the --filter path option, e.g.
cargo run -p oxc_transform_conformance -- --filter react/arrow-functions
--exec
The Babel test suite contains many exec.js files, which need to be executed by a runtime.
These tests are executed with Node.js and Vitest. Apply the --exec flag:
cargo run -p oxc_transform_conformance -- --exec
This is also available as:
just test-transform
The failing test cases are listed in: