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

Add support for jsx syntax highlighting in .js files #968

Closed
BernardoFBBraga opened this issue Aug 1, 2018 · 11 comments
Closed

Add support for jsx syntax highlighting in .js files #968

BernardoFBBraga opened this issue Aug 1, 2018 · 11 comments
Labels
stale-issue There has been no activity for a year.

Comments

@BernardoFBBraga
Copy link

As noted here, using .jsx file extensions is not recommended.

Can we have JSX syntax highlighting in regular .js files?

I use gitlab at work and the syntax highlighting is terrible because of this.

@dblessing
Copy link
Collaborator

We might be able to switch things around slightly and instead of subclassing Javascript we could detect JSX inside the Javascript lexer itself and delegate to JSX. It may take a bit of reworking the current JSX lexer. I'm not familar with JS or JSX. If someone wants to take a crack at implementation that would be awesome. Otherwise, I'll investigate in the future.

@jneen
Copy link
Member

jneen commented Aug 8, 2018

In GitLab you can override the lexer choice based on .gitattributes as well.

https://docs.gitlab.com/ee/user/project/highlighting.html

@dblessing
Copy link
Collaborator

dblessing commented Aug 8, 2018 via email

@jneen
Copy link
Member

jneen commented Aug 8, 2018

JSX isn't supported in vanilla javascript unfortunately :\

@jneen
Copy link
Member

jneen commented Aug 8, 2018

(I'm also not convinced of the reasoning behind not using .jsx as an extension, given the other highlighting issues it seems to be causing...)

@BernardoFBBraga
Copy link
Author

BernardoFBBraga commented Aug 8, 2018

I've created a gitlab project to test and it worked with
*.js gitlab-language=jsx set to the .gitattributes file

@BernardoFBBraga
Copy link
Author

@jneen there are plenty of arguments for and against using .jsx in this thread if you're interested: airbnb/javascript#985

@BernardoFBBraga
Copy link
Author

@dblessing it must be possible to disambiguate since vscode and github both disambiguate, parse and sintax highlight jsx correctly, refering to them as javascript

@jneen
Copy link
Member

jneen commented Aug 9, 2018

Is there a marking or some special comment that indicates that it is jsx, or do these tools just use a jsx lexer for all javascript? The reason I'm hesitant to do the latter is that the jsx lexer is a bit complicated and likely slow.

@BernardoFBBraga
Copy link
Author

I'm not sure. I think vscode checks for imports of React on the javascript lexer to switch as it hints jsx as syntax error indicating that react should be imported

@stale
Copy link

stale bot commented Aug 15, 2019

This issue has been automatically marked as stale because it has not had any activity for more than a year. It will be closed if no additional activity occurs within the next 14 days.

If you would like this issue to remain open, please reply and let us know if the issue is still reproducible.

@stale stale bot added the stale-issue There has been no activity for a year. label Aug 15, 2019
@stale stale bot closed this as completed Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale-issue There has been no activity for a year.
Projects
None yet
Development

No branches or pull requests

3 participants