Merge pull request #11621 from webpack/bugfix/11619

fix called variables with ProvidePlugin
This commit is contained in:
Tobias Koppers 2020-10-10 08:46:05 +02:00 committed by GitHub
commit 36bcfaa149
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 0 deletions

View File

@ -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

View File

@ -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");
});

View File

@ -0,0 +1,5 @@
const fn = (a, b) => {
if(a === fn && b === fn) return "ok";
return "fail";
};
module.exports = fn;

View File

@ -0,0 +1,9 @@
var ProvidePlugin = require("../../../../").ProvidePlugin;
/** @type {import("../../../../").Configuration} */
module.exports = {
plugins: [
new ProvidePlugin({
"xxx.yyy": "aaa"
})
]
};