Repository navigation
Closed
Description
The transformer lowers class fields, private members, static blocks, and using unconditionally (class_properties: Some(..), class_static_block: true, explicit_resource_management: true, src/lib.rs#L800-L810). Every Node.js release that has module.register() runs class fields, private members, and static blocks natively, and using is native from Node.js 24.
Reproduction
// main.ts
class Counter {
count = 1;
#step = 1;
static created = 0;
static {
Counter.created += 1;
}
bump() {
return (this.count += this.#step);
}
}
{
using res = { [Symbol.dispose]() { console.log('disposed'); } };
}
console.log(new Counter().bump(), Counter.toString().includes('count = 1'));@oxc-node/core 0.1.5 output (the same on Node.js 22.18, 24.21, and 26.5):
"use strict";
var _defineProperty = require("@oxc-node/core/helpers/defineProperty");
var _classPrivateFieldInitSpec = require("@oxc-node/core/helpers/classPrivateFieldInitSpec");
var _classPrivateFieldGet = require("@oxc-node/core/helpers/classPrivateFieldGet2");
var _usingCtx2 = require("@oxc-node/core/helpers/usingCtx");
var _Counter;
var _step = /* @__PURE__ */ new WeakMap();
class Counter {
constructor() {
_defineProperty(this, "count", 1);
_classPrivateFieldInitSpec(this, _step, 1);
}
bump() {
return this.count += _classPrivateFieldGet(_step, this);
}
}
_Counter = Counter;
_defineProperty(Counter, "created", 0);
_Counter.created += 1;
try {
var _usingCtx = _usingCtx2();
// ...node --import @oxc-node/core/register main.ts prints disposed and 2 false: the class no longer contains count = 1.
Why it matters
- Almost every runtime helper import, and the resolution machinery from Runtime helpers resolve from the user's file, so a global
oxnodefails withERR_MODULE_NOT_FOUND#794/fix(core): resolve helper imports against the loader, not the user file #803, exists only because of this lowering. Without it, most scripts import no helpers at all. #privatefields becomeWeakMaplookups, which are slower and show up differently in the debugger.- Stack traces and
Function.prototype.toString()drift from the source.
Suggestion
- Lower class features only when native semantics differ:
[[Set]]fields (useDefineForClassFields: false, already computed asset_public_class_fields) and legacy decorators (experimentalDecorators), which are applied to the lowered class. - Lower
usingonly when the running Node.js lacks it, for example from napi'sEnv::get_node_version()(major < 24).
let legacy_decorators = compiler_options.and_then(|c| c.experimental_decorators).unwrap_or(false);
let lower_class_features = set_public_class_fields || legacy_decorators;
// ...
class_static_block: lower_class_features,
class_properties: lower_class_features.then(ClassPropertiesOptions::default),
// ...
es2026: ES2026Options { explicit_resource_management: !native_using },Vite+ carries this change in its vendored copy and runs it on Node.js 22, 24, and 26.
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Priority
None yet
Activity
feat(vpx): run TypeScript scripts with the vendored oxc-node (#2936)