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

Range of jsx_text node is too large #339

Open
llemaitre19 opened this issue Sep 16, 2024 · 2 comments
Open

Range of jsx_text node is too large #339

llemaitre19 opened this issue Sep 16, 2024 · 2 comments
Labels

Comments

@llemaitre19
Copy link

llemaitre19 commented Sep 16, 2024

Hi,

This issue is very similar to this one.

It concerns the jsx_text node. The range of this node is too large as it also covers the white spaces and newlines around it.

Here, how to reproduce the issue:

function test() {
  return (
    <>
        TEXT
    </>
  )
}
(program [0, 0] - [7, 0]
  (export_statement [0, 0] - [6, 1]
    declaration: (function_declaration [0, 15] - [6, 1]
      name: (identifier [0, 24] - [0, 28])
      parameters: (formal_parameters [0, 28] - [0, 30])
      body: (statement_block [0, 31] - [6, 1]
        (return_statement [1, 2] - [5, 3]
          (parenthesized_expression [1, 9] - [5, 3]
            (jsx_element [2, 4] - [4, 7]
              open_tag: (jsx_opening_element [2, 4] - [2, 6])
              (jsx_text [2, 6] - [4, 4])
              close_tag: (jsx_closing_element [4, 4] - [4, 7]))))))))

Thanks in advance for fixing it.

@maxbrunsfeld
Copy link
Contributor

I think this is intentional, because the whitespace is included in the text string that is created by that JSX.

@llemaitre19
Copy link
Author

In JSX (AFAIK with React), if you want whitespaces before and after a text element to be rendered, you have to do something like this:

function test() {
  return (
    <>
        {'   TEXT   '}
    </>
  )
}

For me, having only the text element strict range (without whitespaces) is very more useful for a code editor which uses tree-sitter to indent, fontify, etc...

If it is intended, it is a breaking change, as previous releases did not behave like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants