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

[Enhancement][Treeshaking]: treeshake the new Class #8693

Open
SoonIter opened this issue Dec 10, 2024 · 4 comments
Open

[Enhancement][Treeshaking]: treeshake the new Class #8693

SoonIter opened this issue Dec 10, 2024 · 4 comments
Labels
A-treeshaking Area: treeshaking feat New feature or request team The issue/pr is created by the member of Rspack.

Comments

@SoonIter
Copy link
Member

SoonIter commented Dec 10, 2024

What problem does this feature solve?

// index.js
import { b } from './qux.js'
console.log(b)
// ./qux.js
class A {}
export const a = new A();
export const b = 1;

expected output

aligned with rollup

const b = 1;

console.log(b);

actual output

class A {
}
new A();
const b = 1;
console.log(b);

What does the proposed API look like?

https://rollupjs.org/repl/?version=4.28.1&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQW51bGwlMkMlMjJtb2R1bGVzJTIyJTNBJTVCJTdCJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMCU3QiUyMGIlMjAlN0QlMjBmcm9tJTIwJy4lMkZxdXguanMnJTVDbmNvbnNvbGUubG9nKGIpJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlMkMlMjJuYW1lJTIyJTNBJTIybWFpbi5qcyUyMiU3RCUyQyU3QiUyMmNvZGUlMjIlM0ElMjJjbGFzcyUyMEElMjAlN0IlN0QlNUNuZXhwb3J0JTIwY29uc3QlMjBhJTIwJTNEJTIwbmV3JTIwQSgpJTNCJTVDbmV4cG9ydCUyMGNvbnN0JTIwYiUyMCUzRCUyMDElM0IlMjIlMkMlMjJpc0VudHJ5JTIyJTNBZmFsc2UlMkMlMjJuYW1lJTIyJTNBJTIycXV4LmpzJTIyJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMm91dHB1dCUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmVzJTIyJTdEJTdEJTdE

https://github.com/SoonIter/rslib-treeshaking-new-class

@SoonIter SoonIter changed the title [Feature][Treeshaking][bundle size]: new Class [Feature][Treeshaking][bundle size]: treeshake the new Class Dec 10, 2024
@SoonIter SoonIter changed the title [Feature][Treeshaking][bundle size]: treeshake the new Class [Enhancement][Treeshaking]: treeshake the new Class Dec 10, 2024
@SoonIter
Copy link
Member Author

😄 I do not know why rollup treeshakes this case, this case is very common for treeshaking invalidation, literally speaking, new Class() has sideEffect

@SoonIter
Copy link
Member Author

It could be tree-shaked if no side-effect performed in new, just like in this case. But Rollup seems not considering at all as of now

Your case is wrong, i fixed it 😂

I can ensure that it is a rollup "feature" by this behavior...

real world normal cases

https://rollupjs.org/repl/?version=4.28.1&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQW51bGwlMkMlMjJtb2R1bGVzJTIyJTNBJTVCJTdCJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMCU3QiUyMGIlMjAlN0QlMjBmcm9tJTIwJy4lMkZxdXguanMnJTVDbmNvbnNvbGUubG9nKGIpJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlMkMlMjJuYW1lJTIyJTNBJTIybWFpbi5qcyUyMiU3RCUyQyU3QiUyMmNvZGUlMjIlM0ElMjJjbGFzcyUyMEElMjAlN0IlNUNuJTIwJTIwJTIwYSUzQiU1Q24lMjAlMjAlMjBjb25zdHJ1Y3RvciUyMCgpJTdCJTVDbiUyMCUyMCUyMCUyMCUyMCUyMHRoaXMuYSUyMCUzRCUyMDElNUNuJTIwJTIwJTIwJTdEJTVDbiU3RCU1Q24lNUNuZXhwb3J0JTIwY29uc3QlMjBhJTIwJTNEJTIwbmV3JTIwQSgpJTNCJTVDbmV4cG9ydCUyMGNvbnN0JTIwYiUyMCUzRCUyMDElM0IlMjIlMkMlMjJpc0VudHJ5JTIyJTNBZmFsc2UlMkMlMjJuYW1lJTIyJTNBJTIycXV4LmpzJTIyJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiU3RCU3RA==

https://rollupjs.org/repl/?version=4.28.1&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQW51bGwlMkMlMjJtb2R1bGVzJTIyJTNBJTVCJTdCJTIyY29kZSUyMiUzQSUyMmltcG9ydCUyMCU3QiUyMGIlMjAlN0QlMjBmcm9tJTIwJy4lMkZxdXguanMnJTVDbmNvbnNvbGUubG9nKGIpJTIyJTJDJTIyaXNFbnRyeSUyMiUzQXRydWUlMkMlMjJuYW1lJTIyJTNBJTIybWFpbi5qcyUyMiU3RCUyQyU3QiUyMmNvZGUlMjIlM0ElMjJpbXBvcnQlMjAlN0IlMjB4JTIwJTdEJTIwZnJvbSUyMCdsb2Rhc2gtZXMnJTNCJTVDbiU1Q25jbGFzcyUyMEElMjAlN0IlNUNuJTIwJTIwJTIwJTVDbiUyMCUyMCUyMGNvbnN0cnVjdG9yJTIwKCklN0IlNUNuJTIwJTIwJTIwJTIwJTIwJTIweCgpJTNCJTVDbiUyMCUyMCUyMCU3RCU1Q24lN0QlNUNuJTVDbmV4cG9ydCUyMGNvbnN0JTIwYSUyMCUzRCUyMG5ldyUyMEEoKSUzQiU1Q25leHBvcnQlMjBjb25zdCUyMGIlMjAlM0QlMjAxJTNCJTIyJTJDJTIyaXNFbnRyeSUyMiUzQWZhbHNlJTJDJTIybmFtZSUyMiUzQSUyMnF1eC5qcyUyMiU3RCU1RCUyQyUyMm9wdGlvbnMlMjIlM0ElN0IlN0QlN0Q=

@SoonIter SoonIter transferred this issue from web-infra-dev/rslib Dec 13, 2024
@github-actions github-actions bot added the team The issue/pr is created by the member of Rspack. label Dec 13, 2024
@SoonIter SoonIter added feat New feature or request A-treeshaking Area: treeshaking labels Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-treeshaking Area: treeshaking feat New feature or request team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

No branches or pull requests

2 participants