Skip to content

Commit c2b6edf

Browse files
bmacnaughtonRafaelGSS
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 9950103 commit c2b6edf

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
@@ -1475,11 +1475,11 @@ E('ERR_INVALID_REPL_EVAL_CONFIG',
14751475
E('ERR_INVALID_REPL_INPUT','%s',TypeError);
14761476
E('ERR_INVALID_RETURN_PROPERTY',(input,name,prop,value)=>{
14771477
return`Expected a valid ${input} to be returned for the "${prop}" from the`+
1478-
` "${name}" function but got ${determineSpecificType(value)}.`;
1478+
` "${name}" hook but got ${determineSpecificType(value)}.`;
14791479
},TypeError);
14801480
E('ERR_INVALID_RETURN_PROPERTY_VALUE',(input,name,prop,value)=>{
14811481
return`Expected ${input} to be returned for the "${prop}" from the`+
1482-
` "${name}" function but got ${determineSpecificType(value)}.`;
1482+
` "${name}" hook but got ${determineSpecificType(value)}.`;
14831483
},TypeError);
14841484
E('ERR_INVALID_RETURN_VALUE',(input,name,value)=>{
14851485
consttype=determineSpecificType(value);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function assertBufferSource(body, allowString, hookName) {
128128
*/
129129
functionstringify(body){
130130
if(typeofbody==='string'){returnbody;}
131-
assertBufferSource(body,false,'transformSource');
131+
assertBufferSource(body,false,'load');
132132
const{ TextDecoder }=require('internal/encoding');
133133
DECODER=DECODER===null ? newTextDecoder() : DECODER;
134134
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)