fix: Support tsx with prism syntax highlighter #1391
Merged
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.
Motivation
TSX and any other compositionally defined language (Prism.languages.extend) in prism will not work with the current system because of how language loading works.
Basically the other languages tsx is composed from (jsx and typescript) won't always be loaded first (I don't even have JSX examples so it can never get to that point). If that's the case it won't be able to create the composition properly.
Have you read the Contributing Guidelines on pull requests?
yes
Test Plan
I simply did this modification in my usage where I have lots of tsx (https://resthooks.io). Before I was getting
TypeError: Cannot read property 'rest' of undefined.
and it would fallback to highlight.js, which of course doesn't support tsx.Here's it working:
Related PRs
Inspiration for this fix comes from workarounds in: PrismJS/prism#972