Skip to content

Commit

Permalink
fixup! module: handle Top-Level Await non-fulfills better
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Aug 6, 2020
1 parent 6dd288e commit 5201960
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/internal/modules/run_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ function shouldUseESMLoader(mainPath) {
function runMainESM(mainPath) {
const esmLoader = require('internal/process/esm_loader');
const { pathToFileURL } = require('internal/url');
esmLoader.loadESM((ESMLoader) => {
handleMainPromise(esmLoader.loadESM((ESMLoader) => {
const main = path.isAbsolute(mainPath) ?
pathToFileURL(mainPath).href : mainPath;
handleMainPromise(ESMLoader.import(main));
});
return ESMLoader.import(main);
}));
}

function handleMainPromise(promise) {
Expand Down
7 changes: 3 additions & 4 deletions lib/internal/process/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ function evalModule(source, print) {
throw new ERR_EVAL_ESM_CANNOT_PRINT();
}
const { log } = require('internal/console/global');
const asyncESM = require('internal/process/esm_loader');
const { loadESM } = require('internal/process/esm_loader');
const { handleMainPromise } = require('internal/modules/run_main');
handleMainPromise((async () => {
const loader = await asyncESM.ESMLoader;
handleMainPromise(loadESM(async (loader) => {
const { result } = await loader.eval(source);
if (print) {
log(result);
}
})());
}));
}

function evalScript(name, body, breakFirstLine, print) {
Expand Down
1 change: 1 addition & 0 deletions test/message/esm_display_syntax_error_import.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ SyntaxError: The requested module '../fixtures/es-module-loaders/module-named-ex
at ModuleJob._instantiate (internal/modules/esm/module_job.js:*:*)
at async ModuleJob.run (internal/modules/esm/module_job.js:*:*)
at async Loader.import (internal/modules/esm/loader.js:*:*)
at async Object.loadESM (internal/process/esm_loader.js:*:*)
1 change: 1 addition & 0 deletions test/message/esm_display_syntax_error_import_module.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ SyntaxError: The requested module './module-named-exports.mjs' does not provide
at ModuleJob._instantiate (internal/modules/esm/module_job.js:*:*)
at async ModuleJob.run (internal/modules/esm/module_job.js:*:*)
at async Loader.import (internal/modules/esm/loader.js:*:*)
at async Object.loadESM (internal/process/esm_loader.js:*:*)
6 changes: 3 additions & 3 deletions test/message/esm_loader_not_found_cjs_hint_bare.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
internal/modules/run_main.js:*
internalBinding('errors').triggerUncaughtException(
^
internal/process/esm_loader.js:*
internalBinding('errors').triggerUncaughtException(
^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '*test*fixtures*node_modules*some_module*obj' imported from *test*fixtures*esm_loader_not_found_cjs_hint_bare.mjs
Did you mean to import some_module/obj.js?
Expand Down

0 comments on commit 5201960

Please sign in to comment.