feat(tsx): Extract script and styles from TSX for language-server consumption#1019
Conversation
🦋 Changeset detectedLatest commit: bc2e8b2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| ranges TSXRanges | ||
| // Keep track of how many multi-byte characters we've printed so that they can be skipped whenever we need a character-based index | ||
| // This could be directly in the token / node information, however this would require a fairly large refactor | ||
| bytesToSkip int |
There was a problem hiding this comment.
So, this not really optimal, because it confuse the printed bytes with the source bytes. It's fine in 99.999% of cases, because we're not printing any multi-bytes ourselves that were not part of the source. But it's something we could do and would have to take into account then. (and is trivial to do, but still)
The real fix, but it'd require a large amount of work would be to have this information directly on the tokens / nodes. I first tried to do that, but I quickly realised that I was changing everything and ran into the risk of breaking things everywhere.
If this prove to be an issue, I'd definitely be willing to make the proper change, but in my testing this honestly proved to work just fine.
* fix(tsx): rework how escaping work * nit: remove duplicate code
Changes
Required by withastro/language-tools#900
Previously, the language server would extract scripts and styles manually using both the compiler AST and the HTML AST. Not only is this kinda inefficient, it also lead to sometimes incorrect results due to wrong AST positions, HTML not understanding expressions, etc.
This PR makes it so the compiler instead provide scripts and styles in the TSXResult. Additionally, this PR adds the ability to remove the scripts and styles from the output, for multiple reasons:
These two changes were put under flags, so there's no breaking changes (certain consumer might still need this, for instance, our TS plugin does want the script tags content. Albeit, fixed, but that's for another PR, ha)
Testing
Updated tests
Docs
N/A