Skip to content

Commit 36bcfaa

Browse files
authored
Merge pull request #11621 from webpack/bugfix/11619
fix called variables with ProvidePlugin
2 parents 3e42105 + 9130d10 commit 36bcfaa

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

lib/ProvidePlugin.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ class ProvidePlugin {
6666
parser.state.module.addDependency(dep);
6767
return true;
6868
});
69+
70+
parser.hooks.call.for(name).tap("ProvidePlugin", expr => {
71+
const nameIdentifier = name.includes(".")
72+
? `__webpack_provided_${name.replace(/\./g, "_dot_")}`
73+
: name;
74+
const dep = new ProvidedDependency(
75+
request[0],
76+
nameIdentifier,
77+
request.slice(1),
78+
expr.callee.range
79+
);
80+
dep.loc = expr.callee.loc;
81+
parser.state.module.addDependency(dep);
82+
parser.walkExpressions(expr.arguments);
83+
return true;
84+
});
6985
});
7086
};
7187
normalModuleFactory.hooks.parser
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
it("should provide a module to a called free var", function () {
2+
var x = xxx.yyy(xxx.yyy, xxx.yyy);
3+
expect(x).toBe("ok");
4+
});

test/configCases/parsing/issue-11619/node_modules/aaa.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var ProvidePlugin = require("../../../../").ProvidePlugin;
2+
/** @type {import("../../../../").Configuration} */
3+
module.exports = {
4+
plugins: [
5+
new ProvidePlugin({
6+
"xxx.yyy": "aaa"
7+
})
8+
]
9+
};

0 commit comments

Comments
 (0)