From 653b20b26d8228805e1bef6eba377ac1c2e8ae8f Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Fri, 15 Jun 2018 09:35:42 -0500 Subject: [PATCH] loader: remove unused error code in module_job PR-URL: https://github.com/nodejs/node/pull/21354 Reviewed-By: Bradley Farias Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Guy Bedford Reviewed-By: Ruben Bridgewater --- lib/internal/modules/esm/module_job.js | 20 ++---------------- test/es-module/test-esm-error-cache.js | 28 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 test/es-module/test-esm-error-cache.js diff --git a/lib/internal/modules/esm/module_job.js b/lib/internal/modules/esm/module_job.js index 6f0bb869314404..9735eae8b50c9c 100644 --- a/lib/internal/modules/esm/module_job.js +++ b/lib/internal/modules/esm/module_job.js @@ -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 @@ -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; @@ -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; } } diff --git a/test/es-module/test-esm-error-cache.js b/test/es-module/test-esm-error-cache.js new file mode 100644 index 00000000000000..80431512d75773 --- /dev/null +++ b/test/es-module/test-esm-error-cache.js @@ -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); + } +})();