Skip to content

Commit 2ebed00

Browse files
authoredOct 6, 2021
Ensure named exports are prioritized over wildcard re-exports (#7016)
1 parent 4904f20 commit 2ebed00

File tree

11 files changed

+87
-7
lines changed

11 files changed

+87
-7
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const foo = 2;
2+
export * from './foo.mjs'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './foo.mjs'
2+
export const foo = 2;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import {foo} from './a.mjs';
2+
output = foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import {foo} from './b.mjs';
2+
output = foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 3;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import * as a from './a.mjs';
2+
output = a;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import * as b from './b.mjs';
2+
output = b;

‎packages/core/integration-tests/test/javascript.js

+24
Original file line numberDiff line numberDiff line change
@@ -4843,6 +4843,30 @@ describe('javascript', function() {
48434843
assert.equal(typeof res.c, 'function');
48444844
});
48454845

4846+
it('should prioritize named exports before re-exports withput scope hoisting (before)', async () => {
4847+
let b = await bundle(
4848+
path.join(
4849+
__dirname,
4850+
'integration/scope-hoisting/es6/re-export-priority/entry-a.mjs',
4851+
),
4852+
);
4853+
4854+
let res = await run(b, null, {require: false});
4855+
assert.equal(res.output, 2);
4856+
});
4857+
4858+
it('should prioritize named exports before re-exports without scope hoisting (after)', async () => {
4859+
let b = await bundle(
4860+
path.join(
4861+
__dirname,
4862+
'integration/scope-hoisting/es6/re-export-priority/entry-b.mjs',
4863+
),
4864+
);
4865+
4866+
let res = await run(b, null, {require: false});
4867+
assert.equal(res.output, 2);
4868+
});
4869+
48464870
it('should exclude default from export all declaration', async function() {
48474871
let b = await bundle(
48484872
path.join(__dirname, 'integration/js-export-all/index.js'),

‎packages/core/integration-tests/test/scope-hoisting.js

+48
Original file line numberDiff line numberDiff line change
@@ -3774,6 +3774,54 @@ describe('scope hoisting', function() {
37743774
test: 'foo',
37753775
});
37763776
});
3777+
3778+
it('should prioritize named exports before re-exports (before)', async () => {
3779+
let b = await bundle(
3780+
path.join(
3781+
__dirname,
3782+
'integration/scope-hoisting/es6/re-export-priority/entry-a.mjs',
3783+
),
3784+
);
3785+
3786+
let res = await run(b);
3787+
assert.equal(res, 2);
3788+
});
3789+
3790+
it('should prioritize named exports before re-exports (after)', async () => {
3791+
let b = await bundle(
3792+
path.join(
3793+
__dirname,
3794+
'integration/scope-hoisting/es6/re-export-priority/entry-b.mjs',
3795+
),
3796+
);
3797+
3798+
let res = await run(b);
3799+
assert.equal(res, 2);
3800+
});
3801+
3802+
it('should prioritize named exports before re-exports in namespace (before)', async () => {
3803+
let b = await bundle(
3804+
path.join(
3805+
__dirname,
3806+
'integration/scope-hoisting/es6/re-export-priority/namespace-a.mjs',
3807+
),
3808+
);
3809+
3810+
let res = await run(b);
3811+
assert.deepEqual(res, {foo: 2});
3812+
});
3813+
3814+
it('should prioritize named exports before re-exports in namespace (after)', async () => {
3815+
let b = await bundle(
3816+
path.join(
3817+
__dirname,
3818+
'integration/scope-hoisting/es6/re-export-priority/namespace-b.mjs',
3819+
),
3820+
);
3821+
3822+
let res = await run(b);
3823+
assert.deepEqual(res, {foo: 2});
3824+
});
37773825
});
37783826

37793827
describe('commonjs', function() {

‎packages/packagers/js/src/helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const helpers = {
3838
`,
3939
$parcel$exportWildcard: `function $parcel$exportWildcard(dest, source) {
4040
Object.keys(source).forEach(function(key) {
41-
if (key === 'default' || key === '__esModule') {
41+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
4242
return;
4343
}
4444

‎packages/transformers/js/src/esmodule-helpers.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ exports.defineInteropFlag = function(a) {
88

99
exports.exportAll = function(source, dest) {
1010
Object.keys(source).forEach(function(key) {
11-
if (key === 'default' || key === '__esModule') {
12-
return;
13-
}
14-
15-
// Skip duplicate re-exports when they have the same value.
16-
if (key in dest && dest[key] === source[key]) {
11+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
1712
return;
1813
}
1914

0 commit comments

Comments
 (0)
Please sign in to comment.