Skip to content

Commit

Permalink
Properly render dynamic imports when imported module is empty (#2714)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Feb 23, 2019
1 parent 792cd85 commit e8c078d
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Chunk.ts
Expand Up @@ -382,7 +382,7 @@ export default class Chunk {
for (const { node, resolution } of module.dynamicImports) {
if (!resolution) continue;
if (resolution instanceof Module) {
if (resolution.isIncluded() && resolution.chunk !== this) {
if (!resolution.chunk.isEmpty && resolution.chunk !== this) {
const resolutionChunk = resolution.facadeChunk || resolution.chunk;
let relPath = normalize(relative(dirname(this.id), resolutionChunk.id));
if (!relPath.startsWith('../')) relPath = './' + relPath;
Expand Down
@@ -0,0 +1,6 @@
module.exports = {
description: 'handles dynamic imports when the imported module only reexports from other modules',
options: {
input: ['main']
}
};
@@ -0,0 +1,7 @@
define(['exports'], function (exports) { 'use strict';

const value = 42;

exports.value = value;

});
@@ -0,0 +1,5 @@
define(['require'], function (require) { 'use strict';

new Promise(function (resolve, reject) { require(['./generated-chunk.js'], resolve, reject) }).then(({ value }) => console.log(value));

});
@@ -0,0 +1,5 @@
'use strict';

const value = 42;

exports.value = value;
@@ -0,0 +1,3 @@
'use strict';

Promise.resolve(require('./generated-chunk.js')).then(({ value }) => console.log(value));
@@ -0,0 +1,3 @@
const value = 42;

export { value };
@@ -0,0 +1 @@
import('./generated-chunk.js').then(({ value }) => console.log(value));
@@ -0,0 +1,10 @@
System.register([], function (exports, module) {
'use strict';
return {
execute: function () {

const value = exports('value', 42);

}
};
});
@@ -0,0 +1,10 @@
System.register([], function (exports, module) {
'use strict';
return {
execute: function () {

module.import('./generated-chunk.js').then(({ value }) => console.log(value));

}
};
});
@@ -0,0 +1 @@
export const value = 42;
@@ -0,0 +1 @@
export {value} from './dep';
@@ -0,0 +1 @@
import('./dynamic').then(({ value }) => console.log(value));

0 comments on commit e8c078d

Please sign in to comment.