Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a situation where two different imports with the same name are rendered #2737

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;