@willbooster/tree-sitter-typescript 1.2.5 → 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
@@ -116,6 +120,10 @@ cargo test
116
120
  - a performance check (`test/unit/performance.test.ts`) that recovering from an error on each of 10,000 lines takes
117
121
  linear time with each grammar, since consumers parse files while they are being edited. It loads the Wasm builds
118
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;
119
127
  - checks that both Wasm builds load and parse through @willbooster/web-tree-sitter in Chromium
120
128
  (`test/unit/browser/`) and in Cloudflare Workers with and without Node.js compatibility
121
129
  (`test/unit/workers.test.ts`, running the Worker in `test/fixtures/worker/`).
@@ -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.5",
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.15",
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.5",
86
+ "version": "1.2.6",
81
87
  "license": "MIT",
82
88
  "description": "TypeScript and TSX grammars for tree-sitter",
83
89
  "authors": [