| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a03faf2 commit 30ed93d
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -287,22 +287,33 @@ class ModuleJobSync extends ModuleJobBase { | |||
| 287 | 287 | #loader = null; | |
| 288 | 288 | constructor(loader, url, importAttributes, moduleWrap, isMain, inspectBrk) { | |
| 289 | 289 | super(url, importAttributes, moduleWrap, isMain, inspectBrk, true); | |
| 290 | - assert(this.module instanceof ModuleWrap); | ||
| 291 | 290 | this.#loader = loader; | |
| 292 | - const moduleRequests = this.module.getModuleRequests(); | ||
| 293 | - // Specifiers should be aligned with the moduleRequests array in order. | ||
| 294 | - const specifiers = Array(moduleRequests.length); | ||
| 295 | - const modules = Array(moduleRequests.length); | ||
| 296 | - const jobs = Array(moduleRequests.length); | ||
| 297 | - for (let i = 0; i < moduleRequests.length; ++i) { | ||
| 298 | - const { specifier, attributes } = moduleRequests[i]; | ||
| 299 | - const job = this.#loader.getModuleJobForRequire(specifier, url, attributes); | ||
| 300 | - specifiers[i] = specifier; | ||
| 301 | - modules[i] = job.module; | ||
| 302 | - jobs[i] = job; | ||
| 291 | + | ||
| 292 | + assert(this.module instanceof ModuleWrap); | ||
| 293 | + // Store itself into the cache first before linking in case there are circular | ||
| 294 | + // references in the linking. | ||
| 295 | + loader.loadCache.set(url, importAttributes.type, this); | ||
| 296 | + | ||
| 297 | + try { | ||
| 298 | + const moduleRequests = this.module.getModuleRequests(); | ||
| 299 | + // Specifiers should be aligned with the moduleRequests array in order. | ||
| 300 | + const specifiers = Array(moduleRequests.length); | ||
| 301 | + const modules = Array(moduleRequests.length); | ||
| 302 | + const jobs = Array(moduleRequests.length); | ||
| 303 | + for (let i = 0; i < moduleRequests.length; ++i) { | ||
| 304 | + const { specifier, attributes } = moduleRequests[i]; | ||
| 305 | + const job = this.#loader.getModuleJobForRequire(specifier, url, attributes); | ||
| 306 | + specifiers[i] = specifier; | ||
| 307 | + modules[i] = job.module; | ||
| 308 | + jobs[i] = job; | ||
| 309 | + } | ||
| 310 | + this.module.link(specifiers, modules); | ||
| 311 | + this.linked = jobs; | ||
| 312 | + } finally { | ||
| 313 | + // Restore it - if it succeeds, we'll reset in the caller; Otherwise it's | ||
| 314 | + // not cached and if the error is caught, subsequent attempt would still fail. | ||
| 315 | + loader.loadCache.delete(url, importAttributes.type); | ||
| 303 | 316 | } | |
| 304 | - this.module.link(specifiers, modules); | ||
| 305 | - this.linked = jobs; | ||
| 306 | 317 | } | |
| 307 | 318 | ||
| 308 | 319 | 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