summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2020-11-19 16:31:05 +0100
committerBeth Griggs <bgriggs@redhat.com>2021-02-04 16:56:39 +0000
commit2f7944b18b04a67746926d8e7450765d883349ea (patch)
treebe6d2a5c9eb005104bc6d887e7f929859a07bed1
parent408c7a65f3d8d06155d20473da042d7764db09f7 (diff)
downloadnode-new-2f7944b18b04a67746926d8e7450765d883349ea.tar.gz
util: fix module prefixes during inspection
Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de> Backport-PR-URL: https://github.com/nodejs/node/pull/37100 PR-URL: https://github.com/nodejs/node/pull/36178 Fixes: https://github.com/nodejs/node/issues/35730 Fixes: https://github.com/nodejs/node/issues/36151 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>
-rw-r--r--lib/internal/util/inspect.js4
-rw-r--r--test/es-module/test-esm-loader-custom-condition.mjs14
-rw-r--r--test/parallel/test-repl-import-referrer.js5
-rw-r--r--test/parallel/test-util-inspect-namespace.js8
4 files changed, 26 insertions, 5 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index f6b60ba872..b8f2943961 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -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] `;
@@ -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)) {
diff --git a/test/es-module/test-esm-loader-custom-condition.mjs b/test/es-module/test-esm-loader-custom-condition.mjs
index 26d1db4842..075e4fe2b6 100644
--- a/test/es-module/test-esm-loader-custom-condition.mjs
+++ b/test/es-module/test-esm-loader-custom-condition.mjs
@@ -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" +
+ '}'
+);
diff --git a/test/parallel/test-repl-import-referrer.js b/test/parallel/test-repl-import-referrer.js
index 33bc442e6f..d77d70a031 100644
--- a/test/parallel/test-repl-import-referrer.js
+++ b/test/parallel/test-repl-import-referrer.js
@@ -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');
diff --git a/test/parallel/test-util-inspect-namespace.js b/test/parallel/test-util-inspect-namespace.js
index 89b26fcdbc..00c952c05c 100644
--- a/test/parallel/test-util-inspect-namespace.js
+++ b/test/parallel/test-util-inspect-namespace.js
@@ -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 }'
+ );
})();