tree-sitter / tree-sitter-typescript

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

Add support for `satisfies` #238

Closed mjambon closed 5 months ago

mjambon commented 1 year ago

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

const a = 42 satisfies number;

Here's a link to the TypeScript Playground showing that the snippet above is valid JavaScript or TypeScript:

https://www.typescriptlang.org/play?ts=4.9.5#code/MYewdgzgLgBAhjAvDALAJhhOUCWEBmOAphDGAK4C2ARkQE4DcAUEA

The output of tree-sitter parse is the following:

 tree-sitter-prod parse <(echo 'const a = 42 satisfies number;')
(program [0, 0] - [1, 0]
  (lexical_declaration [0, 0] - [0, 30]
    (variable_declarator [0, 6] - [0, 29]
      name: (identifier [0, 6] - [0, 7])
      (ERROR [0, 10] - [0, 22]
        (number [0, 10] - [0, 12])
        (identifier [0, 13] - [0, 22]))
      value: (identifier [0, 23] - [0, 29]))))
/dev/fd/63  0 ms    (ERROR [0, 10] - [0, 22])

Documentation: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-9.html#the-satisfies-operator

Originally reported here: https://github.com/returntocorp/semgrep/issues/7197

srijan-paul commented 1 year ago

Hya, I'm looking to build a linter for TS in Haskell. For this, I'll need to use haskell-tree-sitter which depends on this lib. Is there any chance of getting support for the satisfies operator anytime soon?

If not, some pointers on how to add it would be useful. I might try and add support for it myself, Thanks!

casr commented 1 year ago

Looks like this was fixed in https://github.com/tree-sitter/tree-sitter-typescript/pull/228