@ast-grep/napi 0.32.1 → 0.32.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/lang/Bash.d.ts +1937 -0
- package/lang/C.d.ts +3863 -0
- package/lang/CSharp.d.ts +5895 -0
- package/lang/Cpp.d.ts +6733 -0
- package/lang/Css.d.ts +2049 -0
- package/lang/Elixir.d.ts +2776 -0
- package/lang/Go.d.ts +2469 -0
- package/lang/Haskell.d.ts +5898 -0
- package/lang/Html.d.ts +283 -0
- package/lang/Java.d.ts +3990 -0
- package/lang/JavaScript.d.ts +2952 -0
- package/lang/Json.d.ts +156 -0
- package/lang/Kotlin.d.ts +9122 -0
- package/lang/Lua.d.ts +1050 -0
- package/lang/Php.d.ts +5198 -0
- package/lang/Python.d.ts +3197 -0
- package/lang/Ruby.d.ts +3492 -0
- package/lang/Rust.d.ts +4850 -0
- package/lang/Scala.d.ts +7325 -0
- package/lang/Tsx.d.ts +5470 -0
- package/lang/TypeScript.d.ts +5228 -0
- package/lang/Yaml.d.ts +481 -0
- package/package.json +10 -10
- package/types/sgnode.d.ts +25 -15
- package/types/staticTypes.d.ts +13 -2
package/lang/Yaml.d.ts
ADDED
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
// Auto-generated from tree-sitter Yaml v0.7.0
|
|
2
|
+
type YamlTypes = {
|
|
3
|
+
"alias": {
|
|
4
|
+
"type": "alias",
|
|
5
|
+
"named": true,
|
|
6
|
+
"fields": {},
|
|
7
|
+
"children": {
|
|
8
|
+
"multiple": false,
|
|
9
|
+
"required": true,
|
|
10
|
+
"types": [
|
|
11
|
+
{
|
|
12
|
+
"type": "alias_name",
|
|
13
|
+
"named": true
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"anchor": {
|
|
19
|
+
"type": "anchor",
|
|
20
|
+
"named": true,
|
|
21
|
+
"fields": {},
|
|
22
|
+
"children": {
|
|
23
|
+
"multiple": false,
|
|
24
|
+
"required": true,
|
|
25
|
+
"types": [
|
|
26
|
+
{
|
|
27
|
+
"type": "anchor_name",
|
|
28
|
+
"named": true
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"block_mapping": {
|
|
34
|
+
"type": "block_mapping",
|
|
35
|
+
"named": true,
|
|
36
|
+
"fields": {},
|
|
37
|
+
"children": {
|
|
38
|
+
"multiple": true,
|
|
39
|
+
"required": true,
|
|
40
|
+
"types": [
|
|
41
|
+
{
|
|
42
|
+
"type": "block_mapping_pair",
|
|
43
|
+
"named": true
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"block_mapping_pair": {
|
|
49
|
+
"type": "block_mapping_pair",
|
|
50
|
+
"named": true,
|
|
51
|
+
"fields": {
|
|
52
|
+
"key": {
|
|
53
|
+
"multiple": false,
|
|
54
|
+
"required": false,
|
|
55
|
+
"types": [
|
|
56
|
+
{
|
|
57
|
+
"type": "block_node",
|
|
58
|
+
"named": true
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"type": "flow_node",
|
|
62
|
+
"named": true
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
"value": {
|
|
67
|
+
"multiple": false,
|
|
68
|
+
"required": false,
|
|
69
|
+
"types": [
|
|
70
|
+
{
|
|
71
|
+
"type": "block_node",
|
|
72
|
+
"named": true
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"type": "flow_node",
|
|
76
|
+
"named": true
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"block_node": {
|
|
83
|
+
"type": "block_node",
|
|
84
|
+
"named": true,
|
|
85
|
+
"fields": {},
|
|
86
|
+
"children": {
|
|
87
|
+
"multiple": true,
|
|
88
|
+
"required": true,
|
|
89
|
+
"types": [
|
|
90
|
+
{
|
|
91
|
+
"type": "anchor",
|
|
92
|
+
"named": true
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"type": "block_mapping",
|
|
96
|
+
"named": true
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"type": "block_scalar",
|
|
100
|
+
"named": true
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"type": "block_sequence",
|
|
104
|
+
"named": true
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"type": "tag",
|
|
108
|
+
"named": true
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"block_scalar": {
|
|
114
|
+
"type": "block_scalar",
|
|
115
|
+
"named": true,
|
|
116
|
+
"fields": {}
|
|
117
|
+
},
|
|
118
|
+
"block_sequence": {
|
|
119
|
+
"type": "block_sequence",
|
|
120
|
+
"named": true,
|
|
121
|
+
"fields": {},
|
|
122
|
+
"children": {
|
|
123
|
+
"multiple": true,
|
|
124
|
+
"required": true,
|
|
125
|
+
"types": [
|
|
126
|
+
{
|
|
127
|
+
"type": "block_sequence_item",
|
|
128
|
+
"named": true
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
"block_sequence_item": {
|
|
134
|
+
"type": "block_sequence_item",
|
|
135
|
+
"named": true,
|
|
136
|
+
"fields": {},
|
|
137
|
+
"children": {
|
|
138
|
+
"multiple": false,
|
|
139
|
+
"required": false,
|
|
140
|
+
"types": [
|
|
141
|
+
{
|
|
142
|
+
"type": "block_node",
|
|
143
|
+
"named": true
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"type": "flow_node",
|
|
147
|
+
"named": true
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
"document": {
|
|
153
|
+
"type": "document",
|
|
154
|
+
"named": true,
|
|
155
|
+
"fields": {},
|
|
156
|
+
"children": {
|
|
157
|
+
"multiple": true,
|
|
158
|
+
"required": false,
|
|
159
|
+
"types": [
|
|
160
|
+
{
|
|
161
|
+
"type": "block_node",
|
|
162
|
+
"named": true
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"type": "flow_node",
|
|
166
|
+
"named": true
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"type": "reserved_directive",
|
|
170
|
+
"named": true
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"type": "tag_directive",
|
|
174
|
+
"named": true
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"type": "yaml_directive",
|
|
178
|
+
"named": true
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
"double_quote_scalar": {
|
|
184
|
+
"type": "double_quote_scalar",
|
|
185
|
+
"named": true,
|
|
186
|
+
"fields": {},
|
|
187
|
+
"children": {
|
|
188
|
+
"multiple": true,
|
|
189
|
+
"required": false,
|
|
190
|
+
"types": [
|
|
191
|
+
{
|
|
192
|
+
"type": "escape_sequence",
|
|
193
|
+
"named": true
|
|
194
|
+
}
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
"flow_mapping": {
|
|
199
|
+
"type": "flow_mapping",
|
|
200
|
+
"named": true,
|
|
201
|
+
"fields": {},
|
|
202
|
+
"children": {
|
|
203
|
+
"multiple": true,
|
|
204
|
+
"required": false,
|
|
205
|
+
"types": [
|
|
206
|
+
{
|
|
207
|
+
"type": "flow_node",
|
|
208
|
+
"named": true
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"type": "flow_pair",
|
|
212
|
+
"named": true
|
|
213
|
+
}
|
|
214
|
+
]
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
"flow_node": {
|
|
218
|
+
"type": "flow_node",
|
|
219
|
+
"named": true,
|
|
220
|
+
"fields": {},
|
|
221
|
+
"children": {
|
|
222
|
+
"multiple": true,
|
|
223
|
+
"required": true,
|
|
224
|
+
"types": [
|
|
225
|
+
{
|
|
226
|
+
"type": "alias",
|
|
227
|
+
"named": true
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"type": "anchor",
|
|
231
|
+
"named": true
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"type": "double_quote_scalar",
|
|
235
|
+
"named": true
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
"type": "flow_mapping",
|
|
239
|
+
"named": true
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"type": "flow_sequence",
|
|
243
|
+
"named": true
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"type": "plain_scalar",
|
|
247
|
+
"named": true
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"type": "single_quote_scalar",
|
|
251
|
+
"named": true
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
"type": "tag",
|
|
255
|
+
"named": true
|
|
256
|
+
}
|
|
257
|
+
]
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
"flow_pair": {
|
|
261
|
+
"type": "flow_pair",
|
|
262
|
+
"named": true,
|
|
263
|
+
"fields": {
|
|
264
|
+
"key": {
|
|
265
|
+
"multiple": false,
|
|
266
|
+
"required": false,
|
|
267
|
+
"types": [
|
|
268
|
+
{
|
|
269
|
+
"type": "flow_node",
|
|
270
|
+
"named": true
|
|
271
|
+
}
|
|
272
|
+
]
|
|
273
|
+
},
|
|
274
|
+
"value": {
|
|
275
|
+
"multiple": false,
|
|
276
|
+
"required": false,
|
|
277
|
+
"types": [
|
|
278
|
+
{
|
|
279
|
+
"type": "flow_node",
|
|
280
|
+
"named": true
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
"flow_sequence": {
|
|
287
|
+
"type": "flow_sequence",
|
|
288
|
+
"named": true,
|
|
289
|
+
"fields": {},
|
|
290
|
+
"children": {
|
|
291
|
+
"multiple": true,
|
|
292
|
+
"required": false,
|
|
293
|
+
"types": [
|
|
294
|
+
{
|
|
295
|
+
"type": "flow_node",
|
|
296
|
+
"named": true
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
"type": "flow_pair",
|
|
300
|
+
"named": true
|
|
301
|
+
}
|
|
302
|
+
]
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
"plain_scalar": {
|
|
306
|
+
"type": "plain_scalar",
|
|
307
|
+
"named": true,
|
|
308
|
+
"fields": {},
|
|
309
|
+
"children": {
|
|
310
|
+
"multiple": false,
|
|
311
|
+
"required": true,
|
|
312
|
+
"types": [
|
|
313
|
+
{
|
|
314
|
+
"type": "boolean_scalar",
|
|
315
|
+
"named": true
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
"type": "float_scalar",
|
|
319
|
+
"named": true
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
"type": "integer_scalar",
|
|
323
|
+
"named": true
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
"type": "null_scalar",
|
|
327
|
+
"named": true
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
"type": "string_scalar",
|
|
331
|
+
"named": true
|
|
332
|
+
}
|
|
333
|
+
]
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
"reserved_directive": {
|
|
337
|
+
"type": "reserved_directive",
|
|
338
|
+
"named": true,
|
|
339
|
+
"fields": {},
|
|
340
|
+
"children": {
|
|
341
|
+
"multiple": true,
|
|
342
|
+
"required": true,
|
|
343
|
+
"types": [
|
|
344
|
+
{
|
|
345
|
+
"type": "directive_name",
|
|
346
|
+
"named": true
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
"type": "directive_parameter",
|
|
350
|
+
"named": true
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
"single_quote_scalar": {
|
|
356
|
+
"type": "single_quote_scalar",
|
|
357
|
+
"named": true,
|
|
358
|
+
"fields": {},
|
|
359
|
+
"children": {
|
|
360
|
+
"multiple": true,
|
|
361
|
+
"required": false,
|
|
362
|
+
"types": [
|
|
363
|
+
{
|
|
364
|
+
"type": "escape_sequence",
|
|
365
|
+
"named": true
|
|
366
|
+
}
|
|
367
|
+
]
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
"stream": {
|
|
371
|
+
"type": "stream",
|
|
372
|
+
"named": true,
|
|
373
|
+
"root": true,
|
|
374
|
+
"fields": {},
|
|
375
|
+
"children": {
|
|
376
|
+
"multiple": true,
|
|
377
|
+
"required": false,
|
|
378
|
+
"types": [
|
|
379
|
+
{
|
|
380
|
+
"type": "document",
|
|
381
|
+
"named": true
|
|
382
|
+
}
|
|
383
|
+
]
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
"tag_directive": {
|
|
387
|
+
"type": "tag_directive",
|
|
388
|
+
"named": true,
|
|
389
|
+
"fields": {},
|
|
390
|
+
"children": {
|
|
391
|
+
"multiple": true,
|
|
392
|
+
"required": true,
|
|
393
|
+
"types": [
|
|
394
|
+
{
|
|
395
|
+
"type": "tag_handle",
|
|
396
|
+
"named": true
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
"type": "tag_prefix",
|
|
400
|
+
"named": true
|
|
401
|
+
}
|
|
402
|
+
]
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
"yaml_directive": {
|
|
406
|
+
"type": "yaml_directive",
|
|
407
|
+
"named": true,
|
|
408
|
+
"fields": {},
|
|
409
|
+
"children": {
|
|
410
|
+
"multiple": false,
|
|
411
|
+
"required": true,
|
|
412
|
+
"types": [
|
|
413
|
+
{
|
|
414
|
+
"type": "yaml_version",
|
|
415
|
+
"named": true
|
|
416
|
+
}
|
|
417
|
+
]
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
"alias_name": {
|
|
421
|
+
"type": "alias_name",
|
|
422
|
+
"named": true
|
|
423
|
+
},
|
|
424
|
+
"anchor_name": {
|
|
425
|
+
"type": "anchor_name",
|
|
426
|
+
"named": true
|
|
427
|
+
},
|
|
428
|
+
"boolean_scalar": {
|
|
429
|
+
"type": "boolean_scalar",
|
|
430
|
+
"named": true
|
|
431
|
+
},
|
|
432
|
+
"comment": {
|
|
433
|
+
"type": "comment",
|
|
434
|
+
"named": true
|
|
435
|
+
},
|
|
436
|
+
"directive_name": {
|
|
437
|
+
"type": "directive_name",
|
|
438
|
+
"named": true
|
|
439
|
+
},
|
|
440
|
+
"directive_parameter": {
|
|
441
|
+
"type": "directive_parameter",
|
|
442
|
+
"named": true
|
|
443
|
+
},
|
|
444
|
+
"escape_sequence": {
|
|
445
|
+
"type": "escape_sequence",
|
|
446
|
+
"named": true
|
|
447
|
+
},
|
|
448
|
+
"float_scalar": {
|
|
449
|
+
"type": "float_scalar",
|
|
450
|
+
"named": true
|
|
451
|
+
},
|
|
452
|
+
"integer_scalar": {
|
|
453
|
+
"type": "integer_scalar",
|
|
454
|
+
"named": true
|
|
455
|
+
},
|
|
456
|
+
"null_scalar": {
|
|
457
|
+
"type": "null_scalar",
|
|
458
|
+
"named": true
|
|
459
|
+
},
|
|
460
|
+
"string_scalar": {
|
|
461
|
+
"type": "string_scalar",
|
|
462
|
+
"named": true
|
|
463
|
+
},
|
|
464
|
+
"tag": {
|
|
465
|
+
"type": "tag",
|
|
466
|
+
"named": true
|
|
467
|
+
},
|
|
468
|
+
"tag_handle": {
|
|
469
|
+
"type": "tag_handle",
|
|
470
|
+
"named": true
|
|
471
|
+
},
|
|
472
|
+
"tag_prefix": {
|
|
473
|
+
"type": "tag_prefix",
|
|
474
|
+
"named": true
|
|
475
|
+
},
|
|
476
|
+
"yaml_version": {
|
|
477
|
+
"type": "yaml_version",
|
|
478
|
+
"named": true
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
export default YamlTypes;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ast-grep/napi",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.2",
|
|
4
4
|
"description": "Search and Rewrite code at large scale using precise AST pattern",
|
|
5
5
|
"homepage": "https://ast-grep.github.io",
|
|
6
6
|
"main": "index.js",
|
|
@@ -76,14 +76,14 @@
|
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
"optionalDependencies": {
|
|
79
|
-
"@ast-grep/napi-win32-x64-msvc": "0.32.
|
|
80
|
-
"@ast-grep/napi-darwin-x64": "0.32.
|
|
81
|
-
"@ast-grep/napi-linux-x64-gnu": "0.32.
|
|
82
|
-
"@ast-grep/napi-win32-ia32-msvc": "0.32.
|
|
83
|
-
"@ast-grep/napi-darwin-arm64": "0.32.
|
|
84
|
-
"@ast-grep/napi-win32-arm64-msvc": "0.32.
|
|
85
|
-
"@ast-grep/napi-linux-arm64-gnu": "0.32.
|
|
86
|
-
"@ast-grep/napi-linux-arm64-musl": "0.32.
|
|
87
|
-
"@ast-grep/napi-linux-x64-musl": "0.32.
|
|
79
|
+
"@ast-grep/napi-win32-x64-msvc": "0.32.2",
|
|
80
|
+
"@ast-grep/napi-darwin-x64": "0.32.2",
|
|
81
|
+
"@ast-grep/napi-linux-x64-gnu": "0.32.2",
|
|
82
|
+
"@ast-grep/napi-win32-ia32-msvc": "0.32.2",
|
|
83
|
+
"@ast-grep/napi-darwin-arm64": "0.32.2",
|
|
84
|
+
"@ast-grep/napi-win32-arm64-msvc": "0.32.2",
|
|
85
|
+
"@ast-grep/napi-linux-arm64-gnu": "0.32.2",
|
|
86
|
+
"@ast-grep/napi-linux-arm64-musl": "0.32.2",
|
|
87
|
+
"@ast-grep/napi-linux-x64-musl": "0.32.2"
|
|
88
88
|
}
|
|
89
89
|
}
|
package/types/sgnode.d.ts
CHANGED
|
@@ -6,6 +6,9 @@ import type {
|
|
|
6
6
|
Kinds,
|
|
7
7
|
NodeFieldInfo,
|
|
8
8
|
RootKind,
|
|
9
|
+
NamedKinds,
|
|
10
|
+
ChildKinds,
|
|
11
|
+
NamedChildKinds,
|
|
9
12
|
} from './staticTypes'
|
|
10
13
|
import type { NapiConfig } from './config'
|
|
11
14
|
|
|
@@ -36,32 +39,33 @@ export declare class SgNode<
|
|
|
36
39
|
M extends TypesMap = TypesMap,
|
|
37
40
|
out T extends Kinds<M> = Kinds<M>,
|
|
38
41
|
> {
|
|
42
|
+
/** Returns the node's id */
|
|
43
|
+
id(): number
|
|
39
44
|
range(): Range
|
|
40
45
|
isLeaf(): boolean
|
|
41
46
|
isNamed(): boolean
|
|
42
47
|
isNamedLeaf(): boolean
|
|
43
|
-
/** Returns the string name of the node kind */
|
|
44
|
-
kind(): T
|
|
45
|
-
readonly kindToRefine: T
|
|
46
|
-
/** Check if the node is the same kind as the given `kind` string */
|
|
47
|
-
is<K extends Kinds<M>>(kind: K): this is SgNode<M, K>
|
|
48
48
|
text(): string
|
|
49
49
|
matches(m: string): boolean
|
|
50
50
|
inside(m: string): boolean
|
|
51
51
|
has(m: string): boolean
|
|
52
52
|
precedes(m: string): boolean
|
|
53
53
|
follows(m: string): boolean
|
|
54
|
-
|
|
54
|
+
/** Returns the string name of the node kind */
|
|
55
|
+
kind(): T
|
|
56
|
+
readonly kindToRefine: T
|
|
57
|
+
/** Check if the node is the same kind as the given `kind` string */
|
|
58
|
+
is<K extends T>(kind: K): this is SgNode<M, K>
|
|
59
|
+
// we need this override to allow string literal union
|
|
60
|
+
is(kind: string): boolean
|
|
61
|
+
|
|
62
|
+
getMatch: NodeMethod<M, [mv: string]>
|
|
55
63
|
getMultipleMatches(m: string): Array<SgNode<M>>
|
|
56
64
|
getTransformed(m: string): string | null
|
|
57
65
|
/** Returns the node's SgRoot */
|
|
58
66
|
getRoot(): SgRoot<M>
|
|
59
67
|
children(): Array<SgNode<M>>
|
|
60
|
-
|
|
61
|
-
id(): number
|
|
62
|
-
find<K extends Kinds<M>>(
|
|
63
|
-
matcher: string | number | NapiConfig<M>,
|
|
64
|
-
): RefineNode<M, K> | null
|
|
68
|
+
find: NodeMethod<M, [matcher: string | number | NapiConfig<M>]>
|
|
65
69
|
findAll<K extends Kinds<M>>(
|
|
66
70
|
matcher: string | number | NapiConfig<M>,
|
|
67
71
|
): Array<RefineNode<M, K>>
|
|
@@ -71,12 +75,13 @@ export declare class SgNode<
|
|
|
71
75
|
fieldChildren<F extends FieldNames<M[T]>>(
|
|
72
76
|
name: F,
|
|
73
77
|
): Exclude<FieldNode<M, T, F>, null>[]
|
|
74
|
-
parent
|
|
75
|
-
child
|
|
78
|
+
parent: NodeMethod<M>
|
|
79
|
+
child(nth: number): SgNode<M, ChildKinds<M, T>> | null
|
|
80
|
+
child<K extends NamedChildKinds<M, T>>(nth: number): RefineNode<M, K> | null
|
|
76
81
|
ancestors(): Array<SgNode<M>>
|
|
77
|
-
next
|
|
82
|
+
next: NodeMethod<M>
|
|
78
83
|
nextAll(): Array<SgNode<M>>
|
|
79
|
-
prev
|
|
84
|
+
prev: NodeMethod<M>
|
|
80
85
|
prevAll(): Array<SgNode<M>>
|
|
81
86
|
replace(text: string): Edit
|
|
82
87
|
commitEdits(edits: Array<Edit>): string
|
|
@@ -92,6 +97,11 @@ export declare class SgRoot<M extends TypesMap = TypesMap> {
|
|
|
92
97
|
filename(): string
|
|
93
98
|
}
|
|
94
99
|
|
|
100
|
+
interface NodeMethod<M extends TypesMap, Args extends unknown[] = []> {
|
|
101
|
+
(...args: Args): SgNode<M> | null
|
|
102
|
+
<K extends NamedKinds<M>>(...args: Args): RefineNode<M, K> | null
|
|
103
|
+
}
|
|
104
|
+
|
|
95
105
|
/**
|
|
96
106
|
* if K contains string, return general SgNode. Otherwise,
|
|
97
107
|
* if K is a literal union, return a union of SgNode of each kind.
|
package/types/staticTypes.d.ts
CHANGED
|
@@ -48,12 +48,23 @@ export type ExtractField<
|
|
|
48
48
|
: NodeFieldInfo
|
|
49
49
|
|
|
50
50
|
// in case of empty types array, return string as fallback
|
|
51
|
-
type NoNever<T, Fallback
|
|
51
|
+
type NoNever<T, Fallback> = [T] extends [never] ? Fallback : T
|
|
52
52
|
|
|
53
53
|
export type TypesInField<M extends TypesMap, I extends NodeFieldInfo> = NoNever<
|
|
54
|
-
ResolveType<M, I['types'][number]['type']
|
|
54
|
+
ResolveType<M, I['types'][number]['type']>,
|
|
55
|
+
Kinds<M>
|
|
55
56
|
>
|
|
56
57
|
|
|
58
|
+
export type NamedChildKinds<
|
|
59
|
+
M extends TypesMap,
|
|
60
|
+
T extends Kinds<M>,
|
|
61
|
+
> = M[T] extends { children: infer C extends NodeFieldInfo }
|
|
62
|
+
? TypesInField<M, C>
|
|
63
|
+
: NamedKinds<M>
|
|
64
|
+
export type ChildKinds<M extends TypesMap, T extends Kinds<M>> =
|
|
65
|
+
| NamedChildKinds<M, T>
|
|
66
|
+
| LowPriorityKey
|
|
67
|
+
|
|
57
68
|
/**
|
|
58
69
|
* resolve subtypes alias. see tree-sitter's reference
|
|
59
70
|
* e.g. like `expression` => `binary_expression` | `unary_expression` | ...
|