Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2f7944b

Browse filesBrowse files
BridgeARBethGriggs
authored andcommitted
util: fix module prefixes during inspection
Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de> Backport-PR-URL: #37100 PR-URL: #36178 Fixes: #35730 Fixes: #36151 Refs: #35754 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 408c7a6 commit 2f7944b
Copy full SHA for 2f7944b

File tree

Expand file treeCollapse file tree

4 files changed

+26
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+26
-5
lines changed
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+2-2Lines changed: 2 additions & 2 deletions
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)) {
Collapse file
+14Lines changed: 14 additions & 0 deletions
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+
);
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-repl-import-referrer.js
+4-1Lines changed: 4 additions & 1 deletion
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');
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect-namespace.js
+6-2Lines changed: 6 additions & 2 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.