ts-eager
ts-eager copied to clipboard
.js files containing JSX is unsupported (error: Unexpected "<")
Hey old friend! I was trying this tool out and ran into a recurring problem with esbuild: it needs to know whether to expect JSX or not. I have a codebase that exclusively used the .js extension for files that contain both plain JS and JSX, unfortunately. This produces a ton of error: Unexpected "<" errors.
Any ideas how ts-eager could try both? For example, esbuild could first try --loader:.js=js and if that fails then --loader:.js=jsx? No worries if you decide that's out of scope for this repo: at least this ticket can help a future person!
P.S. I really wanted to compare compile times to a similar tool for running tools I made that uses babel under the hood: https://github.com/kirbysayshi/ts-run/
Hey hey! Hmmm. Here's what you'd need to change: https://github.com/mhart/ts-eager/blob/87a7c3bd1bae0eb312286e0172f891ce026c7dd8/register.js#L100
I guess that could be exposed somehow – I wonder how common it is to do what you're doing?
Ah, I was thinking about needing multiple attempts when dealing with TS files, since the TSX syntax is incompatible with TS arrow generics syntax.
I wonder if there's any downside to enabling .js->JSX by default (and not exposing it as configurable)?
I frankly don't know how common it is, it's a legacy decision that unfortunately has proven to be shortsighted :D