esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Feature request: config option for _not_ annonating JSX calls as PURE

Open jonikorpi opened this issue 3 years ago • 2 comments

Could esbuild add an option for turning off automatic JSX call /* @__PURE__ */ annotation?

I use a custom library powered by JSX. In the library the JSX calls have important side-effects, but the call results are not always used. Since esbuild marks all JSX calls with /* @__PURE__ */, minifiers/tree-shakers end up deleting JSX calls that shouldn't be deleted.

I realise the default makes sense for libraries like React, but I'm hoping JSX could have uses beyond them too!

jonikorpi avatar Sep 12 '22 08:09 jonikorpi

Interesting, I think it has a workaround to manually keep jsx elements by wrapping with something that uses them, like - (minus):

- <div />;

esbuild --loader=jsx --jsx=automatic --tree-shaking

import { jsx } from "react/jsx-runtime";
-/* @__PURE__ */ jsx("div", {});

hyrious avatar Sep 12 '22 09:09 hyrious

Huh. I was wondering if this would ever happen. I can add a setting for this.

evanw avatar Sep 13 '22 01:09 evanw