Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't retarget dependencies with * #8645

Merged
merged 2 commits into from Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/core/core/src/BundleGraph.js
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
@@ -0,0 +1,5 @@
import { v } from "./library/a.js";

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

output = [v, sideEffectNoop(y).v];
@@ -0,0 +1 @@
export * from "./b.js";
@@ -0,0 +1 @@
export {v} from "./c.js";
@@ -0,0 +1 @@
export const v = 123;
@@ -0,0 +1,3 @@
{
"sideEffects": false
}
11 changes: 11 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
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
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