@willbooster/tree-sitter-typescript 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -103,9 +103,10 @@ cargo test
103
103
 
104
104
  - the corpus in `test/corpus`, with the native build and with the Wasm build (the first run downloads the WASI SDK).
105
105
  Cases run with the `typescript` grammar unless they carry `:language(tsx)`;
106
- - an incremental-parsing check (`test/unit/incremental.test.ts`): `tree-sitter fuzz` edits each corpus case of the
107
- `typescript` grammar at random, reparses it, undoes the edits, and reparses again. `TREE_SITTER_SEED`,
108
- `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
106
+ - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
107
+ edits each corpus case of each grammar at random, reparses it, undoes the edits, and reparses again, on the
108
+ WillBooster/tree-sitter runtime version locked in `Cargo.lock` (the first run builds that CLI with `cargo`).
109
+ `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
109
110
  - a check that the real-world files in `examples/`, the checked-in ones and those of the cloned repositories, fail to
110
111
  parse exactly as listed in `script/known-failures.txt`. `.ts` files are parsed with the `typescript` grammar and
111
112
  `.tsx` files with the `tsx` grammar. The first run clones the repositories. The example repositories are pinned to
@@ -13,6 +13,7 @@ module.exports = function defineGrammar(dialect) {
13
13
  ...previous,
14
14
  ['call', 'instantiation', 'unary', 'binary', $.await_expression, $.arrow_function],
15
15
  ['extends', 'instantiation'],
16
+ ['new', 'generic_call', 'instantiation', 'unary', 'binary'],
16
17
  [
17
18
  $.intersection_type,
18
19
  $.union_type,
@@ -58,10 +59,7 @@ module.exports = function defineGrammar(dialect) {
58
59
 
59
60
  conflicts: ($, previous) => [
60
61
  ...previous,
61
- [$.call_expression, $.instantiation_expression, $.binary_expression],
62
- [$.call_expression, $.instantiation_expression, $.binary_expression, $.unary_expression],
63
- [$.call_expression, $.instantiation_expression, $.binary_expression, $.update_expression],
64
- [$.call_expression, $.instantiation_expression, $.binary_expression, $.await_expression],
62
+ [$.expression, $.call_expression, $.instantiation_expression],
65
63
 
66
64
  // This appears to be necessary to parse a parenthesized class expression
67
65
  [$.class],
@@ -159,22 +157,20 @@ module.exports = function defineGrammar(dialect) {
159
157
 
160
158
  call_expression: ($) =>
161
159
  choice(
162
- prec(
163
- 'call',
164
- seq(
165
- field('function', choice($.expression, $.import)),
166
- field('type_arguments', optional($.type_arguments)),
167
- field('arguments', $.arguments)
168
- )
169
- ),
170
- // A tag with type arguments is parsed like a generic call. Optional type arguments in the `template_call`
171
- // alternative below would make the parser commit to a tagged template at the `<` of `f<T>(x)`.
172
- prec(
173
- 'call',
174
- seq(
175
- field('function', $.expression),
176
- field('type_arguments', $.type_arguments),
177
- field('arguments', $.template_string)
160
+ prec('call', seq(field('function', choice($.expression, $.import)), field('arguments', $.arguments))),
161
+ // Type arguments follow a primary expression, as in TypeScript: `a + b<T>(c)` calls `b`. Where comparisons
162
+ // could also read the input, as in `a < b > (c)`, TypeScript reads a generic call, hence the dynamic
163
+ // precedence. A tag with type arguments is parsed like a generic call. Optional type arguments in the
164
+ // `template_call` alternative below would make the parser commit to a tagged template at the `<` of `f<T>(x)`.
165
+ prec.dynamic(
166
+ 1,
167
+ prec(
168
+ 'generic_call',
169
+ seq(
170
+ field('function', choice($.primary_expression, $.new_expression)),
171
+ field('type_arguments', $.type_arguments),
172
+ field('arguments', choice($.arguments, $.template_string))
173
+ )
178
174
  )
179
175
  ),
180
176
  prec(
@@ -493,7 +489,13 @@ module.exports = function defineGrammar(dialect) {
493
489
  satisfies_expression: ($) => prec.left('binary', seq($.expression, 'satisfies', $.type)),
494
490
 
495
491
  instantiation_expression: ($) =>
496
- prec('instantiation', seq($.expression, field('type_arguments', $.type_arguments))),
492
+ prec.dynamic(
493
+ -1,
494
+ prec(
495
+ 'instantiation',
496
+ seq(choice($.primary_expression, $.new_expression), field('type_arguments', $.type_arguments))
497
+ )
498
+ ),
497
499
 
498
500
  class_heritage: ($) => choice(seq($.extends_clause, optional($.implements_clause)), $.implements_clause),
499
501
 
@@ -1047,8 +1049,10 @@ module.exports = function defineGrammar(dialect) {
1047
1049
  tuple_type: ($) => seq('[', commaSep($._tuple_type_member), optional(','), ']'),
1048
1050
  readonly_type: ($) => seq('readonly', $.type),
1049
1051
 
1050
- union_type: ($) => prec.left(seq(optional($.type), '|', $.type)),
1051
- intersection_type: ($) => prec.left(seq(optional($.type), '&', $.type)),
1052
+ // TypeScript allows a leading `|` or `&` only at the start of a type, so `a < b || c > (d)` compares instead of
1053
+ // calling `a` with `b | | c`. The negative dynamic precedence outweighs that of the generic call.
1054
+ union_type: ($) => prec.left(choice(seq($.type, '|', $.type), prec.dynamic(-2, seq('|', $.type)))),
1055
+ intersection_type: ($) => prec.left(choice(seq($.type, '&', $.type), prec.dynamic(-2, seq('&', $.type)))),
1052
1056
 
1053
1057
  function_type: ($) =>
1054
1058
  prec.left(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-typescript",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "TypeScript and TSX grammars for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
Binary file
Binary file
package/tree-sitter.json CHANGED
@@ -77,7 +77,7 @@
77
77
  }
78
78
  ],
79
79
  "metadata": {
80
- "version": "1.2.0",
80
+ "version": "1.2.2",
81
81
  "license": "MIT",
82
82
  "description": "TypeScript and TSX grammars for tree-sitter",
83
83
  "authors": [
@@ -3103,7 +3103,11 @@
3103
3103
  "required": false,
3104
3104
  "types": [
3105
3105
  {
3106
- "type": "expression",
3106
+ "type": "new_expression",
3107
+ "named": true
3108
+ },
3109
+ {
3110
+ "type": "primary_expression",
3107
3111
  "named": true
3108
3112
  }
3109
3113
  ]
@@ -3099,7 +3099,11 @@
3099
3099
  "required": false,
3100
3100
  "types": [
3101
3101
  {
3102
- "type": "expression",
3102
+ "type": "new_expression",
3103
+ "named": true
3104
+ },
3105
+ {
3106
+ "type": "primary_expression",
3103
3107
  "named": true
3104
3108
  }
3105
3109
  ]