Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
util: fix module prefixes during inspection
Browse files Browse the repository at this point in the history
Backport-PR-URL: nodejs#37100

Signed-off-by: Ruben Bridgewater <[email protected]>

Fixes: nodejs#36151

PR-URL: nodejs#36178
Fixes: nodejs#35730
Refs: nodejs#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]>
  • Loading branch information
BridgeAR authored and Pezmc committed Jan 29, 2021
1 parent 89402af commit 496b466
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) {

function getPrefix(constructor, tag, fallback, size = '') {
if (constructor === null) {
if (tag !== '') {
if (tag !== '' && fallback !== tag) {
return `[${fallback}${size}: null prototype] [${tag}] `;
}
return `[${fallback}${size}: null prototype] `;
Expand Down Expand Up @@ -979,7 +979,7 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
braces[0] = `${getPrefix(constructor, tag, 'WeakMap')}{`;
formatter = ctx.showHidden ? formatWeakMap : formatWeakCollection;
} else if (isModuleNamespaceObject(value)) {
braces[0] = `[${tag}] {`;
braces[0] = `${getPrefix(constructor, tag, 'Module')}{`;
// Special handle keys for namespace objects.
formatter = formatNamespaceObject.bind(null, keys);
} else if (isBoxedPrimitive(value)) {
Expand Down
14 changes: 14 additions & 0 deletions test/es-module/test-esm-loader-custom-condition.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
// Flags: --experimental-loader ./test/fixtures/es-module-loaders/loader-with-custom-condition.mjs
import '../common/index.mjs';
import assert from 'assert';
import util from 'util';

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

assert.deepStrictEqual({ ...ns }, { default: 'from custom condition' });

assert.strictEqual(
util.inspect(ns, { showHidden: false }),
"[Module: null prototype] { default: 'from custom condition' }"
);

assert.strictEqual(
util.inspect(ns, { showHidden: true }),
'[Module: null prototype] {\n' +
" default: 'from custom condition',\n" +
" [Symbol(Symbol.toStringTag)]: 'Module'\n" +
'}'
);
5 changes: 4 additions & 1 deletion test/parallel/test-repl-import-referrer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ child.stdout.on('data', (data) => {

child.on('exit', common.mustCall(() => {
const results = output.replace(/^> /mg, '').split('\n').slice(2);
assert.deepStrictEqual(results, ['[Module] { message: \'A message\' }', '']);
assert.deepStrictEqual(
results,
['[Module: null prototype] { message: \'A message\' }', '']
);
}));

child.stdin.write('await import(\'./message.mjs\');\n');
Expand Down
8 changes: 6 additions & 2 deletions test/parallel/test-util-inspect-namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const { inspect } = require('util');
await m.link(() => 0);
assert.strictEqual(
inspect(m.namespace),
'[Module] { a: <uninitialized>, b: undefined }');
'[Module: null prototype] { a: <uninitialized>, b: undefined }'
);
await m.evaluate();
assert.strictEqual(inspect(m.namespace), '[Module] { a: 1, b: 2 }');
assert.strictEqual(
inspect(m.namespace),
'[Module: null prototype] { a: 1, b: 2 }'
);
})();

0 comments on commit 496b466

Please sign in to comment.