From 5a3a23f3e35b24871453a055c07351682c728841 Mon Sep 17 00:00:00 2001 From: Sean Larkin Date: Sun, 15 Jan 2017 12:02:43 -0600 Subject: [PATCH 1/3] fix(nmf): Fix exports for var injection to include free glob exports or arguments --- lib/NormalModule.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/NormalModule.js b/lib/NormalModule.js index 460615cde36..e5327e4c497 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(module.exportsArgument || 'exports', " : "}.call(this, ") + varExpressions.map(function(e) { return e.source(); }).join(", ") + "))" + varEndCode; From bfccb20920dc43df91bcc6ce921c796af4bb9311 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Mon, 16 Jan 2017 03:21:13 +0100 Subject: [PATCH 2/3] fix PR --- lib/NormalModule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/NormalModule.js b/lib/NormalModule.js index e5327e4c497..37d9666009d 100644 --- a/lib/NormalModule.js +++ b/lib/NormalModule.js @@ -272,7 +272,7 @@ NormalModule.prototype.source = function(dependencyTemplates, outputOptions, req 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(module.exportsArgument || 'exports', " : "}.call(this, ") + + varEndCode = (topLevelBlock === block ? "}.call(" + (topLevelBlock.exportsArgument || "exports") + ", " : "}.call(this, ") + varExpressions.map(function(e) { return e.source(); }).join(", ") + "))" + varEndCode; From bd45bdc6fbb6ae3688a564f8d7c334765fd85442 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Mon, 16 Jan 2017 03:38:02 +0100 Subject: [PATCH 3/3] add test case for global in harmony modules --- test/configCases/parsing/harmony-global/index.js | 5 +++++ test/configCases/parsing/harmony-global/module.js | 1 + test/configCases/parsing/harmony-global/module1.js | 3 +++ test/configCases/parsing/harmony-global/webpack.config.js | 6 ++++++ 4 files changed, 15 insertions(+) create mode 100644 test/configCases/parsing/harmony-global/index.js create mode 100644 test/configCases/parsing/harmony-global/module.js create mode 100644 test/configCases/parsing/harmony-global/module1.js create mode 100644 test/configCases/parsing/harmony-global/webpack.config.js 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 + } +};