Skip to content

Commit

Permalink
fix(ModuleGraph): handle cycles, I forgot to add the check
Browse files Browse the repository at this point in the history
fix #37
  • Loading branch information
jedwards1211 committed May 15, 2024
1 parent 0b12867 commit 6d0b75e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ModuleGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export default class ModuleGraph {
}

register(id: string, parentId: string) {
if (typeof id !== 'string' || !id.trim()) {
throw new Error(`invalid id: ${id}`)
}
if (typeof parentId !== 'string' || !parentId.trim()) {
throw new Error(`invalid parentId: ${parentId}`)
}
if (parentId === id) {
throw new Error(`parentId === id`)
}
const mod = this.getOrCreate(id)
const parent = this.getOrCreate(parentId)
mod.parents.add(parent)
Expand Down Expand Up @@ -75,7 +84,7 @@ export default class ModuleGraph {

while (queue.length) {
const mod = queue.pop()
if (!mod) continue
if (!mod || unloadIds.has(mod.id)) continue
unloadIds.add(mod.id)
if (!mod.parents.size) restart = true
for (const parent of mod.parents) {
Expand Down

0 comments on commit 6d0b75e

Please sign in to comment.