Skip to content

Conversation

jackschu
Copy link
Contributor

@jackschu jackschu commented Jul 7, 2024

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

log
`foo`;

The output of tree-sitter parse is the following:

program [0, 0] - [2, 0]
  expression_statement [0, 0] - [0, 3]
    identifier [0, 0] - [0, 3]
  expression_statement [1, 0] - [1, 5]
    template_string [1, 0] - [1, 5]
      string_fragment [1, 1] - [1, 4]

If you run a snippet like this (playground link)

const log = (x) => console.log(x)

log
`foo`;

3
`foo`;

You'll get this output

[LOG]: ["foo"] 
[ERR]: "Executed JavaScript Failed:" 
[ERR]: 3 is not a function 

So regardless of the first expression in each clause (ie log or 3 ) the runtime treats foo as the back-half of a call expression, but tree sitter outputs the above rather than the below because of automatic semi injection.

(program [0, 0] - [1, 2]
  (expression_statement [0, 0] - [1, 2]
    (call_expression [0, 0] - [1, 2]
      function: (identifier [0, 0] - [0, 1])
      arguments: (template_string [1, 0] - [1, 2]))))

Also modified the test cases

@amaanq amaanq merged commit a92640f into tree-sitter:master Jul 20, 2024
@amaanq
Copy link
Member

amaanq commented Jul 20, 2024

thx!

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

Successfully merging this pull request may close these issues.

2 participants