Skip to content

Commit

Permalink
Make sure tree-shaken dynamic imports do not lead to the creation of
Browse files Browse the repository at this point in the history
namespace objects when inlined
  • Loading branch information
lukastaegert committed Dec 7, 2018
1 parent a9290da commit ae2d424
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/Chunk.ts
Expand Up @@ -248,10 +248,12 @@ export default class Chunk {
const declaration = module.imports[importName];
this.traceAndInitializeImport(declaration.name, declaration.module);
}
for (const { resolution } of module.dynamicImports) {
this.hasDynamicImport = true;
if (resolution instanceof Module && resolution.chunk === this)
resolution.getOrCreateNamespace().include();
for (const { node, resolution } of module.dynamicImports) {
if (node.included) {
this.hasDynamicImport = true;
if (resolution instanceof Module && resolution.chunk === this)
resolution.getOrCreateNamespace().include();
}
}
}

Expand Down
@@ -1,4 +1,4 @@
define(['require'], function (require) { 'use strict';
define(function () { 'use strict';

console.log('main2');

Expand Down
@@ -1,4 +1,4 @@
define(['require'], function (require) { 'use strict';
define(function () { 'use strict';

console.log('main1');

Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/default-identifier-deshadowing/dep.js
@@ -1,4 +1,4 @@
export default function a() {
a = someGlobal;
return a();
}
}
@@ -0,0 +1,6 @@
module.exports = {
description: 'completely removes tree-shaken dynamic imports ',
options: {
inlineDynamicImports: true
}
};
@@ -0,0 +1,5 @@
define(function () { 'use strict';

console.log('main');

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

console.log('main');
@@ -0,0 +1 @@
console.log('main');
@@ -0,0 +1,6 @@
(function () {
'use strict';

console.log('main');

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

console.log('main');

}
};
});
@@ -0,0 +1,9 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, (function () { 'use strict';

console.log('main');

})));
@@ -0,0 +1,2 @@
console.log('dynamic');
export var dynamic = 42;
2 changes: 2 additions & 0 deletions test/form/samples/inlined-treeshaken-dynamic-import/main.js
@@ -0,0 +1,2 @@
console.log('main');
const getFoo = () => import('./dynamic.js');

0 comments on commit ae2d424

Please sign in to comment.