Skip to content

Commit

Permalink
fix infinite loop in inner graph optimization
Browse files Browse the repository at this point in the history
fixes #11678
  • Loading branch information
sokra committed Oct 15, 2020
1 parent 27796db commit b6bc273
Show file tree
Hide file tree
Showing 3 changed files with 3,186 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/optimize/InnerGraph.js
Expand Up @@ -116,6 +116,7 @@ exports.inferDependencyUsage = state => {
}

const { innerGraph, usageCallbackMap } = innerGraphState;
const processed = new Map();
// flatten graph to terminal nodes (string, undefined or true)
const nonTerminal = new Set(innerGraph.keys());
while (nonTerminal.size > 0) {
Expand All @@ -124,7 +125,15 @@ exports.inferDependencyUsage = state => {
let newSet = new Set();
let isTerminal = true;
const value = innerGraph.get(key);
let alreadyProcessed = processed.get(key);
if (alreadyProcessed === undefined) {
alreadyProcessed = new Set();
processed.set(key, alreadyProcessed);
}
if (value !== true && value !== undefined) {
for (const item of value) {
alreadyProcessed.add(item);
}
for (const item of value) {
if (typeof item === "string") {
newSet.add(item);
Expand All @@ -137,7 +146,7 @@ exports.inferDependencyUsage = state => {
if (itemValue !== undefined) {
for (const i of itemValue) {
if (i === key) continue;
if (value.has(i)) continue;
if (alreadyProcessed.has(i)) continue;
newSet.add(i);
if (typeof i !== "string") {
isTerminal = false;
Expand Down

0 comments on commit b6bc273

Please sign in to comment.