Skip to content

Conversation

@mjambon
Copy link
Contributor

@mjambon mjambon commented Sep 18, 2020

We're running into errors when using the latest javascript grammar which includes changes to support optional chaining (?. tree-sitter/tree-sitter-javascript#137).

part 1 (done)

Some of the errors were the same as described and fixed by @maxbrunsfeld for javascript and were due to rules being copied from javascript rather than automatically inherited. The first two commits (b4b4e19 and 60a517f) apply the same fixes as were applied on the javascript grammar. They allow new A.B() to be parsed correctly. These changes also add support for ?. in call_expression since it was not automatically inherited from javascript.

part 2 (done)

Several tests specific to typescript still fail. The first one I'm looking at is "type assertions". The expression <A>b.c is parsed incorrectly as (<A>b).c and I haven't figured out how to fix it. My understanding is that _expression has the lowest precedence (0) and the type_assertion rule is essentially seq(type_arguments, _expression) and has with a higher precedence than all of _expression, while the precedence on member_expression (b.c) has no impact here due to being a choice within _expression. I tried declaring _expression as inline, hoping it might do something but then the generator takes several minutes to terminate (and reports a conflict). There are a few more things I want to try but let me know if you have ideas.

I solved this eventually by changing the precedence of type_assertion from the highest to the same as _expression (zero). I can't tell why its precedence used to be high. It looks reasonable to me now and the "Type assertions" test passes. This is commit b4b4e19.

part 3 (done)

  • Function calls with type arguments (returns wrong tree)

We were failing to parse new A<B>(). Fixed by moving the dynamic precedence annotation in new_expression.

part 4 (in progress)

  • The 'less than' operator i.e. parsing a < b.c; (takes the wrong path, returns ERROR node)

Martin Jambon added 4 commits September 17, 2020 15:42
javascript. See tree-sitter/tree-sitter-javascript#137 (comment)
for full details.
Some conflicts remain and should be solved in a later commit, since they
look different than the issue we had with javascript.
Fixes the behavior of the 'Type assertions' test.
@mjambon
Copy link
Contributor Author

mjambon commented Sep 22, 2020

Closing this PR in favor on a new branch using an updated tree-sitter-javascript: #85

@mjambon mjambon closed this Sep 22, 2020
@mjambon mjambon deleted the compat branch September 22, 2020 19:46
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.

1 participant