Skip to content

Commit ea11e42

Browse files
authored
Merge pull request webpack#4010 from kagawagao/master
fix DefinePlugin stringifyObj bug
2 parents 283689c + 0b7775e commit ea11e42

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎lib/DefinePlugin.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ class DefinePlugin {
3535
}(definitions, ""));
3636

3737
function stringifyObj(obj) {
38-
return "{" + Object.keys(obj).map((key) => {
38+
return "__webpack_require__.i({" + Object.keys(obj).map((key) => {
3939
let code = obj[key];
4040
return JSON.stringify(key) + ":" + toCode(code);
41-
}).join(",") + "}";
41+
}).join(",") + "})";
4242
}
4343

4444
function toCode(code) {

‎test/configCases/plugins/define-plugin/index.js‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,15 @@ it("should define process.env.DEFINED_NESTED_KEY", function() {
7575
});
7676
it("should define process.env.DEFINED_NESTED_KEY_STRING", function() {
7777
if(process.env.DEFINED_NESTED_KEY_STRING !== "string") require("fail");
78-
})
78+
});
79+
it("should assign to process.env", function() {
80+
process.env.TEST = "test";
81+
process.env.TEST.should.be.eql("test");
82+
});
83+
it("should not have brakets on start", function() {
84+
function f() {
85+
throw new Error("should not be called");
86+
}
87+
f // <- no semicolon here
88+
OBJECT;
89+
});

0 commit comments

Comments
 (0)