evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
38.21k stars 1.15k forks source link

Unexpected output #3884

Closed luizbills closed 3 months ago

luizbills commented 3 months ago

The bundler do not remove that "unused" AudioContext instance. Why?

https://esbuild.github.io/try/#YgAwLjIzLjEALS1idW5kbGUAZQBlbnRyeS5qcwBjb25zdCBhID0gbmV3IEF1ZGlvQ29udGV4dCgpCgpjb25zdCBiID0gKCkgPT4gYQoKZ2xvYmFsVGhpcy5jID0gKCkgPT4gImZvbyI

evanw commented 3 months ago

That’s likely because esbuild doesn’t know that new AudioContext() is side-effect free.

luizbills commented 3 months ago

That’s likely because esbuild doesn’t know that new AudioContext() is side-effect free.

make sense!

There are something I can do?

hyrious commented 3 months ago

You can mark your function-call (including new XXX()) as side-effect free with /*@__PURE__*/. Playground Link

luizbills commented 3 months ago

You can mark your function-call (including new XXX()) as side-effect free with /*@__PURE__*/.

thanks!