diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/index.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/index.js new file mode 100644 index 00000000000..3888e43d6b2 --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/index.js @@ -0,0 +1,3 @@ +import { Context } from "./library"; + +output = [Context, () => import("./library/dynamic")]; diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/a.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/a.js new file mode 100644 index 00000000000..9eda04b81ad --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/a.js @@ -0,0 +1,2 @@ +sideEffect("a"); +export const Ctx = 1; diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/b.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/b.js new file mode 100644 index 00000000000..18b74695dea --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/b.js @@ -0,0 +1,2 @@ +sideEffect("b"); +export const Ctx = 2; diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/dynamic.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/dynamic.js new file mode 100644 index 00000000000..74c81826df6 --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/dynamic.js @@ -0,0 +1,4 @@ +sideEffect("dynamic"); +import { Ctx } from "./a.js"; +import { id } from "./index.js"; +export default [Ctx, id]; diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/index.js b/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/index.js new file mode 100644 index 00000000000..21b2f50e4ab --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/index.js @@ -0,0 +1,4 @@ +sideEffect("index"); +export { Ctx } from "./a.js"; +export { Ctx as Context } from "./b.js"; +export const id = 3; diff --git a/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/package.json b/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/package.json new file mode 100644 index 00000000000..1b95642997c --- /dev/null +++ b/packages/core/integration-tests/test/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/library/package.json @@ -0,0 +1,3 @@ +{ + "sideEffects": false +} diff --git a/packages/core/integration-tests/test/javascript.js b/packages/core/integration-tests/test/javascript.js index 8cedde288af..18aa7fc5b57 100644 --- a/packages/core/integration-tests/test/javascript.js +++ b/packages/core/integration-tests/test/javascript.js @@ -7186,6 +7186,43 @@ describe('javascript', function () { assert.deepEqual(res.output, ['foo', 'bar']); }); + it('supports partially used reexporting index file', async function () { + let b = await bundle( + path.join( + __dirname, + '/integration/scope-hoisting/es6/side-effects-re-exports-partially-used/index.js', + ), + options, + ); + + let calls = []; + let res = ( + await run( + b, + { + sideEffect: caller => { + calls.push(caller); + }, + }, + {require: false}, + ) + ).output; + + let [v, async] = res; + + assert.deepEqual(calls, shouldScopeHoist ? ['b'] : ['a', 'b', 'index']); + assert.deepEqual(v, 2); + + v = await async(); + assert.deepEqual( + calls, + shouldScopeHoist + ? ['b', 'a', 'index', 'dynamic'] + : ['a', 'b', 'index', 'dynamic'], + ); + assert.deepEqual(v.default, [1, 3]); + }); + it('supports deferring non-weak dependencies that are not used', async function () { let b = await bundle( path.join(