Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1475,11 +1475,11 @@ E('ERR_INVALID_REPL_EVAL_CONFIG',
E('ERR_INVALID_REPL_INPUT', '%s', TypeError);
E('ERR_INVALID_RETURN_PROPERTY', (input, name, prop, value) => {
return `Expected a valid ${input} to be returned for the "${prop}" from the` +
` "${name}" function but got ${determineSpecificType(value)}.`;
` "${name}" hook but got ${determineSpecificType(value)}.`;
}, TypeError);
E('ERR_INVALID_RETURN_PROPERTY_VALUE', (input, name, prop, value) => {
return `Expected ${input} to be returned for the "${prop}" from the` +
` "${name}" function but got ${determineSpecificType(value)}.`;
` "${name}" hook but got ${determineSpecificType(value)}.`;
}, TypeError);
E('ERR_INVALID_RETURN_VALUE', (input, name, value) => {
const type = determineSpecificType(value);
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function assertBufferSource(body, allowString, hookName) {
*/
function stringify(body) {
if (typeof body === 'string') { return body; }
assertBufferSource(body, false, 'transformSource');
assertBufferSource(body, false, 'load');
const { TextDecoder } = require('internal/encoding');
DECODER = DECODER === null ? new TextDecoder() : DECODER;
return DECODER.decode(body);
Expand Down
9 changes: 9 additions & 0 deletions test/es-module/test-esm-loader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ await assert.rejects(
{ code: 'ERR_INVALID_RETURN_PROPERTY_VALUE' },
);

try {
await import('esmHook/commonJsNullSource.mjs');
} catch ({ code, message }) {
assert.strictEqual(code, 'ERR_INVALID_RETURN_PROPERTY_VALUE');
assert.match(message, /"source"/);
assert.match(message, /'load'/);
assert.match(message, /got type bigint/);
}

await import('../fixtures/es-module-loaders/js-as-esm.js')
.then((parsedModule) => {
assert.strictEqual(typeof parsedModule, 'object');
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/es-module-loaders/hooks-custom.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,13 @@ export function load(url, context, next) {
};
}

if (url.endsWith('esmHook/commonJsNullSource.mjs')) {
return {
format: 'commonjs',
shortCircuit: true,
source: 1n,
};
}

return next(url);
}