Comments (2)
I have tried to add various
/* @__PURE__ */
annotations, but the class A does not get tree shaken.
The way to add a @__PURE__
annotation for the class A
is as follows:
You cannot add the pure annotation to the method
variable reference like this because that's annotating the wrong thing. The @__PURE__
annotation says the result can be removed if it's not used. Except it is being used (as the name of the method) so the annotation doesn't have any effect. That's why it has to go around the whole class declaration. Another way to think about it: Just because the evaluation of the expression method
has no side effects doesn't necessarily mean the evaluation of the ToString operation on that value also has no side effects.
The above example is deliberately simple to demonstrate the issue, but the context where it came from is that any class that declares a custom inspect function like below prevents treeshaking:
[Symbol.for('nodejs.util.inspect.custom')]() { return '...'; }
I appreciate you mentioning the actual use case. It's possible that esbuild could special-case this syntax to still allow tree shaking in this case.
from esbuild.
Thank you ! I appreciate you taking the time to explain the correct way to place the /* @PURE */ annotation !
from esbuild.
Related Issues (20)
- add an optional cache and `exclude` option to the `onResolve` plugin hook HOT 1
- Injecting code into bundled dependency with iife format HOT 3
- Error with minification and banner HOT 2
- Behavior when no legal comment is included
- there are two ββIoββ variable in one project HOT 1
- Incorrect to compile `sass` source code HOT 2
- Feature: Sign esbuild.exe HOT 2
- Tree shaking or minifier issue - noop functions HOT 6
- build() vs context().rebuild() HOT 2
- Feature request: JSR registry package HOT 2
- esbuild should emit a warning when `emitDecoratorMetadata` is found in `tsconfig`
- Wrong cutoff in JSX attributes HOT 3
- esbuild inside Deno.test() leaks resources HOT 2
- Decorator wrapped around declare or abstract fields are failing since 0.19.8 HOT 2
- Minifier always assumes globals are not changed HOT 2
- How do I watch and run a build? HOT 8
- The current esbuild does not support the platform I am currently using, and the CPU model is sw_64. Can this platform be supported in the source code? HOT 5
- Option to preserve unused imports when transforming JS HOT 2
- Bundle PnP import HOT 3
- Allow for including hostname authority component in stack trace file URIs HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esbuild.