You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Translates ESM syntax to CommonJS when `target: 'commonjs'` with `transformSyntax` enabled.
6
+
- Assumes Node 20.11+ runtime with `__filename`/`__dirname` shims supplied by the host.
7
+
- Keeps optional live-binding behavior via `liveBindings` (strict/loose/off).
8
+
9
+
## Imports and interop
10
+
11
+
-`import` statements become `require` calls; side-effect imports become bare `require()` calls.
12
+
- Default imports use the bundler-style helper `__interopDefault = mod => (mod && mod.__esModule ? mod.default : mod)` when `cjsDefault: 'auto'`; otherwise they can target `module.exports` or `.default` directly per option.
13
+
- Namespace imports bind to the full `require` result; named imports destructure from the same binding.
14
+
- Re-exporting a default (`export { default as x } from`) routes through the interop helper to match bundler behavior for CJS sources.
15
+
- When the interop helper is emitted, `exports.__esModule = true` is also seeded for downstream consumers.
16
+
17
+
## Exports
18
+
19
+
- Local named exports emit to `exports.<name>` (or bracket access) with `Object.defineProperty` getters when `liveBindings: 'strict'`.
20
+
-`export default` writes to `module.exports = <expr>`; default functions/classes preserve their identifier before exporting.
21
+
-`export * from` lowers to a `for...in` over the required module, skipping `default`, guarding on `hasOwnProperty`, and defining getters to mirror live bindings.
22
+
- Named re-exports from another module (`export { foo as bar } from`) assign using either a direct property read or the interop helper for `default`.
- Bare `import.meta` becomes `module` so property accesses stay valid in CJS output.
32
+
33
+
## Fixtures for this phase
34
+
35
+
-`test/fixtures/esmDefault.mjs`: default import from the CJS provider, re-exported as default for interop checks (default import yields the CJS module object).
36
+
-`test/fixtures/esmNamed.mjs`: named import and aliasing from the CJS provider, re-exported for assertions.
37
+
-`test/fixtures/esmNamespace.mjs`: namespace import shape from the CJS provider, re-exported as `ns`.
38
+
-`test/fixtures/esmReexport.mjs`: named + star re-exports from the CJS provider (includes live binding passthrough).
39
+
-`test/fixtures/esmProvider.cjs`: CJS source exposing default/named exports plus a mutating `live` counter for binding checks (interval is `unref()`ed; tests wait ≥30ms to observe changes).
0 commit comments