Skip to content

Commit

Permalink
fix(babel): circuit breaker for cyclic dependencies (fixes #1022)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anber committed Jul 27, 2022
1 parent fbdf555 commit c5a863c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-yaks-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@linaria/babel-preset': patch
---

Circuit breaker for cyclic dependencies.
16 changes: 14 additions & 2 deletions packages/babel/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class Module {

#isEvaluated = false;

#evaluatedFragments = new Set<string>();

#exports: Record<string, unknown> | unknown;

// #exportsProxy: Record<string, unknown>;
Expand Down Expand Up @@ -430,8 +432,20 @@ class Module {
});

code.forEach((source, idx) => {
if (this.#evaluatedFragments.has(source)) {
this.debug(
`evaluate:fragment-${padStart(idx + 1, 2)}`,
`is already evaluated`
);
return;
}

this.debug(`evaluate:fragment-${padStart(idx + 1, 2)}`, `\n${source}`);

this.#evaluatedFragments.add(source);

this.#isEvaluated = true;

try {
const script = new vm.Script(
`(function (exports) { ${source}\n})(exports);`,
Expand Down Expand Up @@ -460,8 +474,6 @@ class Module {
);
}
});

this.#isEvaluated = true;
}
}

Expand Down

0 comments on commit c5a863c

Please sign in to comment.