web-infra-dev / web-infra-dev/rspack

[Feature][Treeshaking]: re-assignment breaks treeshaking

Open
#9,727 2 comments 0 reactions 1 assignee View on GitHub

@JSerFeng is already working on this.

Since Apr 7, 2025.

team
Dominant language
Rust
Stars
12.9k
Forks
854
Avg merge
20h 48m
Merged PRs (30d)
316

Description

Details

{
  "sideEffects": ["a.mjs"]
}
1. without re-assignment
// ./src/barrel.mjs
import { a } from './a.mjs';
import { b } from './b.mjs';

// a is unused
export { a, b };
// ./src/index.mjs
import { b } from './barrel.mjs'

console.log(b);

output:

;// CONCATENATED MODULE: ./src/b.mjs
const b = 2;

console.log(b)
2. with re-assignment
// ./src/barrel.mjs
import { a } from './a.mjs';
import { b } from './b.mjs';
// a is unused
const __webpack_exports__a__ = a;
const __webpack_exports__b__ = b;

export { __webpack_exports__a__ as a , __webpack_exports__b__ as b };
// ./src/index.mjs
import { b } from './barrel.mjs'

console.log(b);

output:

;// CONCATENATED MODULE: ./src/a.mjs
const a_a = 2;
window.a = a_a;

;// CONCATENATED MODULE: ./src/b.mjs
const b = 2;

console.log(b)

Reproduction

see https://github.com/SoonIter/rspack-reassign-treeshaking-issue

which is a minimal production of https://github.com/SoonIter/rslib-css-modules-treeshaking

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.