Skip to content

Commit e9bdb05

Browse files
authored
Merge pull request webpack#3971 from webpack/bugfix/fix_available_vars_in_fmtp
fix(nmf): Fix exports for var injection to include free glob export or args
2 parents 437dce4 + bd45bdc commit e9bdb05

5 files changed

Lines changed: 16 additions & 2 deletions

File tree

lib/NormalModule.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,9 @@ NormalModule.prototype.source = function(dependencyTemplates, outputOptions, req
270270

271271
var emitFunction = function emitFunction() {
272272
if(varNames.length === 0) return;
273-
274273
varStartCode += "/* WEBPACK VAR INJECTION */(function(" + varNames.join(", ") + ") {";
275274
// exports === this in the topLevelBlock, but exports do compress better...
276-
varEndCode = (topLevelBlock === block ? "}.call(exports, " : "}.call(this, ") +
275+
varEndCode = (topLevelBlock === block ? "}.call(" + (topLevelBlock.exportsArgument || "exports") + ", " : "}.call(this, ") +
277276
varExpressions.map(function(e) {
278277
return e.source();
279278
}).join(", ") + "))" + varEndCode;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require("should");
2+
it("should be able to use global in a harmony module", function() {
3+
var x = require("./module1");
4+
(x.default === global).should.be.ok();
5+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 1;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var freeGlobal = typeof global === "object" && global && global.Object === Object && global;
2+
3+
export default freeGlobal;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
target: "web",
3+
performance: {
4+
hints: false
5+
}
6+
};

0 commit comments

Comments
 (0)