Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
20 changes: 2 additions & 18 deletions lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class ModuleJob {
// `moduleProvider` is a function
constructor(loader, url, moduleProvider, isMain) {
this.loader = loader;
this.error = null;
this.hadError = false;
this.isMain = isMain;

// This is a Promise<{ module, reflect }>, whose fields will be copied
Expand Down Expand Up @@ -72,15 +70,7 @@ class ModuleJob {
const dependencyJobs = await moduleJob.linked;
return Promise.all(dependencyJobs.map(addJobsToDependencyGraph));
};
try {
await addJobsToDependencyGraph(this);
} catch (e) {
if (!this.hadError) {
this.error = e;
this.hadError = true;
}
throw e;
}
await addJobsToDependencyGraph(this);
try {
if (this.isMain && process._breakFirstLine) {
delete process._breakFirstLine;
Expand All @@ -103,13 +93,7 @@ class ModuleJob {

async run() {
const module = await this.instantiate();
try {
module.evaluate(-1, false);
} catch (e) {
this.hadError = true;
this.error = e;
throw e;
}
module.evaluate(-1, false);
return module;
}
}
Expand Down
28 changes: 28 additions & 0 deletions test/es-module/test-esm-error-cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

// Flags: --experimental-modules

const common = require('../common');
const assert = require('assert');

common.crashOnUnhandledRejection();

const file = '../../fixtures/syntax/bad_syntax.js';

let error;
(async () => {
try {
await import(file);
} catch (e) {
assert.strictEqual(e.name, 'SyntaxError');
error = e;
}

assert(error);

try {
await import(file);
} catch (e) {
assert.strictEqual(error, e);
}
})();