Skip to content

Commit 9130d10

Browse files
committed
fix called variables with ProvidePlugin
fixes #11619
1 parent 57b493f commit 9130d10

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy