Skip to content

Commit 4db35cd

Browse files
authored
Treat re-exports of '*' from empty files as ESM (#9079)
1 parent 44c5d73 commit 4db35cd

File tree

8 files changed

+37
-1
lines changed

8 files changed

+37
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {bar} from 'lib';
2+
3+
output = `foo ${bar}`;

packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-all-empty-no-side-effects/node_modules/lib/bar.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-all-empty-no-side-effects/node_modules/lib/empty.js

Whitespace-only changes.

packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-all-empty-no-side-effects/node_modules/lib/index.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-all-empty-no-side-effects/node_modules/lib/other.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/integration-tests/test/integration/scope-hoisting/es6/re-export-all-empty-no-side-effects/node_modules/lib/package.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,28 @@ describe('scope hoisting', function () {
360360
assert.strictEqual(output, '2 4');
361361
});
362362

363+
it('supports re-exporting all from an empty module without side effects', async function () {
364+
let b = await bundle(
365+
path.join(
366+
__dirname,
367+
'/integration/scope-hoisting/es6/re-export-all-empty-no-side-effects/index.js',
368+
),
369+
{
370+
mode: 'production',
371+
},
372+
);
373+
374+
let output = await run(b);
375+
assert.strictEqual(output, 'foo bar');
376+
377+
let contents = await outputFS.readFile(
378+
b.getBundles().find(b => b.getMainEntry().filePath.endsWith('index.js'))
379+
.filePath,
380+
'utf8',
381+
);
382+
assert.match(contents, /output="foo bar"/);
383+
});
384+
363385
it('supports re-exporting all exports from an external module', async function () {
364386
let b = await bundle(
365387
path.join(

packages/transformers/js/src/JSTransformer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,11 +813,13 @@ export default (new Transformer({
813813
});
814814
}
815815

816-
// Add * symbol if there are CJS exports, no imports/exports at all, or the asset is wrapped.
816+
// Add * symbol if there are CJS exports, no imports/exports at all
817+
// (and the asset has side effects), or the asset is wrapped.
817818
// This allows accessing symbols that don't exist without errors in symbol propagation.
818819
if (
819820
hoist_result.has_cjs_exports ||
820821
(!hoist_result.is_esm &&
822+
asset.sideEffects &&
821823
deps.size === 0 &&
822824
Object.keys(hoist_result.exported_symbols).length === 0) ||
823825
(hoist_result.should_wrap && !asset.symbols.hasExportSymbol('*'))

0 commit comments

Comments
 (0)