Skip to content

Commit

Permalink
fix called variables with ProvidePlugin
Browse files Browse the repository at this point in the history
fixes #11619
  • Loading branch information
sokra committed Oct 10, 2020
1 parent 57b493f commit 9130d10
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/ProvidePlugin.js
Expand Up @@ -66,6 +66,22 @@ class ProvidePlugin {
parser.state.module.addDependency(dep);
return true;
});

parser.hooks.call.for(name).tap("ProvidePlugin", expr => {
const nameIdentifier = name.includes(".")
? `__webpack_provided_${name.replace(/\./g, "_dot_")}`
: name;
const dep = new ProvidedDependency(
request[0],
nameIdentifier,
request.slice(1),
expr.callee.range
);
dep.loc = expr.callee.loc;
parser.state.module.addDependency(dep);
parser.walkExpressions(expr.arguments);
return true;
});
});
};
normalModuleFactory.hooks.parser
Expand Down
4 changes: 4 additions & 0 deletions test/configCases/parsing/issue-11619/index.js
@@ -0,0 +1,4 @@
it("should provide a module to a called free var", function () {
var x = xxx.yyy(xxx.yyy, xxx.yyy);
expect(x).toBe("ok");
});
5 changes: 5 additions & 0 deletions test/configCases/parsing/issue-11619/node_modules/aaa.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions test/configCases/parsing/issue-11619/webpack.config.js
@@ -0,0 +1,9 @@
var ProvidePlugin = require("../../../../").ProvidePlugin;
/** @type {import("../../../../").Configuration} */
module.exports = {
plugins: [
new ProvidePlugin({
"xxx.yyy": "aaa"
})
]
};

0 comments on commit 9130d10

Please sign in to comment.