From 7d1f384122431b90e715161e50a5abf39dc8fd9d Mon Sep 17 00:00:00 2001 From: kingdaro Date: Thu, 7 Dec 2017 04:01:08 -0500 Subject: [PATCH] fix for bundle-loader when using ESM --- src/builtins/bundle-loader.js | 4 ---- test/integration/dynamic-esm/index.js | 7 +++++++ test/integration/dynamic-esm/local.js | 2 ++ test/javascript.js | 17 +++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 test/integration/dynamic-esm/index.js create mode 100644 test/integration/dynamic-esm/local.js diff --git a/src/builtins/bundle-loader.js b/src/builtins/bundle-loader.js index 9f8f482821d..fd069467059 100644 --- a/src/builtins/bundle-loader.js +++ b/src/builtins/bundle-loader.js @@ -77,10 +77,6 @@ function loadCSSBundle(bundle) { function requireModule(id) { let res = require(id); - if (res.__esModule) { - return res.default; - } - return res; } diff --git a/test/integration/dynamic-esm/index.js b/test/integration/dynamic-esm/index.js new file mode 100644 index 00000000000..08637f54fbd --- /dev/null +++ b/test/integration/dynamic-esm/index.js @@ -0,0 +1,7 @@ +var local = import('./local'); + +export default function () { + return local.then(function (l) { + return l.a + l.b; + }); +}; diff --git a/test/integration/dynamic-esm/local.js b/test/integration/dynamic-esm/local.js new file mode 100644 index 00000000000..72ab60e17a2 --- /dev/null +++ b/test/integration/dynamic-esm/local.js @@ -0,0 +1,2 @@ +export const a = 1; +export const b = 2; diff --git a/test/javascript.js b/test/javascript.js index 002f548acfa..ff1d7c4cb80 100644 --- a/test/javascript.js +++ b/test/javascript.js @@ -55,6 +55,23 @@ describe('javascript', function () { assert.equal(await output(), 3); }); + it('should return all exports as an object when using ES modules', async function () { + let b = await bundle(__dirname + '/integration/dynamic-esm/index.js'); + + assertBundleTree(b, { + name: 'index.js', + assets: ['index.js', 'bundle-loader.js', 'bundle-url.js'], + childBundles: [{ + assets: ['local.js'], + childBundles: [] + }] + }); + + let output = run(b).default; + assert.equal(typeof output, 'function'); + assert.equal(await output(), 3); + }); + it('should hoist common dependencies into a parent bundle', async function () { let b = await bundle(__dirname + '/integration/dynamic-hoist/index.js');