Skip to content

Commit 84b0ead

Browse files
bmacnaughtonaduh95
authored andcommitted
esm: fix hook name in error message
PR-URL: #50466 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent c679348 commit 84b0ead

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎lib/internal/errors.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,11 +1354,11 @@ E('ERR_INVALID_REPL_EVAL_CONFIG',
13541354
E('ERR_INVALID_REPL_INPUT','%s',TypeError);
13551355
E('ERR_INVALID_RETURN_PROPERTY',(input,name,prop,value)=>{
13561356
return`Expected a valid ${input} to be returned for the "${prop}" from the`+
1357-
` "${name}" function but got ${determineSpecificType(value)}.`;
1357+
` "${name}" hook but got ${determineSpecificType(value)}.`;
13581358
},TypeError);
13591359
E('ERR_INVALID_RETURN_PROPERTY_VALUE',(input,name,prop,value)=>{
13601360
return`Expected ${input} to be returned for the "${prop}" from the`+
1361-
` "${name}" function but got ${determineSpecificType(value)}.`;
1361+
` "${name}" hook but got ${determineSpecificType(value)}.`;
13621362
},TypeError);
13631363
E('ERR_INVALID_RETURN_VALUE',(input,name,value)=>{
13641364
consttype=determineSpecificType(value);

‎lib/internal/modules/esm/translators.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function assertBufferSource(body, allowString, hookName) {
113113
*/
114114
functionstringify(body){
115115
if(typeofbody==='string'){returnbody;}
116-
assertBufferSource(body,false,'transformSource');
116+
assertBufferSource(body,false,'load');
117117
const{ TextDecoder }=require('internal/encoding');
118118
DECODER=DECODER===null ? newTextDecoder() : DECODER;
119119
returnDECODER.decode(body);

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

Lines changed: 5 additions & 0 deletions
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+
awaitassert.rejects(import('esmHook/commonJsNullSource.mjs'),{
47+
code: 'ERR_INVALID_RETURN_PROPERTY_VALUE',
48+
message: /"source".*'load'.*gottypebigint/,
49+
});
50+
4651
awaitimport('../fixtures/es-module-loaders/js-as-esm.js')
4752
.then((parsedModule)=>{
4853
assert.strictEqual(typeofparsedModule,'object');

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

Lines changed: 8 additions & 0 deletions
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
returnnext(url);
101109
}

0 commit comments

Comments
 (0)