Skip to content

[parity] import * as ns — ns.default is undefined for native modules whose default is the namespace itself #8236

Description

@proggeramlug

Split out of #6766 after PR #8229. Not a perf_hooks bugperf_hooks is just where the node-suite pins it.

import * as ns from "node:<mod>" should expose ns.default (Node lists it among the namespace keys, and it is the CJS module.exports). For perf_hooks the key is now listed but the read is undefined:

import * as hooks from "node:perf_hooks";
Object.keys(hooks)          // ✅ includes "default" after #8229
hooks.default               // ❌ undefined
hooks.default.performance === hooks.performance
// node:  true
// perry: TypeError: Cannot read properties of undefined (reading 'performance')

Pinned by test-parity/node-suite/perf_hooks/imports/namespace-keys (line 1 passes, line 2 does not). Reproduce with ./run_parity_tests.sh --suite node-suite --module perf_hooks.

What I found

cjs_default_export_value("perf_hooks") in crates/perry-runtime/src/object/native_module.rs now returns the module namespace (added in #8229), and get_native_module_constant has a generic property == "default" branch ahead of its per-module match that consults it. Despite that, the read still resolves to undefined, so the PropertyGet { NativeModuleRef(mod), "default" } lowering — js_native_module_esm_export_valuenative_module_property_by_name_impl(…, /* is_cjs */ false) — appears to return before either is reached. I did not chase it further.

Worth checking against the modules that resolve default through the separate <mod>.default tag machinery (cjs_default_namespace_name: os, path, util, url, …) — those may work by a different route, which would make this specifically about modules whose default is the namespace itself (dgram, perf_hooks).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    parityCompatibility gap with Node.js, ECMAScript, or the supported ecosystem

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions