-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript highlighting chokes on some casts #878
Comments
Yeah, I'm pretty sure this production triggers XML mode when it sees the cast, but it's not clear to me how to distinguish between a cast and a JSX fragment. @danquirk, do you know how the TypeScript parser deals with this ambiguity? |
Well we have a big parser for one ;) The main thing is that JSX elements aren't allowed in .ts files. They'll require .tsx. So we can sidestep the issue for now and just fix .ts to handle casts properly and then figure out full JSX later. All we're really doing is implementing the grammar here: https://facebook.github.io/jsx/ I was going to take a stab at fixing it myself but I can't even get 'npm install' in highlight.js to complete successfully. |
I assume old-style casts aren't allowed in In the meantime, I've hacked the TypeScript language definition used in Reviewable to ignore anything that looks like embedded XML. It's not a long-term solution though. |
Right, in .tsx you'll use the My reviews are now beautifully colorful so thanks for unblocking it there. We'll need to figure out what to do with highlight.js as you say. |
Guys, I'll try to look into it coming Tuesday. |
Status update. Since there are apparently two incompatible variants of the syntax, we could probably make it work with two separate language definitions. I couldn't put together one quickly though, need to work out a nice way of reusing the TypeScript definition to add an XML-like mode on top in TypeScript + JSX (or whatever we end up calling it). |
Since TypeScript+JSX is not yet out, perhaps it's worth modifying the 'ts' On Wed, Jul 1, 2015 at 12:52 PM, Ivan Sagalaev notifications@github.com
Piotr Kaminski piotr@ideanest.com |
The relevant discussion is in #878. Removing this unbreaks type casting syntax. Future TypeScript will support JSX and have a different casting syntax but not highlighting the former is still a better failure mode than breaking the latter.
@pkaminski: Indeed! e9b6c64. |
Thanks! On Wed, Jul 1, 2015 at 3:13 PM, Ivan Sagalaev notifications@github.com
Piotr Kaminski piotr@ideanest.com |
Reviewable.io uses highlight.js and I tried to create a code review using it here https://reviewable.io/reviews/Microsoft/TypeScript/3642 and as you can see my code is essentially not highlighted at all.
@pkaminski thinks the cause is a cast like:
causing the highlighter to go into an XML mode and then never get back to TypeScript syntax.
TypeScript will be supporting JSX in the near future so the syntax coloring around <> will get even more complicated.
The text was updated successfully, but these errors were encountered: