Skip to content

Commit

Permalink
Merge pull request #176 from webpack-contrib/166-support-async-chunks…
Browse files Browse the repository at this point in the history
…-with-this

Fix parsing of async chunks that uses `this.webpackJsonp` instead of `window.webpackJsonp`
  • Loading branch information
th0r authored May 9, 2018
2 parents bf86048 + 28bbf3a commit ef1d700
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/parseUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function parseBundle(bundlePath) {
// Additional bundles with webpack 4 are loaded with:
// (window.webpackJsonp=window.webpackJsonp||[]).push([[chunkId], [<module>, <module>], [[optional_entries]]]);
if (
isWindowPropertyPushExpression(node) &&
isAsyncChunkPushExpression(node) &&
args.length === 1 &&
isArgumentContainingChunkIdsAndModulesList(args[0])
) {
Expand Down Expand Up @@ -164,11 +164,18 @@ function isArgumentArrayConcatContainingChunks(arg) {
return false;
}

function isWindowPropertyPushExpression(node) {
return node.callee.type === 'MemberExpression' &&
node.callee.property.name === 'push' &&
node.callee.object.type === 'AssignmentExpression' &&
node.callee.object.left.object.name === 'window';
function isAsyncChunkPushExpression(node) {
const { callee } = node;
return (
callee.type === 'MemberExpression' &&
callee.property.name === 'push' &&
callee.object.type === 'AssignmentExpression' &&
(
callee.object.left.object.name === 'window' ||
// Webpack 4 uses `this` instead of `window`
callee.object.left.object.type === 'ThisExpression'
)
);
}

function isModuleWrapper(node) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(this.webpackJsonp=this.webpackJsonp||[]).push([[27],{1:function(e,n,t){console.log("Chuck Norris")}}]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"modules": {
"1": "function(e,n,t){console.log(\"Chuck Norris\")}"
}
}

0 comments on commit ef1d700

Please sign in to comment.