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

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

Closed
jonikorpi opened this issue Sep 12, 2022 · 2 comments · Fixed by #2546
Closed

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

jonikorpi opened this issue Sep 12, 2022 · 2 comments · Fixed by #2546

Comments

@jonikorpi
Copy link

jonikorpi commented Sep 12, 2022

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!

@hyrious
Copy link

hyrious commented Sep 12, 2022

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", {});

@evanw
Copy link
Owner

evanw commented Sep 13, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants