Skip to content

Commit e39e37b

Browse files
bmacnaughtonrichardlau
authored andcommitted
esm: fix hook name in error message
PR-URL: #50466 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 1aaf156 commit e39e37b

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

lib/internal/errors.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1480,11 +1480,11 @@ E('ERR_INVALID_REPL_EVAL_CONFIG',
14801480
E('ERR_INVALID_REPL_INPUT', '%s', TypeError);
14811481
E('ERR_INVALID_RETURN_PROPERTY', (input, name, prop, value) => {
14821482
return `Expected a valid ${input} to be returned for the "${prop}" from the` +
1483-
` "${name}" function but got ${determineSpecificType(value)}.`;
1483+
` "${name}" hook but got ${determineSpecificType(value)}.`;
14841484
}, TypeError);
14851485
E('ERR_INVALID_RETURN_PROPERTY_VALUE', (input, name, prop, value) => {
14861486
return `Expected ${input} to be returned for the "${prop}" from the` +
1487-
` "${name}" function but got ${determineSpecificType(value)}.`;
1487+
` "${name}" hook but got ${determineSpecificType(value)}.`;
14881488
}, TypeError);
14891489
E('ERR_INVALID_RETURN_VALUE', (input, name, value) => {
14901490
const type = determineSpecificType(value);

lib/internal/modules/esm/translators.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function assertBufferSource(body, allowString, hookName) {
128128
*/
129129
function stringify(body) {
130130
if (typeof body === 'string') { return body; }
131-
assertBufferSource(body, false, 'transformSource');
131+
assertBufferSource(body, false, 'load');
132132
const { TextDecoder } = require('internal/encoding');
133133
DECODER = DECODER === null ? new TextDecoder() : DECODER;
134134
return DECODER.decode(body);

test/es-module/test-esm-loader.mjs

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ await assert.rejects(
4343
{ code: 'ERR_INVALID_RETURN_PROPERTY_VALUE' },
4444
);
4545

46+
await assert.rejects(import('esmHook/commonJsNullSource.mjs'), {
47+
code: 'ERR_INVALID_RETURN_PROPERTY_VALUE',
48+
message: /"source".*'load'.*got type bigint/,
49+
});
50+
4651
await import('../fixtures/es-module-loaders/js-as-esm.js')
4752
.then((parsedModule) => {
4853
assert.strictEqual(typeof parsedModule, 'object');

test/fixtures/es-module-loaders/hooks-custom.mjs

+8
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,13 @@ export function load(url, context, next) {
9797
};
9898
}
9999

100+
if (url.endsWith('esmHook/commonJsNullSource.mjs')) {
101+
return {
102+
format: 'commonjs',
103+
shortCircuit: true,
104+
source: 1n,
105+
};
106+
}
107+
100108
return next(url);
101109
}

0 commit comments

Comments
 (0)