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

Enable JSX in .js files #644

Open
6 tasks done
Janpot opened this issue Sep 4, 2024 · 3 comments
Open
6 tasks done

Enable JSX in .js files #644

Janpot opened this issue Sep 4, 2024 · 3 comments
Labels
bug Something isn't working pending triage

Comments

@Janpot
Copy link

Janpot commented Sep 4, 2024

Acknowledgements

  • I read the documentation and searched existing issues to avoid duplicates
  • I understand this is a bug tracker and anything other than a proven bug will be closed
  • I understand this is a free project and relies on community contributions
  • I read and understood the Contribution guide

Minimal reproduction URL

https://stackblitz.com/edit/node-axhph5?file=src%2Findex.ts

Problem & expected behavior (under 200 words)

Just run pnpm start, then pnpm start2. tsc happily transforms the jsx in the js file.

Bugs are expected to be fixed by those affected by it

  • I'm interested in working on this issue

Compensating engineering work will speed up resolution and support the project

  • I'm willing to offer $10 for financial support
@Janpot Janpot added bug Something isn't working pending triage labels Sep 4, 2024
@privatenumber
Copy link
Owner

I agree for feature parity, tsx should assume that JSX can be used in any JS file if compilerOptions.jsx is enabled.

However, we currently skip compiling .js files that don't contain ESM, which gave us a notable performance boost. If we start compiling all .js files to support JSX, it would undo that performance gain.

@Janpot
Copy link
Author

Janpot commented Sep 4, 2024

To expand on our use-case

  • We have lots of JSX + ESM in .js files.
  • All of our tooling standardised on .js, tsx and ts files, we never added support for .jsx
  • We want to migrate from babel-node to tsx, some of our scripts import frontend code.

However, we currently skip compiling .js files that don't contain ESM

Our js files contain ESM. Is there a way for us to signal that our .js files are ESM+JSX without changing the file extension or type: 'module'?

@privatenumber
Copy link
Owner

I'll investigate treating all non-dependency .js files as JSX if jsx is enabled in tsconfig.json but it will be a breaking change for v5.

If you're blocked, the fastest way to move forward would be to rename them to .jsx:

find /path/to/your/directory -name "*.js" -exec bash -c 'mv "$0" "${0%.js}.jsx"' {} \;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending triage
Projects
None yet
Development

No branches or pull requests

2 participants