-
Notifications
You must be signed in to change notification settings - Fork 107
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
Split JSX into separate grammar? #244
Comments
PR Welcome - though I do find having it as one language simpler, but I can see the benefits of splitting it. |
PR submitted 😄 |
Hi, I don't think we want a separate grammar for JSX, because in most codebases, you can't tell whether a file is going to use JSX statically. They often just use the |
How is splitting javascript/jsx any different than splitting typescript/tsx? Since the ts parser is split it makes sense to split this one, otherwise the same argument for keeping this parser combined could apply to the ts parser, could it not?
That may be, however, I would argue that jsx is not javascript and therefore should not be included in |
Do they really? I have only worked with React and Typescript, and the file extension was always |
TypeScript and TSX must use different file extensions, because the two languages are mutually incompatible. So the TypeScript compiler needs to know up front which is which. In practice, JavaScript is not that way. People just use the |
Should this issue be closed then? |
As a user I want to be able to have separate settings for Javascript and JSX in my configuration. Currently support for JSX files (React.js extension for Javascript) is included in the Javascript grammar. However, Javascript and JSX are different languages, and I want to have separate per-filetype settings in my text editor.
I have recently added support for JSX in nvim-ts-rainbow2 where I have two sets of queries for JSX files: one matches the angle brackets of tags, other other matches entire tags. This means a lot of copy-pasting between both queries.
If the two file types were separate I could make the JSX query inherit the Javascript query and add only the queries for the JSX extension. Example in TSX, note the first line which Neovim understands:
This is only possible because the https://github.com/tree-sitter/
tree-sitter-typescript repo splits the two languages this way as well. The result is a very terse query. If I want to change how I highlight tags I only need to write a query for that part and can piggy-back off the Typescript query for everything else.
The text was updated successfully, but these errors were encountered: