Skip to content

Commit 2f7944b

Browse files
BridgeARBethGriggs
authored andcommitted
util: fix module prefixes during inspection
Signed-off-by: Ruben Bridgewater <[email protected]> Backport-PR-URL: #37100 PR-URL: #36178 Fixes: #35730 Fixes: #36151 Refs: #35754 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 408c7a6 commit 2f7944b

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

lib/internal/util/inspect.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) {
645645

646646
function getPrefix(constructor, tag, fallback, size = '') {
647647
if (constructor === null) {
648-
if (tag !== '') {
648+
if (tag !== '' && fallback !== tag) {
649649
return `[${fallback}${size}: null prototype] [${tag}] `;
650650
}
651651
return `[${fallback}${size}: null prototype] `;
@@ -979,7 +979,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
979979
braces[0] = `${getPrefix(constructor, tag, 'WeakMap')}{`;
980980
formatter = ctx.showHidden ? formatWeakMap : formatWeakCollection;
981981
} else if (isModuleNamespaceObject(value)) {
982-
braces[0] = `[${tag}] {`;
982+
braces[0] = `${getPrefix(constructor, tag, 'Module')}{`;
983983
// Special handle keys for namespace objects.
984984
formatter = formatNamespaceObject.bind(null, keys);
985985
} else if (isBoxedPrimitive(value)) {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
// Flags: --experimental-loader ./test/fixtures/es-module-loaders/loader-with-custom-condition.mjs
22
import '../common/index.mjs';
33
import assert from 'assert';
4+
import util from 'util';
45

56
import * as ns from '../fixtures/es-modules/conditional-exports.mjs';
67

78
assert.deepStrictEqual({ ...ns }, { default: 'from custom condition' });
9+
10+
assert.strictEqual(
11+
util.inspect(ns, { showHidden: false }),
12+
"[Module: null prototype] { default: 'from custom condition' }"
13+
);
14+
15+
assert.strictEqual(
16+
util.inspect(ns, { showHidden: true }),
17+
'[Module: null prototype] {\n' +
18+
" default: 'from custom condition',\n" +
19+
" [Symbol(Symbol.toStringTag)]: 'Module'\n" +
20+
'}'
21+
);

test/parallel/test-repl-import-referrer.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ child.stdout.on('data', (data) => {
1616

1717
child.on('exit', common.mustCall(() => {
1818
const results = output.replace(/^> /mg, '').split('\n').slice(2);
19-
assert.deepStrictEqual(results, ['[Module] { message: \'A message\' }', '']);
19+
assert.deepStrictEqual(
20+
results,
21+
['[Module: null prototype] { message: \'A message\' }', '']
22+
);
2023
}));
2124

2225
child.stdin.write('await import(\'./message.mjs\');\n');

test/parallel/test-util-inspect-namespace.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ const { inspect } = require('util');
1313
await m.link(() => 0);
1414
assert.strictEqual(
1515
inspect(m.namespace),
16-
'[Module] { a: <uninitialized>, b: undefined }');
16+
'[Module: null prototype] { a: <uninitialized>, b: undefined }'
17+
);
1718
await m.evaluate();
18-
assert.strictEqual(inspect(m.namespace), '[Module] { a: 1, b: 2 }');
19+
assert.strictEqual(
20+
inspect(m.namespace),
21+
'[Module: null prototype] { a: 1, b: 2 }'
22+
);
1923
})();

0 commit comments

Comments
 (0)