Skip to content

Commit

Permalink
Fix nested async imports from a shared module (#1724)
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored and fathyb committed Jul 13, 2018
1 parent 52f9766 commit e0d8821
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/packagers/JSConcatPackager.js
Expand Up @@ -151,7 +151,7 @@ class JSConcatPackager extends Packager {
}

for (let [dep, mod] of asset.depAssets) {
if (dep.dynamic && this.bundle.childBundles.has(mod.parentBundle)) {
if (dep.dynamic) {
for (let child of mod.parentBundle.siblingBundles) {
if (!child.isEmpty) {
await this.addBundleLoader(child.type, asset);
Expand Down
2 changes: 1 addition & 1 deletion src/packagers/JSPackager.js
Expand Up @@ -49,7 +49,7 @@ class JSPackager extends Packager {
let deps = {};
for (let [dep, mod] of asset.depAssets) {
// For dynamic dependencies, list the child bundles to load along with the module id
if (dep.dynamic && this.bundle.childBundles.has(mod.parentBundle)) {
if (dep.dynamic) {
let bundles = [this.getBundleSpecifier(mod.parentBundle)];
for (let child of mod.parentBundle.siblingBundles) {
if (!child.isEmpty) {
Expand Down
Empty file.
1 change: 1 addition & 0 deletions test/integration/dynamic-hoist-deep/a.js
@@ -0,0 +1 @@
import './c';
1 change: 1 addition & 0 deletions test/integration/dynamic-hoist-deep/b.js
@@ -0,0 +1 @@
import './c';
1 change: 1 addition & 0 deletions test/integration/dynamic-hoist-deep/c.js
@@ -0,0 +1 @@
import('./1');
6 changes: 6 additions & 0 deletions test/integration/dynamic-hoist-deep/index.js
@@ -0,0 +1,6 @@
import('./a');
import('./b');

export default {
asdf: 1,
};
38 changes: 38 additions & 0 deletions test/javascript.js
Expand Up @@ -396,6 +396,44 @@ describe('javascript', function() {
assert.equal(await output(), 5);
});

it('should support hoisting shared modules with async imports up multiple levels', async function() {
let b = await bundle(
__dirname + '/integration/dynamic-hoist-deep/index.js',
{
sourceMaps: false
}
);

await assertBundleTree(b, {
name: 'index.js',
assets: [
'index.js',
'c.js',
'bundle-loader.js',
'bundle-url.js',
'js-loader.js'
],
childBundles: [
{
assets: ['a.js'],
childBundles: [
{
assets: ['1.js'],
childBundles: []
}
]
},
{
assets: ['b.js'],
childBundles: []
}
]
});

let output = await run(b);
assert.deepEqual(output, {default: {asdf: 1}});
});

it('should support requiring JSON files', async function() {
let b = await bundle(__dirname + '/integration/json/index.js');

Expand Down

0 comments on commit e0d8821

Please sign in to comment.