Skip to content

Commit 1ab9fdb

Browse files
committed
Fixed Parser so that this Expression can work with ProvidePlugin
1 parent 5044762 commit 1ab9fdb

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

lib/Parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,7 @@ class Parser extends Tapable {
20082008
free = true;
20092009
exprName.push(this.scope.renames.get("this"));
20102010
} else if (expr.type === "ThisExpression") {
2011-
free = false;
2011+
free = this.scope.topLevelScope;
20122012
exprName.push("this");
20132013
} else {
20142014
return null;

test/configCases/plugins/provide-plugin/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ it("should provide a module for a nested var within a IIFE's argument", function
1616
}(process));
1717
});
1818

19+
it("should provide a module for thisExpression", () => {
20+
(this.aaa).should.be.eql("aaa");
21+
});
22+
1923
it("should provide a module for a nested var within a IIFE's this", function() {
2024
(function() {
2125
(this.env.NODE_ENV).should.be.eql("development");

test/configCases/plugins/provide-plugin/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module.exports = {
99
es2015: "./harmony",
1010
es2015_name: ["./harmony", "default"],
1111
es2015_alias: ["./harmony", "alias"],
12-
es2015_year: ["./harmony", "year"]
12+
es2015_year: ["./harmony", "year"],
13+
"this.aaa": "./aaa"
1314
})
1415
]
1516
};

0 commit comments

Comments
 (0)