diff --git a/lib/NormalModule.js b/lib/NormalModule.js index 460615cde36..37d9666009d 100644 --- a/lib/NormalModule.js +++ b/lib/NormalModule.js @@ -270,10 +270,9 @@ NormalModule.prototype.source = function(dependencyTemplates, outputOptions, req var emitFunction = function emitFunction() { if(varNames.length === 0) return; - varStartCode += "/* WEBPACK VAR INJECTION */(function(" + varNames.join(", ") + ") {"; // exports === this in the topLevelBlock, but exports do compress better... - varEndCode = (topLevelBlock === block ? "}.call(exports, " : "}.call(this, ") + + varEndCode = (topLevelBlock === block ? "}.call(" + (topLevelBlock.exportsArgument || "exports") + ", " : "}.call(this, ") + varExpressions.map(function(e) { return e.source(); }).join(", ") + "))" + varEndCode; diff --git a/test/configCases/parsing/harmony-global/index.js b/test/configCases/parsing/harmony-global/index.js new file mode 100644 index 00000000000..fde7f60f6cd --- /dev/null +++ b/test/configCases/parsing/harmony-global/index.js @@ -0,0 +1,5 @@ +require("should"); +it("should be able to use global in a harmony module", function() { + var x = require("./module1"); + (x.default === global).should.be.ok(); +}); diff --git a/test/configCases/parsing/harmony-global/module.js b/test/configCases/parsing/harmony-global/module.js new file mode 100644 index 00000000000..aef22247d75 --- /dev/null +++ b/test/configCases/parsing/harmony-global/module.js @@ -0,0 +1 @@ +export default 1; diff --git a/test/configCases/parsing/harmony-global/module1.js b/test/configCases/parsing/harmony-global/module1.js new file mode 100644 index 00000000000..88c7502263b --- /dev/null +++ b/test/configCases/parsing/harmony-global/module1.js @@ -0,0 +1,3 @@ +var freeGlobal = typeof global === "object" && global && global.Object === Object && global; + +export default freeGlobal; diff --git a/test/configCases/parsing/harmony-global/webpack.config.js b/test/configCases/parsing/harmony-global/webpack.config.js new file mode 100644 index 00000000000..a65179e2b46 --- /dev/null +++ b/test/configCases/parsing/harmony-global/webpack.config.js @@ -0,0 +1,6 @@ +module.exports = { + target: "web", + performance: { + hints: false + } +};