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

jsx_opening_element with if-else inside of it can't be queried properly #79

Closed
resolritter opened this issue Apr 19, 2020 · 2 comments
Closed

Comments

@resolritter
Copy link
Contributor

resolritter commented Apr 19, 2020

Example code

export function Button() {
  return (
    <button
      className={style.className}
      onClick={function () {
        if (activeTheme == "light") {
          updateTheme(themes.dark)
        } else {
          updateTheme(themes.light)
        }
      }}
    >
      Change the theme
    </button>
    </>
  )
}

Given the following query

(jsx_opening_element
 "<" @operator
 ">" @operator)

The query weirdly yields no matches for the <button> element due to the if-else function inside of the onClick attribute. Removing the else statement seems to fix the problem.

EDIT: Seems to be a more general problem with any two or more expressions inside of the function's body.

i.e.

      onClick={function () {
        const activeTheme = getActiveTheme()
        if (activeTheme == "light") {
          updateTheme(themes.dark)
        }
      }}

also reproduces in the same problem

@maxbrunsfeld
Copy link
Contributor

I think this is a manifestation of this bug in Tree-sitter's query engine. I'm working on a fix, but not sure when it will be done.

@maxbrunsfeld
Copy link
Contributor

I'm going to close this out actually, and ask you to subscribe to tree-sitter/tree-sitter#634 instead. I will verify that this specific case is fixed before closing that issue.

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

No branches or pull requests

2 participants