tree-sitter / tree-sitter-typescript

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

Have special semicolon rules for method definitions #182

Closed resolritter closed 2 years ago

resolritter commented 2 years ago

Closes https://github.com/tree-sitter/tree-sitter-typescript/issues/140

Why it works is already explained in the comment. I had the idea by looking at the following line:

https://github.com/tree-sitter/tree-sitter-typescript/blob/d08f57f2689f9006c8a362454a6070d578aa8017/common/scanner.h#L118-L119

Given that method definitions are also functions and therefore their definition is similar, I thought it was fine to re-use that token instead of creating a new one.


Initial measurements of parser.c against d08f57f2689f9006c8a362454a6070d578aa8017

typescript:

-#define STATE_COUNT 5987
-#define LARGE_STATE_COUNT 1269
+#define STATE_COUNT 6031
+#define LARGE_STATE_COUNT 1270

tsx:

-#define STATE_COUNT 6292
-#define LARGE_STATE_COUNT 1270
+#define STATE_COUNT 6336
+#define LARGE_STATE_COUNT 1271

Checklist:

maxbrunsfeld commented 2 years ago

Thanks!