Closed xiaoxiangmoe closed 3 years ago
@brillout Because we can copy and paste the TSX code to mdx. And it helps a lot for TS users.
I'd be curious if performance (in the context of large .mdx
files) is affected at all by this change, but we don't have benchmarks. Some cursory manual tests would probably be enough. Any volunteers? :P
Also, as I understand it, the (only?) benefit is that you don't have to strip type assertions when pasting TSX from another file.
Also, as I understand it, the (only?) benefit is that you don't have to strip type assertions when pasting TSX from another file.
Probably also to be able to use stuff like enums.
The error comes when @babel/parser
tries to parse it somewhere after applying rehype plugins, I'm not sure where exactly, the stack trace doesn't seem to say.
I was going to suggest a rehype plugin that transpiles TSX into JSX, but I'm not sure if that's possible to do 😬 esbuild doesn't support this yet (https://github.com/evanw/esbuild/issues/735), as for Babel I'm not sure if it's possible to pass a custom TypeScript configuration so it doesn't take the project's one.
That would've been a really nice solution to hack MDX to support TSX because it would put you in control, so I'm sad that it didn't seem to go anywhere. 😢
I just wanted to write this to balance out my discouraging words above, so that you know I tried. 😄
esbuild doesn't support this yet
We can use sucrase to strip the types.
But it needs a JSX transform, too, it can't only strip types.
@silvenon Esbuild does that
I think pasting TypeScript into MDX is rare enough that we won't support this.
Your best bet is making a Remark plugin.
@aleclarson I meant that sucrase doesn't seem to be able to turn TSX to JSX, only TSX to JS. transforms: ["typescript"]
doesn't work for me, I need to configure it with transforms: ["jsx", "typescript"]
.
But yeah, I agree that this plugin shouldn't be doing this.
👍
I'm curious; why do you want this?
TS without intellisense is mostly useless and TS cannot handle
.mdx
files, so I'm not sure about the benefits here?