mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
util: fix module prefixes during inspection
Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de> Fixes: https://github.com/nodejs/node/issues/36151 PR-URL: https://github.com/nodejs/node/pull/36178 Fixes: https://github.com/nodejs/node/issues/35730 Refs: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
738cd60418
commit
f78da00ab7
@ -637,7 +637,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] `;
|
||||
@ -971,7 +971,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)) {
|
||||
|
@ -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" +
|
||||
'}'
|
||||
);
|
||||
|
@ -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');
|
||||
|
@ -11,7 +11,10 @@ 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 }'
|
||||
);
|
||||
})().then(common.mustCall());
|
||||
|
Loading…
Reference in New Issue
Block a user