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

bug: #317

Open
2 tasks done
alexgorbatchev opened this issue Oct 24, 2024 · 0 comments
Open
2 tasks done

bug: #317

alexgorbatchev opened this issue Oct 24, 2024 · 0 comments
Labels

Comments

@alexgorbatchev
Copy link

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues of tree-sitter-typescript

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

tree-sitter 0.22.6

Describe the bug

Crossposting from getgrit/gritql#561 (was told it's a grammar issue)


I was testing grit on a large corporate project and some .tsx files are throwing an error. Unfortunately I can't paste code here verbatim due to IP, but here's is one complete file and one snippet that fail to parse:

> grit --version
grit 0.1.1
import * as React from 'react';

import { ExternalLink } from 'internal';

import { SLACK_CHANNEL, SLACK_URL } from '../../constants';

export function OnboardingDocLink() {
  return (
    <ExternalLink
      to="https://edited/pages/viewpage.action?spaceKey=edited&title=edited"
                                                               ^----- grit pointed here
      testId="onboarding-doc-link"
    >
      Onboarding document
    </ExternalLink>
  );
}

export function SlackLink() {
  return (
    <ExternalLink to={SLACK_URL} testId="slack-link">
      {SLACK_CHANNEL}
    </ExternalLink>
  );
}

in another file

const renderButton = (props: { onClick: () => void }) => (
  <Button {...props}>Add Infrastructure & Onboard to Acme</Button>
   ^----- grit pointed here
);

Steps To Reproduce/Bad Parse Tree

I don't have tree-sitter setup for a test, however I'm seeing ERROR for both examples when I put the code into https://tree-sitter.github.io/tree-sitter/playground . I don't know if this is equivalent:

[program](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [24, 0]
  [import_statement](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 31]
    [import_clause](https://tree-sitter.github.io/tree-sitter/playground#) [0, 7] - [0, 17]
      [namespace_import](https://tree-sitter.github.io/tree-sitter/playground#) [0, 7] - [0, 17]
        [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 12] - [0, 17]
    source: [string](https://tree-sitter.github.io/tree-sitter/playground#) [0, 23] - [0, 30]
      [string_fragment](https://tree-sitter.github.io/tree-sitter/playground#) [0, 24] - [0, 29]
  [import_statement](https://tree-sitter.github.io/tree-sitter/playground#) [2, 0] - [2, 40]
    [import_clause](https://tree-sitter.github.io/tree-sitter/playground#) [2, 7] - [2, 23]
      [named_imports](https://tree-sitter.github.io/tree-sitter/playground#) [2, 7] - [2, 23]
        [import_specifier](https://tree-sitter.github.io/tree-sitter/playground#) [2, 9] - [2, 21]
          name: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [2, 9] - [2, 21]
    source: [string](https://tree-sitter.github.io/tree-sitter/playground#) [2, 29] - [2, 39]
      [string_fragment](https://tree-sitter.github.io/tree-sitter/playground#) [2, 30] - [2, 38]
  [import_statement](https://tree-sitter.github.io/tree-sitter/playground#) [4, 0] - [4, 59]
    [import_clause](https://tree-sitter.github.io/tree-sitter/playground#) [4, 7] - [4, 35]
      [named_imports](https://tree-sitter.github.io/tree-sitter/playground#) [4, 7] - [4, 35]
        [import_specifier](https://tree-sitter.github.io/tree-sitter/playground#) [4, 9] - [4, 22]
          name: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [4, 9] - [4, 22]
        [import_specifier](https://tree-sitter.github.io/tree-sitter/playground#) [4, 24] - [4, 33]
          name: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [4, 24] - [4, 33]
    source: [string](https://tree-sitter.github.io/tree-sitter/playground#) [4, 41] - [4, 58]
      [string_fragment](https://tree-sitter.github.io/tree-sitter/playground#) [4, 42] - [4, 57]
  [export_statement](https://tree-sitter.github.io/tree-sitter/playground#) [6, 0] - [15, 1]
    declaration: [function_declaration](https://tree-sitter.github.io/tree-sitter/playground#) [6, 7] - [15, 1]
      name: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [6, 16] - [6, 33]
      parameters: [formal_parameters](https://tree-sitter.github.io/tree-sitter/playground#) [6, 33] - [6, 35]
      body: [statement_block](https://tree-sitter.github.io/tree-sitter/playground#) [6, 36] - [15, 1]
        [return_statement](https://tree-sitter.github.io/tree-sitter/playground#) [7, 2] - [14, 4]
          [parenthesized_expression](https://tree-sitter.github.io/tree-sitter/playground#) [7, 9] - [14, 3]
            [ERROR](https://tree-sitter.github.io/tree-sitter/playground#) [8, 4] - [12, 16]
              [type_parameters](https://tree-sitter.github.io/tree-sitter/playground#) [8, 4] - [11, 5]
                [type_parameter](https://tree-sitter.github.io/tree-sitter/playground#) [8, 5] - [10, 34]
                  name: [type_identifier](https://tree-sitter.github.io/tree-sitter/playground#) [8, 5] - [8, 17]
                  [ERROR](https://tree-sitter.github.io/tree-sitter/playground#) [9, 6] - [9, 8]
                    [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [9, 6] - [9, 8]
                  value: [default_type](https://tree-sitter.github.io/tree-sitter/playground#) [9, 8] - [10, 34]
                    [ERROR](https://tree-sitter.github.io/tree-sitter/playground#) [9, 9] - [10, 13]
                      [literal_type](https://tree-sitter.github.io/tree-sitter/playground#) [9, 9] - [9, 76]
                        [string](https://tree-sitter.github.io/tree-sitter/playground#) [9, 9] - [9, 76]
                          [string_fragment](https://tree-sitter.github.io/tree-sitter/playground#) [9, 10] - [9, 75]
                      [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [10, 6] - [10, 12]
                    [literal_type](https://tree-sitter.github.io/tree-sitter/playground#) [10, 13] - [10, 34]
                      [string](https://tree-sitter.github.io/tree-sitter/playground#) [10, 13] - [10, 34]
                        [string_fragment](https://tree-sitter.github.io/tree-sitter/playground#) [10, 14] - [10, 33]
              [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [12, 6] - [12, 16]
            [binary_expression](https://tree-sitter.github.io/tree-sitter/playground#) [12, 17] - [13, 19]
              left: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [12, 17] - [12, 25]
              right: [regex](https://tree-sitter.github.io/tree-sitter/playground#) [13, 5] - [13, 19]
                pattern: [regex_pattern](https://tree-sitter.github.io/tree-sitter/playground#) [13, 6] - [13, 19]
                [MISSING /](https://tree-sitter.github.io/tree-sitter/playground#) [13, 19] - [13, 19]
  [export_statement](https://tree-sitter.github.io/tree-sitter/playground#) [17, 0] - [23, 1]
    declaration: [function_declaration](https://tree-sitter.github.io/tree-sitter/playground#) [17, 7] - [23, 1]
      name: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [17, 16] - [17, 25]
      parameters: [formal_parameters](https://tree-sitter.github.io/tree-sitter/playground#) [17, 25] - [17, 27]
      body: [statement_block](https://tree-sitter.github.io/tree-sitter/playground#) [17, 28] - [23, 1]
        [return_statement](https://tree-sitter.github.io/tree-sitter/playground#) [18, 2] - [22, 4]
          [parenthesized_expression](https://tree-sitter.github.io/tree-sitter/playground#) [18, 9] - [22, 3]
            [ERROR](https://tree-sitter.github.io/tree-sitter/playground#) [19, 4] - [19, 53]
              [type_parameters](https://tree-sitter.github.io/tree-sitter/playground#) [19, 4] - [19, 53]
                [type_parameter](https://tree-sitter.github.io/tree-sitter/playground#) [19, 5] - [19, 52]
                  name: [type_identifier](https://tree-sitter.github.io/tree-sitter/playground#) [19, 5] - [19, 17]
                  [ERROR](https://tree-sitter.github.io/tree-sitter/playground#) [19, 18] - [19, 20]
                    [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [19, 18] - [19, 20]
                  value: [default_type](https://tree-sitter.github.io/tree-sitter/playground#) [19, 20] - [19, 52]
                    [ERROR](https://tree-sitter.github.io/tree-sitter/playground#) [19, 21] - [19, 40]
                      [object_type](https://tree-sitter.github.io/tree-sitter/playground#) [19, 21] - [19, 32]
                        [property_signature](https://tree-sitter.github.io/tree-sitter/playground#) [19, 22] - [19, 31]
                          name: [property_identifier](https://tree-sitter.github.io/tree-sitter/playground#) [19, 22] - [19, 31]
                      [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [19, 33] - [19, 39]
                    [literal_type](https://tree-sitter.github.io/tree-sitter/playground#) [19, 40] - [19, 52]
                      [string](https://tree-sitter.github.io/tree-sitter/playground#) [19, 40] - [19, 52]
                        [string_fragment](https://tree-sitter.github.io/tree-sitter/playground#) [19, 41] - [19, 51]
            [binary_expression](https://tree-sitter.github.io/tree-sitter/playground#) [20, 6] - [21, 19]
              left: [object](https://tree-sitter.github.io/tree-sitter/playground#) [20, 6] - [20, 21]
                [shorthand_property_identifier](https://tree-sitter.github.io/tree-sitter/playground#) [20, 7] - [20, 20]
              right: [regex](https://tree-sitter.github.io/tree-sitter/playground#) [21, 5] - [21, 19]
                pattern: [regex_pattern](https://tree-sitter.github.io/tree-sitter/playground#) [21, 6] - [21, 19]
                [MISSING /](https://tree-sitter.github.io/tree-sitter/playground#) [21, 19] - [21, 19]

Expected Behavior/Parse Tree

should parse OK

Repro

import * as React from 'react';

import { ExternalLink } from 'internal';

import { SLACK_CHANNEL, SLACK_URL } from '../../constants';

export function OnboardingDocLink() {
  return (
    <ExternalLink
      to="https://edited/pages/viewpage.action?spaceKey=edited&title=edited"
      testId="onboarding-doc-link"
    >
      Onboarding document
    </ExternalLink>
  );
}

export function SlackLink() {
  return (
    <ExternalLink to={SLACK_URL} testId="slack-link">
      {SLACK_CHANNEL}
    </ExternalLink>
  );
}
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

1 participant