@willbooster/tree-sitter-typescript 1.2.4 → 1.2.6

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
@@ -67,7 +67,9 @@ const parser = new Parser();
67
67
  parser.setLanguage(await Language.load(typescript));
68
68
  ```
69
69
 
70
- The package also ships the node types in `typescript/src/node-types.json` and `tsx/src/node-types.json`.
70
+ The package also ships the node types in `typescript/src/node-types.json` and `tsx/src/node-types.json`, and the
71
+ highlighting, injection, locals, and tags queries that `tree-sitter.json` lists: this grammar's in `queries/` and, in
72
+ `javascript/queries/`, those of the JavaScript grammar it extends.
71
73
 
72
74
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-typescript) and on
73
75
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
@@ -86,6 +88,8 @@ parser.set_language(&tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into())?;
86
88
  // or `tree_sitter_typescript::LANGUAGE_TSX` for TSX
87
89
  ```
88
90
 
91
+ The crate ships the same `tree-sitter.json` and query files as the npm package.
92
+
89
93
  ## Development
90
94
 
91
95
  ```sh
@@ -105,7 +109,8 @@ cargo test
105
109
  Cases run with the `typescript` grammar unless they carry `:language(tsx)`;
106
110
  - an incremental-parsing check (`test/unit/incremental.test.ts`): `script/fuzz-corpus` runs `tree-sitter fuzz`, which
107
111
  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`).
112
+ WillBooster/tree-sitter runtime version locked in `Cargo.lock` (the first run downloads that CLI from its GitHub
113
+ Release, or builds it with `cargo` when the download fails or the release has no binary that runs here).
109
114
  `TREE_SITTER_SEED`, `TREE_SITTER_ITERATIONS`, and `TREE_SITTER_EDITS` run other or more edits;
110
115
  - a check that the real-world files in `examples/`, the checked-in ones and those of the cloned repositories, fail to
111
116
  parse exactly as listed in `script/known-failures.txt`. `.ts` files are parsed with the `typescript` grammar and
@@ -115,6 +120,10 @@ cargo test
115
120
  - a performance check (`test/unit/performance.test.ts`) that recovering from an error on each of 10,000 lines takes
116
121
  linear time with each grammar, since consumers parse files while they are being edited. It loads the Wasm builds
117
122
  through @willbooster/web-tree-sitter, which `bun run build/ci` rebuilds after regenerating the parsers;
123
+ - a check (`test/unit/queries.test.ts`) that the queries `tree-sitter.json` lists compile against each grammar, are
124
+ published in the npm package and the crate, and that `javascript/queries/` matches the queries of the installed
125
+ @willbooster/tree-sitter-javascript; after updating that dependency, `script/copy-javascript-queries` refreshes the
126
+ copies;
118
127
  - checks that both Wasm builds load and parse through @willbooster/web-tree-sitter in Chromium
119
128
  (`test/unit/browser/`) and in Cloudflare Workers with and without Node.js compatibility
120
129
  (`test/unit/workers.test.ts`, running the Worker in `test/fixtures/worker/`).
@@ -1,6 +1,26 @@
1
1
  // oxlint-disable unicorn/prefer-module -- This package is CommonJS, so tree-sitter loads the grammar as CommonJS.
2
2
  const JavaScript = require('@willbooster/tree-sitter-javascript/grammar');
3
3
 
4
+ // Words that are keywords only in some positions and identifiers elsewhere, besides the JavaScript grammar's.
5
+ const TYPESCRIPT_CONTEXTUAL_KEYWORDS = [
6
+ 'declare',
7
+ 'namespace',
8
+ 'type',
9
+ 'public',
10
+ 'private',
11
+ 'protected',
12
+ 'override',
13
+ 'readonly',
14
+ 'module',
15
+ 'any',
16
+ 'number',
17
+ 'boolean',
18
+ 'string',
19
+ 'symbol',
20
+ 'object',
21
+ 'new',
22
+ ];
23
+
4
24
  module.exports = function defineGrammar(dialect) {
5
25
  return grammar(JavaScript, {
6
26
  name: dialect,
@@ -63,6 +83,8 @@ module.exports = function defineGrammar(dialect) {
63
83
  [$.primary_expression, $._for_header, $._for_using_declaration],
64
84
  [$._for_header, $._binding_identifier],
65
85
  [$.expression, $.call_expression, $.instantiation_expression],
86
+ [$._field_name, $._property_name],
87
+ [$._property_name, $.public_field_definition],
66
88
 
67
89
  // This appears to be necessary to parse a parenthesized class expression
68
90
  [$.class],
@@ -118,6 +140,9 @@ module.exports = function defineGrammar(dialect) {
118
140
  ],
119
141
 
120
142
  rules: {
143
+ // A field named `get`, `set`, or `static` is told apart from a member that the word modifies by the line-break
144
+ // sentinels allowed right after the name, as in the JavaScript grammar's field_definition. They are not allowed
145
+ // after a type annotation, which may continue on the next line.
121
146
  public_field_definition: ($) =>
122
147
  seq(
123
148
  repeat(field('decorator', $.decorator)),
@@ -128,17 +153,64 @@ module.exports = function defineGrammar(dialect) {
128
153
  )
129
154
  ),
130
155
  choice(
131
- seq(optional('static'), optional($.override_modifier), optional('readonly')),
132
- seq(optional('abstract'), optional('readonly')),
133
- seq(optional('readonly'), optional('abstract')),
134
- optional('accessor')
135
- ),
136
- field('name', $._property_name),
137
- optional(choice('?', '!')),
138
- field('type', optional($.type_annotation)),
139
- optional($._initializer)
156
+ seq(
157
+ choice(
158
+ seq(optional('static'), optional($.override_modifier), optional('readonly')),
159
+ seq(optional('abstract'), optional('readonly')),
160
+ seq(optional('readonly'), optional('abstract')),
161
+ optional('accessor')
162
+ ),
163
+ choice(
164
+ seq(
165
+ field('name', $._field_name),
166
+ choice(
167
+ optional(choice($._initializer, $._line_break_after_field)),
168
+ seq($._field_annotations, optional($._initializer))
169
+ )
170
+ ),
171
+ // A line break after `get` or `set` continues a getter or setter. Allowing both sentinels here tells
172
+ // the scanner that a `*` on the next line cannot continue the member, unlike after `static`.
173
+ seq(
174
+ field('name', alias(choice('get', 'set'), $.property_identifier)),
175
+ choice(
176
+ optional(choice($._initializer, $._line_break_after_modifier, $._line_break_after_field)),
177
+ seq($._field_annotations, optional($._initializer))
178
+ )
179
+ )
180
+ )
181
+ ),
182
+ // A line break after a leading `static` continues a static member.
183
+ seq(
184
+ field('name', alias('static', $.property_identifier)),
185
+ choice(
186
+ optional(choice($._initializer, $._line_break_after_modifier)),
187
+ seq($._field_annotations, optional($._initializer))
188
+ )
189
+ ),
190
+ // After a modifier, `static` is a field name, which a line break ends.
191
+ seq(
192
+ choice(
193
+ seq('static', optional($.override_modifier), optional('readonly')),
194
+ seq($.override_modifier, optional('readonly')),
195
+ seq('readonly', optional('abstract')),
196
+ seq('abstract', optional('readonly')),
197
+ 'accessor'
198
+ ),
199
+ field('name', alias('static', $.property_identifier)),
200
+ choice(
201
+ optional(choice($._initializer, $._line_break_after_field)),
202
+ seq($._field_annotations, optional($._initializer))
203
+ )
204
+ )
205
+ )
140
206
  ),
141
207
 
208
+ _field_annotations: ($) =>
209
+ choice(seq(choice('?', '!'), field('type', optional($.type_annotation))), field('type', $.type_annotation)),
210
+
211
+ _field_name: ($, previous) =>
212
+ choice(previous, alias(choice(...TYPESCRIPT_CONTEXTUAL_KEYWORDS), $.property_identifier)),
213
+
142
214
  // override original catch_clause, add optional type annotation
143
215
  catch_clause: ($) =>
144
216
  seq(
@@ -251,15 +323,6 @@ module.exports = function defineGrammar(dialect) {
251
323
  )
252
324
  ),
253
325
 
254
- // Any identifier name may name a JSX attribute, such as `class` in `<div class="x" />`, which the JavaScript
255
- // grammar's reserved words reject (WillBooster/tree-sitter-javascript#25).
256
- _jsx_attribute_name: ($) =>
257
- choice(
258
- alias($.jsx_identifier, $.property_identifier),
259
- alias(reserved('properties', $.identifier), $.property_identifier),
260
- $.jsx_namespace_name
261
- ),
262
-
263
326
  // This rule is only referenced by expression when the dialect is 'tsx'
264
327
  jsx_opening_element: ($) => prec.dynamic(-1, seq($._jsx_start_opening_element, '>')),
265
328
 
@@ -268,9 +331,7 @@ module.exports = function defineGrammar(dialect) {
268
331
 
269
332
  export_specifier: (_, previous) => seq(optional(choice('type', 'typeof')), previous),
270
333
 
271
- // Any identifier name may be exported or imported. The JavaScript grammar rejects reserved words other than
272
- // `default`, for which it leaves no node (WillBooster/tree-sitter-javascript#17 and #24).
273
- _module_export_name: ($) => choice(reserved('properties', $.identifier), $.string),
334
+ _local_export_specifier: (_, previous) => seq(optional(choice('type', 'typeof')), previous),
274
335
 
275
336
  _import_identifier: ($) => choice($.identifier, alias('type', $.identifier)),
276
337
 
@@ -301,7 +362,7 @@ module.exports = function defineGrammar(dialect) {
301
362
  'import',
302
363
  optional(choice('type', 'typeof')),
303
364
  choice(seq($.import_clause, $._from_clause), $.import_require_clause, field('source', $.string)),
304
- optional($.import_attribute),
365
+ optional(choice($.import_attribute, $._line_break_before_attributes)),
305
366
  $._semicolon
306
367
  ),
307
368
 
@@ -314,33 +375,6 @@ module.exports = function defineGrammar(dialect) {
314
375
  seq('export', 'as', 'namespace', $.identifier, $._semicolon)
315
376
  ),
316
377
 
317
- // The JavaScript grammar leaves `await (x).y` ambiguous with a call of an identifier named `await`, and GLR keeps
318
- // the call; TypeScript and V8 read the operator (WillBooster/tree-sitter-javascript#23).
319
- await_expression: ($) => prec.dynamic(2, prec('unary_void', seq('await', $.expression))),
320
-
321
- // The JavaScript grammar's for header takes no `using` declaration, although ECMAScript allows one.
322
- for_statement: ($) =>
323
- seq(
324
- 'for',
325
- '(',
326
- choice(
327
- field(
328
- 'initializer',
329
- choice(
330
- alias($.for_lexical_declaration, $.lexical_declaration),
331
- alias($.for_variable_declaration, $.variable_declaration),
332
- alias($._for_using_declaration, $.using_declaration)
333
- )
334
- ),
335
- seq(field('initializer', $._expressions), ';'),
336
- field('initializer', $.empty_statement)
337
- ),
338
- field('condition', choice(seq($._expressions, ';'), $.empty_statement)),
339
- field('increment', optional($._expressions)),
340
- ')',
341
- field('body', $.statement)
342
- ),
343
-
344
378
  // ECMAScript binds only identifiers in a using declaration, so `using [a] = b` assigns to a subscript of a
345
379
  // variable named `using`.
346
380
  using_declaration: ($) =>
@@ -391,8 +425,11 @@ module.exports = function defineGrammar(dialect) {
391
425
  choice(
392
426
  seq(
393
427
  field('name', choice($._binding_identifier, $._destructuring_pattern)),
394
- field('type', optional($.type_annotation)),
395
- optional($._initializer)
428
+ // The line-break sentinel applies only right after the name: a type may continue on the next line.
429
+ choice(
430
+ optional(choice($._initializer, $._line_break_after_binding)),
431
+ seq(field('type', $.type_annotation), optional($._initializer))
432
+ )
396
433
  ),
397
434
  prec('declaration', seq(field('name', $._binding_identifier), '!', field('type', $.type_annotation)))
398
435
  ),
@@ -450,7 +487,14 @@ module.exports = function defineGrammar(dialect) {
450
487
  prec(
451
488
  'call',
452
489
  seq(
453
- field('function', choice($.identifier, alias($.decorator_member_expression, $.member_expression))),
490
+ field(
491
+ 'function',
492
+ choice(
493
+ $.identifier,
494
+ alias($.decorator_member_expression, $.member_expression),
495
+ alias($.decorator_parenthesized_expression, $.parenthesized_expression)
496
+ )
497
+ ),
454
498
  optional(field('type_arguments', $.type_arguments)),
455
499
  field('arguments', $.arguments)
456
500
  )
@@ -458,18 +502,6 @@ module.exports = function defineGrammar(dialect) {
458
502
 
459
503
  decorator_parenthesized_expression: ($) => seq('(', $._expressions, ')'),
460
504
 
461
- // A decorator's member name may be any identifier name, as a member expression's may, which the JavaScript
462
- // grammar's reserved words reject.
463
- decorator_member_expression: ($) =>
464
- prec(
465
- 'member',
466
- seq(
467
- field('object', choice($.identifier, alias($.decorator_member_expression, $.member_expression))),
468
- '.',
469
- field('property', reserved('properties', alias($.identifier, $.property_identifier)))
470
- )
471
- ),
472
-
473
505
  class_body: ($) =>
474
506
  seq(
475
507
  '{',
@@ -508,7 +540,7 @@ module.exports = function defineGrammar(dialect) {
508
540
  field('name', $._property_name),
509
541
  optional('?'),
510
542
  $._call_signature,
511
- field('body', $.statement_block)
543
+ field('body', alias($._class_member_body, $.statement_block))
512
544
  )
513
545
  ),
514
546
 
@@ -619,17 +651,6 @@ module.exports = function defineGrammar(dialect) {
619
651
 
620
652
  import_alias: ($) => seq('import', $.identifier, '=', choice($.identifier, $.nested_identifier), $._semicolon),
621
653
 
622
- // A qualified name may end in any identifier name, as a member expression may.
623
- nested_identifier: ($) =>
624
- prec(
625
- 'member',
626
- seq(
627
- field('object', choice($.identifier, alias($.nested_identifier, $.member_expression))),
628
- '.',
629
- field('property', reserved('properties', alias($.identifier, $.property_identifier)))
630
- )
631
- ),
632
-
633
654
  nested_type_identifier: ($) =>
634
655
  prec(
635
656
  'member',
@@ -1112,29 +1133,7 @@ module.exports = function defineGrammar(dialect) {
1112
1133
  // allowed on the identifier inside the alias: around the alias, the keyword token still wins in the lexer.
1113
1134
  _type_identifier: ($) => alias(reserved('properties', $.identifier), $.type_identifier),
1114
1135
 
1115
- _reserved_identifier: (_, previous) =>
1116
- choice(
1117
- 'declare',
1118
- 'namespace',
1119
- 'type',
1120
- 'public',
1121
- 'private',
1122
- 'protected',
1123
- 'override',
1124
- 'readonly',
1125
- 'module',
1126
- 'any',
1127
- 'number',
1128
- 'boolean',
1129
- 'string',
1130
- 'symbol',
1131
- 'export',
1132
- 'object',
1133
- 'new',
1134
- 'readonly',
1135
- 'using',
1136
- previous
1137
- ),
1136
+ _reserved_identifier: (_, previous) => choice(...TYPESCRIPT_CONTEXTUAL_KEYWORDS, previous),
1138
1137
  },
1139
1138
  });
1140
1139
  };
@@ -0,0 +1,8 @@
1
+ (jsx_opening_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
2
+ (jsx_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
3
+ (jsx_self_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
4
+
5
+ (jsx_attribute (property_identifier) @attribute)
6
+ (jsx_opening_element (["<" ">"]) @punctuation.bracket)
7
+ (jsx_closing_element (["</" ">"]) @punctuation.bracket)
8
+ (jsx_self_closing_element (["<" "/>"]) @punctuation.bracket)
@@ -0,0 +1,218 @@
1
+ ; Variables
2
+ ;----------
3
+
4
+ (identifier) @variable
5
+
6
+ ; Properties
7
+ ;-----------
8
+
9
+ (property_identifier) @property
10
+
11
+ ; Function and method definitions
12
+ ;--------------------------------
13
+
14
+ (function_expression
15
+ name: (identifier) @function)
16
+ (function_declaration
17
+ name: (identifier) @function)
18
+ (method_definition
19
+ name: (property_identifier) @function.method)
20
+
21
+ (pair
22
+ key: (property_identifier) @function.method
23
+ value: [(function_expression) (arrow_function)])
24
+
25
+ (assignment_expression
26
+ left: (member_expression
27
+ property: (property_identifier) @function.method)
28
+ right: [(function_expression) (arrow_function)])
29
+
30
+ (variable_declarator
31
+ name: (identifier) @function
32
+ value: [(function_expression) (arrow_function)])
33
+
34
+ (assignment_expression
35
+ left: (identifier) @function
36
+ right: [(function_expression) (arrow_function)])
37
+
38
+ ; Function and method calls
39
+ ;--------------------------
40
+
41
+ (call_expression
42
+ function: (identifier) @function)
43
+
44
+ (call_expression
45
+ function: (member_expression
46
+ property: (property_identifier) @function.method))
47
+
48
+ ; Special identifiers
49
+ ;--------------------
50
+
51
+ ((identifier) @constructor
52
+ (#match? @constructor "^[A-Z]"))
53
+
54
+ ([
55
+ (identifier)
56
+ (shorthand_property_identifier)
57
+ (shorthand_property_identifier_pattern)
58
+ ] @constant
59
+ (#match? @constant "^[A-Z_][A-Z\\d_]+$"))
60
+
61
+ ((identifier) @variable.builtin
62
+ (#match? @variable.builtin "^(arguments|module|console|window|document)$")
63
+ (#is-not? local))
64
+
65
+ ((identifier) @function.builtin
66
+ (#eq? @function.builtin "require")
67
+ (#is-not? local))
68
+
69
+ ; Literals
70
+ ;---------
71
+
72
+ (this) @variable.builtin
73
+ (super) @variable.builtin
74
+
75
+ [
76
+ (true)
77
+ (false)
78
+ (null)
79
+ (undefined)
80
+ ] @constant.builtin
81
+
82
+ (comment) @comment
83
+
84
+ [
85
+ (string)
86
+ (template_string)
87
+ ] @string
88
+
89
+ (regex) @string.special
90
+ (number) @number
91
+
92
+ ; Tokens
93
+ ;-------
94
+
95
+ [
96
+ ";"
97
+ (optional_chain)
98
+ "."
99
+ ","
100
+ ] @punctuation.delimiter
101
+
102
+ [
103
+ "-"
104
+ "--"
105
+ "-="
106
+ "+"
107
+ "++"
108
+ "+="
109
+ "*"
110
+ "*="
111
+ "**"
112
+ "**="
113
+ "/"
114
+ "/="
115
+ "%"
116
+ "%="
117
+ "<"
118
+ "<="
119
+ "<<"
120
+ "<<="
121
+ "="
122
+ "=="
123
+ "==="
124
+ "!"
125
+ "!="
126
+ "!=="
127
+ "=>"
128
+ ">"
129
+ ">="
130
+ ">>"
131
+ ">>="
132
+ ">>>"
133
+ ">>>="
134
+ "~"
135
+ "^"
136
+ "&"
137
+ "|"
138
+ "^="
139
+ "&="
140
+ "|="
141
+ "&&"
142
+ "||"
143
+ "??"
144
+ "&&="
145
+ "||="
146
+ "??="
147
+ ] @operator
148
+
149
+ [
150
+ "("
151
+ ")"
152
+ "["
153
+ "]"
154
+ "{"
155
+ "}"
156
+ ] @punctuation.bracket
157
+
158
+ (template_substitution
159
+ "${" @punctuation.special
160
+ "}" @punctuation.special) @embedded
161
+
162
+ [
163
+ "as"
164
+ "async"
165
+ "await"
166
+ "break"
167
+ "case"
168
+ "catch"
169
+ "class"
170
+ "const"
171
+ "continue"
172
+ "debugger"
173
+ "default"
174
+ "delete"
175
+ "do"
176
+ "else"
177
+ "export"
178
+ "extends"
179
+ "finally"
180
+ "for"
181
+ "from"
182
+ "function"
183
+ "get"
184
+ "if"
185
+ "import"
186
+ "in"
187
+ "instanceof"
188
+ "let"
189
+ "new"
190
+ "of"
191
+ "return"
192
+ "set"
193
+ "static"
194
+ "switch"
195
+ "target"
196
+ "throw"
197
+ "try"
198
+ "typeof"
199
+ "var"
200
+ "void"
201
+ "while"
202
+ "with"
203
+ "yield"
204
+ ] @keyword
205
+
206
+ ; `default` as a module export name is an identifier node.
207
+ (export_specifier
208
+ name: (identifier) @keyword
209
+ (#eq? @keyword "default"))
210
+ (export_specifier
211
+ alias: (identifier) @keyword
212
+ (#eq? @keyword "default"))
213
+ (import_specifier
214
+ name: (identifier) @keyword
215
+ (#eq? @keyword "default"))
216
+ (namespace_export
217
+ (identifier) @keyword
218
+ (#eq? @keyword "default"))
@@ -0,0 +1,31 @@
1
+ ; Parse the contents of tagged template literals using
2
+ ; a language inferred from the tag.
3
+
4
+ (call_expression
5
+ function: [
6
+ (identifier) @injection.language
7
+ (member_expression
8
+ property: (property_identifier) @injection.language)
9
+ ]
10
+ arguments: (template_string (string_fragment) @injection.content)
11
+ (#set! injection.combined)
12
+ (#set! injection.include-children))
13
+
14
+
15
+ ; Parse regex syntax within regex literals
16
+
17
+ ((regex_pattern) @injection.content
18
+ (#set! injection.language "regex"))
19
+
20
+ ; Parse JSDoc annotations in comments
21
+
22
+ ((comment) @injection.content
23
+ (#set! injection.language "jsdoc"))
24
+
25
+ ; Parse Ember/Glimmer/Handlebars/HTMLBars/etc. template literals
26
+ ; e.g.: await render(hbs`<SomeComponent />`)
27
+ (call_expression
28
+ function: ((identifier) @_name
29
+ (#eq? @_name "hbs"))
30
+ arguments: ((template_string) @glimmer
31
+ (#offset! @glimmer 0 1 0 -1)))
@@ -0,0 +1,23 @@
1
+ ; Scopes
2
+ ;-------
3
+
4
+ [
5
+ (statement_block)
6
+ (function_expression)
7
+ (arrow_function)
8
+ (function_declaration)
9
+ (method_definition)
10
+ ] @local.scope
11
+
12
+ ; Definitions
13
+ ;------------
14
+
15
+ (pattern/identifier) @local.definition
16
+
17
+ (variable_declarator
18
+ name: (identifier) @local.definition)
19
+
20
+ ; References
21
+ ;------------
22
+
23
+ (identifier) @local.reference
@@ -0,0 +1,99 @@
1
+ (
2
+ (comment)* @doc
3
+ .
4
+ (method_definition
5
+ name: (property_identifier) @name) @definition.method
6
+ (#not-eq? @name "constructor")
7
+ (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
8
+ (#select-adjacent! @doc @definition.method)
9
+ )
10
+
11
+ (
12
+ (comment)* @doc
13
+ .
14
+ [
15
+ (class
16
+ name: (_) @name)
17
+ (class_declaration
18
+ name: (_) @name)
19
+ ] @definition.class
20
+ (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
21
+ (#select-adjacent! @doc @definition.class)
22
+ )
23
+
24
+ (
25
+ (comment)* @doc
26
+ .
27
+ [
28
+ (function_expression
29
+ name: (identifier) @name)
30
+ (function_declaration
31
+ name: (identifier) @name)
32
+ (generator_function
33
+ name: (identifier) @name)
34
+ (generator_function_declaration
35
+ name: (identifier) @name)
36
+ ] @definition.function
37
+ (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
38
+ (#select-adjacent! @doc @definition.function)
39
+ )
40
+
41
+ (
42
+ (comment)* @doc
43
+ .
44
+ (lexical_declaration
45
+ (variable_declarator
46
+ name: (identifier) @name
47
+ value: [(arrow_function) (function_expression)]) @definition.function)
48
+ (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
49
+ (#select-adjacent! @doc @definition.function)
50
+ )
51
+
52
+ (
53
+ (comment)* @doc
54
+ .
55
+ (variable_declaration
56
+ (variable_declarator
57
+ name: (identifier) @name
58
+ value: [(arrow_function) (function_expression)]) @definition.function)
59
+ (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
60
+ (#select-adjacent! @doc @definition.function)
61
+ )
62
+
63
+ (assignment_expression
64
+ left: [
65
+ (identifier) @name
66
+ (member_expression
67
+ property: (property_identifier) @name)
68
+ ]
69
+ right: [(arrow_function) (function_expression)]
70
+ ) @definition.function
71
+
72
+ (pair
73
+ key: (property_identifier) @name
74
+ value: [(arrow_function) (function_expression)]) @definition.function
75
+
76
+ (
77
+ (call_expression
78
+ function: (identifier) @name) @reference.call
79
+ (#not-match? @name "^(require)$")
80
+ )
81
+
82
+ (call_expression
83
+ function: (member_expression
84
+ property: (property_identifier) @name)
85
+ arguments: (_) @reference.call)
86
+
87
+ (new_expression
88
+ constructor: (_) @name) @reference.class
89
+
90
+ (export_statement value: (assignment_expression left: (identifier) @name right: ([
91
+ (number)
92
+ (string)
93
+ (identifier)
94
+ (undefined)
95
+ (null)
96
+ (new_expression)
97
+ (binary_expression)
98
+ (call_expression)
99
+ ]))) @definition.constant
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-typescript",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "TypeScript and TSX grammars for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -22,6 +22,8 @@
22
22
  "tree-sitter.json",
23
23
  "typescript/src/node-types.json",
24
24
  "tsx/src/node-types.json",
25
+ "queries/*.scm",
26
+ "javascript/queries/*.scm",
25
27
  "*.wasm"
26
28
  ],
27
29
  "scripts": {
@@ -48,7 +50,7 @@
48
50
  "@vitest/browser-playwright": "5.0.1",
49
51
  "@willbooster/oxfmt-config": "1.2.2",
50
52
  "@willbooster/oxlint-config": "1.4.8",
51
- "@willbooster/tree-sitter-javascript": "1.0.3",
53
+ "@willbooster/tree-sitter-javascript": "1.0.16",
52
54
  "@willbooster/wb": "22.13.0",
53
55
  "@willbooster/web-tree-sitter": "1.0.7",
54
56
  "conventional-changelog-conventionalcommits": "10.4.0",
@@ -0,0 +1,35 @@
1
+ ; Types
2
+
3
+ (type_identifier) @type
4
+ (predefined_type) @type.builtin
5
+
6
+ ((identifier) @type
7
+ (#match? @type "^[A-Z]"))
8
+
9
+ (type_arguments
10
+ "<" @punctuation.bracket
11
+ ">" @punctuation.bracket)
12
+
13
+ ; Variables
14
+
15
+ (required_parameter (identifier) @variable.parameter)
16
+ (optional_parameter (identifier) @variable.parameter)
17
+
18
+ ; Keywords
19
+
20
+ [ "abstract"
21
+ "declare"
22
+ "enum"
23
+ "export"
24
+ "implements"
25
+ "interface"
26
+ "keyof"
27
+ "namespace"
28
+ "private"
29
+ "protected"
30
+ "public"
31
+ "type"
32
+ "readonly"
33
+ "override"
34
+ "satisfies"
35
+ ] @keyword
@@ -0,0 +1,2 @@
1
+ (required_parameter (identifier) @local.definition)
2
+ (optional_parameter (identifier) @local.definition)
@@ -0,0 +1,23 @@
1
+ (function_signature
2
+ name: (identifier) @name) @definition.function
3
+
4
+ (method_signature
5
+ name: (property_identifier) @name) @definition.method
6
+
7
+ (abstract_method_signature
8
+ name: (property_identifier) @name) @definition.method
9
+
10
+ (abstract_class_declaration
11
+ name: (type_identifier) @name) @definition.class
12
+
13
+ (module
14
+ name: (identifier) @name) @definition.module
15
+
16
+ (interface_declaration
17
+ name: (type_identifier) @name) @definition.interface
18
+
19
+ (type_annotation
20
+ (type_identifier) @name) @reference.type
21
+
22
+ (new_expression
23
+ constructor: (identifier) @name) @reference.class
Binary file
Binary file
package/tree-sitter.json CHANGED
@@ -14,16 +14,16 @@
14
14
  ],
15
15
  "highlights": [
16
16
  "queries/highlights.scm",
17
- "node_modules/@willbooster/tree-sitter-javascript/queries/highlights.scm"
17
+ "javascript/queries/highlights.scm"
18
18
  ],
19
- "injections": "node_modules/@willbooster/tree-sitter-javascript/queries/injections.scm",
19
+ "injections": "javascript/queries/injections.scm",
20
20
  "locals": [
21
21
  "queries/locals.scm",
22
- "node_modules/@willbooster/tree-sitter-javascript/queries/locals.scm"
22
+ "javascript/queries/locals.scm"
23
23
  ],
24
24
  "tags": [
25
25
  "queries/tags.scm",
26
- "node_modules/@willbooster/tree-sitter-javascript/queries/tags.scm"
26
+ "javascript/queries/tags.scm"
27
27
  ],
28
28
  "injection-regex": "^(ts|typescript)$"
29
29
  },
@@ -40,14 +40,17 @@
40
40
  ],
41
41
  "highlights": [
42
42
  "queries/highlights.scm",
43
- "node_modules/@willbooster/tree-sitter-javascript/queries/highlights-jsx.scm",
44
- "node_modules/@willbooster/tree-sitter-javascript/queries/highlights.scm"
43
+ "javascript/queries/highlights-jsx.scm",
44
+ "javascript/queries/highlights.scm"
45
+ ],
46
+ "injections": "javascript/queries/injections.scm",
47
+ "locals": [
48
+ "queries/locals.scm",
49
+ "javascript/queries/locals.scm"
45
50
  ],
46
- "injections": "node_modules/@willbooster/tree-sitter-javascript/queries/injections.scm",
47
- "locals": "node_modules/@willbooster/tree-sitter-javascript/queries/locals.scm",
48
51
  "tags": [
49
52
  "queries/tags.scm",
50
- "node_modules/@willbooster/tree-sitter-javascript/queries/tags.scm"
53
+ "javascript/queries/tags.scm"
51
54
  ],
52
55
  "injection-regex": "^(ts|typescript)$"
53
56
  },
@@ -64,20 +67,23 @@
64
67
  ],
65
68
  "highlights": [
66
69
  "queries/highlights.scm",
67
- "node_modules/@willbooster/tree-sitter-javascript/queries/highlights-jsx.scm",
68
- "node_modules/@willbooster/tree-sitter-javascript/queries/highlights.scm"
70
+ "javascript/queries/highlights-jsx.scm",
71
+ "javascript/queries/highlights.scm"
72
+ ],
73
+ "injections": "javascript/queries/injections.scm",
74
+ "locals": [
75
+ "queries/locals.scm",
76
+ "javascript/queries/locals.scm"
69
77
  ],
70
- "injections": "node_modules/@willbooster/tree-sitter-javascript/queries/injections.scm",
71
- "locals": "node_modules/@willbooster/tree-sitter-javascript/queries/locals.scm",
72
78
  "tags": [
73
79
  "queries/tags.scm",
74
- "node_modules/@willbooster/tree-sitter-javascript/queries/tags.scm"
80
+ "javascript/queries/tags.scm"
75
81
  ],
76
82
  "content-regex": "@flow"
77
83
  }
78
84
  ],
79
85
  "metadata": {
80
- "version": "1.2.4",
86
+ "version": "1.2.6",
81
87
  "license": "MIT",
82
88
  "description": "TypeScript and TSX grammars for tree-sitter",
83
89
  "authors": [
@@ -159,6 +159,10 @@
159
159
  "type": "object_pattern",
160
160
  "named": true
161
161
  },
162
+ {
163
+ "type": "parenthesized_expression",
164
+ "named": true
165
+ },
162
166
  {
163
167
  "type": "rest_pattern",
164
168
  "named": true
@@ -2018,7 +2022,7 @@
2018
2022
  }
2019
2023
  },
2020
2024
  "children": {
2021
- "multiple": false,
2025
+ "multiple": true,
2022
2026
  "required": false,
2023
2027
  "types": [
2024
2028
  {
@@ -2033,6 +2037,10 @@
2033
2037
  "type": "identifier",
2034
2038
  "named": true
2035
2039
  },
2040
+ {
2041
+ "type": "import_attribute",
2042
+ "named": true
2043
+ },
2036
2044
  {
2037
2045
  "type": "namespace_export",
2038
2046
  "named": true
@@ -4739,6 +4747,10 @@
4739
4747
  "type": "object_pattern",
4740
4748
  "named": true
4741
4749
  },
4750
+ {
4751
+ "type": "parenthesized_expression",
4752
+ "named": true
4753
+ },
4742
4754
  {
4743
4755
  "type": "subscript_expression",
4744
4756
  "named": true
@@ -155,6 +155,10 @@
155
155
  "type": "object_pattern",
156
156
  "named": true
157
157
  },
158
+ {
159
+ "type": "parenthesized_expression",
160
+ "named": true
161
+ },
158
162
  {
159
163
  "type": "rest_pattern",
160
164
  "named": true
@@ -2014,7 +2018,7 @@
2014
2018
  }
2015
2019
  },
2016
2020
  "children": {
2017
- "multiple": false,
2021
+ "multiple": true,
2018
2022
  "required": false,
2019
2023
  "types": [
2020
2024
  {
@@ -2029,6 +2033,10 @@
2029
2033
  "type": "identifier",
2030
2034
  "named": true
2031
2035
  },
2036
+ {
2037
+ "type": "import_attribute",
2038
+ "named": true
2039
+ },
2032
2040
  {
2033
2041
  "type": "namespace_export",
2034
2042
  "named": true
@@ -4490,6 +4498,10 @@
4490
4498
  "type": "object_pattern",
4491
4499
  "named": true
4492
4500
  },
4501
+ {
4502
+ "type": "parenthesized_expression",
4503
+ "named": true
4504
+ },
4493
4505
  {
4494
4506
  "type": "subscript_expression",
4495
4507
  "named": true