mirror of https://github.com/webpack/webpack.git
Merge pull request #11621 from webpack/bugfix/11619
fix called variables with ProvidePlugin
This commit is contained in:
commit
36bcfaa149
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
});
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
const fn = (a, b) => {
|
||||
if(a === fn && b === fn) return "ok";
|
||||
return "fail";
|
||||
};
|
||||
module.exports = fn;
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
var ProvidePlugin = require("../../../../").ProvidePlugin;
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
plugins: [
|
||||
new ProvidePlugin({
|
||||
"xxx.yyy": "aaa"
|
||||
})
|
||||
]
|
||||
};
|
||||
Loading…
Reference in New Issue