fix(finalizer): unwrap oxc-runtime helper namespace on CJS require#9472
fix(finalizer): unwrap oxc-runtime helper namespace on CJS require#9472Kyujenius wants to merge 2 commits into
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
| // Fixes #9263. | ||
| if resolved_id.id.as_str().strip_prefix('\0').is_some_and(is_virtual_runtime_helper) { | ||
| raw_rec.meta.insert(ImportRecordMeta::RuntimeHelper); | ||
| } |
There was a problem hiding this comment.
We should identify the root cause instead of merely patching the runtime module.
There was a problem hiding this comment.
Can you try to verify external user code will not regress it again?
There was a problem hiding this comment.
Synthesized-helpers-only was meant as a deliberate boundary, not a patch - the two call sites carry different contracts. The transformer emits require('@oxc-project/runtime/helpers/...') as a default import expecting the callable, so the namespace round-trip strips it. A user require() of a default-only ESM lives under the esbuild/webpack interop contract instead, which is why #4984 went behind viteMode.
The three new fixtures pin both sides: user code stays namespace, synthesized helpers unwrap to .default, and the multi-helper case shows the boundary is the resolved-id prefix, not a per-helper guard.
Apparently, the test case has no relation to Rollup's |
The oxc transformer lowers
class { count = 0 }to_defineProperty(this, "count", 0)undertarget: es2021and synthesizesvar _defineProperty = require('@oxc-project/runtime/helpers/defineProperty.js'). The helper is a default-only ESM module, but the CJS-wrap path intry_rewrite_global_require_callreturned the namespace object - binding_definePropertyto{ default: <fn>, __esModule: true }and throwingTypeError: _defineProperty is not a functionat init (reproduction).This mirrors the JSON path (#4984): a new
ImportRecordMeta::RuntimeHelperbit is set in the module loader next toJsonModule, and the finalizer appends.defaultwhen either bit is present. Scope is intentionally synthesized-helpers only - broadly unwrapping any default-only ESM in CJS callers drifts 8 snapshots including #9261's, so the namespace convention for user-writtenrequirestays untouched.This also matches Rollup's
output.interop: "default"; the Rollup test suite (packages/rollup-tests) holds at 1212 passing fixtures with zero regression.Fixes #9263.