diff --git a/lib/ContextModule.js b/lib/ContextModule.js index 6163225f15d..d6e66ce2a46 100644 --- a/lib/ContextModule.js +++ b/lib/ContextModule.js @@ -269,12 +269,12 @@ class ContextModule extends Module { getReturn(type) { if (type === 1) return "module"; if (type === 2) - return 'Object.assign({/* fake namespace object */}, module, { "default": module })'; + return 'Object.assign({/* fake namespace object */}, typeof module === "object" && module, { "default": module })'; if (type === 0) { if (this.options.namespaceObject === "strict") { return '/* fake namespace object */ { "default": module }'; } else { - return '(typeof module === "object" && module && module.__esModule ? module : /* fake namespace object */ { "default": module })'; + return '(typeof module === "object" && module && module.__esModule ? module : Object.assign({/* fake namespace object */}, typeof module === "object" && module, { "default": module }))'; } } } diff --git a/lib/RuntimeTemplate.js b/lib/RuntimeTemplate.js index c229d364c64..05554bd6c3c 100644 --- a/lib/RuntimeTemplate.js +++ b/lib/RuntimeTemplate.js @@ -94,7 +94,7 @@ module.exports = class RuntimeTemplate { } else { return `Object(function() { var module = ${ rawModule - }; return typeof module === "object" && module && module.__esModule ? module : { /* fake namespace object */ "default": module }; }())`; + }; return typeof module === "object" && module && module.__esModule ? module : Object.assign({/* fake namespace object */}, typeof module === "object" && module, { "default": module }); }())`; } } @@ -150,7 +150,7 @@ module.exports = class RuntimeTemplate { } else { getModuleFunction = `function() { ${header}var module = ${ rawModule - }; return typeof module === "object" && module && module.__esModule ? module : { /* fake namespace object */ "default": module }; }`; + }; return typeof module === "object" && module && module.__esModule ? module : Object.assign({/* fake namespace object */}, typeof module === "object" && module, { "default": module }); }`; } return `${promise || "Promise.resolve()"}.then(${getModuleFunction})`; diff --git a/test/cases/mjs/non-mjs-namespace-object-lazy/index.js b/test/cases/mjs/non-mjs-namespace-object-lazy/index.js index c44f3bfb9cd..c9c6d829c9e 100644 --- a/test/cases/mjs/non-mjs-namespace-object-lazy/index.js +++ b/test/cases/mjs/non-mjs-namespace-object-lazy/index.js @@ -1,6 +1,6 @@ it("should receive a namespace object when importing commonjs", function(done) { import("./cjs").then(function(result) { - result.should.be.eql({ default: { named: "named", default: "default" } }); + result.should.be.eql({ named: "named", default: { named: "named", default: "default" } }); done(); }).catch(done); }); @@ -60,9 +60,9 @@ function promiseTest(promise, equalsTo) { it("should receive a namespace object when importing commonjs via context", function() { return Promise.all([ - promiseTest(contextCJS("one"), { default: { named: "named", default: "default" } }), + promiseTest(contextCJS("one"), { named: "named", default: { named: "named", default: "default" } }), promiseTest(contextCJS("two"), { __esModule: true, named: "named", default: "default" }), - promiseTest(contextCJS("three"), { default: { named: "named", default: "default" } }), + promiseTest(contextCJS("three"), { named: "named", default: { named: "named", default: "default" } }), promiseTest(contextCJS("null"), { default: null }) ]); }); @@ -77,7 +77,7 @@ it("should receive a namespace object when importing harmony via context", funct it("should receive a namespace object when importing mixed content via context", function() { return Promise.all([ - promiseTest(contextMixed("one"), { default: { named: "named", default: "default" } }), + promiseTest(contextMixed("one"), { named: "named", default: { named: "named", default: "default" } }), promiseTest(contextMixed("two"), { __esModule: true, named: "named", default: "default" }), promiseTest(contextMixed("three"), { named: "named", default: "default" }), promiseTest(contextMixed("null"), { default: null }) diff --git a/test/statsCases/aggressive-splitting-entry/expected.txt b/test/statsCases/aggressive-splitting-entry/expected.txt index 493e0a7a8ff..8cbc870fabc 100644 --- a/test/statsCases/aggressive-splitting-entry/expected.txt +++ b/test/statsCases/aggressive-splitting-entry/expected.txt @@ -5,7 +5,7 @@ Child fitting: Built at: Thu Jan 01 1970 00:00:00 GMT Asset Size Chunks Chunk Names fb95acf7c457672e70d0.js 1.05 KiB 0 [emitted] - a1e683753eca705a0882.js 9.92 KiB 1 [emitted] + a1e683753eca705a0882.js 9.97 KiB 1 [emitted] d43339a3d0f86c6b8d90.js 1.94 KiB 2 [emitted] 6c7fb52c5514dbfbf094.js 1.94 KiB 3 [emitted] Entrypoint main = d43339a3d0f86c6b8d90.js 6c7fb52c5514dbfbf094.js a1e683753eca705a0882.js @@ -31,7 +31,7 @@ Child content-change: Built at: Thu Jan 01 1970 00:00:00 GMT Asset Size Chunks Chunk Names fb95acf7c457672e70d0.js 1.05 KiB 0 [emitted] - a1e683753eca705a0882.js 9.92 KiB 1 [emitted] + a1e683753eca705a0882.js 9.97 KiB 1 [emitted] d43339a3d0f86c6b8d90.js 1.94 KiB 2 [emitted] 6c7fb52c5514dbfbf094.js 1.94 KiB 3 [emitted] Entrypoint main = d43339a3d0f86c6b8d90.js 6c7fb52c5514dbfbf094.js a1e683753eca705a0882.js diff --git a/test/statsCases/import-weak/expected.txt b/test/statsCases/import-weak/expected.txt index 89db3bb279b..921e5d9a75a 100644 --- a/test/statsCases/import-weak/expected.txt +++ b/test/statsCases/import-weak/expected.txt @@ -3,7 +3,7 @@ Time: Xms Built at: Thu Jan 01 1970 00:00:00 GMT Asset Size Chunks Chunk Names 0.js 149 bytes 0 [emitted] -entry.js 7.63 KiB 1 [emitted] entry +entry.js 7.79 KiB 1 [emitted] entry Entrypoint entry = entry.js [0] ./modules/b.js 22 bytes {0} [built] [1] ./entry.js 120 bytes {1} [built] diff --git a/test/statsCases/limit-chunk-count-plugin/expected.txt b/test/statsCases/limit-chunk-count-plugin/expected.txt index 5062c302fc9..e7654d94f74 100644 --- a/test/statsCases/limit-chunk-count-plugin/expected.txt +++ b/test/statsCases/limit-chunk-count-plugin/expected.txt @@ -4,7 +4,7 @@ Child 1 chunks: Time: Xms Built at: Thu Jan 01 1970 00:00:00 GMT Asset Size Chunks Chunk Names - bundle.js 5.52 KiB 0 [emitted] main + bundle.js 5.68 KiB 0 [emitted] main Entrypoint main = bundle.js chunk {0} bundle.js (main) 191 bytes <{0}> >{0}< [entry] [rendered] [0] ./index.js 73 bytes {0} [built] @@ -17,9 +17,9 @@ Child 2 chunks: Hash: f90c7b21ae5c6e853a0d Time: Xms Built at: Thu Jan 01 1970 00:00:00 GMT - Asset Size Chunks Chunk Names - 0.bundle.js 912 bytes 0 [emitted] - bundle.js 7.14 KiB 1 [emitted] main + Asset Size Chunks Chunk Names + 0.bundle.js 1 KiB 0 [emitted] + bundle.js 7.19 KiB 1 [emitted] main Entrypoint main = bundle.js chunk {0} 0.bundle.js 118 bytes <{0}> <{1}> >{0}< [rendered] [0] ./d.js 22 bytes {0} [built] @@ -34,9 +34,9 @@ Child 3 chunks: Time: Xms Built at: Thu Jan 01 1970 00:00:00 GMT Asset Size Chunks Chunk Names - 0.bundle.js 774 bytes 0 [emitted] + 0.bundle.js 886 bytes 0 [emitted] 1.bundle.js 245 bytes 1 [emitted] - bundle.js 7.14 KiB 2 [emitted] main + bundle.js 7.19 KiB 2 [emitted] main Entrypoint main = bundle.js chunk {0} 0.bundle.js 74 bytes <{0}> <{2}> >{0}< >{1}< [rendered] [0] ./d.js 22 bytes {0} [built] @@ -54,8 +54,8 @@ Child 4 chunks: Asset Size Chunks Chunk Names 0.bundle.js 236 bytes 0 [emitted] 1.bundle.js 245 bytes 1 [emitted] - 2.bundle.js 603 bytes 2 [emitted] - bundle.js 7.14 KiB 3 [emitted] main + 2.bundle.js 715 bytes 2 [emitted] + bundle.js 7.19 KiB 3 [emitted] main Entrypoint main = bundle.js chunk {0} 0.bundle.js 44 bytes <{2}> <{3}> [rendered] [0] ./d.js 22 bytes {0} [built] diff --git a/test/statsCases/named-chunks-plugin-async/expected.txt b/test/statsCases/named-chunks-plugin-async/expected.txt index 78f3b18053a..f5d8b300c07 100644 --- a/test/statsCases/named-chunks-plugin-async/expected.txt +++ b/test/statsCases/named-chunks-plugin-async/expected.txt @@ -2,9 +2,9 @@ Hash: c5b0089a4015e8744f8e Time: Xms Built at: Thu Jan 01 1970 00:00:00 GMT Asset Size Chunks Chunk Names -chunk-containing-__a_js.js 453 bytes chunk-containing-__a_js [emitted] +chunk-containing-__a_js.js 509 bytes chunk-containing-__a_js [emitted] chunk-containing-__b_js.js 173 bytes chunk-containing-__b_js [emitted] - entry.js 7.17 KiB entry [emitted] entry + entry.js 7.28 KiB entry [emitted] entry Entrypoint entry = entry.js [0] ./modules/b.js 22 bytes {chunk-containing-__b_js} [built] [1] ./modules/a.js 37 bytes {chunk-containing-__a_js} [built]