Skip to content

Commit

Permalink
Don't retarget dependencies with * (#8645)
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic authored Nov 27, 2022
1 parent 711ae18 commit 143b773
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/core/core/src/BundleGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ export default class BundleGraph {
node.usedSymbolsUp.size > 0 &&
// Only perform rewriting if the dependency only points to a single asset (e.g. CSS modules)
!hasAmbiguousSymbols &&
// It doesn't make sense to retarget dependencies where `*` is used, because the
// retargeting won't enable any benefits in that case (apart from potentially even more
// code being generated).
!node.usedSymbolsUp.has('*') &&
// TODO We currently can't rename imports in async imports, e.g. from
// (parcelRequire("...")).then(({ a }) => a);
// to
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { v } from "./library/a.js";

import * as y from "./library/a.js";

output = [v, sideEffectNoop(y).v];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./b.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {v} from "./c.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v = 123;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sideEffects": false
}
11 changes: 11 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,17 @@ describe('scope hoisting', function () {
]);
});

it('should correctly retarget dependencies when both namespace and indvidual export are used', async function () {
let b = await bundle(
path.join(
__dirname,
'/integration/scope-hoisting/es6/retarget-namespace-single/index.js',
),
);
let output = await run(b);
assert.deepEqual(output, [123, 123]);
});

it('should correctly handle circular dependencies', async function () {
let b = await bundle(
path.join(__dirname, '/integration/scope-hoisting/es6/circular/a.mjs'),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test-utils/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export async function runBundles(

// A utility to prevent optimizers from removing side-effect-free code needed for testing
// $FlowFixMe[prop-missing]
ctx.sideEffectNoop = () => {};
ctx.sideEffectNoop = v => v;

vm.createContext(ctx);
let esmOutput;
Expand Down

0 comments on commit 143b773

Please sign in to comment.