privatenumber / tsx

⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js
https://tsx.is
MIT License
9.8k stars 154 forks source link

Enable JSX in `.js` files #644

Open Janpot opened 2 months ago

Janpot commented 2 months ago

Acknowledgements

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

Compensating engineering work will speed up resolution and support the project

privatenumber commented 2 months ago

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 commented 2 months ago

To expand on our use-case

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 commented 2 months ago

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"' {} \;