From 7733d2b1c18c9fb656cf8d64e5466df585df259b Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Mon, 7 Oct 2019 10:52:35 +0200 Subject: [PATCH] fix infinite loop on circular inner graph references --- lib/optimize/InnerGraphPlugin.js | 1 + test/cases/inner-graph/circular2/index.js | 14 ++++++ test/cases/inner-graph/circular2/module.js | 49 +++++++++++++++++++ .../temp-watch-1569996664301/bundle.js | 24 +++++++++ 4 files changed, 88 insertions(+) create mode 100644 test/cases/inner-graph/circular2/index.js create mode 100644 test/cases/inner-graph/circular2/module.js create mode 100644 test/fixtures/temp-watch-1569996664301/bundle.js diff --git a/lib/optimize/InnerGraphPlugin.js b/lib/optimize/InnerGraphPlugin.js index 9873787f7..3db4a8911 100644 --- a/lib/optimize/InnerGraphPlugin.js +++ b/lib/optimize/InnerGraphPlugin.js @@ -117,6 +117,7 @@ class InnerGraphPlugin { if (itemValue !== undefined) { for (const i of itemValue) { if (i === key) continue; + if (value.has(i)) continue; newSet.add(i); if (typeof i !== "string") { isTerminal = false; diff --git a/test/cases/inner-graph/circular2/index.js b/test/cases/inner-graph/circular2/index.js new file mode 100644 index 000000000..abee2105e --- /dev/null +++ b/test/cases/inner-graph/circular2/index.js @@ -0,0 +1,14 @@ +import { x, y, z, a, f3 } from "./module"; + +it("should be able to handle circular referenced", () => { + expect(x()).toEqual([y, z]); + const [_a, b, c, d] = a(); + expect(b()).toEqual([a, b, c, d]); + expect(c()).toEqual([a, b, c, d]); + expect(d()).toEqual([a, b, c, d]); + const [f2, f4] = f3(); + const [f1, _f3] = f2(); + expect(_f3).toBe(f3); + expect(f3()).toEqual(f1()); + expect(f2()).toEqual(f4()); +}); diff --git a/test/cases/inner-graph/circular2/module.js b/test/cases/inner-graph/circular2/module.js new file mode 100644 index 000000000..aabde457b --- /dev/null +++ b/test/cases/inner-graph/circular2/module.js @@ -0,0 +1,49 @@ +function x() { + return [y, z]; +} + +function y() { + return [x, z]; +} + +function z() { + return [x, y]; +} + +export { x, y, z }; + +function a() { + return [a, b, c, d]; +} + +function b() { + return [a, b, c, d]; +} + +function c() { + return [a, b, c, d]; +} + +function d() { + return [a, b, c, d]; +} + +export { a }; + +function f1() { + return [f2, f4]; +} + +function f2() { + return [f1, f3]; +} + +function f3() { + return [f2, f4]; +} + +function f4() { + return [f1, f3]; +} + +export { f3 }; diff --git a/test/fixtures/temp-watch-1569996664301/bundle.js b/test/fixtures/temp-watch-1569996664301/bundle.js new file mode 100644 index 000000000..69d176dd3 --- /dev/null +++ b/test/fixtures/temp-watch-1569996664301/bundle.js @@ -0,0 +1,24 @@ +/******/ (() => { // webpackBootstrap +/******/ var __webpack_modules__ = ({ + +/***/ "./test/fixtures/temp-watch-1569996664301/file.js": +/*!****************************************************************!*\ + !*** (webpack)/test/fixtures/temp-watch-1569996664301/file.js ***! + \****************************************************************/ +/*! exports [maybe provided (runtime-defined)] [no usage info] */ +/*! runtime requirements: */ +/***/ (() => { + +eval("'bar'\n\n//# sourceURL=webpack:///(webpack)/test/fixtures/temp-watch-1569996664301/file.js?"); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ +/************************************************************************/ +/******/ // startup +/******/ // Load entry module +/******/ __webpack_modules__["./test/fixtures/temp-watch-1569996664301/file.js"](); +/******/ })() +; \ No newline at end of file