Skip to content
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) Add JSX support to Typescript #1155

Closed
pkaminski opened this issue Apr 20, 2016 · 14 comments · Fixed by #2569 · May be fixed by turkdevops/highlight.js#292
Closed

(typescript) Add JSX support to Typescript #1155

pkaminski opened this issue Apr 20, 2016 · 14 comments · Fixed by #2569 · May be fixed by turkdevops/highlight.js#292
Assignees
Labels
enhancement An enhancement or new feature good first issue Should be easier for first time contributors help welcome Could use help from community language
Milestone

Comments

@pkaminski
Copy link
Contributor

There's a somewhat popular variant of TypeScript that incorporates JSX, and replaces TypeScript's normal angle-bracket casts with the as keyword. Source files typically end in .tsx. It would be nice to have a language definition for this -- it's not hard to make one, but not clear how to cleanly share the bulk of the definition with typescript.

Related issues: #878, Reviewable/Reviewable#285

@pkaminski
Copy link
Contributor Author

Ping @isagalaev?

@isagalaev
Copy link
Member

isagalaev commented May 21, 2016

We'll get to this (and other) issues eventually. No estimates though, as there are too few of us…

@pkaminski
Copy link
Contributor Author

OK, no problem -- I just noticed that this was the only open issue without a label so I was afraid you'd missed it. :)

@jakubrohleder
Copy link

Is there any progress on this? @pkaminski have you figured out any other solution?

Thanks :)

@pkaminski
Copy link
Contributor Author

Nope, I don't have any workaround at this time, sorry.

@jakubrohleder
Copy link

Thanks for the answer. I'll use 'js' as language than, it looks good enough.

ddevault pushed a commit to ddevault/highlight.js that referenced this issue Dec 12, 2017
This uses the same rules as JavaScript's JSX support.

Fixes highlightjs#1155
ddevault pushed a commit to ddevault/highlight.js that referenced this issue Dec 12, 2017
This uses the same rules as JavaScript's JSX support.

Fixes highlightjs#1155
rhigdon pushed a commit to rhigdon/highlight.js that referenced this issue Jan 31, 2019
This uses the same rules as JavaScript's JSX support.

Fixes highlightjs#1155
rhigdon pushed a commit to rhigdon/highlight.js that referenced this issue Jan 31, 2019
This uses the same rules as JavaScript's JSX support.

Fixes highlightjs#1155
rhigdon pushed a commit to rhigdon/highlight.js that referenced this issue Jan 31, 2019
This uses the same rules as JavaScript's JSX support.

Fixes highlightjs#1155
@joshgoebel joshgoebel changed the title Support for TypeScript + JSX language (.tsx) Add TypeScript + JSX grammar (.tsx) Oct 7, 2019
@joshgoebel joshgoebel changed the title Add TypeScript + JSX grammar (.tsx) (typescript) Add JSX support to existing language Oct 17, 2019
@joshgoebel joshgoebel added good first issue Should be easier for first time contributors help welcome Could use help from community enhancement An enhancement or new feature language and removed new language labels Oct 17, 2019
@joshgoebel
Copy link
Member

Tagging this beginner friendly and help welcome incase @ddevault doesn't have time to see this thru to completition.

@joshgoebel joshgoebel changed the title (typescript) Add JSX support to existing language (typescript) Add JSX support to Typescript Oct 17, 2019
@joshgoebel
Copy link
Member

This will be closed by #2568 when it closes.

@joshgoebel
Copy link
Member

joshgoebel commented Oct 8, 2020

No. It's built into Typescript now just like Javascript. It's not a different grammar.

@bennycode
Copy link

@joshgoebel it would be much nicer to use tsx (rather than integrating it into ts) because IDEs might differentiate between ts and tsx.

My IDE (WebStorm) complains when writing TSX code inside of a ts code block:

image

But it does not complain when the code from above is inside of a tsx code block:

image

Unfortunately, highlight.js only renders syntax highlighting when using ts (and not tsx). 😥

@joshgoebel
Copy link
Member

because IDEs might differentiate between ts and tsx.

But how is this relevant to us? If you just mean "people think of it as tsx"... then it seems like perhaps we should add an alias to typescript for tsx in addition to ts, so people could label it as such. That would make sense.


Right now our current grammar should "just work" regardless of whether you throw TS or TSX at it... meaning there is no need for two grammars. Having a separate TS grammar would be simpler in one or two regards (highlighting operators, no having to tell type annotations from HTML), but I dunno if having yet another variant is actually a good idea or not. Because if we went that way we'd really need 4:

  • JS and JSX
  • TS and TSX

Definitely something to keep in mind if I ever find the time to try and finish/flesh out our TSX support further.

@joshgoebel
Copy link
Member

joshgoebel commented Dec 17, 2020

In fact since we already do this for jsx (an alias of JavaScript) seems obvious we should add the alias, yes?

@bennycode
Copy link

Using an alias sounds like a great idea. It will improve the developer experience for people like me who edit files, which are later highlighted by highlight.js, and want to have syntax support in their IDEs (which differentiate between TS and TSX).

@joshgoebel
Copy link
Member

0c14f68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment