From 2116b666e15c205be0c8215a974fa35eadcbf0dc Mon Sep 17 00:00:00 2001 From: Chris Sauve Date: Wed, 16 Oct 2019 10:05:53 -0400 Subject: [PATCH] Allow self for globalObject in async chunks Update changelog --- CHANGELOG.md | 3 +++ src/parseUtils.js | 2 ++ .../validWebpack4AsyncChunkUsingSelfInsteadOfWindow.js | 1 + ...idWebpack4AsyncChunkUsingSelfInsteadOfWindow.modules.json | 5 +++++ 4 files changed, 11 insertions(+) create mode 100644 test/bundles/validWebpack4AsyncChunkUsingSelfInsteadOfWindow.js create mode 100644 test/bundles/validWebpack4AsyncChunkUsingSelfInsteadOfWindow.modules.json diff --git a/CHANGELOG.md b/CHANGELOG.md index e3c32102..10e0f74b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ _Note: Gaps between patch versions are faulty, broken or test releases._ + * **Improvement** + * Support webpack builds where `output.globalObject` is set to `'self'` ([#323](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/323) by [@lemonmade](https://github.com/lemonmade)) + ## 3.5.2 * **Bug Fix** diff --git a/src/parseUtils.js b/src/parseUtils.js index 6e5dee88..b4dfeff2 100644 --- a/src/parseUtils.js +++ b/src/parseUtils.js @@ -185,6 +185,8 @@ function isAsyncChunkPushExpression(node) { callee.object.left.object && ( callee.object.left.object.name === 'window' || + // `self` is a common output.globalObject value used to support both workers and browsers + callee.object.left.object.name === 'self' || // Webpack 4 uses `this` instead of `window` callee.object.left.object.type === 'ThisExpression' ) && diff --git a/test/bundles/validWebpack4AsyncChunkUsingSelfInsteadOfWindow.js b/test/bundles/validWebpack4AsyncChunkUsingSelfInsteadOfWindow.js new file mode 100644 index 00000000..9e509fd9 --- /dev/null +++ b/test/bundles/validWebpack4AsyncChunkUsingSelfInsteadOfWindow.js @@ -0,0 +1 @@ +(self.webpackJsonp=self.webpackJsonp||[]).push([[27],{1:function(e,n,t){console.log("Chuck Norris")}}]); diff --git a/test/bundles/validWebpack4AsyncChunkUsingSelfInsteadOfWindow.modules.json b/test/bundles/validWebpack4AsyncChunkUsingSelfInsteadOfWindow.modules.json new file mode 100644 index 00000000..cabfce7a --- /dev/null +++ b/test/bundles/validWebpack4AsyncChunkUsingSelfInsteadOfWindow.modules.json @@ -0,0 +1,5 @@ +{ + "modules": { + "1": "function(e,n,t){console.log(\"Chuck Norris\")}" + } +}