@willbooster/tree-sitter-typescript 1.2.0 → 1.2.1
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 +4 -3
- package/common/defineGrammar.js +27 -23
- package/package.json +1 -1
- package/tree-sitter-tsx.wasm +0 -0
- package/tree-sitter-typescript.wasm +0 -0
- package/tree-sitter.json +1 -1
- package/tsx/src/node-types.json +5 -1
- package/typescript/src/node-types.json +5 -1
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
|
|
107
|
-
|
|
108
|
-
|
|
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
|
package/common/defineGrammar.js
CHANGED
|
@@ -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
|
-
[$.
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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(
|
|
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
|
-
|
|
1051
|
-
|
|
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
package/tree-sitter-tsx.wasm
CHANGED
|
Binary file
|
|
Binary file
|
package/tree-sitter.json
CHANGED
package/tsx/src/node-types.json
CHANGED