fix(tsx): rework how escaping work#1023
Conversation
|
| `; | ||
| const output = `${TSXPrefix}<Fragment> | ||
| <div> | ||
| <div div {...{"<":true}}> |
There was a problem hiding this comment.
(note that this is not new, this exact example is same as current output)
This is what I mean by it not being perfect. Ideally, it would just be outputted as written, but the compiler thinks that those are attributes. This is very wonky looking, but as far as I could test, in the editor it's not a problem, TypeScript just think there's some text further on and an expression.
It might be possible to fix this, because the JS output actually does support this strangely enough. But it's perhaps a bit more complicated in TSX due to all the escaping required, not sure.
…sumption (#1019) * feat(tsx): Extract script and styles from TSX for language-server consumption * feat: add options for styles * fix: reverse order of operation * test: fix * test: add tests * fix: count printed bytes so that we can skip over them later * chore: fix format * chore: uugh * chore: biome what is GOING on * fix(tsx): rework how escaping work (#1023) * fix(tsx): rework how escaping work * nit: remove duplicate code * nit: formatting * chore: changeset * fix: also do it for escaped text
Changes
Change how escaping works in TSX. Previously, if a TextNode had any of the following characters:
<>{}'", we'd escape the entire thing. This is fine, however, it doesn't work for TSX that is being written, as many times you'll end up with nodes that look like this:Where
<divnot being a completed tag, means that it get escaped (becomes<div></div>{` <div`}) and thus considered a string in the editor.This PR changes two things:
is:raw>and}), ex:<div>></div>becomes<div>{`>`}</div>The result isn't perfect, as the compiler still fundamentally does not understand unclosed tags, however it at least doesn't escape it in the vast majority of cases that affect editor tooling.
Fixes #862
Testing
Added tests
Docs
N/A