| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dcdb259 commit dbe6e63
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -335,7 +335,7 @@ class ModuleJob extends ModuleJobBase { | |||
| 335 | 335 | const parentFilename = urlToFilename(parent?.filename); | |
| 336 | 336 | this.module.hasAsyncGraph ??= this.module.isGraphAsync(); | |
| 337 | 337 | ||
| 338 | - if (this.module.async && !getOptionValue('--experimental-print-required-tla')) { | ||
| 338 | + if (this.module.hasAsyncGraph && !getOptionValue('--experimental-print-required-tla')) { | ||
| 339 | 339 | throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename); | |
| 340 | 340 | } | |
| 341 | 341 | if (status === kInstantiated) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,21 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + // This tests that in the require() in imported CJS can retry loading an ESM with TLA | ||
| 3 | + // twice and get the correct error both times. | ||
| 4 | + | ||
| 5 | + require('../common'); | ||
| 6 | + const { spawnSyncAndAssert } = require('../common/child_process'); | ||
| 7 | + const fixtures = require('../common/fixtures'); | ||
| 8 | + const assert = require('assert'); | ||
| 9 | + | ||
| 10 | + spawnSyncAndAssert( | ||
| 11 | + process.execPath, | ||
| 12 | + ['--import', fixtures.fileURL('es-modules', 'import-require-tla-twice', 'hook.js'), | ||
| 13 | + fixtures.path('es-modules', 'import-require-tla-twice', 'require-tla.js'), | ||
| 14 | + ], | ||
| 15 | + { | ||
| 16 | + stdout(output) { | ||
| 17 | + const matches = output.matchAll(/e\.code === ERR_REQUIRE_ASYNC_MODULE true/g); | ||
| 18 | + assert.strictEqual([...matches].length, 2); | ||
| 19 | + } | ||
| 20 | + } | ||
| 21 | + ); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + const { registerHooks } = require('module'); | ||
| 2 | + registerHooks({ | ||
| 3 | + load(url, context, nextLoad) { | ||
| 4 | + return nextLoad(url, context); | ||
| 5 | + } | ||
| 6 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + try { | ||
| 2 | + require('./tla.mjs'); | ||
| 3 | + } catch (e) { | ||
| 4 | + console.log('e.code === ERR_REQUIRE_ASYNC_MODULE', e.code === 'ERR_REQUIRE_ASYNC_MODULE'); | ||
| 5 | + } | ||
| 6 | + | ||
| 7 | + try { | ||
| 8 | + require('./tla.mjs'); | ||
| 9 | + } catch (e) { | ||
| 10 | + console.log('e.code === ERR_REQUIRE_ASYNC_MODULE', e.code === 'ERR_REQUIRE_ASYNC_MODULE'); | ||
| 11 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + await Promise.resolve('1'); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments