Skip to content

Commit

Permalink
Resolve a situation where different default exports referencing the same
Browse files Browse the repository at this point in the history
original variable would be rendered as two different imports of a chunk
which have the same name
  • Loading branch information
lukastaegert committed Mar 7, 2019
1 parent 6903425 commit 962362d
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Chunk.ts
Expand Up @@ -830,21 +830,23 @@ export default class Chunk {
}

const importsAsArray = Array.from(this.imports);
const renderedImports = new Set<Variable>();
const dependencies: ChunkDependencies = [];

for (const dep of this.dependencies) {
const imports: ImportSpecifier[] = [];
for (const variable of importsAsArray) {
const renderedVariable =
variable instanceof ExportDefaultVariable && variable.referencesOriginal()
? variable.getOriginalVariable()
: variable;
if (
(variable.module instanceof Module
? variable.module.chunk === dep
: variable.module === dep) &&
!(
variable instanceof ExportDefaultVariable &&
variable.referencesOriginal() &&
this.imports.has(variable.getOriginalVariable())
)
!renderedImports.has(renderedVariable)
) {
renderedImports.add(renderedVariable);
const local = variable.getName();
const imported =
variable.module instanceof ExternalModule
Expand Down
@@ -0,0 +1,7 @@
module.exports = {
description:
'do not import variables that reference an original if another variable referencing it is already imported',
options: {
input: ['main1', 'main2']
}
};
@@ -0,0 +1,8 @@
define(['exports'], function (exports) { 'use strict';

const foo = {};

exports.foo = foo;
exports.bar = foo;

});
@@ -0,0 +1,5 @@
define(['./generated-chunk.js'], function (__chunk_1) { 'use strict';

console.log(__chunk_1.bar, __chunk_1.bar);

});
@@ -0,0 +1,5 @@
define(['./generated-chunk.js'], function (__chunk_1) { 'use strict';

console.log(__chunk_1.bar, __chunk_1.bar);

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

const foo = {};

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

var __chunk_1 = require('./generated-chunk.js');

console.log(__chunk_1.bar, __chunk_1.bar);
@@ -0,0 +1,5 @@
'use strict';

var __chunk_1 = require('./generated-chunk.js');

console.log(__chunk_1.bar, __chunk_1.bar);
@@ -0,0 +1,3 @@
const foo = {};

export { foo as a, foo as b };
@@ -0,0 +1,3 @@
import { a as bar } from './generated-chunk.js';

console.log(bar, bar);
@@ -0,0 +1,3 @@
import { a as bar } from './generated-chunk.js';

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

const foo = {};

exports('a', foo);

exports('b', foo);

}
};
});
@@ -0,0 +1,14 @@
System.register(['./generated-chunk.js'], function (exports, module) {
'use strict';
var bar;
return {
setters: [function (module) {
bar = module.a;
}],
execute: function () {

console.log(bar, bar);

}
};
});
@@ -0,0 +1,14 @@
System.register(['./generated-chunk.js'], function (exports, module) {
'use strict';
var bar;
return {
setters: [function (module) {
bar = module.a;
}],
execute: function () {

console.log(bar, bar);

}
};
});
@@ -0,0 +1 @@
export const foo = {};
@@ -0,0 +1,4 @@
import foo from './proxy1';
import bar from './proxy2';

console.log(foo, bar);
@@ -0,0 +1,4 @@
import foo from './proxy1';
import bar from './proxy2';

console.log(foo, bar);
@@ -0,0 +1,3 @@
import { foo } from './foo';

export default foo;
@@ -0,0 +1,3 @@
import { foo } from './foo';

export default foo;

0 comments on commit 962362d

Please sign in to comment.