feat: expose registry-free tokenize function - #88
Open
danielroe wants to merge 1 commit into
Open
Conversation
Member
|
Awesome! Let me take a look... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
we're adopting speed-highlight in nuxt/cli 🎉
we're trying to get the size of nuxt/cli as small as possible, and noticed that bundling
highlightTextfrom/terminalto highlight just JSON and HTML costs 22.7 kB, because the entry reaches the language registry and nothing tree-shakes.this PR adds
@speed-highlight/core/tokenize, which takes the definitions the caller already imported:it's synchronous, and a
subnaming a language that isn't inlanguagesis emitted as plain text rather than throwing. (nb. I added a try/catch as esbuild rewrites the dynamic import into a shim that fails synchronously...)highlightTextfrom/terminaltokenize+ JSON + HTML (8 grammars)tokenize+jsonrather than fork the loop, I pulled it into a generator that yields the name of each language it needs and expects the definition back. the sync entry feeds it from the
languagesmap, andsrc/index.jsfeeds it from the existinglangscache and dynamic import, so the async API behaves as before.Note
this also adds
./common.jsto theexportsmap, so callers importing from the language subpaths can resolveexpandrules. let me know if you want me to split this into a separate PR or drop it entirelya sync
highlightText(#29) would be easy on top of this but I left it out to keep the change small. let me know if you have any better ideas, and feel free to push changes if 🙏