tree-sitter / tree-sitter-javascript

Javascript grammar for tree-sitter
MIT License
314 stars 108 forks source link

Fail to parse nested do{}while() #298

Closed mingodad closed 3 months ago

mingodad commented 3 months ago

The following piece of code is valid but it is parsed incorrectly:

do
    if (true)
    do {
    } while (false);
while (0);

The above example is parsed fine with node/browser/playground but fails with this repository.

Probably is a good idea to update the playground !

mingodad commented 3 months ago
tree-sitter parse test.js
(program [0, 0] - [5, 0]
  (do_statement [0, 0] - [4, 9]
    body: (if_statement [1, 4] - [3, 16]
      condition: (parenthesized_expression [1, 7] - [1, 13]
        (true [1, 8] - [1, 12]))
      consequence: (do_statement [2, 1] - [3, 16]
        body: (statement_block [2, 4] - [3, 2])
        condition: (parenthesized_expression [3, 9] - [3, 16]
          (false [3, 10] - [3, 15]))))
    (ERROR [3, 16] - [3, 17])
    condition: (parenthesized_expression [4, 6] - [4, 9]
      (number [4, 7] - [4, 8])))
  (empty_statement [4, 9] - [4, 10]))
jsparser-nb/test.js    0.12 ms     447 bytes/ms (ERROR [3, 16] - [3, 17])
amaanq commented 3 months ago

yeah good suggestion, I'll look into upgrading the playground's parsers. thanks for your bug reports lately, I appreciate it and will fix them soon.