tree-sitter / tree-sitter-typescript

TypeScript grammar for tree-sitter
MIT License
341 stars 104 forks source link

Incorrect parse error on array destructuring when LHS includes a property access #162

Closed eaftan closed 2 years ago

eaftan commented 3 years ago

The following code

[obj.a] = foo();

is parsed as

program [0, 0] - [1, 0]
  expression_statement [0, 0] - [0, 16]
    assignment_expression [0, 0] - [0, 15]
      left: non_null_expression [0, 0] - [0, 7]
        array [0, 0] - [0, 7]
          member_expression [0, 1] - [0, 6]
            object: identifier [0, 1] - [0, 4]
            property: property_identifier [0, 5] - [0, 6]
        MISSING ! [0, 7] - [0, 7]
      right: call_expression [0, 10] - [0, 15]
        function: identifier [0, 10] - [0, 13]
        arguments: arguments [0, 13] - [0, 15]

Note the MISSING ! error node. This may be related to https://github.com/tree-sitter/tree-sitter-javascript/issues/178, though the MISSING ! error here is specific to TypeScript. In JavaScript, there is an ERROR node in the parse tree.

resolritter commented 2 years ago

Once https://github.com/tree-sitter/tree-sitter-javascript/pull/187 gets merged in the JS repo, fixing this might be a matter of updating the tree-sitter-javascript dependency.

https://github.com/tree-sitter/tree-sitter-typescript/blob/74a2748896434c13cac7697c4d182b43ec170d30/package.json#L22

resolritter commented 2 years ago

[obj.a] = foo(); is parsed without errors in the playground

@mjambon I think this can be closed

mjambon commented 2 years ago

oh yes, that's great. It looks like it may have been fixed by https://github.com/tree-sitter/tree-sitter-javascript/pull/187