Skip to content

Commit

Permalink
Don't include the default export in static reexports (parcel-bundler#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Binns-Smith authored Aug 10, 2021
1 parent 4df85e3 commit 2e58db8
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export {default} from './b.js';
export * from './b.js';

export {default as other} from './c.js';
export * from './c.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import _default, {other} from './a.js';

sideEffectNoop(_default, other);

export default _default;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 42;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 99;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import _default, {other} from './a.js';

output = import('./async').then(mod => mod.default);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports.foo = 42;
module.exports.__esModule = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './a';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as a from './a.js';

output = import('./async').then(mod => mod.__esModule);
22 changes: 22 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -3714,6 +3714,28 @@ describe('scope hoisting', function() {
let test = await run(b);
assert.equal(test({foo: 2}), 2);
});

it('should not include default when reexporting * without $parcel$exportWildcard', async () => {
let b = await bundle(
path.join(
__dirname,
'integration/scope-hoisting/es6/no-reexport-default/index.js',
),
);

assert.equal(await run(b), 42);
});

it('should not include __esModule when reexporting * without $parcel$exportWildcard', async () => {
let b = await bundle(
path.join(
__dirname,
'integration/scope-hoisting/es6/no-reexport-esmodule/index.js',
),
);

assert.equal(await run(b), undefined);
});
});

describe('commonjs', function() {
Expand Down
7 changes: 7 additions & 0 deletions packages/packagers/js/src/ScopeHoistingPackager.js
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,13 @@ ${code}
this.usedHelpers.add('$parcel$exportWildcard');
} else {
for (let symbol of this.bundleGraph.getUsedSymbols(dep)) {
if (
symbol === 'default' || // `export * as ...` does not include the default export
symbol === '__esModule'
) {
continue;
}

let resolvedSymbol = this.getSymbolResolution(
asset,
resolved,
Expand Down

0 comments on commit 2e58db8

Please sign in to comment.