Skip to content

Commit

Permalink
keep nested exports with preserveModules (#2854) (#2863)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Caserta authored and lukastaegert committed May 17, 2019
1 parent 7e3225f commit 6a79bc1
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Chunk.ts
Expand Up @@ -338,6 +338,7 @@ export default class Chunk {
const dynamicDependencies: Set<Chunk | ExternalModule> = new Set();
for (const module of this.orderedModules) {
this.addChunksFromDependencies(module.dependencies, dependencies);
this.addChunksFromDependencies(module.getReexportModules(), dependencies);
this.addChunksFromDependencies(module.dynamicDependencies, dynamicDependencies);
this.setUpModuleImports(module);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Module.ts
Expand Up @@ -311,6 +311,10 @@ export default class Module {
);
}

getReexportModules() {
return this.getReexports().map(exportName => this.getVariableForExportName(exportName).module);
}

getReexports(walkedModuleIds = new Set<string>()) {
// avoid infinite recursion when using circular `export * from X`
if (walkedModuleIds.has(this.id)) {
Expand Down
@@ -0,0 +1,7 @@
module.exports = {
description: 'confirm exports are preserved when exporting a module',
options: {
input: ['main1.js', 'main2.js'],
preserveModules: true
}
};
@@ -0,0 +1,7 @@
define(['exports'], function (exports) { 'use strict';

const foo = 1;

exports.foo = foo;

});
@@ -0,0 +1,9 @@
define(['exports', './dep'], function (exports, __chunk_1) { 'use strict';



exports.foo = __chunk_1.foo;

Object.defineProperty(exports, '__esModule', { value: true });

});
@@ -0,0 +1,9 @@
define(['exports', './dep'], function (exports, __chunk_1) { 'use strict';



exports.foo = __chunk_1.foo;

Object.defineProperty(exports, '__esModule', { value: true });

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

const foo = 1;

exports.foo = foo;
@@ -0,0 +1,9 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var __chunk_1 = require('./dep.js');



exports.foo = __chunk_1.foo;
@@ -0,0 +1,9 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var __chunk_1 = require('./dep.js');



exports.foo = __chunk_1.foo;
@@ -0,0 +1,3 @@
const foo = 1;

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

const foo = exports('foo', 1);

}
};
});
@@ -0,0 +1,13 @@
System.register(['./dep.js'], function (exports, module) {
'use strict';
return {
setters: [function (module) {
exports('foo', module.foo);
}],
execute: function () {



}
};
});
@@ -0,0 +1,13 @@
System.register(['./dep.js'], function (exports, module) {
'use strict';
return {
setters: [function (module) {
exports('foo', module.foo);
}],
execute: function () {



}
};
});
@@ -0,0 +1,3 @@
const foo = 1;

export { foo };
@@ -0,0 +1 @@
export { foo } from './dep';
@@ -0,0 +1 @@
export { foo } from './main1.js';

0 comments on commit 6a79bc1

Please sign in to comment.