| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1f8eaec commit f74beb5
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -295,22 +295,33 @@ class ModuleJobSync extends ModuleJobBase { | |||
| 295 | 295 | #loader = null; | |
| 296 | 296 | constructor(loader, url, importAttributes, moduleWrap, isMain, inspectBrk) { | |
| 297 | 297 | super(url, importAttributes, moduleWrap, isMain, inspectBrk, true); | |
| 298 | - assert(this.module instanceof ModuleWrap); | ||
| 299 | 298 | this.#loader = loader; | |
| 300 | - const moduleRequests = this.module.getModuleRequests(); | ||
| 301 | - // Specifiers should be aligned with the moduleRequests array in order. | ||
| 302 | - const specifiers = Array(moduleRequests.length); | ||
| 303 | - const modules = Array(moduleRequests.length); | ||
| 304 | - const jobs = Array(moduleRequests.length); | ||
| 305 | - for (let i = 0; i < moduleRequests.length; ++i) { | ||
| 306 | - const { specifier, attributes } = moduleRequests[i]; | ||
| 307 | - const job = this.#loader.getModuleJobForRequire(specifier, url, attributes); | ||
| 308 | - specifiers[i] = specifier; | ||
| 309 | - modules[i] = job.module; | ||
| 310 | - jobs[i] = job; | ||
| 299 | + | ||
| 300 | + assert(this.module instanceof ModuleWrap); | ||
| 301 | + // Store itself into the cache first before linking in case there are circular | ||
| 302 | + // references in the linking. | ||
| 303 | + loader.loadCache.set(url, importAttributes.type, this); | ||
| 304 | + | ||
| 305 | + try { | ||
| 306 | + const moduleRequests = this.module.getModuleRequests(); | ||
| 307 | + // Specifiers should be aligned with the moduleRequests array in order. | ||
| 308 | + const specifiers = Array(moduleRequests.length); | ||
| 309 | + const modules = Array(moduleRequests.length); | ||
| 310 | + const jobs = Array(moduleRequests.length); | ||
| 311 | + for (let i = 0; i < moduleRequests.length; ++i) { | ||
| 312 | + const { specifier, attributes } = moduleRequests[i]; | ||
| 313 | + const job = this.#loader.getModuleJobForRequire(specifier, url, attributes); | ||
| 314 | + specifiers[i] = specifier; | ||
| 315 | + modules[i] = job.module; | ||
| 316 | + jobs[i] = job; | ||
| 317 | + } | ||
| 318 | + this.module.link(specifiers, modules); | ||
| 319 | + this.linked = jobs; | ||
| 320 | + } finally { | ||
| 321 | + // Restore it - if it succeeds, we'll reset in the caller; Otherwise it's | ||
| 322 | + // not cached and if the error is caught, subsequent attempt would still fail. | ||
| 323 | + loader.loadCache.delete(url, importAttributes.type); | ||
| 311 | 324 | } | |
| 312 | - this.module.link(specifiers, modules); | ||
| 313 | - this.linked = jobs; | ||
| 314 | 325 | } | |
| 315 | 326 | ||
| 316 | 327 | get modulePromise() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -114,6 +114,12 @@ class LoadCache extends SafeMap { | |||
| 114 | 114 | validateString(type, 'type'); | |
| 115 | 115 | return super.get(url)?.[type] !== undefined; | |
| 116 | 116 | } | |
| 117 | + delete(url, type = kImplicitAssertType) { | ||
| 118 | + const cached = super.get(url); | ||
| 119 | + if (cached) { | ||
| 120 | + cached[type] = undefined; | ||
| 121 | + } | ||
| 122 | + } | ||
| 117 | 123 | } | |
| 118 | 124 | ||
| 119 | 125 | module.exports = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,8 @@ | |||
| 1 | + // Flags: --experimental-require-module | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + // This tests that ESM <-> ESM cycle is allowed in a require()-d graph. | ||
| 5 | + const common = require('../common'); | ||
| 6 | + const cycle = require('../fixtures/es-modules/cjs-esm-esm-cycle/c.cjs'); | ||
| 7 | + | ||
| 8 | + common.expectRequiredModule(cycle, { b: 5 }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + export { b } from './b.mjs'; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + import './a.mjs' | ||
| 2 | + export const b = 5; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + module.exports = require('./a.mjs'); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments