@kerebron/wasm 0.5.4 → 0.6.0

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.
@@ -0,0 +1,4007 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/edit.ts
5
+ var Edit = class {
6
+ static {
7
+ __name(this, "Edit");
8
+ }
9
+ /** The start position of the change. */
10
+ startPosition;
11
+ /** The end position of the change before the edit. */
12
+ oldEndPosition;
13
+ /** The end position of the change after the edit. */
14
+ newEndPosition;
15
+ /** The start index of the change. */
16
+ startIndex;
17
+ /** The end index of the change before the edit. */
18
+ oldEndIndex;
19
+ /** The end index of the change after the edit. */
20
+ newEndIndex;
21
+ constructor({
22
+ startIndex,
23
+ oldEndIndex,
24
+ newEndIndex,
25
+ startPosition,
26
+ oldEndPosition,
27
+ newEndPosition
28
+ }) {
29
+ this.startIndex = startIndex >>> 0;
30
+ this.oldEndIndex = oldEndIndex >>> 0;
31
+ this.newEndIndex = newEndIndex >>> 0;
32
+ this.startPosition = startPosition;
33
+ this.oldEndPosition = oldEndPosition;
34
+ this.newEndPosition = newEndPosition;
35
+ }
36
+ /**
37
+ * Edit a point and index to keep it in-sync with source code that has been edited.
38
+ *
39
+ * This function updates a single point's byte offset and row/column position
40
+ * based on an edit operation. This is useful for editing points without
41
+ * requiring a tree or node instance.
42
+ */
43
+ editPoint(point, index) {
44
+ let newIndex = index;
45
+ const newPoint = { ...point };
46
+ if (index >= this.oldEndIndex) {
47
+ newIndex = this.newEndIndex + (index - this.oldEndIndex);
48
+ const originalRow = point.row;
49
+ newPoint.row = this.newEndPosition.row + (point.row - this.oldEndPosition.row);
50
+ newPoint.column = originalRow === this.oldEndPosition.row ? this.newEndPosition.column + (point.column - this.oldEndPosition.column) : point.column;
51
+ } else if (index > this.startIndex) {
52
+ newIndex = this.newEndIndex;
53
+ newPoint.row = this.newEndPosition.row;
54
+ newPoint.column = this.newEndPosition.column;
55
+ }
56
+ return { point: newPoint, index: newIndex };
57
+ }
58
+ /**
59
+ * Edit a range to keep it in-sync with source code that has been edited.
60
+ *
61
+ * This function updates a range's start and end positions based on an edit
62
+ * operation. This is useful for editing ranges without requiring a tree
63
+ * or node instance.
64
+ */
65
+ editRange(range) {
66
+ const newRange = {
67
+ startIndex: range.startIndex,
68
+ startPosition: { ...range.startPosition },
69
+ endIndex: range.endIndex,
70
+ endPosition: { ...range.endPosition }
71
+ };
72
+ if (range.endIndex >= this.oldEndIndex) {
73
+ if (range.endIndex !== Number.MAX_SAFE_INTEGER) {
74
+ newRange.endIndex = this.newEndIndex + (range.endIndex - this.oldEndIndex);
75
+ newRange.endPosition = {
76
+ row: this.newEndPosition.row + (range.endPosition.row - this.oldEndPosition.row),
77
+ column: range.endPosition.row === this.oldEndPosition.row ? this.newEndPosition.column + (range.endPosition.column - this.oldEndPosition.column) : range.endPosition.column
78
+ };
79
+ if (newRange.endIndex < this.newEndIndex) {
80
+ newRange.endIndex = Number.MAX_SAFE_INTEGER;
81
+ newRange.endPosition = { row: Number.MAX_SAFE_INTEGER, column: Number.MAX_SAFE_INTEGER };
82
+ }
83
+ }
84
+ } else if (range.endIndex > this.startIndex) {
85
+ newRange.endIndex = this.startIndex;
86
+ newRange.endPosition = { ...this.startPosition };
87
+ }
88
+ if (range.startIndex >= this.oldEndIndex) {
89
+ newRange.startIndex = this.newEndIndex + (range.startIndex - this.oldEndIndex);
90
+ newRange.startPosition = {
91
+ row: this.newEndPosition.row + (range.startPosition.row - this.oldEndPosition.row),
92
+ column: range.startPosition.row === this.oldEndPosition.row ? this.newEndPosition.column + (range.startPosition.column - this.oldEndPosition.column) : range.startPosition.column
93
+ };
94
+ if (newRange.startIndex < this.newEndIndex) {
95
+ newRange.startIndex = Number.MAX_SAFE_INTEGER;
96
+ newRange.startPosition = { row: Number.MAX_SAFE_INTEGER, column: Number.MAX_SAFE_INTEGER };
97
+ }
98
+ } else if (range.startIndex > this.startIndex) {
99
+ newRange.startIndex = this.startIndex;
100
+ newRange.startPosition = { ...this.startPosition };
101
+ }
102
+ return newRange;
103
+ }
104
+ };
105
+
106
+ // src/constants.ts
107
+ var SIZE_OF_SHORT = 2;
108
+ var SIZE_OF_INT = 4;
109
+ var SIZE_OF_CURSOR = 4 * SIZE_OF_INT;
110
+ var SIZE_OF_NODE = 5 * SIZE_OF_INT;
111
+ var SIZE_OF_POINT = 2 * SIZE_OF_INT;
112
+ var SIZE_OF_RANGE = 2 * SIZE_OF_INT + 2 * SIZE_OF_POINT;
113
+ var ZERO_POINT = { row: 0, column: 0 };
114
+ var INTERNAL = /* @__PURE__ */ Symbol("INTERNAL");
115
+ function assertInternal(x) {
116
+ if (x !== INTERNAL) throw new Error("Illegal constructor");
117
+ }
118
+ __name(assertInternal, "assertInternal");
119
+ function isPoint(point) {
120
+ return !!point && typeof point.row === "number" && typeof point.column === "number";
121
+ }
122
+ __name(isPoint, "isPoint");
123
+ function setModule(module2) {
124
+ C = module2;
125
+ }
126
+ __name(setModule, "setModule");
127
+ var C;
128
+
129
+ // src/lookahead_iterator.ts
130
+ var LookaheadIterator = class {
131
+ static {
132
+ __name(this, "LookaheadIterator");
133
+ }
134
+ /** @internal */
135
+ [0] = 0;
136
+ // Internal handle for Wasm
137
+ /** @internal */
138
+ language;
139
+ /** @internal */
140
+ constructor(internal, address, language) {
141
+ assertInternal(internal);
142
+ this[0] = address;
143
+ this.language = language;
144
+ }
145
+ /** Get the current symbol of the lookahead iterator. */
146
+ get currentTypeId() {
147
+ return C._ts_lookahead_iterator_current_symbol(this[0]);
148
+ }
149
+ /** Get the current symbol name of the lookahead iterator. */
150
+ get currentType() {
151
+ return this.language.types[this.currentTypeId] || "ERROR";
152
+ }
153
+ /** Delete the lookahead iterator, freeing its resources. */
154
+ delete() {
155
+ C._ts_lookahead_iterator_delete(this[0]);
156
+ this[0] = 0;
157
+ }
158
+ /**
159
+ * Reset the lookahead iterator.
160
+ *
161
+ * This returns `true` if the language was set successfully and `false`
162
+ * otherwise.
163
+ */
164
+ reset(language, stateId) {
165
+ if (C._ts_lookahead_iterator_reset(this[0], language[0], stateId)) {
166
+ this.language = language;
167
+ return true;
168
+ }
169
+ return false;
170
+ }
171
+ /**
172
+ * Reset the lookahead iterator to another state.
173
+ *
174
+ * This returns `true` if the iterator was reset to the given state and
175
+ * `false` otherwise.
176
+ */
177
+ resetState(stateId) {
178
+ return Boolean(C._ts_lookahead_iterator_reset_state(this[0], stateId));
179
+ }
180
+ /**
181
+ * Returns an iterator that iterates over the symbols of the lookahead iterator.
182
+ *
183
+ * The iterator will yield the current symbol name as a string for each step
184
+ * until there are no more symbols to iterate over.
185
+ */
186
+ [Symbol.iterator]() {
187
+ return {
188
+ next: /* @__PURE__ */ __name(() => {
189
+ if (C._ts_lookahead_iterator_next(this[0])) {
190
+ return { done: false, value: this.currentType };
191
+ }
192
+ return { done: true, value: "" };
193
+ }, "next")
194
+ };
195
+ }
196
+ };
197
+
198
+ // src/tree.ts
199
+ function getText(tree, startIndex, endIndex, startPosition) {
200
+ const length = endIndex - startIndex;
201
+ let result = tree.textCallback(startIndex, startPosition);
202
+ if (result) {
203
+ startIndex += result.length;
204
+ while (startIndex < endIndex) {
205
+ const string = tree.textCallback(startIndex, startPosition);
206
+ if (string && string.length > 0) {
207
+ startIndex += string.length;
208
+ result += string;
209
+ } else {
210
+ break;
211
+ }
212
+ }
213
+ if (startIndex > endIndex) {
214
+ result = result.slice(0, length);
215
+ }
216
+ }
217
+ return result ?? "";
218
+ }
219
+ __name(getText, "getText");
220
+ var Tree = class _Tree {
221
+ static {
222
+ __name(this, "Tree");
223
+ }
224
+ /** @internal */
225
+ [0] = 0;
226
+ // Internal handle for Wasm
227
+ /** @internal */
228
+ textCallback;
229
+ /** The language that was used to parse the syntax tree. */
230
+ language;
231
+ /** @internal */
232
+ constructor(internal, address, language, textCallback) {
233
+ assertInternal(internal);
234
+ this[0] = address;
235
+ this.language = language;
236
+ this.textCallback = textCallback;
237
+ }
238
+ /** Create a shallow copy of the syntax tree. This is very fast. */
239
+ copy() {
240
+ const address = C._ts_tree_copy(this[0]);
241
+ return new _Tree(INTERNAL, address, this.language, this.textCallback);
242
+ }
243
+ /** Delete the syntax tree, freeing its resources. */
244
+ delete() {
245
+ C._ts_tree_delete(this[0]);
246
+ this[0] = 0;
247
+ }
248
+ /** Get the root node of the syntax tree. */
249
+ get rootNode() {
250
+ C._ts_tree_root_node_wasm(this[0]);
251
+ return unmarshalNode(this);
252
+ }
253
+ /**
254
+ * Get the root node of the syntax tree, but with its position shifted
255
+ * forward by the given offset.
256
+ */
257
+ rootNodeWithOffset(offsetBytes, offsetExtent) {
258
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
259
+ C.setValue(address, offsetBytes, "i32");
260
+ marshalPoint(address + SIZE_OF_INT, offsetExtent);
261
+ C._ts_tree_root_node_with_offset_wasm(this[0]);
262
+ return unmarshalNode(this);
263
+ }
264
+ /**
265
+ * Edit the syntax tree to keep it in sync with source code that has been
266
+ * edited.
267
+ *
268
+ * You must describe the edit both in terms of byte offsets and in terms of
269
+ * row/column coordinates.
270
+ */
271
+ edit(edit) {
272
+ marshalEdit(edit);
273
+ C._ts_tree_edit_wasm(this[0]);
274
+ }
275
+ /** Create a new {@link TreeCursor} starting from the root of the tree. */
276
+ walk() {
277
+ return this.rootNode.walk();
278
+ }
279
+ /**
280
+ * Compare this old edited syntax tree to a new syntax tree representing
281
+ * the same document, returning a sequence of ranges whose syntactic
282
+ * structure has changed.
283
+ *
284
+ * For this to work correctly, this syntax tree must have been edited such
285
+ * that its ranges match up to the new tree. Generally, you'll want to
286
+ * call this method right after calling one of the [`Parser::parse`]
287
+ * functions. Call it on the old tree that was passed to parse, and
288
+ * pass the new tree that was returned from `parse`.
289
+ */
290
+ getChangedRanges(other) {
291
+ if (!(other instanceof _Tree)) {
292
+ throw new TypeError("Argument must be a Tree");
293
+ }
294
+ C._ts_tree_get_changed_ranges_wasm(this[0], other[0]);
295
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
296
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
297
+ const result = new Array(count);
298
+ if (count > 0) {
299
+ let address = buffer;
300
+ for (let i2 = 0; i2 < count; i2++) {
301
+ result[i2] = unmarshalRange(address);
302
+ address += SIZE_OF_RANGE;
303
+ }
304
+ C._free(buffer);
305
+ }
306
+ return result;
307
+ }
308
+ /** Get the included ranges that were used to parse the syntax tree. */
309
+ getIncludedRanges() {
310
+ C._ts_tree_included_ranges_wasm(this[0]);
311
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
312
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
313
+ const result = new Array(count);
314
+ if (count > 0) {
315
+ let address = buffer;
316
+ for (let i2 = 0; i2 < count; i2++) {
317
+ result[i2] = unmarshalRange(address);
318
+ address += SIZE_OF_RANGE;
319
+ }
320
+ C._free(buffer);
321
+ }
322
+ return result;
323
+ }
324
+ };
325
+
326
+ // src/tree_cursor.ts
327
+ var TreeCursor = class _TreeCursor {
328
+ static {
329
+ __name(this, "TreeCursor");
330
+ }
331
+ /** @internal */
332
+ // @ts-expect-error: never read
333
+ [0] = 0;
334
+ // Internal handle for Wasm
335
+ /** @internal */
336
+ // @ts-expect-error: never read
337
+ [1] = 0;
338
+ // Internal handle for Wasm
339
+ /** @internal */
340
+ // @ts-expect-error: never read
341
+ [2] = 0;
342
+ // Internal handle for Wasm
343
+ /** @internal */
344
+ // @ts-expect-error: never read
345
+ [3] = 0;
346
+ // Internal handle for Wasm
347
+ /** @internal */
348
+ tree;
349
+ /** @internal */
350
+ constructor(internal, tree) {
351
+ assertInternal(internal);
352
+ this.tree = tree;
353
+ unmarshalTreeCursor(this);
354
+ }
355
+ /** Creates a deep copy of the tree cursor. This allocates new memory. */
356
+ copy() {
357
+ const copy = new _TreeCursor(INTERNAL, this.tree);
358
+ C._ts_tree_cursor_copy_wasm(this.tree[0]);
359
+ unmarshalTreeCursor(copy);
360
+ return copy;
361
+ }
362
+ /** Delete the tree cursor, freeing its resources. */
363
+ delete() {
364
+ marshalTreeCursor(this);
365
+ C._ts_tree_cursor_delete_wasm(this.tree[0]);
366
+ this[0] = this[1] = this[2] = 0;
367
+ }
368
+ /** Get the tree cursor's current {@link Node}. */
369
+ get currentNode() {
370
+ marshalTreeCursor(this);
371
+ C._ts_tree_cursor_current_node_wasm(this.tree[0]);
372
+ return unmarshalNode(this.tree);
373
+ }
374
+ /**
375
+ * Get the numerical field id of this tree cursor's current node.
376
+ *
377
+ * See also {@link TreeCursor#currentFieldName}.
378
+ */
379
+ get currentFieldId() {
380
+ marshalTreeCursor(this);
381
+ return C._ts_tree_cursor_current_field_id_wasm(this.tree[0]);
382
+ }
383
+ /** Get the field name of this tree cursor's current node. */
384
+ get currentFieldName() {
385
+ return this.tree.language.fields[this.currentFieldId];
386
+ }
387
+ /**
388
+ * Get the depth of the cursor's current node relative to the original
389
+ * node that the cursor was constructed with.
390
+ */
391
+ get currentDepth() {
392
+ marshalTreeCursor(this);
393
+ return C._ts_tree_cursor_current_depth_wasm(this.tree[0]);
394
+ }
395
+ /**
396
+ * Get the index of the cursor's current node out of all of the
397
+ * descendants of the original node that the cursor was constructed with.
398
+ */
399
+ get currentDescendantIndex() {
400
+ marshalTreeCursor(this);
401
+ return C._ts_tree_cursor_current_descendant_index_wasm(this.tree[0]);
402
+ }
403
+ /** Get the type of the cursor's current node. */
404
+ get nodeType() {
405
+ return this.tree.language.types[this.nodeTypeId] || "ERROR";
406
+ }
407
+ /** Get the type id of the cursor's current node. */
408
+ get nodeTypeId() {
409
+ marshalTreeCursor(this);
410
+ return C._ts_tree_cursor_current_node_type_id_wasm(this.tree[0]);
411
+ }
412
+ /** Get the state id of the cursor's current node. */
413
+ get nodeStateId() {
414
+ marshalTreeCursor(this);
415
+ return C._ts_tree_cursor_current_node_state_id_wasm(this.tree[0]);
416
+ }
417
+ /** Get the id of the cursor's current node. */
418
+ get nodeId() {
419
+ marshalTreeCursor(this);
420
+ return C._ts_tree_cursor_current_node_id_wasm(this.tree[0]);
421
+ }
422
+ /**
423
+ * Check if the cursor's current node is *named*.
424
+ *
425
+ * Named nodes correspond to named rules in the grammar, whereas
426
+ * *anonymous* nodes correspond to string literals in the grammar.
427
+ */
428
+ get nodeIsNamed() {
429
+ marshalTreeCursor(this);
430
+ return C._ts_tree_cursor_current_node_is_named_wasm(this.tree[0]) === 1;
431
+ }
432
+ /**
433
+ * Check if the cursor's current node is *missing*.
434
+ *
435
+ * Missing nodes are inserted by the parser in order to recover from
436
+ * certain kinds of syntax errors.
437
+ */
438
+ get nodeIsMissing() {
439
+ marshalTreeCursor(this);
440
+ return C._ts_tree_cursor_current_node_is_missing_wasm(this.tree[0]) === 1;
441
+ }
442
+ /** Get the string content of the cursor's current node. */
443
+ get nodeText() {
444
+ marshalTreeCursor(this);
445
+ const startIndex = C._ts_tree_cursor_start_index_wasm(this.tree[0]);
446
+ const endIndex = C._ts_tree_cursor_end_index_wasm(this.tree[0]);
447
+ C._ts_tree_cursor_start_position_wasm(this.tree[0]);
448
+ const startPosition = unmarshalPoint(TRANSFER_BUFFER);
449
+ return getText(this.tree, startIndex, endIndex, startPosition);
450
+ }
451
+ /** Get the start position of the cursor's current node. */
452
+ get startPosition() {
453
+ marshalTreeCursor(this);
454
+ C._ts_tree_cursor_start_position_wasm(this.tree[0]);
455
+ return unmarshalPoint(TRANSFER_BUFFER);
456
+ }
457
+ /** Get the end position of the cursor's current node. */
458
+ get endPosition() {
459
+ marshalTreeCursor(this);
460
+ C._ts_tree_cursor_end_position_wasm(this.tree[0]);
461
+ return unmarshalPoint(TRANSFER_BUFFER);
462
+ }
463
+ /** Get the start index of the cursor's current node. */
464
+ get startIndex() {
465
+ marshalTreeCursor(this);
466
+ return C._ts_tree_cursor_start_index_wasm(this.tree[0]);
467
+ }
468
+ /** Get the end index of the cursor's current node. */
469
+ get endIndex() {
470
+ marshalTreeCursor(this);
471
+ return C._ts_tree_cursor_end_index_wasm(this.tree[0]);
472
+ }
473
+ /**
474
+ * Move this cursor to the first child of its current node.
475
+ *
476
+ * This returns `true` if the cursor successfully moved, and returns
477
+ * `false` if there were no children.
478
+ */
479
+ gotoFirstChild() {
480
+ marshalTreeCursor(this);
481
+ const result = C._ts_tree_cursor_goto_first_child_wasm(this.tree[0]);
482
+ unmarshalTreeCursor(this);
483
+ return result === 1;
484
+ }
485
+ /**
486
+ * Move this cursor to the last child of its current node.
487
+ *
488
+ * This returns `true` if the cursor successfully moved, and returns
489
+ * `false` if there were no children.
490
+ *
491
+ * Note that this function may be slower than
492
+ * {@link TreeCursor#gotoFirstChild} because it needs to
493
+ * iterate through all the children to compute the child's position.
494
+ */
495
+ gotoLastChild() {
496
+ marshalTreeCursor(this);
497
+ const result = C._ts_tree_cursor_goto_last_child_wasm(this.tree[0]);
498
+ unmarshalTreeCursor(this);
499
+ return result === 1;
500
+ }
501
+ /**
502
+ * Move this cursor to the parent of its current node.
503
+ *
504
+ * This returns `true` if the cursor successfully moved, and returns
505
+ * `false` if there was no parent node (the cursor was already on the
506
+ * root node).
507
+ *
508
+ * Note that the node the cursor was constructed with is considered the root
509
+ * of the cursor, and the cursor cannot walk outside this node.
510
+ */
511
+ gotoParent() {
512
+ marshalTreeCursor(this);
513
+ const result = C._ts_tree_cursor_goto_parent_wasm(this.tree[0]);
514
+ unmarshalTreeCursor(this);
515
+ return result === 1;
516
+ }
517
+ /**
518
+ * Move this cursor to the next sibling of its current node.
519
+ *
520
+ * This returns `true` if the cursor successfully moved, and returns
521
+ * `false` if there was no next sibling node.
522
+ *
523
+ * Note that the node the cursor was constructed with is considered the root
524
+ * of the cursor, and the cursor cannot walk outside this node.
525
+ */
526
+ gotoNextSibling() {
527
+ marshalTreeCursor(this);
528
+ const result = C._ts_tree_cursor_goto_next_sibling_wasm(this.tree[0]);
529
+ unmarshalTreeCursor(this);
530
+ return result === 1;
531
+ }
532
+ /**
533
+ * Move this cursor to the previous sibling of its current node.
534
+ *
535
+ * This returns `true` if the cursor successfully moved, and returns
536
+ * `false` if there was no previous sibling node.
537
+ *
538
+ * Note that this function may be slower than
539
+ * {@link TreeCursor#gotoNextSibling} due to how node
540
+ * positions are stored. In the worst case, this will need to iterate
541
+ * through all the children up to the previous sibling node to recalculate
542
+ * its position. Also note that the node the cursor was constructed with is
543
+ * considered the root of the cursor, and the cursor cannot walk outside this node.
544
+ */
545
+ gotoPreviousSibling() {
546
+ marshalTreeCursor(this);
547
+ const result = C._ts_tree_cursor_goto_previous_sibling_wasm(this.tree[0]);
548
+ unmarshalTreeCursor(this);
549
+ return result === 1;
550
+ }
551
+ /**
552
+ * Move the cursor to the node that is the nth descendant of
553
+ * the original node that the cursor was constructed with, where
554
+ * zero represents the original node itself.
555
+ */
556
+ gotoDescendant(goalDescendantIndex) {
557
+ marshalTreeCursor(this);
558
+ C._ts_tree_cursor_goto_descendant_wasm(this.tree[0], goalDescendantIndex);
559
+ unmarshalTreeCursor(this);
560
+ }
561
+ /**
562
+ * Move this cursor to the first child of its current node that contains or
563
+ * starts after the given byte offset.
564
+ *
565
+ * This returns `true` if the cursor successfully moved to a child node, and returns
566
+ * `false` if no such child was found.
567
+ */
568
+ gotoFirstChildForIndex(goalIndex) {
569
+ marshalTreeCursor(this);
570
+ C.setValue(TRANSFER_BUFFER + SIZE_OF_CURSOR, goalIndex, "i32");
571
+ const result = C._ts_tree_cursor_goto_first_child_for_index_wasm(this.tree[0]);
572
+ unmarshalTreeCursor(this);
573
+ return result === 1;
574
+ }
575
+ /**
576
+ * Move this cursor to the first child of its current node that contains or
577
+ * starts after the given byte offset.
578
+ *
579
+ * This returns the index of the child node if one was found, and returns
580
+ * `null` if no such child was found.
581
+ */
582
+ gotoFirstChildForPosition(goalPosition) {
583
+ marshalTreeCursor(this);
584
+ marshalPoint(TRANSFER_BUFFER + SIZE_OF_CURSOR, goalPosition);
585
+ const result = C._ts_tree_cursor_goto_first_child_for_position_wasm(this.tree[0]);
586
+ unmarshalTreeCursor(this);
587
+ return result === 1;
588
+ }
589
+ /**
590
+ * Re-initialize this tree cursor to start at the original node that the
591
+ * cursor was constructed with.
592
+ */
593
+ reset(node) {
594
+ marshalNode(node);
595
+ marshalTreeCursor(this, TRANSFER_BUFFER + SIZE_OF_NODE);
596
+ C._ts_tree_cursor_reset_wasm(this.tree[0]);
597
+ unmarshalTreeCursor(this);
598
+ }
599
+ /**
600
+ * Re-initialize a tree cursor to the same position as another cursor.
601
+ *
602
+ * Unlike {@link TreeCursor#reset}, this will not lose parent
603
+ * information and allows reusing already created cursors.
604
+ */
605
+ resetTo(cursor) {
606
+ marshalTreeCursor(this, TRANSFER_BUFFER);
607
+ marshalTreeCursor(cursor, TRANSFER_BUFFER + SIZE_OF_CURSOR);
608
+ C._ts_tree_cursor_reset_to_wasm(this.tree[0], cursor.tree[0]);
609
+ unmarshalTreeCursor(this);
610
+ }
611
+ };
612
+
613
+ // src/node.ts
614
+ var Node = class {
615
+ static {
616
+ __name(this, "Node");
617
+ }
618
+ /** @internal */
619
+ // @ts-expect-error: never read
620
+ [0] = 0;
621
+ // Internal handle for Wasm
622
+ /** @internal */
623
+ _children;
624
+ /** @internal */
625
+ _namedChildren;
626
+ /** @internal */
627
+ constructor(internal, {
628
+ id,
629
+ tree,
630
+ startIndex,
631
+ startPosition,
632
+ other
633
+ }) {
634
+ assertInternal(internal);
635
+ this[0] = other;
636
+ this.id = id;
637
+ this.tree = tree;
638
+ this.startIndex = startIndex;
639
+ this.startPosition = startPosition;
640
+ }
641
+ /**
642
+ * The numeric id for this node that is unique.
643
+ *
644
+ * Within a given syntax tree, no two nodes have the same id. However:
645
+ *
646
+ * * If a new tree is created based on an older tree, and a node from the old tree is reused in
647
+ * the process, then that node will have the same id in both trees.
648
+ *
649
+ * * A node not marked as having changes does not guarantee it was reused.
650
+ *
651
+ * * If a node is marked as having changed in the old tree, it will not be reused.
652
+ */
653
+ id;
654
+ /** The byte index where this node starts. */
655
+ startIndex;
656
+ /** The position where this node starts. */
657
+ startPosition;
658
+ /** The tree that this node belongs to. */
659
+ tree;
660
+ /** Get this node's type as a numerical id. */
661
+ get typeId() {
662
+ marshalNode(this);
663
+ return C._ts_node_symbol_wasm(this.tree[0]);
664
+ }
665
+ /**
666
+ * Get the node's type as a numerical id as it appears in the grammar,
667
+ * ignoring aliases.
668
+ */
669
+ get grammarId() {
670
+ marshalNode(this);
671
+ return C._ts_node_grammar_symbol_wasm(this.tree[0]);
672
+ }
673
+ /** Get this node's type as a string. */
674
+ get type() {
675
+ return this.tree.language.types[this.typeId] || "ERROR";
676
+ }
677
+ /**
678
+ * Get this node's symbol name as it appears in the grammar, ignoring
679
+ * aliases as a string.
680
+ */
681
+ get grammarType() {
682
+ return this.tree.language.types[this.grammarId] || "ERROR";
683
+ }
684
+ /**
685
+ * Check if this node is *named*.
686
+ *
687
+ * Named nodes correspond to named rules in the grammar, whereas
688
+ * *anonymous* nodes correspond to string literals in the grammar.
689
+ */
690
+ get isNamed() {
691
+ marshalNode(this);
692
+ return C._ts_node_is_named_wasm(this.tree[0]) === 1;
693
+ }
694
+ /**
695
+ * Check if this node is *extra*.
696
+ *
697
+ * Extra nodes represent things like comments, which are not required
698
+ * by the grammar, but can appear anywhere.
699
+ */
700
+ get isExtra() {
701
+ marshalNode(this);
702
+ return C._ts_node_is_extra_wasm(this.tree[0]) === 1;
703
+ }
704
+ /**
705
+ * Check if this node represents a syntax error.
706
+ *
707
+ * Syntax errors represent parts of the code that could not be incorporated
708
+ * into a valid syntax tree.
709
+ */
710
+ get isError() {
711
+ marshalNode(this);
712
+ return C._ts_node_is_error_wasm(this.tree[0]) === 1;
713
+ }
714
+ /**
715
+ * Check if this node is *missing*.
716
+ *
717
+ * Missing nodes are inserted by the parser in order to recover from
718
+ * certain kinds of syntax errors.
719
+ */
720
+ get isMissing() {
721
+ marshalNode(this);
722
+ return C._ts_node_is_missing_wasm(this.tree[0]) === 1;
723
+ }
724
+ /** Check if this node has been edited. */
725
+ get hasChanges() {
726
+ marshalNode(this);
727
+ return C._ts_node_has_changes_wasm(this.tree[0]) === 1;
728
+ }
729
+ /**
730
+ * Check if this node represents a syntax error or contains any syntax
731
+ * errors anywhere within it.
732
+ */
733
+ get hasError() {
734
+ marshalNode(this);
735
+ return C._ts_node_has_error_wasm(this.tree[0]) === 1;
736
+ }
737
+ /** Get the byte index where this node ends. */
738
+ get endIndex() {
739
+ marshalNode(this);
740
+ return C._ts_node_end_index_wasm(this.tree[0]);
741
+ }
742
+ /** Get the position where this node ends. */
743
+ get endPosition() {
744
+ marshalNode(this);
745
+ C._ts_node_end_point_wasm(this.tree[0]);
746
+ return unmarshalPoint(TRANSFER_BUFFER);
747
+ }
748
+ /** Get the string content of this node. */
749
+ get text() {
750
+ return getText(this.tree, this.startIndex, this.endIndex, this.startPosition);
751
+ }
752
+ /** Get this node's parse state. */
753
+ get parseState() {
754
+ marshalNode(this);
755
+ return C._ts_node_parse_state_wasm(this.tree[0]);
756
+ }
757
+ /** Get the parse state after this node. */
758
+ get nextParseState() {
759
+ marshalNode(this);
760
+ return C._ts_node_next_parse_state_wasm(this.tree[0]);
761
+ }
762
+ /** Check if this node is equal to another node. */
763
+ equals(other) {
764
+ return this.tree === other.tree && this.id === other.id;
765
+ }
766
+ /**
767
+ * Get the node's child at the given index, where zero represents the first child.
768
+ *
769
+ * This method is fairly fast, but its cost is technically log(n), so if
770
+ * you might be iterating over a long list of children, you should use
771
+ * {@link Node#children} instead.
772
+ */
773
+ child(index) {
774
+ marshalNode(this);
775
+ C._ts_node_child_wasm(this.tree[0], index);
776
+ return unmarshalNode(this.tree);
777
+ }
778
+ /**
779
+ * Get this node's *named* child at the given index.
780
+ *
781
+ * See also {@link Node#isNamed}.
782
+ * This method is fairly fast, but its cost is technically log(n), so if
783
+ * you might be iterating over a long list of children, you should use
784
+ * {@link Node#namedChildren} instead.
785
+ */
786
+ namedChild(index) {
787
+ marshalNode(this);
788
+ C._ts_node_named_child_wasm(this.tree[0], index);
789
+ return unmarshalNode(this.tree);
790
+ }
791
+ /**
792
+ * Get this node's child with the given numerical field id.
793
+ *
794
+ * See also {@link Node#childForFieldName}. You can
795
+ * convert a field name to an id using {@link Language#fieldIdForName}.
796
+ */
797
+ childForFieldId(fieldId) {
798
+ marshalNode(this);
799
+ C._ts_node_child_by_field_id_wasm(this.tree[0], fieldId);
800
+ return unmarshalNode(this.tree);
801
+ }
802
+ /**
803
+ * Get the first child with the given field name.
804
+ *
805
+ * If multiple children may have the same field name, access them using
806
+ * {@link Node#childrenForFieldName}.
807
+ */
808
+ childForFieldName(fieldName) {
809
+ const fieldId = this.tree.language.fields.indexOf(fieldName);
810
+ if (fieldId !== -1) return this.childForFieldId(fieldId);
811
+ return null;
812
+ }
813
+ /** Get the field name of this node's child at the given index. */
814
+ fieldNameForChild(index) {
815
+ marshalNode(this);
816
+ const address = C._ts_node_field_name_for_child_wasm(this.tree[0], index);
817
+ if (!address) return null;
818
+ return C.AsciiToString(address);
819
+ }
820
+ /** Get the field name of this node's named child at the given index. */
821
+ fieldNameForNamedChild(index) {
822
+ marshalNode(this);
823
+ const address = C._ts_node_field_name_for_named_child_wasm(this.tree[0], index);
824
+ if (!address) return null;
825
+ return C.AsciiToString(address);
826
+ }
827
+ /**
828
+ * Get an array of this node's children with a given field name.
829
+ *
830
+ * See also {@link Node#children}.
831
+ */
832
+ childrenForFieldName(fieldName) {
833
+ const fieldId = this.tree.language.fields.indexOf(fieldName);
834
+ if (fieldId !== -1 && fieldId !== 0) return this.childrenForFieldId(fieldId);
835
+ return [];
836
+ }
837
+ /**
838
+ * Get an array of this node's children with a given field id.
839
+ *
840
+ * See also {@link Node#childrenForFieldName}.
841
+ */
842
+ childrenForFieldId(fieldId) {
843
+ marshalNode(this);
844
+ C._ts_node_children_by_field_id_wasm(this.tree[0], fieldId);
845
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
846
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
847
+ const result = new Array(count);
848
+ if (count > 0) {
849
+ let address = buffer;
850
+ for (let i2 = 0; i2 < count; i2++) {
851
+ result[i2] = unmarshalNode(this.tree, address);
852
+ address += SIZE_OF_NODE;
853
+ }
854
+ C._free(buffer);
855
+ }
856
+ return result;
857
+ }
858
+ /** Get the node's first child that contains or starts after the given byte offset. */
859
+ firstChildForIndex(index) {
860
+ marshalNode(this);
861
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
862
+ C.setValue(address, index, "i32");
863
+ C._ts_node_first_child_for_byte_wasm(this.tree[0]);
864
+ return unmarshalNode(this.tree);
865
+ }
866
+ /** Get the node's first named child that contains or starts after the given byte offset. */
867
+ firstNamedChildForIndex(index) {
868
+ marshalNode(this);
869
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
870
+ C.setValue(address, index, "i32");
871
+ C._ts_node_first_named_child_for_byte_wasm(this.tree[0]);
872
+ return unmarshalNode(this.tree);
873
+ }
874
+ /** Get this node's number of children. */
875
+ get childCount() {
876
+ marshalNode(this);
877
+ return C._ts_node_child_count_wasm(this.tree[0]);
878
+ }
879
+ /**
880
+ * Get this node's number of *named* children.
881
+ *
882
+ * See also {@link Node#isNamed}.
883
+ */
884
+ get namedChildCount() {
885
+ marshalNode(this);
886
+ return C._ts_node_named_child_count_wasm(this.tree[0]);
887
+ }
888
+ /** Get this node's first child. */
889
+ get firstChild() {
890
+ return this.child(0);
891
+ }
892
+ /**
893
+ * Get this node's first named child.
894
+ *
895
+ * See also {@link Node#isNamed}.
896
+ */
897
+ get firstNamedChild() {
898
+ return this.namedChild(0);
899
+ }
900
+ /** Get this node's last child. */
901
+ get lastChild() {
902
+ return this.child(this.childCount - 1);
903
+ }
904
+ /**
905
+ * Get this node's last named child.
906
+ *
907
+ * See also {@link Node#isNamed}.
908
+ */
909
+ get lastNamedChild() {
910
+ return this.namedChild(this.namedChildCount - 1);
911
+ }
912
+ /**
913
+ * Iterate over this node's children.
914
+ *
915
+ * If you're walking the tree recursively, you may want to use the
916
+ * {@link TreeCursor} APIs directly instead.
917
+ */
918
+ get children() {
919
+ if (!this._children) {
920
+ marshalNode(this);
921
+ C._ts_node_children_wasm(this.tree[0]);
922
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
923
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
924
+ this._children = new Array(count);
925
+ if (count > 0) {
926
+ let address = buffer;
927
+ for (let i2 = 0; i2 < count; i2++) {
928
+ this._children[i2] = unmarshalNode(this.tree, address);
929
+ address += SIZE_OF_NODE;
930
+ }
931
+ C._free(buffer);
932
+ }
933
+ }
934
+ return this._children;
935
+ }
936
+ /**
937
+ * Iterate over this node's named children.
938
+ *
939
+ * See also {@link Node#children}.
940
+ */
941
+ get namedChildren() {
942
+ if (!this._namedChildren) {
943
+ marshalNode(this);
944
+ C._ts_node_named_children_wasm(this.tree[0]);
945
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
946
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
947
+ this._namedChildren = new Array(count);
948
+ if (count > 0) {
949
+ let address = buffer;
950
+ for (let i2 = 0; i2 < count; i2++) {
951
+ this._namedChildren[i2] = unmarshalNode(this.tree, address);
952
+ address += SIZE_OF_NODE;
953
+ }
954
+ C._free(buffer);
955
+ }
956
+ }
957
+ return this._namedChildren;
958
+ }
959
+ /**
960
+ * Get the descendants of this node that are the given type, or in the given types array.
961
+ *
962
+ * The types array should contain node type strings, which can be retrieved from {@link Language#types}.
963
+ *
964
+ * Additionally, a `startPosition` and `endPosition` can be passed in to restrict the search to a byte range.
965
+ */
966
+ descendantsOfType(types, startPosition = ZERO_POINT, endPosition = ZERO_POINT) {
967
+ if (!Array.isArray(types)) types = [types];
968
+ const symbols = [];
969
+ const typesBySymbol = this.tree.language.types;
970
+ for (const node_type of types) {
971
+ if (node_type == "ERROR") {
972
+ symbols.push(65535);
973
+ }
974
+ }
975
+ for (let i2 = 0, n = typesBySymbol.length; i2 < n; i2++) {
976
+ if (types.includes(typesBySymbol[i2])) {
977
+ symbols.push(i2);
978
+ }
979
+ }
980
+ const symbolsAddress = C._malloc(SIZE_OF_INT * symbols.length);
981
+ for (let i2 = 0, n = symbols.length; i2 < n; i2++) {
982
+ C.setValue(symbolsAddress + i2 * SIZE_OF_INT, symbols[i2], "i32");
983
+ }
984
+ marshalNode(this);
985
+ C._ts_node_descendants_of_type_wasm(
986
+ this.tree[0],
987
+ symbolsAddress,
988
+ symbols.length,
989
+ startPosition.row,
990
+ startPosition.column,
991
+ endPosition.row,
992
+ endPosition.column
993
+ );
994
+ const descendantCount = C.getValue(TRANSFER_BUFFER, "i32");
995
+ const descendantAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
996
+ const result = new Array(descendantCount);
997
+ if (descendantCount > 0) {
998
+ let address = descendantAddress;
999
+ for (let i2 = 0; i2 < descendantCount; i2++) {
1000
+ result[i2] = unmarshalNode(this.tree, address);
1001
+ address += SIZE_OF_NODE;
1002
+ }
1003
+ }
1004
+ C._free(descendantAddress);
1005
+ C._free(symbolsAddress);
1006
+ return result;
1007
+ }
1008
+ /** Get this node's next sibling. */
1009
+ get nextSibling() {
1010
+ marshalNode(this);
1011
+ C._ts_node_next_sibling_wasm(this.tree[0]);
1012
+ return unmarshalNode(this.tree);
1013
+ }
1014
+ /** Get this node's previous sibling. */
1015
+ get previousSibling() {
1016
+ marshalNode(this);
1017
+ C._ts_node_prev_sibling_wasm(this.tree[0]);
1018
+ return unmarshalNode(this.tree);
1019
+ }
1020
+ /**
1021
+ * Get this node's next *named* sibling.
1022
+ *
1023
+ * See also {@link Node#isNamed}.
1024
+ */
1025
+ get nextNamedSibling() {
1026
+ marshalNode(this);
1027
+ C._ts_node_next_named_sibling_wasm(this.tree[0]);
1028
+ return unmarshalNode(this.tree);
1029
+ }
1030
+ /**
1031
+ * Get this node's previous *named* sibling.
1032
+ *
1033
+ * See also {@link Node#isNamed}.
1034
+ */
1035
+ get previousNamedSibling() {
1036
+ marshalNode(this);
1037
+ C._ts_node_prev_named_sibling_wasm(this.tree[0]);
1038
+ return unmarshalNode(this.tree);
1039
+ }
1040
+ /** Get the node's number of descendants, including one for the node itself. */
1041
+ get descendantCount() {
1042
+ marshalNode(this);
1043
+ return C._ts_node_descendant_count_wasm(this.tree[0]);
1044
+ }
1045
+ /**
1046
+ * Get this node's immediate parent.
1047
+ * Prefer {@link Node#childWithDescendant} for iterating over this node's ancestors.
1048
+ */
1049
+ get parent() {
1050
+ marshalNode(this);
1051
+ C._ts_node_parent_wasm(this.tree[0]);
1052
+ return unmarshalNode(this.tree);
1053
+ }
1054
+ /**
1055
+ * Get the node that contains `descendant`.
1056
+ *
1057
+ * Note that this can return `descendant` itself.
1058
+ */
1059
+ childWithDescendant(descendant) {
1060
+ marshalNode(this);
1061
+ marshalNode(descendant, 1);
1062
+ C._ts_node_child_with_descendant_wasm(this.tree[0]);
1063
+ return unmarshalNode(this.tree);
1064
+ }
1065
+ /** Get the smallest node within this node that spans the given byte range. */
1066
+ descendantForIndex(start2, end = start2) {
1067
+ if (typeof start2 !== "number" || typeof end !== "number") {
1068
+ throw new Error("Arguments must be numbers");
1069
+ }
1070
+ marshalNode(this);
1071
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
1072
+ C.setValue(address, start2, "i32");
1073
+ C.setValue(address + SIZE_OF_INT, end, "i32");
1074
+ C._ts_node_descendant_for_index_wasm(this.tree[0]);
1075
+ return unmarshalNode(this.tree);
1076
+ }
1077
+ /** Get the smallest named node within this node that spans the given byte range. */
1078
+ namedDescendantForIndex(start2, end = start2) {
1079
+ if (typeof start2 !== "number" || typeof end !== "number") {
1080
+ throw new Error("Arguments must be numbers");
1081
+ }
1082
+ marshalNode(this);
1083
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
1084
+ C.setValue(address, start2, "i32");
1085
+ C.setValue(address + SIZE_OF_INT, end, "i32");
1086
+ C._ts_node_named_descendant_for_index_wasm(this.tree[0]);
1087
+ return unmarshalNode(this.tree);
1088
+ }
1089
+ /** Get the smallest node within this node that spans the given point range. */
1090
+ descendantForPosition(start2, end = start2) {
1091
+ if (!isPoint(start2) || !isPoint(end)) {
1092
+ throw new Error("Arguments must be {row, column} objects");
1093
+ }
1094
+ marshalNode(this);
1095
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
1096
+ marshalPoint(address, start2);
1097
+ marshalPoint(address + SIZE_OF_POINT, end);
1098
+ C._ts_node_descendant_for_position_wasm(this.tree[0]);
1099
+ return unmarshalNode(this.tree);
1100
+ }
1101
+ /** Get the smallest named node within this node that spans the given point range. */
1102
+ namedDescendantForPosition(start2, end = start2) {
1103
+ if (!isPoint(start2) || !isPoint(end)) {
1104
+ throw new Error("Arguments must be {row, column} objects");
1105
+ }
1106
+ marshalNode(this);
1107
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
1108
+ marshalPoint(address, start2);
1109
+ marshalPoint(address + SIZE_OF_POINT, end);
1110
+ C._ts_node_named_descendant_for_position_wasm(this.tree[0]);
1111
+ return unmarshalNode(this.tree);
1112
+ }
1113
+ /**
1114
+ * Create a new {@link TreeCursor} starting from this node.
1115
+ *
1116
+ * Note that the given node is considered the root of the cursor,
1117
+ * and the cursor cannot walk outside this node.
1118
+ */
1119
+ walk() {
1120
+ marshalNode(this);
1121
+ C._ts_tree_cursor_new_wasm(this.tree[0]);
1122
+ return new TreeCursor(INTERNAL, this.tree);
1123
+ }
1124
+ /**
1125
+ * Edit this node to keep it in-sync with source code that has been edited.
1126
+ *
1127
+ * This function is only rarely needed. When you edit a syntax tree with
1128
+ * the {@link Tree#edit} method, all of the nodes that you retrieve from
1129
+ * the tree afterward will already reflect the edit. You only need to
1130
+ * use {@link Node#edit} when you have a specific {@link Node} instance that
1131
+ * you want to keep and continue to use after an edit.
1132
+ */
1133
+ edit(edit) {
1134
+ if (this.startIndex >= edit.oldEndIndex) {
1135
+ this.startIndex = edit.newEndIndex + (this.startIndex - edit.oldEndIndex);
1136
+ let subbedPointRow;
1137
+ let subbedPointColumn;
1138
+ if (this.startPosition.row > edit.oldEndPosition.row) {
1139
+ subbedPointRow = this.startPosition.row - edit.oldEndPosition.row;
1140
+ subbedPointColumn = this.startPosition.column;
1141
+ } else {
1142
+ subbedPointRow = 0;
1143
+ subbedPointColumn = this.startPosition.column;
1144
+ if (this.startPosition.column >= edit.oldEndPosition.column) {
1145
+ subbedPointColumn = this.startPosition.column - edit.oldEndPosition.column;
1146
+ }
1147
+ }
1148
+ if (subbedPointRow > 0) {
1149
+ this.startPosition.row += subbedPointRow;
1150
+ this.startPosition.column = subbedPointColumn;
1151
+ } else {
1152
+ this.startPosition.column += subbedPointColumn;
1153
+ }
1154
+ } else if (this.startIndex > edit.startIndex) {
1155
+ this.startIndex = edit.newEndIndex;
1156
+ this.startPosition.row = edit.newEndPosition.row;
1157
+ this.startPosition.column = edit.newEndPosition.column;
1158
+ }
1159
+ }
1160
+ /** Get the S-expression representation of this node. */
1161
+ toString() {
1162
+ marshalNode(this);
1163
+ const address = C._ts_node_to_string_wasm(this.tree[0]);
1164
+ const result = C.AsciiToString(address);
1165
+ C._free(address);
1166
+ return result;
1167
+ }
1168
+ };
1169
+
1170
+ // src/marshal.ts
1171
+ function unmarshalCaptures(query, tree, address, patternIndex, result) {
1172
+ for (let i2 = 0, n = result.length; i2 < n; i2++) {
1173
+ const captureIndex = C.getValue(address, "i32");
1174
+ address += SIZE_OF_INT;
1175
+ const node = unmarshalNode(tree, address);
1176
+ address += SIZE_OF_NODE;
1177
+ result[i2] = { patternIndex, name: query.captureNames[captureIndex], node };
1178
+ }
1179
+ return address;
1180
+ }
1181
+ __name(unmarshalCaptures, "unmarshalCaptures");
1182
+ function marshalNode(node, index = 0) {
1183
+ let address = TRANSFER_BUFFER + index * SIZE_OF_NODE;
1184
+ C.setValue(address, node.id, "i32");
1185
+ address += SIZE_OF_INT;
1186
+ C.setValue(address, node.startIndex, "i32");
1187
+ address += SIZE_OF_INT;
1188
+ C.setValue(address, node.startPosition.row, "i32");
1189
+ address += SIZE_OF_INT;
1190
+ C.setValue(address, node.startPosition.column, "i32");
1191
+ address += SIZE_OF_INT;
1192
+ C.setValue(address, node[0], "i32");
1193
+ }
1194
+ __name(marshalNode, "marshalNode");
1195
+ function unmarshalNode(tree, address = TRANSFER_BUFFER) {
1196
+ const id = C.getValue(address, "i32");
1197
+ address += SIZE_OF_INT;
1198
+ if (id === 0) return null;
1199
+ const index = C.getValue(address, "i32");
1200
+ address += SIZE_OF_INT;
1201
+ const row = C.getValue(address, "i32");
1202
+ address += SIZE_OF_INT;
1203
+ const column = C.getValue(address, "i32");
1204
+ address += SIZE_OF_INT;
1205
+ const other = C.getValue(address, "i32");
1206
+ const result = new Node(INTERNAL, {
1207
+ id,
1208
+ tree,
1209
+ startIndex: index,
1210
+ startPosition: { row, column },
1211
+ other
1212
+ });
1213
+ return result;
1214
+ }
1215
+ __name(unmarshalNode, "unmarshalNode");
1216
+ function marshalTreeCursor(cursor, address = TRANSFER_BUFFER) {
1217
+ C.setValue(address + 0 * SIZE_OF_INT, cursor[0], "i32");
1218
+ C.setValue(address + 1 * SIZE_OF_INT, cursor[1], "i32");
1219
+ C.setValue(address + 2 * SIZE_OF_INT, cursor[2], "i32");
1220
+ C.setValue(address + 3 * SIZE_OF_INT, cursor[3], "i32");
1221
+ }
1222
+ __name(marshalTreeCursor, "marshalTreeCursor");
1223
+ function unmarshalTreeCursor(cursor) {
1224
+ cursor[0] = C.getValue(TRANSFER_BUFFER + 0 * SIZE_OF_INT, "i32");
1225
+ cursor[1] = C.getValue(TRANSFER_BUFFER + 1 * SIZE_OF_INT, "i32");
1226
+ cursor[2] = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
1227
+ cursor[3] = C.getValue(TRANSFER_BUFFER + 3 * SIZE_OF_INT, "i32");
1228
+ }
1229
+ __name(unmarshalTreeCursor, "unmarshalTreeCursor");
1230
+ function marshalPoint(address, point) {
1231
+ C.setValue(address, point.row, "i32");
1232
+ C.setValue(address + SIZE_OF_INT, point.column, "i32");
1233
+ }
1234
+ __name(marshalPoint, "marshalPoint");
1235
+ function unmarshalPoint(address) {
1236
+ const result = {
1237
+ row: C.getValue(address, "i32") >>> 0,
1238
+ column: C.getValue(address + SIZE_OF_INT, "i32") >>> 0
1239
+ };
1240
+ return result;
1241
+ }
1242
+ __name(unmarshalPoint, "unmarshalPoint");
1243
+ function marshalRange(address, range) {
1244
+ marshalPoint(address, range.startPosition);
1245
+ address += SIZE_OF_POINT;
1246
+ marshalPoint(address, range.endPosition);
1247
+ address += SIZE_OF_POINT;
1248
+ C.setValue(address, range.startIndex, "i32");
1249
+ address += SIZE_OF_INT;
1250
+ C.setValue(address, range.endIndex, "i32");
1251
+ address += SIZE_OF_INT;
1252
+ }
1253
+ __name(marshalRange, "marshalRange");
1254
+ function unmarshalRange(address) {
1255
+ const result = {};
1256
+ result.startPosition = unmarshalPoint(address);
1257
+ address += SIZE_OF_POINT;
1258
+ result.endPosition = unmarshalPoint(address);
1259
+ address += SIZE_OF_POINT;
1260
+ result.startIndex = C.getValue(address, "i32") >>> 0;
1261
+ address += SIZE_OF_INT;
1262
+ result.endIndex = C.getValue(address, "i32") >>> 0;
1263
+ return result;
1264
+ }
1265
+ __name(unmarshalRange, "unmarshalRange");
1266
+ function marshalEdit(edit, address = TRANSFER_BUFFER) {
1267
+ marshalPoint(address, edit.startPosition);
1268
+ address += SIZE_OF_POINT;
1269
+ marshalPoint(address, edit.oldEndPosition);
1270
+ address += SIZE_OF_POINT;
1271
+ marshalPoint(address, edit.newEndPosition);
1272
+ address += SIZE_OF_POINT;
1273
+ C.setValue(address, edit.startIndex, "i32");
1274
+ address += SIZE_OF_INT;
1275
+ C.setValue(address, edit.oldEndIndex, "i32");
1276
+ address += SIZE_OF_INT;
1277
+ C.setValue(address, edit.newEndIndex, "i32");
1278
+ address += SIZE_OF_INT;
1279
+ }
1280
+ __name(marshalEdit, "marshalEdit");
1281
+ function unmarshalLanguageMetadata(address) {
1282
+ const major_version = C.getValue(address, "i32");
1283
+ const minor_version = C.getValue(address += SIZE_OF_INT, "i32");
1284
+ const patch_version = C.getValue(address += SIZE_OF_INT, "i32");
1285
+ return { major_version, minor_version, patch_version };
1286
+ }
1287
+ __name(unmarshalLanguageMetadata, "unmarshalLanguageMetadata");
1288
+
1289
+ // src/language.ts
1290
+ var LANGUAGE_FUNCTION_REGEX = /^tree_sitter_\w+$/;
1291
+ var Language = class _Language {
1292
+ static {
1293
+ __name(this, "Language");
1294
+ }
1295
+ /** @internal */
1296
+ [0] = 0;
1297
+ // Internal handle for Wasm
1298
+ /**
1299
+ * A list of all node types in the language. The index of each type in this
1300
+ * array is its node type id.
1301
+ */
1302
+ types;
1303
+ /**
1304
+ * A list of all field names in the language. The index of each field name in
1305
+ * this array is its field id.
1306
+ */
1307
+ fields;
1308
+ /** @internal */
1309
+ constructor(internal, address) {
1310
+ assertInternal(internal);
1311
+ this[0] = address;
1312
+ this.types = new Array(C._ts_language_symbol_count(this[0]));
1313
+ for (let i2 = 0, n = this.types.length; i2 < n; i2++) {
1314
+ if (C._ts_language_symbol_type(this[0], i2) < 2) {
1315
+ this.types[i2] = C.UTF8ToString(C._ts_language_symbol_name(this[0], i2));
1316
+ }
1317
+ }
1318
+ this.fields = new Array(C._ts_language_field_count(this[0]) + 1);
1319
+ for (let i2 = 0, n = this.fields.length; i2 < n; i2++) {
1320
+ const fieldName = C._ts_language_field_name_for_id(this[0], i2);
1321
+ if (fieldName !== 0) {
1322
+ this.fields[i2] = C.UTF8ToString(fieldName);
1323
+ } else {
1324
+ this.fields[i2] = null;
1325
+ }
1326
+ }
1327
+ }
1328
+ /**
1329
+ * Gets the name of the language.
1330
+ */
1331
+ get name() {
1332
+ const ptr = C._ts_language_name(this[0]);
1333
+ if (ptr === 0) return null;
1334
+ return C.UTF8ToString(ptr);
1335
+ }
1336
+ /**
1337
+ * Gets the ABI version of the language.
1338
+ */
1339
+ get abiVersion() {
1340
+ return C._ts_language_abi_version(this[0]);
1341
+ }
1342
+ /**
1343
+ * Get the metadata for this language. This information is generated by the
1344
+ * CLI, and relies on the language author providing the correct metadata in
1345
+ * the language's `tree-sitter.json` file.
1346
+ */
1347
+ get metadata() {
1348
+ C._ts_language_metadata_wasm(this[0]);
1349
+ const length = C.getValue(TRANSFER_BUFFER, "i32");
1350
+ if (length === 0) return null;
1351
+ return unmarshalLanguageMetadata(TRANSFER_BUFFER + SIZE_OF_INT);
1352
+ }
1353
+ /**
1354
+ * Gets the number of fields in the language.
1355
+ */
1356
+ get fieldCount() {
1357
+ return this.fields.length - 1;
1358
+ }
1359
+ /**
1360
+ * Gets the number of states in the language.
1361
+ */
1362
+ get stateCount() {
1363
+ return C._ts_language_state_count(this[0]);
1364
+ }
1365
+ /**
1366
+ * Get the field id for a field name.
1367
+ */
1368
+ fieldIdForName(fieldName) {
1369
+ const result = this.fields.indexOf(fieldName);
1370
+ return result !== -1 ? result : null;
1371
+ }
1372
+ /**
1373
+ * Get the field name for a field id.
1374
+ */
1375
+ fieldNameForId(fieldId) {
1376
+ return this.fields[fieldId] ?? null;
1377
+ }
1378
+ /**
1379
+ * Get the node type id for a node type name.
1380
+ */
1381
+ idForNodeType(type, named) {
1382
+ const typeLength = C.lengthBytesUTF8(type);
1383
+ const typeAddress = C._malloc(typeLength + 1);
1384
+ C.stringToUTF8(type, typeAddress, typeLength + 1);
1385
+ const result = C._ts_language_symbol_for_name(this[0], typeAddress, typeLength, named ? 1 : 0);
1386
+ C._free(typeAddress);
1387
+ return result || null;
1388
+ }
1389
+ /**
1390
+ * Gets the number of node types in the language.
1391
+ */
1392
+ get nodeTypeCount() {
1393
+ return C._ts_language_symbol_count(this[0]);
1394
+ }
1395
+ /**
1396
+ * Get the node type name for a node type id.
1397
+ */
1398
+ nodeTypeForId(typeId) {
1399
+ const name2 = C._ts_language_symbol_name(this[0], typeId);
1400
+ return name2 ? C.UTF8ToString(name2) : null;
1401
+ }
1402
+ /**
1403
+ * Check if a node type is named.
1404
+ *
1405
+ * @see {@link https://tree-sitter.github.io/tree-sitter/using-parsers/2-basic-parsing.html#named-vs-anonymous-nodes}
1406
+ */
1407
+ nodeTypeIsNamed(typeId) {
1408
+ return C._ts_language_type_is_named_wasm(this[0], typeId) ? true : false;
1409
+ }
1410
+ /**
1411
+ * Check if a node type is visible.
1412
+ */
1413
+ nodeTypeIsVisible(typeId) {
1414
+ return C._ts_language_type_is_visible_wasm(this[0], typeId) ? true : false;
1415
+ }
1416
+ /**
1417
+ * Get the supertypes ids of this language.
1418
+ *
1419
+ * @see {@link https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types.html?highlight=supertype#supertype-nodes}
1420
+ */
1421
+ get supertypes() {
1422
+ C._ts_language_supertypes_wasm(this[0]);
1423
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
1424
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
1425
+ const result = new Array(count);
1426
+ if (count > 0) {
1427
+ let address = buffer;
1428
+ for (let i2 = 0; i2 < count; i2++) {
1429
+ result[i2] = C.getValue(address, "i16");
1430
+ address += SIZE_OF_SHORT;
1431
+ }
1432
+ }
1433
+ return result;
1434
+ }
1435
+ /**
1436
+ * Get the subtype ids for a given supertype node id.
1437
+ */
1438
+ subtypes(supertype) {
1439
+ C._ts_language_subtypes_wasm(this[0], supertype);
1440
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
1441
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
1442
+ const result = new Array(count);
1443
+ if (count > 0) {
1444
+ let address = buffer;
1445
+ for (let i2 = 0; i2 < count; i2++) {
1446
+ result[i2] = C.getValue(address, "i16");
1447
+ address += SIZE_OF_SHORT;
1448
+ }
1449
+ }
1450
+ return result;
1451
+ }
1452
+ /**
1453
+ * Get the next state id for a given state id and node type id.
1454
+ */
1455
+ nextState(stateId, typeId) {
1456
+ return C._ts_language_next_state(this[0], stateId, typeId);
1457
+ }
1458
+ /**
1459
+ * Create a new lookahead iterator for this language and parse state.
1460
+ *
1461
+ * This returns `null` if state is invalid for this language.
1462
+ *
1463
+ * Iterating {@link LookaheadIterator} will yield valid symbols in the given
1464
+ * parse state. Newly created lookahead iterators will return the `ERROR`
1465
+ * symbol from {@link LookaheadIterator#currentType}.
1466
+ *
1467
+ * Lookahead iterators can be useful for generating suggestions and improving
1468
+ * syntax error diagnostics. To get symbols valid in an `ERROR` node, use the
1469
+ * lookahead iterator on its first leaf node state. For `MISSING` nodes, a
1470
+ * lookahead iterator created on the previous non-extra leaf node may be
1471
+ * appropriate.
1472
+ */
1473
+ lookaheadIterator(stateId) {
1474
+ const address = C._ts_lookahead_iterator_new(this[0], stateId);
1475
+ if (address) return new LookaheadIterator(INTERNAL, address, this);
1476
+ return null;
1477
+ }
1478
+ /**
1479
+ * Load a language from a WebAssembly module.
1480
+ * The module can be provided as a path to a file or as a buffer.
1481
+ */
1482
+ static async load(input) {
1483
+ let binary2;
1484
+ if (input instanceof Uint8Array) {
1485
+ binary2 = input;
1486
+ } else if (globalThis.process?.versions.node) {
1487
+ const fs2 = await import("fs/promises");
1488
+ binary2 = await fs2.readFile(input);
1489
+ } else {
1490
+ const response = await fetch(input);
1491
+ if (!response.ok) {
1492
+ const body2 = await response.text();
1493
+ throw new Error(`Language.load failed with status ${response.status}.
1494
+
1495
+ ${body2}`);
1496
+ }
1497
+ const retryResp = response.clone();
1498
+ try {
1499
+ binary2 = await WebAssembly.compileStreaming(response);
1500
+ } catch (reason) {
1501
+ console.error("wasm streaming compile failed:", reason);
1502
+ console.error("falling back to ArrayBuffer instantiation");
1503
+ binary2 = new Uint8Array(await retryResp.arrayBuffer());
1504
+ }
1505
+ }
1506
+ const mod = await C.loadWebAssemblyModule(binary2, { loadAsync: true });
1507
+ const symbolNames = Object.keys(mod);
1508
+ const functionName = symbolNames.find((key) => LANGUAGE_FUNCTION_REGEX.test(key) && !key.includes("external_scanner_"));
1509
+ if (!functionName) {
1510
+ console.log(`Couldn't find language function in Wasm file. Symbols:
1511
+ ${JSON.stringify(symbolNames, null, 2)}`);
1512
+ throw new Error("Language.load failed: no language function found in Wasm file");
1513
+ }
1514
+ const languageAddress = mod[functionName]();
1515
+ return new _Language(INTERNAL, languageAddress);
1516
+ }
1517
+ };
1518
+
1519
+ // lib/web-tree-sitter.mjs
1520
+ async function Module2(moduleArg = {}) {
1521
+ var moduleRtn;
1522
+ var Module = moduleArg;
1523
+ var ENVIRONMENT_IS_WEB = typeof window == "object";
1524
+ var ENVIRONMENT_IS_WORKER = typeof WorkerGlobalScope != "undefined";
1525
+ var ENVIRONMENT_IS_NODE = typeof process == "object" && process.versions?.node && process.type != "renderer";
1526
+ if (ENVIRONMENT_IS_NODE) {
1527
+ const { createRequire } = await import("module");
1528
+ var require = createRequire(import.meta.url);
1529
+ }
1530
+ Module.currentQueryProgressCallback = null;
1531
+ Module.currentProgressCallback = null;
1532
+ Module.currentLogCallback = null;
1533
+ Module.currentParseCallback = null;
1534
+ var arguments_ = [];
1535
+ var thisProgram = "./this.program";
1536
+ var quit_ = /* @__PURE__ */ __name((status, toThrow) => {
1537
+ throw toThrow;
1538
+ }, "quit_");
1539
+ var _scriptName = import.meta.url;
1540
+ var scriptDirectory = "";
1541
+ function locateFile(path) {
1542
+ if (Module["locateFile"]) {
1543
+ return Module["locateFile"](path, scriptDirectory);
1544
+ }
1545
+ return scriptDirectory + path;
1546
+ }
1547
+ __name(locateFile, "locateFile");
1548
+ var readAsync, readBinary;
1549
+ if (ENVIRONMENT_IS_NODE) {
1550
+ var fs = require("fs");
1551
+ if (_scriptName.startsWith("file:")) {
1552
+ scriptDirectory = require("path").dirname(require("url").fileURLToPath(_scriptName)) + "/";
1553
+ }
1554
+ readBinary = /* @__PURE__ */ __name((filename) => {
1555
+ filename = isFileURI(filename) ? new URL(filename) : filename;
1556
+ var ret = fs.readFileSync(filename);
1557
+ return ret;
1558
+ }, "readBinary");
1559
+ readAsync = /* @__PURE__ */ __name(async (filename, binary2 = true) => {
1560
+ filename = isFileURI(filename) ? new URL(filename) : filename;
1561
+ var ret = fs.readFileSync(filename, binary2 ? void 0 : "utf8");
1562
+ return ret;
1563
+ }, "readAsync");
1564
+ if (process.argv.length > 1) {
1565
+ thisProgram = process.argv[1].replace(/\\/g, "/");
1566
+ }
1567
+ arguments_ = process.argv.slice(2);
1568
+ quit_ = /* @__PURE__ */ __name((status, toThrow) => {
1569
+ process.exitCode = status;
1570
+ throw toThrow;
1571
+ }, "quit_");
1572
+ } else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
1573
+ try {
1574
+ scriptDirectory = new URL(".", _scriptName).href;
1575
+ } catch {
1576
+ }
1577
+ {
1578
+ if (ENVIRONMENT_IS_WORKER) {
1579
+ readBinary = /* @__PURE__ */ __name((url) => {
1580
+ var xhr = new XMLHttpRequest();
1581
+ xhr.open("GET", url, false);
1582
+ xhr.responseType = "arraybuffer";
1583
+ xhr.send(null);
1584
+ return new Uint8Array(
1585
+ /** @type{!ArrayBuffer} */
1586
+ xhr.response
1587
+ );
1588
+ }, "readBinary");
1589
+ }
1590
+ readAsync = /* @__PURE__ */ __name(async (url) => {
1591
+ if (isFileURI(url)) {
1592
+ return new Promise((resolve, reject) => {
1593
+ var xhr = new XMLHttpRequest();
1594
+ xhr.open("GET", url, true);
1595
+ xhr.responseType = "arraybuffer";
1596
+ xhr.onload = () => {
1597
+ if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
1598
+ resolve(xhr.response);
1599
+ return;
1600
+ }
1601
+ reject(xhr.status);
1602
+ };
1603
+ xhr.onerror = reject;
1604
+ xhr.send(null);
1605
+ });
1606
+ }
1607
+ var response = await fetch(url, {
1608
+ credentials: "same-origin"
1609
+ });
1610
+ if (response.ok) {
1611
+ return response.arrayBuffer();
1612
+ }
1613
+ throw new Error(response.status + " : " + response.url);
1614
+ }, "readAsync");
1615
+ }
1616
+ } else {
1617
+ }
1618
+ var out = console.log.bind(console);
1619
+ var err = console.error.bind(console);
1620
+ var dynamicLibraries = [];
1621
+ var wasmBinary;
1622
+ var ABORT = false;
1623
+ var EXITSTATUS;
1624
+ var isFileURI = /* @__PURE__ */ __name((filename) => filename.startsWith("file://"), "isFileURI");
1625
+ var readyPromiseResolve, readyPromiseReject;
1626
+ var wasmMemory;
1627
+ var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
1628
+ var HEAP64, HEAPU64;
1629
+ var HEAP_DATA_VIEW;
1630
+ var runtimeInitialized = false;
1631
+ function updateMemoryViews() {
1632
+ var b = wasmMemory.buffer;
1633
+ Module["HEAP8"] = HEAP8 = new Int8Array(b);
1634
+ Module["HEAP16"] = HEAP16 = new Int16Array(b);
1635
+ Module["HEAPU8"] = HEAPU8 = new Uint8Array(b);
1636
+ Module["HEAPU16"] = HEAPU16 = new Uint16Array(b);
1637
+ Module["HEAP32"] = HEAP32 = new Int32Array(b);
1638
+ Module["HEAPU32"] = HEAPU32 = new Uint32Array(b);
1639
+ Module["HEAPF32"] = HEAPF32 = new Float32Array(b);
1640
+ Module["HEAPF64"] = HEAPF64 = new Float64Array(b);
1641
+ Module["HEAP64"] = HEAP64 = new BigInt64Array(b);
1642
+ Module["HEAPU64"] = HEAPU64 = new BigUint64Array(b);
1643
+ Module["HEAP_DATA_VIEW"] = HEAP_DATA_VIEW = new DataView(b);
1644
+ LE_HEAP_UPDATE();
1645
+ }
1646
+ __name(updateMemoryViews, "updateMemoryViews");
1647
+ function initMemory() {
1648
+ if (Module["wasmMemory"]) {
1649
+ wasmMemory = Module["wasmMemory"];
1650
+ } else {
1651
+ var INITIAL_MEMORY = Module["INITIAL_MEMORY"] || 33554432;
1652
+ wasmMemory = new WebAssembly.Memory({
1653
+ "initial": INITIAL_MEMORY / 65536,
1654
+ // In theory we should not need to emit the maximum if we want "unlimited"
1655
+ // or 4GB of memory, but VMs error on that atm, see
1656
+ // https://github.com/emscripten-core/emscripten/issues/14130
1657
+ // And in the pthreads case we definitely need to emit a maximum. So
1658
+ // always emit one.
1659
+ "maximum": 32768
1660
+ });
1661
+ }
1662
+ updateMemoryViews();
1663
+ }
1664
+ __name(initMemory, "initMemory");
1665
+ var __RELOC_FUNCS__ = [];
1666
+ function preRun() {
1667
+ if (Module["preRun"]) {
1668
+ if (typeof Module["preRun"] == "function") Module["preRun"] = [Module["preRun"]];
1669
+ while (Module["preRun"].length) {
1670
+ addOnPreRun(Module["preRun"].shift());
1671
+ }
1672
+ }
1673
+ callRuntimeCallbacks(onPreRuns);
1674
+ }
1675
+ __name(preRun, "preRun");
1676
+ function initRuntime() {
1677
+ runtimeInitialized = true;
1678
+ callRuntimeCallbacks(__RELOC_FUNCS__);
1679
+ wasmExports["__wasm_call_ctors"]();
1680
+ callRuntimeCallbacks(onPostCtors);
1681
+ }
1682
+ __name(initRuntime, "initRuntime");
1683
+ function preMain() {
1684
+ }
1685
+ __name(preMain, "preMain");
1686
+ function postRun() {
1687
+ if (Module["postRun"]) {
1688
+ if (typeof Module["postRun"] == "function") Module["postRun"] = [Module["postRun"]];
1689
+ while (Module["postRun"].length) {
1690
+ addOnPostRun(Module["postRun"].shift());
1691
+ }
1692
+ }
1693
+ callRuntimeCallbacks(onPostRuns);
1694
+ }
1695
+ __name(postRun, "postRun");
1696
+ function abort(what) {
1697
+ Module["onAbort"]?.(what);
1698
+ what = "Aborted(" + what + ")";
1699
+ err(what);
1700
+ ABORT = true;
1701
+ what += ". Build with -sASSERTIONS for more info.";
1702
+ var e = new WebAssembly.RuntimeError(what);
1703
+ readyPromiseReject?.(e);
1704
+ throw e;
1705
+ }
1706
+ __name(abort, "abort");
1707
+ var wasmBinaryFile;
1708
+ function findWasmBinary() {
1709
+ if (Module["locateFile"]) {
1710
+ return locateFile("web-tree-sitter.wasm");
1711
+ }
1712
+ return new URL("web-tree-sitter.wasm", import.meta.url).href;
1713
+ }
1714
+ __name(findWasmBinary, "findWasmBinary");
1715
+ function getBinarySync(file) {
1716
+ if (file == wasmBinaryFile && wasmBinary) {
1717
+ return new Uint8Array(wasmBinary);
1718
+ }
1719
+ if (readBinary) {
1720
+ return readBinary(file);
1721
+ }
1722
+ throw "both async and sync fetching of the wasm failed";
1723
+ }
1724
+ __name(getBinarySync, "getBinarySync");
1725
+ async function getWasmBinary(binaryFile) {
1726
+ if (!wasmBinary) {
1727
+ try {
1728
+ var response = await readAsync(binaryFile);
1729
+ return new Uint8Array(response);
1730
+ } catch {
1731
+ }
1732
+ }
1733
+ return getBinarySync(binaryFile);
1734
+ }
1735
+ __name(getWasmBinary, "getWasmBinary");
1736
+ async function instantiateArrayBuffer(binaryFile, imports) {
1737
+ try {
1738
+ var binary2 = await getWasmBinary(binaryFile);
1739
+ var instance2 = await WebAssembly.instantiate(binary2, imports);
1740
+ return instance2;
1741
+ } catch (reason) {
1742
+ err(`failed to asynchronously prepare wasm: ${reason}`);
1743
+ abort(reason);
1744
+ }
1745
+ }
1746
+ __name(instantiateArrayBuffer, "instantiateArrayBuffer");
1747
+ async function instantiateAsync(binary2, binaryFile, imports) {
1748
+ if (!binary2 && !isFileURI(binaryFile) && !ENVIRONMENT_IS_NODE) {
1749
+ try {
1750
+ var response = fetch(binaryFile, {
1751
+ credentials: "same-origin"
1752
+ });
1753
+ var instantiationResult = await WebAssembly.instantiateStreaming(response, imports);
1754
+ return instantiationResult;
1755
+ } catch (reason) {
1756
+ err(`wasm streaming compile failed: ${reason}`);
1757
+ err("falling back to ArrayBuffer instantiation");
1758
+ }
1759
+ }
1760
+ return instantiateArrayBuffer(binaryFile, imports);
1761
+ }
1762
+ __name(instantiateAsync, "instantiateAsync");
1763
+ function getWasmImports() {
1764
+ return {
1765
+ "env": wasmImports,
1766
+ "wasi_snapshot_preview1": wasmImports,
1767
+ "GOT.mem": new Proxy(wasmImports, GOTHandler),
1768
+ "GOT.func": new Proxy(wasmImports, GOTHandler)
1769
+ };
1770
+ }
1771
+ __name(getWasmImports, "getWasmImports");
1772
+ async function createWasm() {
1773
+ function receiveInstance(instance2, module2) {
1774
+ wasmExports = instance2.exports;
1775
+ wasmExports = relocateExports(wasmExports, 1024);
1776
+ var metadata2 = getDylinkMetadata(module2);
1777
+ if (metadata2.neededDynlibs) {
1778
+ dynamicLibraries = metadata2.neededDynlibs.concat(dynamicLibraries);
1779
+ }
1780
+ mergeLibSymbols(wasmExports, "main");
1781
+ LDSO.init();
1782
+ loadDylibs();
1783
+ __RELOC_FUNCS__.push(wasmExports["__wasm_apply_data_relocs"]);
1784
+ assignWasmExports(wasmExports);
1785
+ return wasmExports;
1786
+ }
1787
+ __name(receiveInstance, "receiveInstance");
1788
+ function receiveInstantiationResult(result2) {
1789
+ return receiveInstance(result2["instance"], result2["module"]);
1790
+ }
1791
+ __name(receiveInstantiationResult, "receiveInstantiationResult");
1792
+ var info2 = getWasmImports();
1793
+ if (Module["instantiateWasm"]) {
1794
+ return new Promise((resolve, reject) => {
1795
+ Module["instantiateWasm"](info2, (mod, inst) => {
1796
+ resolve(receiveInstance(mod, inst));
1797
+ });
1798
+ });
1799
+ }
1800
+ wasmBinaryFile ??= findWasmBinary();
1801
+ var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info2);
1802
+ var exports = receiveInstantiationResult(result);
1803
+ return exports;
1804
+ }
1805
+ __name(createWasm, "createWasm");
1806
+ class ExitStatus {
1807
+ static {
1808
+ __name(this, "ExitStatus");
1809
+ }
1810
+ name = "ExitStatus";
1811
+ constructor(status) {
1812
+ this.message = `Program terminated with exit(${status})`;
1813
+ this.status = status;
1814
+ }
1815
+ }
1816
+ var GOT = {};
1817
+ var currentModuleWeakSymbols = /* @__PURE__ */ new Set([]);
1818
+ var GOTHandler = {
1819
+ get(obj, symName) {
1820
+ var rtn = GOT[symName];
1821
+ if (!rtn) {
1822
+ rtn = GOT[symName] = new WebAssembly.Global({
1823
+ "value": "i32",
1824
+ "mutable": true
1825
+ });
1826
+ }
1827
+ if (!currentModuleWeakSymbols.has(symName)) {
1828
+ rtn.required = true;
1829
+ }
1830
+ return rtn;
1831
+ }
1832
+ };
1833
+ var LE_ATOMICS_NATIVE_BYTE_ORDER = [];
1834
+ var LE_HEAP_LOAD_F32 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getFloat32(byteOffset, true), "LE_HEAP_LOAD_F32");
1835
+ var LE_HEAP_LOAD_F64 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getFloat64(byteOffset, true), "LE_HEAP_LOAD_F64");
1836
+ var LE_HEAP_LOAD_I16 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getInt16(byteOffset, true), "LE_HEAP_LOAD_I16");
1837
+ var LE_HEAP_LOAD_I32 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getInt32(byteOffset, true), "LE_HEAP_LOAD_I32");
1838
+ var LE_HEAP_LOAD_I64 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getBigInt64(byteOffset, true), "LE_HEAP_LOAD_I64");
1839
+ var LE_HEAP_LOAD_U32 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getUint32(byteOffset, true), "LE_HEAP_LOAD_U32");
1840
+ var LE_HEAP_STORE_F32 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setFloat32(byteOffset, value, true), "LE_HEAP_STORE_F32");
1841
+ var LE_HEAP_STORE_F64 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setFloat64(byteOffset, value, true), "LE_HEAP_STORE_F64");
1842
+ var LE_HEAP_STORE_I16 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setInt16(byteOffset, value, true), "LE_HEAP_STORE_I16");
1843
+ var LE_HEAP_STORE_I32 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setInt32(byteOffset, value, true), "LE_HEAP_STORE_I32");
1844
+ var LE_HEAP_STORE_I64 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setBigInt64(byteOffset, value, true), "LE_HEAP_STORE_I64");
1845
+ var LE_HEAP_STORE_U32 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setUint32(byteOffset, value, true), "LE_HEAP_STORE_U32");
1846
+ var callRuntimeCallbacks = /* @__PURE__ */ __name((callbacks) => {
1847
+ while (callbacks.length > 0) {
1848
+ callbacks.shift()(Module);
1849
+ }
1850
+ }, "callRuntimeCallbacks");
1851
+ var onPostRuns = [];
1852
+ var addOnPostRun = /* @__PURE__ */ __name((cb) => onPostRuns.push(cb), "addOnPostRun");
1853
+ var onPreRuns = [];
1854
+ var addOnPreRun = /* @__PURE__ */ __name((cb) => onPreRuns.push(cb), "addOnPreRun");
1855
+ var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder() : void 0;
1856
+ var findStringEnd = /* @__PURE__ */ __name((heapOrArray, idx, maxBytesToRead, ignoreNul) => {
1857
+ var maxIdx = idx + maxBytesToRead;
1858
+ if (ignoreNul) return maxIdx;
1859
+ while (heapOrArray[idx] && !(idx >= maxIdx)) ++idx;
1860
+ return idx;
1861
+ }, "findStringEnd");
1862
+ var UTF8ArrayToString = /* @__PURE__ */ __name((heapOrArray, idx = 0, maxBytesToRead, ignoreNul) => {
1863
+ var endPtr = findStringEnd(heapOrArray, idx, maxBytesToRead, ignoreNul);
1864
+ if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
1865
+ return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
1866
+ }
1867
+ var str = "";
1868
+ while (idx < endPtr) {
1869
+ var u0 = heapOrArray[idx++];
1870
+ if (!(u0 & 128)) {
1871
+ str += String.fromCharCode(u0);
1872
+ continue;
1873
+ }
1874
+ var u1 = heapOrArray[idx++] & 63;
1875
+ if ((u0 & 224) == 192) {
1876
+ str += String.fromCharCode((u0 & 31) << 6 | u1);
1877
+ continue;
1878
+ }
1879
+ var u2 = heapOrArray[idx++] & 63;
1880
+ if ((u0 & 240) == 224) {
1881
+ u0 = (u0 & 15) << 12 | u1 << 6 | u2;
1882
+ } else {
1883
+ u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heapOrArray[idx++] & 63;
1884
+ }
1885
+ if (u0 < 65536) {
1886
+ str += String.fromCharCode(u0);
1887
+ } else {
1888
+ var ch = u0 - 65536;
1889
+ str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023);
1890
+ }
1891
+ }
1892
+ return str;
1893
+ }, "UTF8ArrayToString");
1894
+ var getDylinkMetadata = /* @__PURE__ */ __name((binary2) => {
1895
+ var offset = 0;
1896
+ var end = 0;
1897
+ function getU8() {
1898
+ return binary2[offset++];
1899
+ }
1900
+ __name(getU8, "getU8");
1901
+ function getLEB() {
1902
+ var ret = 0;
1903
+ var mul = 1;
1904
+ while (1) {
1905
+ var byte = binary2[offset++];
1906
+ ret += (byte & 127) * mul;
1907
+ mul *= 128;
1908
+ if (!(byte & 128)) break;
1909
+ }
1910
+ return ret;
1911
+ }
1912
+ __name(getLEB, "getLEB");
1913
+ function getString() {
1914
+ var len = getLEB();
1915
+ offset += len;
1916
+ return UTF8ArrayToString(binary2, offset - len, len);
1917
+ }
1918
+ __name(getString, "getString");
1919
+ function getStringList() {
1920
+ var count2 = getLEB();
1921
+ var rtn = [];
1922
+ while (count2--) rtn.push(getString());
1923
+ return rtn;
1924
+ }
1925
+ __name(getStringList, "getStringList");
1926
+ function failIf(condition, message) {
1927
+ if (condition) throw new Error(message);
1928
+ }
1929
+ __name(failIf, "failIf");
1930
+ if (binary2 instanceof WebAssembly.Module) {
1931
+ var dylinkSection = WebAssembly.Module.customSections(binary2, "dylink.0");
1932
+ failIf(dylinkSection.length === 0, "need dylink section");
1933
+ binary2 = new Uint8Array(dylinkSection[0]);
1934
+ end = binary2.length;
1935
+ } else {
1936
+ var int32View = new Uint32Array(new Uint8Array(binary2.subarray(0, 24)).buffer);
1937
+ var magicNumberFound = int32View[0] == 1836278016 || int32View[0] == 6386541;
1938
+ failIf(!magicNumberFound, "need to see wasm magic number");
1939
+ failIf(binary2[8] !== 0, "need the dylink section to be first");
1940
+ offset = 9;
1941
+ var section_size = getLEB();
1942
+ end = offset + section_size;
1943
+ var name2 = getString();
1944
+ failIf(name2 !== "dylink.0");
1945
+ }
1946
+ var customSection = {
1947
+ neededDynlibs: [],
1948
+ tlsExports: /* @__PURE__ */ new Set(),
1949
+ weakImports: /* @__PURE__ */ new Set(),
1950
+ runtimePaths: []
1951
+ };
1952
+ var WASM_DYLINK_MEM_INFO = 1;
1953
+ var WASM_DYLINK_NEEDED = 2;
1954
+ var WASM_DYLINK_EXPORT_INFO = 3;
1955
+ var WASM_DYLINK_IMPORT_INFO = 4;
1956
+ var WASM_DYLINK_RUNTIME_PATH = 5;
1957
+ var WASM_SYMBOL_TLS = 256;
1958
+ var WASM_SYMBOL_BINDING_MASK = 3;
1959
+ var WASM_SYMBOL_BINDING_WEAK = 1;
1960
+ while (offset < end) {
1961
+ var subsectionType = getU8();
1962
+ var subsectionSize = getLEB();
1963
+ if (subsectionType === WASM_DYLINK_MEM_INFO) {
1964
+ customSection.memorySize = getLEB();
1965
+ customSection.memoryAlign = getLEB();
1966
+ customSection.tableSize = getLEB();
1967
+ customSection.tableAlign = getLEB();
1968
+ } else if (subsectionType === WASM_DYLINK_NEEDED) {
1969
+ customSection.neededDynlibs = getStringList();
1970
+ } else if (subsectionType === WASM_DYLINK_EXPORT_INFO) {
1971
+ var count = getLEB();
1972
+ while (count--) {
1973
+ var symname = getString();
1974
+ var flags2 = getLEB();
1975
+ if (flags2 & WASM_SYMBOL_TLS) {
1976
+ customSection.tlsExports.add(symname);
1977
+ }
1978
+ }
1979
+ } else if (subsectionType === WASM_DYLINK_IMPORT_INFO) {
1980
+ var count = getLEB();
1981
+ while (count--) {
1982
+ var modname = getString();
1983
+ var symname = getString();
1984
+ var flags2 = getLEB();
1985
+ if ((flags2 & WASM_SYMBOL_BINDING_MASK) == WASM_SYMBOL_BINDING_WEAK) {
1986
+ customSection.weakImports.add(symname);
1987
+ }
1988
+ }
1989
+ } else if (subsectionType === WASM_DYLINK_RUNTIME_PATH) {
1990
+ customSection.runtimePaths = getStringList();
1991
+ } else {
1992
+ offset += subsectionSize;
1993
+ }
1994
+ }
1995
+ return customSection;
1996
+ }, "getDylinkMetadata");
1997
+ function getValue(ptr, type = "i8") {
1998
+ if (type.endsWith("*")) type = "*";
1999
+ switch (type) {
2000
+ case "i1":
2001
+ return HEAP8[ptr];
2002
+ case "i8":
2003
+ return HEAP8[ptr];
2004
+ case "i16":
2005
+ return LE_HEAP_LOAD_I16((ptr >> 1) * 2);
2006
+ case "i32":
2007
+ return LE_HEAP_LOAD_I32((ptr >> 2) * 4);
2008
+ case "i64":
2009
+ return LE_HEAP_LOAD_I64((ptr >> 3) * 8);
2010
+ case "float":
2011
+ return LE_HEAP_LOAD_F32((ptr >> 2) * 4);
2012
+ case "double":
2013
+ return LE_HEAP_LOAD_F64((ptr >> 3) * 8);
2014
+ case "*":
2015
+ return LE_HEAP_LOAD_U32((ptr >> 2) * 4);
2016
+ default:
2017
+ abort(`invalid type for getValue: ${type}`);
2018
+ }
2019
+ }
2020
+ __name(getValue, "getValue");
2021
+ var newDSO = /* @__PURE__ */ __name((name2, handle2, syms) => {
2022
+ var dso = {
2023
+ refcount: Infinity,
2024
+ name: name2,
2025
+ exports: syms,
2026
+ global: true
2027
+ };
2028
+ LDSO.loadedLibsByName[name2] = dso;
2029
+ if (handle2 != void 0) {
2030
+ LDSO.loadedLibsByHandle[handle2] = dso;
2031
+ }
2032
+ return dso;
2033
+ }, "newDSO");
2034
+ var LDSO = {
2035
+ loadedLibsByName: {},
2036
+ loadedLibsByHandle: {},
2037
+ init() {
2038
+ newDSO("__main__", 0, wasmImports);
2039
+ }
2040
+ };
2041
+ var ___heap_base = 78240;
2042
+ var alignMemory = /* @__PURE__ */ __name((size, alignment) => Math.ceil(size / alignment) * alignment, "alignMemory");
2043
+ var getMemory = /* @__PURE__ */ __name((size) => {
2044
+ if (runtimeInitialized) {
2045
+ return _calloc(size, 1);
2046
+ }
2047
+ var ret = ___heap_base;
2048
+ var end = ret + alignMemory(size, 16);
2049
+ ___heap_base = end;
2050
+ GOT["__heap_base"].value = end;
2051
+ return ret;
2052
+ }, "getMemory");
2053
+ var isInternalSym = /* @__PURE__ */ __name((symName) => ["__cpp_exception", "__c_longjmp", "__wasm_apply_data_relocs", "__dso_handle", "__tls_size", "__tls_align", "__set_stack_limits", "_emscripten_tls_init", "__wasm_init_tls", "__wasm_call_ctors", "__start_em_asm", "__stop_em_asm", "__start_em_js", "__stop_em_js"].includes(symName) || symName.startsWith("__em_js__"), "isInternalSym");
2054
+ var uleb128EncodeWithLen = /* @__PURE__ */ __name((arr) => {
2055
+ const n = arr.length;
2056
+ return [n % 128 | 128, n >> 7, ...arr];
2057
+ }, "uleb128EncodeWithLen");
2058
+ var wasmTypeCodes = {
2059
+ "i": 127,
2060
+ // i32
2061
+ "p": 127,
2062
+ // i32
2063
+ "j": 126,
2064
+ // i64
2065
+ "f": 125,
2066
+ // f32
2067
+ "d": 124,
2068
+ // f64
2069
+ "e": 111
2070
+ };
2071
+ var generateTypePack = /* @__PURE__ */ __name((types) => uleb128EncodeWithLen(Array.from(types, (type) => {
2072
+ var code = wasmTypeCodes[type];
2073
+ return code;
2074
+ })), "generateTypePack");
2075
+ var convertJsFunctionToWasm = /* @__PURE__ */ __name((func2, sig) => {
2076
+ var bytes = Uint8Array.of(
2077
+ 0,
2078
+ 97,
2079
+ 115,
2080
+ 109,
2081
+ // magic ("\0asm")
2082
+ 1,
2083
+ 0,
2084
+ 0,
2085
+ 0,
2086
+ // version: 1
2087
+ 1,
2088
+ ...uleb128EncodeWithLen([
2089
+ 1,
2090
+ // count: 1
2091
+ 96,
2092
+ // param types
2093
+ ...generateTypePack(sig.slice(1)),
2094
+ // return types (for now only supporting [] if `void` and single [T] otherwise)
2095
+ ...generateTypePack(sig[0] === "v" ? "" : sig[0])
2096
+ ]),
2097
+ // The rest of the module is static
2098
+ 2,
2099
+ 7,
2100
+ // import section
2101
+ // (import "e" "f" (func 0 (type 0)))
2102
+ 1,
2103
+ 1,
2104
+ 101,
2105
+ 1,
2106
+ 102,
2107
+ 0,
2108
+ 0,
2109
+ 7,
2110
+ 5,
2111
+ // export section
2112
+ // (export "f" (func 0 (type 0)))
2113
+ 1,
2114
+ 1,
2115
+ 102,
2116
+ 0,
2117
+ 0
2118
+ );
2119
+ var module2 = new WebAssembly.Module(bytes);
2120
+ var instance2 = new WebAssembly.Instance(module2, {
2121
+ "e": {
2122
+ "f": func2
2123
+ }
2124
+ });
2125
+ var wrappedFunc = instance2.exports["f"];
2126
+ return wrappedFunc;
2127
+ }, "convertJsFunctionToWasm");
2128
+ var wasmTableMirror = [];
2129
+ var wasmTable = new WebAssembly.Table({
2130
+ "initial": 31,
2131
+ "element": "anyfunc"
2132
+ });
2133
+ var getWasmTableEntry = /* @__PURE__ */ __name((funcPtr) => {
2134
+ var func2 = wasmTableMirror[funcPtr];
2135
+ if (!func2) {
2136
+ wasmTableMirror[funcPtr] = func2 = wasmTable.get(funcPtr);
2137
+ }
2138
+ return func2;
2139
+ }, "getWasmTableEntry");
2140
+ var updateTableMap = /* @__PURE__ */ __name((offset, count) => {
2141
+ if (functionsInTableMap) {
2142
+ for (var i2 = offset; i2 < offset + count; i2++) {
2143
+ var item = getWasmTableEntry(i2);
2144
+ if (item) {
2145
+ functionsInTableMap.set(item, i2);
2146
+ }
2147
+ }
2148
+ }
2149
+ }, "updateTableMap");
2150
+ var functionsInTableMap;
2151
+ var getFunctionAddress = /* @__PURE__ */ __name((func2) => {
2152
+ if (!functionsInTableMap) {
2153
+ functionsInTableMap = /* @__PURE__ */ new WeakMap();
2154
+ updateTableMap(0, wasmTable.length);
2155
+ }
2156
+ return functionsInTableMap.get(func2) || 0;
2157
+ }, "getFunctionAddress");
2158
+ var freeTableIndexes = [];
2159
+ var getEmptyTableSlot = /* @__PURE__ */ __name(() => {
2160
+ if (freeTableIndexes.length) {
2161
+ return freeTableIndexes.pop();
2162
+ }
2163
+ return wasmTable["grow"](1);
2164
+ }, "getEmptyTableSlot");
2165
+ var setWasmTableEntry = /* @__PURE__ */ __name((idx, func2) => {
2166
+ wasmTable.set(idx, func2);
2167
+ wasmTableMirror[idx] = wasmTable.get(idx);
2168
+ }, "setWasmTableEntry");
2169
+ var addFunction = /* @__PURE__ */ __name((func2, sig) => {
2170
+ var rtn = getFunctionAddress(func2);
2171
+ if (rtn) {
2172
+ return rtn;
2173
+ }
2174
+ var ret = getEmptyTableSlot();
2175
+ try {
2176
+ setWasmTableEntry(ret, func2);
2177
+ } catch (err2) {
2178
+ if (!(err2 instanceof TypeError)) {
2179
+ throw err2;
2180
+ }
2181
+ var wrapped = convertJsFunctionToWasm(func2, sig);
2182
+ setWasmTableEntry(ret, wrapped);
2183
+ }
2184
+ functionsInTableMap.set(func2, ret);
2185
+ return ret;
2186
+ }, "addFunction");
2187
+ var updateGOT = /* @__PURE__ */ __name((exports, replace) => {
2188
+ for (var symName in exports) {
2189
+ if (isInternalSym(symName)) {
2190
+ continue;
2191
+ }
2192
+ var value = exports[symName];
2193
+ GOT[symName] ||= new WebAssembly.Global({
2194
+ "value": "i32",
2195
+ "mutable": true
2196
+ });
2197
+ if (replace || GOT[symName].value == 0) {
2198
+ if (typeof value == "function") {
2199
+ GOT[symName].value = addFunction(value);
2200
+ } else if (typeof value == "number") {
2201
+ GOT[symName].value = value;
2202
+ } else {
2203
+ err(`unhandled export type for '${symName}': ${typeof value}`);
2204
+ }
2205
+ }
2206
+ }
2207
+ }, "updateGOT");
2208
+ var relocateExports = /* @__PURE__ */ __name((exports, memoryBase2, replace) => {
2209
+ var relocated = {};
2210
+ for (var e in exports) {
2211
+ var value = exports[e];
2212
+ if (typeof value == "object") {
2213
+ value = value.value;
2214
+ }
2215
+ if (typeof value == "number") {
2216
+ value += memoryBase2;
2217
+ }
2218
+ relocated[e] = value;
2219
+ }
2220
+ updateGOT(relocated, replace);
2221
+ return relocated;
2222
+ }, "relocateExports");
2223
+ var isSymbolDefined = /* @__PURE__ */ __name((symName) => {
2224
+ var existing = wasmImports[symName];
2225
+ if (!existing || existing.stub) {
2226
+ return false;
2227
+ }
2228
+ return true;
2229
+ }, "isSymbolDefined");
2230
+ var dynCall = /* @__PURE__ */ __name((sig, ptr, args2 = [], promising = false) => {
2231
+ var func2 = getWasmTableEntry(ptr);
2232
+ var rtn = func2(...args2);
2233
+ function convert(rtn2) {
2234
+ return rtn2;
2235
+ }
2236
+ __name(convert, "convert");
2237
+ return convert(rtn);
2238
+ }, "dynCall");
2239
+ var stackSave = /* @__PURE__ */ __name(() => _emscripten_stack_get_current(), "stackSave");
2240
+ var stackRestore = /* @__PURE__ */ __name((val) => __emscripten_stack_restore(val), "stackRestore");
2241
+ var createInvokeFunction = /* @__PURE__ */ __name((sig) => (ptr, ...args2) => {
2242
+ var sp = stackSave();
2243
+ try {
2244
+ return dynCall(sig, ptr, args2);
2245
+ } catch (e) {
2246
+ stackRestore(sp);
2247
+ if (e !== e + 0) throw e;
2248
+ _setThrew(1, 0);
2249
+ if (sig[0] == "j") return 0n;
2250
+ }
2251
+ }, "createInvokeFunction");
2252
+ var resolveGlobalSymbol = /* @__PURE__ */ __name((symName, direct = false) => {
2253
+ var sym;
2254
+ if (isSymbolDefined(symName)) {
2255
+ sym = wasmImports[symName];
2256
+ } else if (symName.startsWith("invoke_")) {
2257
+ sym = wasmImports[symName] = createInvokeFunction(symName.split("_")[1]);
2258
+ }
2259
+ return {
2260
+ sym,
2261
+ name: symName
2262
+ };
2263
+ }, "resolveGlobalSymbol");
2264
+ var onPostCtors = [];
2265
+ var addOnPostCtor = /* @__PURE__ */ __name((cb) => onPostCtors.push(cb), "addOnPostCtor");
2266
+ var UTF8ToString = /* @__PURE__ */ __name((ptr, maxBytesToRead, ignoreNul) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : "", "UTF8ToString");
2267
+ var loadWebAssemblyModule = /* @__PURE__ */ __name((binary, flags, libName, localScope, handle) => {
2268
+ var metadata = getDylinkMetadata(binary);
2269
+ function loadModule() {
2270
+ var memAlign = Math.pow(2, metadata.memoryAlign);
2271
+ var memoryBase = metadata.memorySize ? alignMemory(getMemory(metadata.memorySize + memAlign), memAlign) : 0;
2272
+ var tableBase = metadata.tableSize ? wasmTable.length : 0;
2273
+ if (handle) {
2274
+ HEAP8[handle + 8] = 1;
2275
+ LE_HEAP_STORE_U32((handle + 12 >> 2) * 4, memoryBase);
2276
+ LE_HEAP_STORE_I32((handle + 16 >> 2) * 4, metadata.memorySize);
2277
+ LE_HEAP_STORE_U32((handle + 20 >> 2) * 4, tableBase);
2278
+ LE_HEAP_STORE_I32((handle + 24 >> 2) * 4, metadata.tableSize);
2279
+ }
2280
+ if (metadata.tableSize) {
2281
+ wasmTable.grow(metadata.tableSize);
2282
+ }
2283
+ var moduleExports;
2284
+ function resolveSymbol(sym) {
2285
+ var resolved = resolveGlobalSymbol(sym).sym;
2286
+ if (!resolved && localScope) {
2287
+ resolved = localScope[sym];
2288
+ }
2289
+ if (!resolved) {
2290
+ resolved = moduleExports[sym];
2291
+ }
2292
+ return resolved;
2293
+ }
2294
+ __name(resolveSymbol, "resolveSymbol");
2295
+ var proxyHandler = {
2296
+ get(stubs, prop) {
2297
+ switch (prop) {
2298
+ case "__memory_base":
2299
+ return memoryBase;
2300
+ case "__table_base":
2301
+ return tableBase;
2302
+ }
2303
+ if (prop in wasmImports && !wasmImports[prop].stub) {
2304
+ var res = wasmImports[prop];
2305
+ return res;
2306
+ }
2307
+ if (!(prop in stubs)) {
2308
+ var resolved;
2309
+ stubs[prop] = (...args2) => {
2310
+ resolved ||= resolveSymbol(prop);
2311
+ return resolved(...args2);
2312
+ };
2313
+ }
2314
+ return stubs[prop];
2315
+ }
2316
+ };
2317
+ var proxy = new Proxy({}, proxyHandler);
2318
+ currentModuleWeakSymbols = metadata.weakImports;
2319
+ var info = {
2320
+ "GOT.mem": new Proxy({}, GOTHandler),
2321
+ "GOT.func": new Proxy({}, GOTHandler),
2322
+ "env": proxy,
2323
+ "wasi_snapshot_preview1": proxy
2324
+ };
2325
+ function postInstantiation(module, instance) {
2326
+ updateTableMap(tableBase, metadata.tableSize);
2327
+ moduleExports = relocateExports(instance.exports, memoryBase);
2328
+ if (!flags.allowUndefined) {
2329
+ reportUndefinedSymbols();
2330
+ }
2331
+ function addEmAsm(addr, body) {
2332
+ var args = [];
2333
+ var arity = 0;
2334
+ for (; arity < 16; arity++) {
2335
+ if (body.indexOf("$" + arity) != -1) {
2336
+ args.push("$" + arity);
2337
+ } else {
2338
+ break;
2339
+ }
2340
+ }
2341
+ args = args.join(",");
2342
+ var func = `(${args}) => { ${body} };`;
2343
+ ASM_CONSTS[start] = eval(func);
2344
+ }
2345
+ __name(addEmAsm, "addEmAsm");
2346
+ if ("__start_em_asm" in moduleExports) {
2347
+ var start = moduleExports["__start_em_asm"];
2348
+ var stop = moduleExports["__stop_em_asm"];
2349
+ while (start < stop) {
2350
+ var jsString = UTF8ToString(start);
2351
+ addEmAsm(start, jsString);
2352
+ start = HEAPU8.indexOf(0, start) + 1;
2353
+ }
2354
+ }
2355
+ function addEmJs(name, cSig, body) {
2356
+ var jsArgs = [];
2357
+ cSig = cSig.slice(1, -1);
2358
+ if (cSig != "void") {
2359
+ cSig = cSig.split(",");
2360
+ for (var i in cSig) {
2361
+ var jsArg = cSig[i].split(" ").pop();
2362
+ jsArgs.push(jsArg.replace("*", ""));
2363
+ }
2364
+ }
2365
+ var func = `(${jsArgs}) => ${body};`;
2366
+ moduleExports[name] = eval(func);
2367
+ }
2368
+ __name(addEmJs, "addEmJs");
2369
+ for (var name in moduleExports) {
2370
+ if (name.startsWith("__em_js__")) {
2371
+ var start = moduleExports[name];
2372
+ var jsString = UTF8ToString(start);
2373
+ var parts = jsString.split("<::>");
2374
+ addEmJs(name.replace("__em_js__", ""), parts[0], parts[1]);
2375
+ delete moduleExports[name];
2376
+ }
2377
+ }
2378
+ var applyRelocs = moduleExports["__wasm_apply_data_relocs"];
2379
+ if (applyRelocs) {
2380
+ if (runtimeInitialized) {
2381
+ applyRelocs();
2382
+ } else {
2383
+ __RELOC_FUNCS__.push(applyRelocs);
2384
+ }
2385
+ }
2386
+ var init = moduleExports["__wasm_call_ctors"];
2387
+ if (init) {
2388
+ if (runtimeInitialized) {
2389
+ init();
2390
+ } else {
2391
+ addOnPostCtor(init);
2392
+ }
2393
+ }
2394
+ return moduleExports;
2395
+ }
2396
+ __name(postInstantiation, "postInstantiation");
2397
+ if (flags.loadAsync) {
2398
+ return (async () => {
2399
+ var instance2;
2400
+ if (binary instanceof WebAssembly.Module) {
2401
+ instance2 = new WebAssembly.Instance(binary, info);
2402
+ } else {
2403
+ ({ module: binary, instance: instance2 } = await WebAssembly.instantiate(binary, info));
2404
+ }
2405
+ return postInstantiation(binary, instance2);
2406
+ })();
2407
+ }
2408
+ var module = binary instanceof WebAssembly.Module ? binary : new WebAssembly.Module(binary);
2409
+ var instance = new WebAssembly.Instance(module, info);
2410
+ return postInstantiation(module, instance);
2411
+ }
2412
+ __name(loadModule, "loadModule");
2413
+ flags = {
2414
+ ...flags,
2415
+ rpath: {
2416
+ parentLibPath: libName,
2417
+ paths: metadata.runtimePaths
2418
+ }
2419
+ };
2420
+ if (flags.loadAsync) {
2421
+ return metadata.neededDynlibs.reduce((chain, dynNeeded) => chain.then(() => loadDynamicLibrary(dynNeeded, flags, localScope)), Promise.resolve()).then(loadModule);
2422
+ }
2423
+ metadata.neededDynlibs.forEach((needed) => loadDynamicLibrary(needed, flags, localScope));
2424
+ return loadModule();
2425
+ }, "loadWebAssemblyModule");
2426
+ var mergeLibSymbols = /* @__PURE__ */ __name((exports, libName2) => {
2427
+ for (var [sym, exp] of Object.entries(exports)) {
2428
+ const setImport = /* @__PURE__ */ __name((target) => {
2429
+ if (!isSymbolDefined(target)) {
2430
+ wasmImports[target] = exp;
2431
+ }
2432
+ }, "setImport");
2433
+ setImport(sym);
2434
+ const main_alias = "__main_argc_argv";
2435
+ if (sym == "main") {
2436
+ setImport(main_alias);
2437
+ }
2438
+ if (sym == main_alias) {
2439
+ setImport("main");
2440
+ }
2441
+ }
2442
+ }, "mergeLibSymbols");
2443
+ var asyncLoad = /* @__PURE__ */ __name(async (url) => {
2444
+ var arrayBuffer = await readAsync(url);
2445
+ return new Uint8Array(arrayBuffer);
2446
+ }, "asyncLoad");
2447
+ function loadDynamicLibrary(libName2, flags2 = {
2448
+ global: true,
2449
+ nodelete: true
2450
+ }, localScope2, handle2) {
2451
+ var dso = LDSO.loadedLibsByName[libName2];
2452
+ if (dso) {
2453
+ if (!flags2.global) {
2454
+ if (localScope2) {
2455
+ Object.assign(localScope2, dso.exports);
2456
+ }
2457
+ } else if (!dso.global) {
2458
+ dso.global = true;
2459
+ mergeLibSymbols(dso.exports, libName2);
2460
+ }
2461
+ if (flags2.nodelete && dso.refcount !== Infinity) {
2462
+ dso.refcount = Infinity;
2463
+ }
2464
+ dso.refcount++;
2465
+ if (handle2) {
2466
+ LDSO.loadedLibsByHandle[handle2] = dso;
2467
+ }
2468
+ return flags2.loadAsync ? Promise.resolve(true) : true;
2469
+ }
2470
+ dso = newDSO(libName2, handle2, "loading");
2471
+ dso.refcount = flags2.nodelete ? Infinity : 1;
2472
+ dso.global = flags2.global;
2473
+ function loadLibData() {
2474
+ if (handle2) {
2475
+ var data = LE_HEAP_LOAD_U32((handle2 + 28 >> 2) * 4);
2476
+ var dataSize = LE_HEAP_LOAD_U32((handle2 + 32 >> 2) * 4);
2477
+ if (data && dataSize) {
2478
+ var libData = HEAP8.slice(data, data + dataSize);
2479
+ return flags2.loadAsync ? Promise.resolve(libData) : libData;
2480
+ }
2481
+ }
2482
+ var libFile = locateFile(libName2);
2483
+ if (flags2.loadAsync) {
2484
+ return asyncLoad(libFile);
2485
+ }
2486
+ if (!readBinary) {
2487
+ throw new Error(`${libFile}: file not found, and synchronous loading of external files is not available`);
2488
+ }
2489
+ return readBinary(libFile);
2490
+ }
2491
+ __name(loadLibData, "loadLibData");
2492
+ function getExports() {
2493
+ if (flags2.loadAsync) {
2494
+ return loadLibData().then((libData) => loadWebAssemblyModule(libData, flags2, libName2, localScope2, handle2));
2495
+ }
2496
+ return loadWebAssemblyModule(loadLibData(), flags2, libName2, localScope2, handle2);
2497
+ }
2498
+ __name(getExports, "getExports");
2499
+ function moduleLoaded(exports) {
2500
+ if (dso.global) {
2501
+ mergeLibSymbols(exports, libName2);
2502
+ } else if (localScope2) {
2503
+ Object.assign(localScope2, exports);
2504
+ }
2505
+ dso.exports = exports;
2506
+ }
2507
+ __name(moduleLoaded, "moduleLoaded");
2508
+ if (flags2.loadAsync) {
2509
+ return getExports().then((exports) => {
2510
+ moduleLoaded(exports);
2511
+ return true;
2512
+ });
2513
+ }
2514
+ moduleLoaded(getExports());
2515
+ return true;
2516
+ }
2517
+ __name(loadDynamicLibrary, "loadDynamicLibrary");
2518
+ var reportUndefinedSymbols = /* @__PURE__ */ __name(() => {
2519
+ for (var [symName, entry] of Object.entries(GOT)) {
2520
+ if (entry.value == 0) {
2521
+ var value = resolveGlobalSymbol(symName, true).sym;
2522
+ if (!value && !entry.required) {
2523
+ continue;
2524
+ }
2525
+ if (typeof value == "function") {
2526
+ entry.value = addFunction(value, value.sig);
2527
+ } else if (typeof value == "number") {
2528
+ entry.value = value;
2529
+ } else {
2530
+ throw new Error(`bad export type for '${symName}': ${typeof value}`);
2531
+ }
2532
+ }
2533
+ }
2534
+ }, "reportUndefinedSymbols");
2535
+ var runDependencies = 0;
2536
+ var dependenciesFulfilled = null;
2537
+ var removeRunDependency = /* @__PURE__ */ __name((id) => {
2538
+ runDependencies--;
2539
+ Module["monitorRunDependencies"]?.(runDependencies);
2540
+ if (runDependencies == 0) {
2541
+ if (dependenciesFulfilled) {
2542
+ var callback = dependenciesFulfilled;
2543
+ dependenciesFulfilled = null;
2544
+ callback();
2545
+ }
2546
+ }
2547
+ }, "removeRunDependency");
2548
+ var addRunDependency = /* @__PURE__ */ __name((id) => {
2549
+ runDependencies++;
2550
+ Module["monitorRunDependencies"]?.(runDependencies);
2551
+ }, "addRunDependency");
2552
+ var loadDylibs = /* @__PURE__ */ __name(async () => {
2553
+ if (!dynamicLibraries.length) {
2554
+ reportUndefinedSymbols();
2555
+ return;
2556
+ }
2557
+ addRunDependency("loadDylibs");
2558
+ for (var lib of dynamicLibraries) {
2559
+ await loadDynamicLibrary(lib, {
2560
+ loadAsync: true,
2561
+ global: true,
2562
+ nodelete: true,
2563
+ allowUndefined: true
2564
+ });
2565
+ }
2566
+ reportUndefinedSymbols();
2567
+ removeRunDependency("loadDylibs");
2568
+ }, "loadDylibs");
2569
+ var noExitRuntime = true;
2570
+ function setValue(ptr, value, type = "i8") {
2571
+ if (type.endsWith("*")) type = "*";
2572
+ switch (type) {
2573
+ case "i1":
2574
+ HEAP8[ptr] = value;
2575
+ break;
2576
+ case "i8":
2577
+ HEAP8[ptr] = value;
2578
+ break;
2579
+ case "i16":
2580
+ LE_HEAP_STORE_I16((ptr >> 1) * 2, value);
2581
+ break;
2582
+ case "i32":
2583
+ LE_HEAP_STORE_I32((ptr >> 2) * 4, value);
2584
+ break;
2585
+ case "i64":
2586
+ LE_HEAP_STORE_I64((ptr >> 3) * 8, BigInt(value));
2587
+ break;
2588
+ case "float":
2589
+ LE_HEAP_STORE_F32((ptr >> 2) * 4, value);
2590
+ break;
2591
+ case "double":
2592
+ LE_HEAP_STORE_F64((ptr >> 3) * 8, value);
2593
+ break;
2594
+ case "*":
2595
+ LE_HEAP_STORE_U32((ptr >> 2) * 4, value);
2596
+ break;
2597
+ default:
2598
+ abort(`invalid type for setValue: ${type}`);
2599
+ }
2600
+ }
2601
+ __name(setValue, "setValue");
2602
+ var ___memory_base = new WebAssembly.Global({
2603
+ "value": "i32",
2604
+ "mutable": false
2605
+ }, 1024);
2606
+ var ___stack_high = 78240;
2607
+ var ___stack_low = 12704;
2608
+ var ___stack_pointer = new WebAssembly.Global({
2609
+ "value": "i32",
2610
+ "mutable": true
2611
+ }, 78240);
2612
+ var ___table_base = new WebAssembly.Global({
2613
+ "value": "i32",
2614
+ "mutable": false
2615
+ }, 1);
2616
+ var __abort_js = /* @__PURE__ */ __name(() => abort(""), "__abort_js");
2617
+ __abort_js.sig = "v";
2618
+ var getHeapMax = /* @__PURE__ */ __name(() => (
2619
+ // Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate
2620
+ // full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side
2621
+ // for any code that deals with heap sizes, which would require special
2622
+ // casing all heap size related code to treat 0 specially.
2623
+ 2147483648
2624
+ ), "getHeapMax");
2625
+ var growMemory = /* @__PURE__ */ __name((size) => {
2626
+ var oldHeapSize = wasmMemory.buffer.byteLength;
2627
+ var pages = (size - oldHeapSize + 65535) / 65536 | 0;
2628
+ try {
2629
+ wasmMemory.grow(pages);
2630
+ updateMemoryViews();
2631
+ return 1;
2632
+ } catch (e) {
2633
+ }
2634
+ }, "growMemory");
2635
+ var _emscripten_resize_heap = /* @__PURE__ */ __name((requestedSize) => {
2636
+ var oldSize = HEAPU8.length;
2637
+ requestedSize >>>= 0;
2638
+ var maxHeapSize = getHeapMax();
2639
+ if (requestedSize > maxHeapSize) {
2640
+ return false;
2641
+ }
2642
+ for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
2643
+ var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown);
2644
+ overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296);
2645
+ var newSize = Math.min(maxHeapSize, alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536));
2646
+ var replacement = growMemory(newSize);
2647
+ if (replacement) {
2648
+ return true;
2649
+ }
2650
+ }
2651
+ return false;
2652
+ }, "_emscripten_resize_heap");
2653
+ _emscripten_resize_heap.sig = "ip";
2654
+ var _fd_close = /* @__PURE__ */ __name((fd) => 52, "_fd_close");
2655
+ _fd_close.sig = "ii";
2656
+ var INT53_MAX = 9007199254740992;
2657
+ var INT53_MIN = -9007199254740992;
2658
+ var bigintToI53Checked = /* @__PURE__ */ __name((num) => num < INT53_MIN || num > INT53_MAX ? NaN : Number(num), "bigintToI53Checked");
2659
+ function _fd_seek(fd, offset, whence, newOffset) {
2660
+ offset = bigintToI53Checked(offset);
2661
+ return 70;
2662
+ }
2663
+ __name(_fd_seek, "_fd_seek");
2664
+ _fd_seek.sig = "iijip";
2665
+ var printCharBuffers = [null, [], []];
2666
+ var printChar = /* @__PURE__ */ __name((stream, curr) => {
2667
+ var buffer = printCharBuffers[stream];
2668
+ if (curr === 0 || curr === 10) {
2669
+ (stream === 1 ? out : err)(UTF8ArrayToString(buffer));
2670
+ buffer.length = 0;
2671
+ } else {
2672
+ buffer.push(curr);
2673
+ }
2674
+ }, "printChar");
2675
+ var _fd_write = /* @__PURE__ */ __name((fd, iov, iovcnt, pnum) => {
2676
+ var num = 0;
2677
+ for (var i2 = 0; i2 < iovcnt; i2++) {
2678
+ var ptr = LE_HEAP_LOAD_U32((iov >> 2) * 4);
2679
+ var len = LE_HEAP_LOAD_U32((iov + 4 >> 2) * 4);
2680
+ iov += 8;
2681
+ for (var j = 0; j < len; j++) {
2682
+ printChar(fd, HEAPU8[ptr + j]);
2683
+ }
2684
+ num += len;
2685
+ }
2686
+ LE_HEAP_STORE_U32((pnum >> 2) * 4, num);
2687
+ return 0;
2688
+ }, "_fd_write");
2689
+ _fd_write.sig = "iippp";
2690
+ function _tree_sitter_log_callback(isLexMessage, messageAddress) {
2691
+ if (Module.currentLogCallback) {
2692
+ const message = UTF8ToString(messageAddress);
2693
+ Module.currentLogCallback(message, isLexMessage !== 0);
2694
+ }
2695
+ }
2696
+ __name(_tree_sitter_log_callback, "_tree_sitter_log_callback");
2697
+ function _tree_sitter_parse_callback(inputBufferAddress, index, row, column, lengthAddress) {
2698
+ const INPUT_BUFFER_SIZE = 10 * 1024;
2699
+ const string = Module.currentParseCallback(index, {
2700
+ row,
2701
+ column
2702
+ });
2703
+ if (typeof string === "string") {
2704
+ setValue(lengthAddress, string.length, "i32");
2705
+ stringToUTF16(string, inputBufferAddress, INPUT_BUFFER_SIZE);
2706
+ } else {
2707
+ setValue(lengthAddress, 0, "i32");
2708
+ }
2709
+ }
2710
+ __name(_tree_sitter_parse_callback, "_tree_sitter_parse_callback");
2711
+ function _tree_sitter_progress_callback(currentOffset, hasError) {
2712
+ if (Module.currentProgressCallback) {
2713
+ return Module.currentProgressCallback({
2714
+ currentOffset,
2715
+ hasError
2716
+ });
2717
+ }
2718
+ return false;
2719
+ }
2720
+ __name(_tree_sitter_progress_callback, "_tree_sitter_progress_callback");
2721
+ function _tree_sitter_query_progress_callback(currentOffset) {
2722
+ if (Module.currentQueryProgressCallback) {
2723
+ return Module.currentQueryProgressCallback({
2724
+ currentOffset
2725
+ });
2726
+ }
2727
+ return false;
2728
+ }
2729
+ __name(_tree_sitter_query_progress_callback, "_tree_sitter_query_progress_callback");
2730
+ var runtimeKeepaliveCounter = 0;
2731
+ var keepRuntimeAlive = /* @__PURE__ */ __name(() => noExitRuntime || runtimeKeepaliveCounter > 0, "keepRuntimeAlive");
2732
+ var _proc_exit = /* @__PURE__ */ __name((code) => {
2733
+ EXITSTATUS = code;
2734
+ if (!keepRuntimeAlive()) {
2735
+ Module["onExit"]?.(code);
2736
+ ABORT = true;
2737
+ }
2738
+ quit_(code, new ExitStatus(code));
2739
+ }, "_proc_exit");
2740
+ _proc_exit.sig = "vi";
2741
+ var exitJS = /* @__PURE__ */ __name((status, implicit) => {
2742
+ EXITSTATUS = status;
2743
+ _proc_exit(status);
2744
+ }, "exitJS");
2745
+ var handleException = /* @__PURE__ */ __name((e) => {
2746
+ if (e instanceof ExitStatus || e == "unwind") {
2747
+ return EXITSTATUS;
2748
+ }
2749
+ quit_(1, e);
2750
+ }, "handleException");
2751
+ var lengthBytesUTF8 = /* @__PURE__ */ __name((str) => {
2752
+ var len = 0;
2753
+ for (var i2 = 0; i2 < str.length; ++i2) {
2754
+ var c = str.charCodeAt(i2);
2755
+ if (c <= 127) {
2756
+ len++;
2757
+ } else if (c <= 2047) {
2758
+ len += 2;
2759
+ } else if (c >= 55296 && c <= 57343) {
2760
+ len += 4;
2761
+ ++i2;
2762
+ } else {
2763
+ len += 3;
2764
+ }
2765
+ }
2766
+ return len;
2767
+ }, "lengthBytesUTF8");
2768
+ var stringToUTF8Array = /* @__PURE__ */ __name((str, heap, outIdx, maxBytesToWrite) => {
2769
+ if (!(maxBytesToWrite > 0)) return 0;
2770
+ var startIdx = outIdx;
2771
+ var endIdx = outIdx + maxBytesToWrite - 1;
2772
+ for (var i2 = 0; i2 < str.length; ++i2) {
2773
+ var u = str.codePointAt(i2);
2774
+ if (u <= 127) {
2775
+ if (outIdx >= endIdx) break;
2776
+ heap[outIdx++] = u;
2777
+ } else if (u <= 2047) {
2778
+ if (outIdx + 1 >= endIdx) break;
2779
+ heap[outIdx++] = 192 | u >> 6;
2780
+ heap[outIdx++] = 128 | u & 63;
2781
+ } else if (u <= 65535) {
2782
+ if (outIdx + 2 >= endIdx) break;
2783
+ heap[outIdx++] = 224 | u >> 12;
2784
+ heap[outIdx++] = 128 | u >> 6 & 63;
2785
+ heap[outIdx++] = 128 | u & 63;
2786
+ } else {
2787
+ if (outIdx + 3 >= endIdx) break;
2788
+ heap[outIdx++] = 240 | u >> 18;
2789
+ heap[outIdx++] = 128 | u >> 12 & 63;
2790
+ heap[outIdx++] = 128 | u >> 6 & 63;
2791
+ heap[outIdx++] = 128 | u & 63;
2792
+ i2++;
2793
+ }
2794
+ }
2795
+ heap[outIdx] = 0;
2796
+ return outIdx - startIdx;
2797
+ }, "stringToUTF8Array");
2798
+ var stringToUTF8 = /* @__PURE__ */ __name((str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite), "stringToUTF8");
2799
+ var stackAlloc = /* @__PURE__ */ __name((sz) => __emscripten_stack_alloc(sz), "stackAlloc");
2800
+ var stringToUTF8OnStack = /* @__PURE__ */ __name((str) => {
2801
+ var size = lengthBytesUTF8(str) + 1;
2802
+ var ret = stackAlloc(size);
2803
+ stringToUTF8(str, ret, size);
2804
+ return ret;
2805
+ }, "stringToUTF8OnStack");
2806
+ var AsciiToString = /* @__PURE__ */ __name((ptr) => {
2807
+ var str = "";
2808
+ while (1) {
2809
+ var ch = HEAPU8[ptr++];
2810
+ if (!ch) return str;
2811
+ str += String.fromCharCode(ch);
2812
+ }
2813
+ }, "AsciiToString");
2814
+ var stringToUTF16 = /* @__PURE__ */ __name((str, outPtr, maxBytesToWrite) => {
2815
+ maxBytesToWrite ??= 2147483647;
2816
+ if (maxBytesToWrite < 2) return 0;
2817
+ maxBytesToWrite -= 2;
2818
+ var startPtr = outPtr;
2819
+ var numCharsToWrite = maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length;
2820
+ for (var i2 = 0; i2 < numCharsToWrite; ++i2) {
2821
+ var codeUnit = str.charCodeAt(i2);
2822
+ LE_HEAP_STORE_I16((outPtr >> 1) * 2, codeUnit);
2823
+ outPtr += 2;
2824
+ }
2825
+ LE_HEAP_STORE_I16((outPtr >> 1) * 2, 0);
2826
+ return outPtr - startPtr;
2827
+ }, "stringToUTF16");
2828
+ LE_ATOMICS_NATIVE_BYTE_ORDER = new Int8Array(new Int16Array([1]).buffer)[0] === 1 ? [
2829
+ /* little endian */
2830
+ ((x) => x),
2831
+ ((x) => x),
2832
+ void 0,
2833
+ ((x) => x)
2834
+ ] : [
2835
+ /* big endian */
2836
+ ((x) => x),
2837
+ ((x) => ((x & 65280) << 8 | (x & 255) << 24) >> 16),
2838
+ void 0,
2839
+ ((x) => x >> 24 & 255 | x >> 8 & 65280 | (x & 65280) << 8 | (x & 255) << 24)
2840
+ ];
2841
+ function LE_HEAP_UPDATE() {
2842
+ HEAPU16.unsigned = ((x) => x & 65535);
2843
+ HEAPU32.unsigned = ((x) => x >>> 0);
2844
+ }
2845
+ __name(LE_HEAP_UPDATE, "LE_HEAP_UPDATE");
2846
+ {
2847
+ initMemory();
2848
+ if (Module["noExitRuntime"]) noExitRuntime = Module["noExitRuntime"];
2849
+ if (Module["print"]) out = Module["print"];
2850
+ if (Module["printErr"]) err = Module["printErr"];
2851
+ if (Module["dynamicLibraries"]) dynamicLibraries = Module["dynamicLibraries"];
2852
+ if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
2853
+ if (Module["arguments"]) arguments_ = Module["arguments"];
2854
+ if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
2855
+ if (Module["preInit"]) {
2856
+ if (typeof Module["preInit"] == "function") Module["preInit"] = [Module["preInit"]];
2857
+ while (Module["preInit"].length > 0) {
2858
+ Module["preInit"].shift()();
2859
+ }
2860
+ }
2861
+ }
2862
+ Module["setValue"] = setValue;
2863
+ Module["getValue"] = getValue;
2864
+ Module["UTF8ToString"] = UTF8ToString;
2865
+ Module["stringToUTF8"] = stringToUTF8;
2866
+ Module["lengthBytesUTF8"] = lengthBytesUTF8;
2867
+ Module["AsciiToString"] = AsciiToString;
2868
+ Module["stringToUTF16"] = stringToUTF16;
2869
+ Module["loadWebAssemblyModule"] = loadWebAssemblyModule;
2870
+ Module["LE_HEAP_STORE_I64"] = LE_HEAP_STORE_I64;
2871
+ var ASM_CONSTS = {};
2872
+ var _malloc, _calloc, _realloc, _free, _ts_range_edit, _memcmp, _ts_language_symbol_count, _ts_language_state_count, _ts_language_abi_version, _ts_language_name, _ts_language_field_count, _ts_language_next_state, _ts_language_symbol_name, _ts_language_symbol_for_name, _strncmp, _ts_language_symbol_type, _ts_language_field_name_for_id, _ts_lookahead_iterator_new, _ts_lookahead_iterator_delete, _ts_lookahead_iterator_reset_state, _ts_lookahead_iterator_reset, _ts_lookahead_iterator_next, _ts_lookahead_iterator_current_symbol, _ts_point_edit, _ts_parser_delete, _ts_parser_reset, _ts_parser_set_language, _ts_parser_set_included_ranges, _ts_query_new, _ts_query_delete, _iswspace, _iswalnum, _ts_query_pattern_count, _ts_query_capture_count, _ts_query_string_count, _ts_query_capture_name_for_id, _ts_query_capture_quantifier_for_id, _ts_query_string_value_for_id, _ts_query_predicates_for_pattern, _ts_query_start_byte_for_pattern, _ts_query_end_byte_for_pattern, _ts_query_is_pattern_rooted, _ts_query_is_pattern_non_local, _ts_query_is_pattern_guaranteed_at_step, _ts_query_disable_capture, _ts_query_disable_pattern, _ts_tree_copy, _ts_tree_delete, _ts_init, _ts_parser_new_wasm, _ts_parser_enable_logger_wasm, _ts_parser_parse_wasm, _ts_parser_included_ranges_wasm, _ts_language_type_is_named_wasm, _ts_language_type_is_visible_wasm, _ts_language_metadata_wasm, _ts_language_supertypes_wasm, _ts_language_subtypes_wasm, _ts_tree_root_node_wasm, _ts_tree_root_node_with_offset_wasm, _ts_tree_edit_wasm, _ts_tree_included_ranges_wasm, _ts_tree_get_changed_ranges_wasm, _ts_tree_cursor_new_wasm, _ts_tree_cursor_copy_wasm, _ts_tree_cursor_delete_wasm, _ts_tree_cursor_reset_wasm, _ts_tree_cursor_reset_to_wasm, _ts_tree_cursor_goto_first_child_wasm, _ts_tree_cursor_goto_last_child_wasm, _ts_tree_cursor_goto_first_child_for_index_wasm, _ts_tree_cursor_goto_first_child_for_position_wasm, _ts_tree_cursor_goto_next_sibling_wasm, _ts_tree_cursor_goto_previous_sibling_wasm, _ts_tree_cursor_goto_descendant_wasm, _ts_tree_cursor_goto_parent_wasm, _ts_tree_cursor_current_node_type_id_wasm, _ts_tree_cursor_current_node_state_id_wasm, _ts_tree_cursor_current_node_is_named_wasm, _ts_tree_cursor_current_node_is_missing_wasm, _ts_tree_cursor_current_node_id_wasm, _ts_tree_cursor_start_position_wasm, _ts_tree_cursor_end_position_wasm, _ts_tree_cursor_start_index_wasm, _ts_tree_cursor_end_index_wasm, _ts_tree_cursor_current_field_id_wasm, _ts_tree_cursor_current_depth_wasm, _ts_tree_cursor_current_descendant_index_wasm, _ts_tree_cursor_current_node_wasm, _ts_node_symbol_wasm, _ts_node_field_name_for_child_wasm, _ts_node_field_name_for_named_child_wasm, _ts_node_children_by_field_id_wasm, _ts_node_first_child_for_byte_wasm, _ts_node_first_named_child_for_byte_wasm, _ts_node_grammar_symbol_wasm, _ts_node_child_count_wasm, _ts_node_named_child_count_wasm, _ts_node_child_wasm, _ts_node_named_child_wasm, _ts_node_child_by_field_id_wasm, _ts_node_next_sibling_wasm, _ts_node_prev_sibling_wasm, _ts_node_next_named_sibling_wasm, _ts_node_prev_named_sibling_wasm, _ts_node_descendant_count_wasm, _ts_node_parent_wasm, _ts_node_child_with_descendant_wasm, _ts_node_descendant_for_index_wasm, _ts_node_named_descendant_for_index_wasm, _ts_node_descendant_for_position_wasm, _ts_node_named_descendant_for_position_wasm, _ts_node_start_point_wasm, _ts_node_end_point_wasm, _ts_node_start_index_wasm, _ts_node_end_index_wasm, _ts_node_to_string_wasm, _ts_node_children_wasm, _ts_node_named_children_wasm, _ts_node_descendants_of_type_wasm, _ts_node_is_named_wasm, _ts_node_has_changes_wasm, _ts_node_has_error_wasm, _ts_node_is_error_wasm, _ts_node_is_missing_wasm, _ts_node_is_extra_wasm, _ts_node_parse_state_wasm, _ts_node_next_parse_state_wasm, _ts_query_matches_wasm, _ts_query_captures_wasm, _memset, _memcpy, _memmove, _iswalpha, _iswblank, _iswdigit, _iswlower, _iswupper, _iswxdigit, _memchr, _strlen, _strcmp, _strncat, _strncpy, _towlower, _towupper, _setThrew, __emscripten_stack_restore, __emscripten_stack_alloc, _emscripten_stack_get_current, ___wasm_apply_data_relocs;
2873
+ function assignWasmExports(wasmExports2) {
2874
+ Module["_malloc"] = _malloc = wasmExports2["malloc"];
2875
+ Module["_calloc"] = _calloc = wasmExports2["calloc"];
2876
+ Module["_realloc"] = _realloc = wasmExports2["realloc"];
2877
+ Module["_free"] = _free = wasmExports2["free"];
2878
+ Module["_ts_range_edit"] = _ts_range_edit = wasmExports2["ts_range_edit"];
2879
+ Module["_memcmp"] = _memcmp = wasmExports2["memcmp"];
2880
+ Module["_ts_language_symbol_count"] = _ts_language_symbol_count = wasmExports2["ts_language_symbol_count"];
2881
+ Module["_ts_language_state_count"] = _ts_language_state_count = wasmExports2["ts_language_state_count"];
2882
+ Module["_ts_language_abi_version"] = _ts_language_abi_version = wasmExports2["ts_language_abi_version"];
2883
+ Module["_ts_language_name"] = _ts_language_name = wasmExports2["ts_language_name"];
2884
+ Module["_ts_language_field_count"] = _ts_language_field_count = wasmExports2["ts_language_field_count"];
2885
+ Module["_ts_language_next_state"] = _ts_language_next_state = wasmExports2["ts_language_next_state"];
2886
+ Module["_ts_language_symbol_name"] = _ts_language_symbol_name = wasmExports2["ts_language_symbol_name"];
2887
+ Module["_ts_language_symbol_for_name"] = _ts_language_symbol_for_name = wasmExports2["ts_language_symbol_for_name"];
2888
+ Module["_strncmp"] = _strncmp = wasmExports2["strncmp"];
2889
+ Module["_ts_language_symbol_type"] = _ts_language_symbol_type = wasmExports2["ts_language_symbol_type"];
2890
+ Module["_ts_language_field_name_for_id"] = _ts_language_field_name_for_id = wasmExports2["ts_language_field_name_for_id"];
2891
+ Module["_ts_lookahead_iterator_new"] = _ts_lookahead_iterator_new = wasmExports2["ts_lookahead_iterator_new"];
2892
+ Module["_ts_lookahead_iterator_delete"] = _ts_lookahead_iterator_delete = wasmExports2["ts_lookahead_iterator_delete"];
2893
+ Module["_ts_lookahead_iterator_reset_state"] = _ts_lookahead_iterator_reset_state = wasmExports2["ts_lookahead_iterator_reset_state"];
2894
+ Module["_ts_lookahead_iterator_reset"] = _ts_lookahead_iterator_reset = wasmExports2["ts_lookahead_iterator_reset"];
2895
+ Module["_ts_lookahead_iterator_next"] = _ts_lookahead_iterator_next = wasmExports2["ts_lookahead_iterator_next"];
2896
+ Module["_ts_lookahead_iterator_current_symbol"] = _ts_lookahead_iterator_current_symbol = wasmExports2["ts_lookahead_iterator_current_symbol"];
2897
+ Module["_ts_point_edit"] = _ts_point_edit = wasmExports2["ts_point_edit"];
2898
+ Module["_ts_parser_delete"] = _ts_parser_delete = wasmExports2["ts_parser_delete"];
2899
+ Module["_ts_parser_reset"] = _ts_parser_reset = wasmExports2["ts_parser_reset"];
2900
+ Module["_ts_parser_set_language"] = _ts_parser_set_language = wasmExports2["ts_parser_set_language"];
2901
+ Module["_ts_parser_set_included_ranges"] = _ts_parser_set_included_ranges = wasmExports2["ts_parser_set_included_ranges"];
2902
+ Module["_ts_query_new"] = _ts_query_new = wasmExports2["ts_query_new"];
2903
+ Module["_ts_query_delete"] = _ts_query_delete = wasmExports2["ts_query_delete"];
2904
+ Module["_iswspace"] = _iswspace = wasmExports2["iswspace"];
2905
+ Module["_iswalnum"] = _iswalnum = wasmExports2["iswalnum"];
2906
+ Module["_ts_query_pattern_count"] = _ts_query_pattern_count = wasmExports2["ts_query_pattern_count"];
2907
+ Module["_ts_query_capture_count"] = _ts_query_capture_count = wasmExports2["ts_query_capture_count"];
2908
+ Module["_ts_query_string_count"] = _ts_query_string_count = wasmExports2["ts_query_string_count"];
2909
+ Module["_ts_query_capture_name_for_id"] = _ts_query_capture_name_for_id = wasmExports2["ts_query_capture_name_for_id"];
2910
+ Module["_ts_query_capture_quantifier_for_id"] = _ts_query_capture_quantifier_for_id = wasmExports2["ts_query_capture_quantifier_for_id"];
2911
+ Module["_ts_query_string_value_for_id"] = _ts_query_string_value_for_id = wasmExports2["ts_query_string_value_for_id"];
2912
+ Module["_ts_query_predicates_for_pattern"] = _ts_query_predicates_for_pattern = wasmExports2["ts_query_predicates_for_pattern"];
2913
+ Module["_ts_query_start_byte_for_pattern"] = _ts_query_start_byte_for_pattern = wasmExports2["ts_query_start_byte_for_pattern"];
2914
+ Module["_ts_query_end_byte_for_pattern"] = _ts_query_end_byte_for_pattern = wasmExports2["ts_query_end_byte_for_pattern"];
2915
+ Module["_ts_query_is_pattern_rooted"] = _ts_query_is_pattern_rooted = wasmExports2["ts_query_is_pattern_rooted"];
2916
+ Module["_ts_query_is_pattern_non_local"] = _ts_query_is_pattern_non_local = wasmExports2["ts_query_is_pattern_non_local"];
2917
+ Module["_ts_query_is_pattern_guaranteed_at_step"] = _ts_query_is_pattern_guaranteed_at_step = wasmExports2["ts_query_is_pattern_guaranteed_at_step"];
2918
+ Module["_ts_query_disable_capture"] = _ts_query_disable_capture = wasmExports2["ts_query_disable_capture"];
2919
+ Module["_ts_query_disable_pattern"] = _ts_query_disable_pattern = wasmExports2["ts_query_disable_pattern"];
2920
+ Module["_ts_tree_copy"] = _ts_tree_copy = wasmExports2["ts_tree_copy"];
2921
+ Module["_ts_tree_delete"] = _ts_tree_delete = wasmExports2["ts_tree_delete"];
2922
+ Module["_ts_init"] = _ts_init = wasmExports2["ts_init"];
2923
+ Module["_ts_parser_new_wasm"] = _ts_parser_new_wasm = wasmExports2["ts_parser_new_wasm"];
2924
+ Module["_ts_parser_enable_logger_wasm"] = _ts_parser_enable_logger_wasm = wasmExports2["ts_parser_enable_logger_wasm"];
2925
+ Module["_ts_parser_parse_wasm"] = _ts_parser_parse_wasm = wasmExports2["ts_parser_parse_wasm"];
2926
+ Module["_ts_parser_included_ranges_wasm"] = _ts_parser_included_ranges_wasm = wasmExports2["ts_parser_included_ranges_wasm"];
2927
+ Module["_ts_language_type_is_named_wasm"] = _ts_language_type_is_named_wasm = wasmExports2["ts_language_type_is_named_wasm"];
2928
+ Module["_ts_language_type_is_visible_wasm"] = _ts_language_type_is_visible_wasm = wasmExports2["ts_language_type_is_visible_wasm"];
2929
+ Module["_ts_language_metadata_wasm"] = _ts_language_metadata_wasm = wasmExports2["ts_language_metadata_wasm"];
2930
+ Module["_ts_language_supertypes_wasm"] = _ts_language_supertypes_wasm = wasmExports2["ts_language_supertypes_wasm"];
2931
+ Module["_ts_language_subtypes_wasm"] = _ts_language_subtypes_wasm = wasmExports2["ts_language_subtypes_wasm"];
2932
+ Module["_ts_tree_root_node_wasm"] = _ts_tree_root_node_wasm = wasmExports2["ts_tree_root_node_wasm"];
2933
+ Module["_ts_tree_root_node_with_offset_wasm"] = _ts_tree_root_node_with_offset_wasm = wasmExports2["ts_tree_root_node_with_offset_wasm"];
2934
+ Module["_ts_tree_edit_wasm"] = _ts_tree_edit_wasm = wasmExports2["ts_tree_edit_wasm"];
2935
+ Module["_ts_tree_included_ranges_wasm"] = _ts_tree_included_ranges_wasm = wasmExports2["ts_tree_included_ranges_wasm"];
2936
+ Module["_ts_tree_get_changed_ranges_wasm"] = _ts_tree_get_changed_ranges_wasm = wasmExports2["ts_tree_get_changed_ranges_wasm"];
2937
+ Module["_ts_tree_cursor_new_wasm"] = _ts_tree_cursor_new_wasm = wasmExports2["ts_tree_cursor_new_wasm"];
2938
+ Module["_ts_tree_cursor_copy_wasm"] = _ts_tree_cursor_copy_wasm = wasmExports2["ts_tree_cursor_copy_wasm"];
2939
+ Module["_ts_tree_cursor_delete_wasm"] = _ts_tree_cursor_delete_wasm = wasmExports2["ts_tree_cursor_delete_wasm"];
2940
+ Module["_ts_tree_cursor_reset_wasm"] = _ts_tree_cursor_reset_wasm = wasmExports2["ts_tree_cursor_reset_wasm"];
2941
+ Module["_ts_tree_cursor_reset_to_wasm"] = _ts_tree_cursor_reset_to_wasm = wasmExports2["ts_tree_cursor_reset_to_wasm"];
2942
+ Module["_ts_tree_cursor_goto_first_child_wasm"] = _ts_tree_cursor_goto_first_child_wasm = wasmExports2["ts_tree_cursor_goto_first_child_wasm"];
2943
+ Module["_ts_tree_cursor_goto_last_child_wasm"] = _ts_tree_cursor_goto_last_child_wasm = wasmExports2["ts_tree_cursor_goto_last_child_wasm"];
2944
+ Module["_ts_tree_cursor_goto_first_child_for_index_wasm"] = _ts_tree_cursor_goto_first_child_for_index_wasm = wasmExports2["ts_tree_cursor_goto_first_child_for_index_wasm"];
2945
+ Module["_ts_tree_cursor_goto_first_child_for_position_wasm"] = _ts_tree_cursor_goto_first_child_for_position_wasm = wasmExports2["ts_tree_cursor_goto_first_child_for_position_wasm"];
2946
+ Module["_ts_tree_cursor_goto_next_sibling_wasm"] = _ts_tree_cursor_goto_next_sibling_wasm = wasmExports2["ts_tree_cursor_goto_next_sibling_wasm"];
2947
+ Module["_ts_tree_cursor_goto_previous_sibling_wasm"] = _ts_tree_cursor_goto_previous_sibling_wasm = wasmExports2["ts_tree_cursor_goto_previous_sibling_wasm"];
2948
+ Module["_ts_tree_cursor_goto_descendant_wasm"] = _ts_tree_cursor_goto_descendant_wasm = wasmExports2["ts_tree_cursor_goto_descendant_wasm"];
2949
+ Module["_ts_tree_cursor_goto_parent_wasm"] = _ts_tree_cursor_goto_parent_wasm = wasmExports2["ts_tree_cursor_goto_parent_wasm"];
2950
+ Module["_ts_tree_cursor_current_node_type_id_wasm"] = _ts_tree_cursor_current_node_type_id_wasm = wasmExports2["ts_tree_cursor_current_node_type_id_wasm"];
2951
+ Module["_ts_tree_cursor_current_node_state_id_wasm"] = _ts_tree_cursor_current_node_state_id_wasm = wasmExports2["ts_tree_cursor_current_node_state_id_wasm"];
2952
+ Module["_ts_tree_cursor_current_node_is_named_wasm"] = _ts_tree_cursor_current_node_is_named_wasm = wasmExports2["ts_tree_cursor_current_node_is_named_wasm"];
2953
+ Module["_ts_tree_cursor_current_node_is_missing_wasm"] = _ts_tree_cursor_current_node_is_missing_wasm = wasmExports2["ts_tree_cursor_current_node_is_missing_wasm"];
2954
+ Module["_ts_tree_cursor_current_node_id_wasm"] = _ts_tree_cursor_current_node_id_wasm = wasmExports2["ts_tree_cursor_current_node_id_wasm"];
2955
+ Module["_ts_tree_cursor_start_position_wasm"] = _ts_tree_cursor_start_position_wasm = wasmExports2["ts_tree_cursor_start_position_wasm"];
2956
+ Module["_ts_tree_cursor_end_position_wasm"] = _ts_tree_cursor_end_position_wasm = wasmExports2["ts_tree_cursor_end_position_wasm"];
2957
+ Module["_ts_tree_cursor_start_index_wasm"] = _ts_tree_cursor_start_index_wasm = wasmExports2["ts_tree_cursor_start_index_wasm"];
2958
+ Module["_ts_tree_cursor_end_index_wasm"] = _ts_tree_cursor_end_index_wasm = wasmExports2["ts_tree_cursor_end_index_wasm"];
2959
+ Module["_ts_tree_cursor_current_field_id_wasm"] = _ts_tree_cursor_current_field_id_wasm = wasmExports2["ts_tree_cursor_current_field_id_wasm"];
2960
+ Module["_ts_tree_cursor_current_depth_wasm"] = _ts_tree_cursor_current_depth_wasm = wasmExports2["ts_tree_cursor_current_depth_wasm"];
2961
+ Module["_ts_tree_cursor_current_descendant_index_wasm"] = _ts_tree_cursor_current_descendant_index_wasm = wasmExports2["ts_tree_cursor_current_descendant_index_wasm"];
2962
+ Module["_ts_tree_cursor_current_node_wasm"] = _ts_tree_cursor_current_node_wasm = wasmExports2["ts_tree_cursor_current_node_wasm"];
2963
+ Module["_ts_node_symbol_wasm"] = _ts_node_symbol_wasm = wasmExports2["ts_node_symbol_wasm"];
2964
+ Module["_ts_node_field_name_for_child_wasm"] = _ts_node_field_name_for_child_wasm = wasmExports2["ts_node_field_name_for_child_wasm"];
2965
+ Module["_ts_node_field_name_for_named_child_wasm"] = _ts_node_field_name_for_named_child_wasm = wasmExports2["ts_node_field_name_for_named_child_wasm"];
2966
+ Module["_ts_node_children_by_field_id_wasm"] = _ts_node_children_by_field_id_wasm = wasmExports2["ts_node_children_by_field_id_wasm"];
2967
+ Module["_ts_node_first_child_for_byte_wasm"] = _ts_node_first_child_for_byte_wasm = wasmExports2["ts_node_first_child_for_byte_wasm"];
2968
+ Module["_ts_node_first_named_child_for_byte_wasm"] = _ts_node_first_named_child_for_byte_wasm = wasmExports2["ts_node_first_named_child_for_byte_wasm"];
2969
+ Module["_ts_node_grammar_symbol_wasm"] = _ts_node_grammar_symbol_wasm = wasmExports2["ts_node_grammar_symbol_wasm"];
2970
+ Module["_ts_node_child_count_wasm"] = _ts_node_child_count_wasm = wasmExports2["ts_node_child_count_wasm"];
2971
+ Module["_ts_node_named_child_count_wasm"] = _ts_node_named_child_count_wasm = wasmExports2["ts_node_named_child_count_wasm"];
2972
+ Module["_ts_node_child_wasm"] = _ts_node_child_wasm = wasmExports2["ts_node_child_wasm"];
2973
+ Module["_ts_node_named_child_wasm"] = _ts_node_named_child_wasm = wasmExports2["ts_node_named_child_wasm"];
2974
+ Module["_ts_node_child_by_field_id_wasm"] = _ts_node_child_by_field_id_wasm = wasmExports2["ts_node_child_by_field_id_wasm"];
2975
+ Module["_ts_node_next_sibling_wasm"] = _ts_node_next_sibling_wasm = wasmExports2["ts_node_next_sibling_wasm"];
2976
+ Module["_ts_node_prev_sibling_wasm"] = _ts_node_prev_sibling_wasm = wasmExports2["ts_node_prev_sibling_wasm"];
2977
+ Module["_ts_node_next_named_sibling_wasm"] = _ts_node_next_named_sibling_wasm = wasmExports2["ts_node_next_named_sibling_wasm"];
2978
+ Module["_ts_node_prev_named_sibling_wasm"] = _ts_node_prev_named_sibling_wasm = wasmExports2["ts_node_prev_named_sibling_wasm"];
2979
+ Module["_ts_node_descendant_count_wasm"] = _ts_node_descendant_count_wasm = wasmExports2["ts_node_descendant_count_wasm"];
2980
+ Module["_ts_node_parent_wasm"] = _ts_node_parent_wasm = wasmExports2["ts_node_parent_wasm"];
2981
+ Module["_ts_node_child_with_descendant_wasm"] = _ts_node_child_with_descendant_wasm = wasmExports2["ts_node_child_with_descendant_wasm"];
2982
+ Module["_ts_node_descendant_for_index_wasm"] = _ts_node_descendant_for_index_wasm = wasmExports2["ts_node_descendant_for_index_wasm"];
2983
+ Module["_ts_node_named_descendant_for_index_wasm"] = _ts_node_named_descendant_for_index_wasm = wasmExports2["ts_node_named_descendant_for_index_wasm"];
2984
+ Module["_ts_node_descendant_for_position_wasm"] = _ts_node_descendant_for_position_wasm = wasmExports2["ts_node_descendant_for_position_wasm"];
2985
+ Module["_ts_node_named_descendant_for_position_wasm"] = _ts_node_named_descendant_for_position_wasm = wasmExports2["ts_node_named_descendant_for_position_wasm"];
2986
+ Module["_ts_node_start_point_wasm"] = _ts_node_start_point_wasm = wasmExports2["ts_node_start_point_wasm"];
2987
+ Module["_ts_node_end_point_wasm"] = _ts_node_end_point_wasm = wasmExports2["ts_node_end_point_wasm"];
2988
+ Module["_ts_node_start_index_wasm"] = _ts_node_start_index_wasm = wasmExports2["ts_node_start_index_wasm"];
2989
+ Module["_ts_node_end_index_wasm"] = _ts_node_end_index_wasm = wasmExports2["ts_node_end_index_wasm"];
2990
+ Module["_ts_node_to_string_wasm"] = _ts_node_to_string_wasm = wasmExports2["ts_node_to_string_wasm"];
2991
+ Module["_ts_node_children_wasm"] = _ts_node_children_wasm = wasmExports2["ts_node_children_wasm"];
2992
+ Module["_ts_node_named_children_wasm"] = _ts_node_named_children_wasm = wasmExports2["ts_node_named_children_wasm"];
2993
+ Module["_ts_node_descendants_of_type_wasm"] = _ts_node_descendants_of_type_wasm = wasmExports2["ts_node_descendants_of_type_wasm"];
2994
+ Module["_ts_node_is_named_wasm"] = _ts_node_is_named_wasm = wasmExports2["ts_node_is_named_wasm"];
2995
+ Module["_ts_node_has_changes_wasm"] = _ts_node_has_changes_wasm = wasmExports2["ts_node_has_changes_wasm"];
2996
+ Module["_ts_node_has_error_wasm"] = _ts_node_has_error_wasm = wasmExports2["ts_node_has_error_wasm"];
2997
+ Module["_ts_node_is_error_wasm"] = _ts_node_is_error_wasm = wasmExports2["ts_node_is_error_wasm"];
2998
+ Module["_ts_node_is_missing_wasm"] = _ts_node_is_missing_wasm = wasmExports2["ts_node_is_missing_wasm"];
2999
+ Module["_ts_node_is_extra_wasm"] = _ts_node_is_extra_wasm = wasmExports2["ts_node_is_extra_wasm"];
3000
+ Module["_ts_node_parse_state_wasm"] = _ts_node_parse_state_wasm = wasmExports2["ts_node_parse_state_wasm"];
3001
+ Module["_ts_node_next_parse_state_wasm"] = _ts_node_next_parse_state_wasm = wasmExports2["ts_node_next_parse_state_wasm"];
3002
+ Module["_ts_query_matches_wasm"] = _ts_query_matches_wasm = wasmExports2["ts_query_matches_wasm"];
3003
+ Module["_ts_query_captures_wasm"] = _ts_query_captures_wasm = wasmExports2["ts_query_captures_wasm"];
3004
+ Module["_memset"] = _memset = wasmExports2["memset"];
3005
+ Module["_memcpy"] = _memcpy = wasmExports2["memcpy"];
3006
+ Module["_memmove"] = _memmove = wasmExports2["memmove"];
3007
+ Module["_iswalpha"] = _iswalpha = wasmExports2["iswalpha"];
3008
+ Module["_iswblank"] = _iswblank = wasmExports2["iswblank"];
3009
+ Module["_iswdigit"] = _iswdigit = wasmExports2["iswdigit"];
3010
+ Module["_iswlower"] = _iswlower = wasmExports2["iswlower"];
3011
+ Module["_iswupper"] = _iswupper = wasmExports2["iswupper"];
3012
+ Module["_iswxdigit"] = _iswxdigit = wasmExports2["iswxdigit"];
3013
+ Module["_memchr"] = _memchr = wasmExports2["memchr"];
3014
+ Module["_strlen"] = _strlen = wasmExports2["strlen"];
3015
+ Module["_strcmp"] = _strcmp = wasmExports2["strcmp"];
3016
+ Module["_strncat"] = _strncat = wasmExports2["strncat"];
3017
+ Module["_strncpy"] = _strncpy = wasmExports2["strncpy"];
3018
+ Module["_towlower"] = _towlower = wasmExports2["towlower"];
3019
+ Module["_towupper"] = _towupper = wasmExports2["towupper"];
3020
+ _setThrew = wasmExports2["setThrew"];
3021
+ __emscripten_stack_restore = wasmExports2["_emscripten_stack_restore"];
3022
+ __emscripten_stack_alloc = wasmExports2["_emscripten_stack_alloc"];
3023
+ _emscripten_stack_get_current = wasmExports2["emscripten_stack_get_current"];
3024
+ ___wasm_apply_data_relocs = wasmExports2["__wasm_apply_data_relocs"];
3025
+ }
3026
+ __name(assignWasmExports, "assignWasmExports");
3027
+ var wasmImports = {
3028
+ /** @export */
3029
+ __heap_base: ___heap_base,
3030
+ /** @export */
3031
+ __indirect_function_table: wasmTable,
3032
+ /** @export */
3033
+ __memory_base: ___memory_base,
3034
+ /** @export */
3035
+ __stack_high: ___stack_high,
3036
+ /** @export */
3037
+ __stack_low: ___stack_low,
3038
+ /** @export */
3039
+ __stack_pointer: ___stack_pointer,
3040
+ /** @export */
3041
+ __table_base: ___table_base,
3042
+ /** @export */
3043
+ _abort_js: __abort_js,
3044
+ /** @export */
3045
+ emscripten_resize_heap: _emscripten_resize_heap,
3046
+ /** @export */
3047
+ fd_close: _fd_close,
3048
+ /** @export */
3049
+ fd_seek: _fd_seek,
3050
+ /** @export */
3051
+ fd_write: _fd_write,
3052
+ /** @export */
3053
+ memory: wasmMemory,
3054
+ /** @export */
3055
+ tree_sitter_log_callback: _tree_sitter_log_callback,
3056
+ /** @export */
3057
+ tree_sitter_parse_callback: _tree_sitter_parse_callback,
3058
+ /** @export */
3059
+ tree_sitter_progress_callback: _tree_sitter_progress_callback,
3060
+ /** @export */
3061
+ tree_sitter_query_progress_callback: _tree_sitter_query_progress_callback
3062
+ };
3063
+ function callMain(args2 = []) {
3064
+ var entryFunction = resolveGlobalSymbol("main").sym;
3065
+ if (!entryFunction) return;
3066
+ args2.unshift(thisProgram);
3067
+ var argc = args2.length;
3068
+ var argv = stackAlloc((argc + 1) * 4);
3069
+ var argv_ptr = argv;
3070
+ args2.forEach((arg) => {
3071
+ LE_HEAP_STORE_U32((argv_ptr >> 2) * 4, stringToUTF8OnStack(arg));
3072
+ argv_ptr += 4;
3073
+ });
3074
+ LE_HEAP_STORE_U32((argv_ptr >> 2) * 4, 0);
3075
+ try {
3076
+ var ret = entryFunction(argc, argv);
3077
+ exitJS(
3078
+ ret,
3079
+ /* implicit = */
3080
+ true
3081
+ );
3082
+ return ret;
3083
+ } catch (e) {
3084
+ return handleException(e);
3085
+ }
3086
+ }
3087
+ __name(callMain, "callMain");
3088
+ function run(args2 = arguments_) {
3089
+ if (runDependencies > 0) {
3090
+ dependenciesFulfilled = run;
3091
+ return;
3092
+ }
3093
+ preRun();
3094
+ if (runDependencies > 0) {
3095
+ dependenciesFulfilled = run;
3096
+ return;
3097
+ }
3098
+ function doRun() {
3099
+ Module["calledRun"] = true;
3100
+ if (ABORT) return;
3101
+ initRuntime();
3102
+ preMain();
3103
+ readyPromiseResolve?.(Module);
3104
+ Module["onRuntimeInitialized"]?.();
3105
+ var noInitialRun = Module["noInitialRun"] || false;
3106
+ if (!noInitialRun) callMain(args2);
3107
+ postRun();
3108
+ }
3109
+ __name(doRun, "doRun");
3110
+ if (Module["setStatus"]) {
3111
+ Module["setStatus"]("Running...");
3112
+ setTimeout(() => {
3113
+ setTimeout(() => Module["setStatus"](""), 1);
3114
+ doRun();
3115
+ }, 1);
3116
+ } else {
3117
+ doRun();
3118
+ }
3119
+ }
3120
+ __name(run, "run");
3121
+ var wasmExports;
3122
+ wasmExports = await createWasm();
3123
+ run();
3124
+ if (runtimeInitialized) {
3125
+ moduleRtn = Module;
3126
+ } else {
3127
+ moduleRtn = new Promise((resolve, reject) => {
3128
+ readyPromiseResolve = resolve;
3129
+ readyPromiseReject = reject;
3130
+ });
3131
+ }
3132
+ return moduleRtn;
3133
+ }
3134
+ __name(Module2, "Module");
3135
+ var web_tree_sitter_default = Module2;
3136
+
3137
+ // src/bindings.ts
3138
+ var Module3 = null;
3139
+ async function initializeBinding(moduleOptions) {
3140
+ return Module3 ??= await web_tree_sitter_default(moduleOptions);
3141
+ }
3142
+ __name(initializeBinding, "initializeBinding");
3143
+ function checkModule() {
3144
+ return !!Module3;
3145
+ }
3146
+ __name(checkModule, "checkModule");
3147
+
3148
+ // src/parser.ts
3149
+ var TRANSFER_BUFFER;
3150
+ var LANGUAGE_VERSION;
3151
+ var MIN_COMPATIBLE_VERSION;
3152
+ var Parser = class {
3153
+ static {
3154
+ __name(this, "Parser");
3155
+ }
3156
+ /** @internal */
3157
+ [0] = 0;
3158
+ // Internal handle for Wasm
3159
+ /** @internal */
3160
+ [1] = 0;
3161
+ // Internal handle for Wasm
3162
+ /** @internal */
3163
+ logCallback = null;
3164
+ /** The parser's current language. */
3165
+ language = null;
3166
+ /**
3167
+ * This must always be called before creating a Parser.
3168
+ *
3169
+ * You can optionally pass in options to configure the Wasm module, the most common
3170
+ * one being `locateFile` to help the module find the `.wasm` file.
3171
+ */
3172
+ static async init(moduleOptions) {
3173
+ setModule(await initializeBinding(moduleOptions));
3174
+ TRANSFER_BUFFER = C._ts_init();
3175
+ LANGUAGE_VERSION = C.getValue(TRANSFER_BUFFER, "i32");
3176
+ MIN_COMPATIBLE_VERSION = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
3177
+ }
3178
+ /**
3179
+ * Create a new parser.
3180
+ */
3181
+ constructor() {
3182
+ this.initialize();
3183
+ }
3184
+ /** @internal */
3185
+ initialize() {
3186
+ if (!checkModule()) {
3187
+ throw new Error("cannot construct a Parser before calling `init()`");
3188
+ }
3189
+ C._ts_parser_new_wasm();
3190
+ this[0] = C.getValue(TRANSFER_BUFFER, "i32");
3191
+ this[1] = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
3192
+ }
3193
+ /** Delete the parser, freeing its resources. */
3194
+ delete() {
3195
+ C._ts_parser_delete(this[0]);
3196
+ C._free(this[1]);
3197
+ this[0] = 0;
3198
+ this[1] = 0;
3199
+ }
3200
+ /**
3201
+ * Set the language that the parser should use for parsing.
3202
+ *
3203
+ * If the language was not successfully assigned, an error will be thrown.
3204
+ * This happens if the language was generated with an incompatible
3205
+ * version of the Tree-sitter CLI. Check the language's version using
3206
+ * {@link Language#version} and compare it to this library's
3207
+ * {@link LANGUAGE_VERSION} and {@link MIN_COMPATIBLE_VERSION} constants.
3208
+ */
3209
+ setLanguage(language) {
3210
+ let address;
3211
+ if (!language) {
3212
+ address = 0;
3213
+ this.language = null;
3214
+ } else if (language.constructor === Language) {
3215
+ address = language[0];
3216
+ const version = C._ts_language_abi_version(address);
3217
+ if (version < MIN_COMPATIBLE_VERSION || LANGUAGE_VERSION < version) {
3218
+ throw new Error(
3219
+ `Incompatible language version ${version}. Compatibility range ${MIN_COMPATIBLE_VERSION} through ${LANGUAGE_VERSION}.`
3220
+ );
3221
+ }
3222
+ this.language = language;
3223
+ } else {
3224
+ throw new Error("Argument must be a Language");
3225
+ }
3226
+ C._ts_parser_set_language(this[0], address);
3227
+ return this;
3228
+ }
3229
+ /**
3230
+ * Parse a slice of UTF8 text.
3231
+ *
3232
+ * @param {string | ParseCallback} callback - The UTF8-encoded text to parse or a callback function.
3233
+ *
3234
+ * @param {Tree | null} [oldTree] - A previous syntax tree parsed from the same document. If the text of the
3235
+ * document has changed since `oldTree` was created, then you must edit `oldTree` to match
3236
+ * the new text using {@link Tree#edit}.
3237
+ *
3238
+ * @param {ParseOptions} [options] - Options for parsing the text.
3239
+ * This can be used to set the included ranges, or a progress callback.
3240
+ *
3241
+ * @returns {Tree | null} A {@link Tree} if parsing succeeded, or `null` if:
3242
+ * - The parser has not yet had a language assigned with {@link Parser#setLanguage}.
3243
+ * - The progress callback returned true.
3244
+ */
3245
+ parse(callback, oldTree, options) {
3246
+ if (typeof callback === "string") {
3247
+ C.currentParseCallback = (index) => callback.slice(index);
3248
+ } else if (typeof callback === "function") {
3249
+ C.currentParseCallback = callback;
3250
+ } else {
3251
+ throw new Error("Argument must be a string or a function");
3252
+ }
3253
+ if (options?.progressCallback) {
3254
+ C.currentProgressCallback = options.progressCallback;
3255
+ } else {
3256
+ C.currentProgressCallback = null;
3257
+ }
3258
+ if (this.logCallback) {
3259
+ C.currentLogCallback = this.logCallback;
3260
+ C._ts_parser_enable_logger_wasm(this[0], 1);
3261
+ } else {
3262
+ C.currentLogCallback = null;
3263
+ C._ts_parser_enable_logger_wasm(this[0], 0);
3264
+ }
3265
+ let rangeCount = 0;
3266
+ let rangeAddress = 0;
3267
+ if (options?.includedRanges) {
3268
+ rangeCount = options.includedRanges.length;
3269
+ rangeAddress = C._calloc(rangeCount, SIZE_OF_RANGE);
3270
+ let address = rangeAddress;
3271
+ for (let i2 = 0; i2 < rangeCount; i2++) {
3272
+ marshalRange(address, options.includedRanges[i2]);
3273
+ address += SIZE_OF_RANGE;
3274
+ }
3275
+ }
3276
+ const treeAddress = C._ts_parser_parse_wasm(
3277
+ this[0],
3278
+ this[1],
3279
+ oldTree ? oldTree[0] : 0,
3280
+ rangeAddress,
3281
+ rangeCount
3282
+ );
3283
+ if (!treeAddress) {
3284
+ C.currentParseCallback = null;
3285
+ C.currentLogCallback = null;
3286
+ C.currentProgressCallback = null;
3287
+ return null;
3288
+ }
3289
+ if (!this.language) {
3290
+ throw new Error("Parser must have a language to parse");
3291
+ }
3292
+ const result = new Tree(INTERNAL, treeAddress, this.language, C.currentParseCallback);
3293
+ C.currentParseCallback = null;
3294
+ C.currentLogCallback = null;
3295
+ C.currentProgressCallback = null;
3296
+ return result;
3297
+ }
3298
+ /**
3299
+ * Instruct the parser to start the next parse from the beginning.
3300
+ *
3301
+ * If the parser previously failed because of a callback,
3302
+ * then by default, it will resume where it left off on the
3303
+ * next call to {@link Parser#parse} or other parsing functions.
3304
+ * If you don't want to resume, and instead intend to use this parser to
3305
+ * parse some other document, you must call `reset` first.
3306
+ */
3307
+ reset() {
3308
+ C._ts_parser_reset(this[0]);
3309
+ }
3310
+ /** Get the ranges of text that the parser will include when parsing. */
3311
+ getIncludedRanges() {
3312
+ C._ts_parser_included_ranges_wasm(this[0]);
3313
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
3314
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
3315
+ const result = new Array(count);
3316
+ if (count > 0) {
3317
+ let address = buffer;
3318
+ for (let i2 = 0; i2 < count; i2++) {
3319
+ result[i2] = unmarshalRange(address);
3320
+ address += SIZE_OF_RANGE;
3321
+ }
3322
+ C._free(buffer);
3323
+ }
3324
+ return result;
3325
+ }
3326
+ /** Set the logging callback that a parser should use during parsing. */
3327
+ setLogger(callback) {
3328
+ if (!callback) {
3329
+ this.logCallback = null;
3330
+ } else if (typeof callback !== "function") {
3331
+ throw new Error("Logger callback must be a function");
3332
+ } else {
3333
+ this.logCallback = callback;
3334
+ }
3335
+ return this;
3336
+ }
3337
+ /** Get the parser's current logger. */
3338
+ getLogger() {
3339
+ return this.logCallback;
3340
+ }
3341
+ };
3342
+
3343
+ // src/query.ts
3344
+ var PREDICATE_STEP_TYPE_CAPTURE = 1;
3345
+ var PREDICATE_STEP_TYPE_STRING = 2;
3346
+ var QUERY_WORD_REGEX = /[\w-]+/g;
3347
+ var CaptureQuantifier = {
3348
+ Zero: 0,
3349
+ ZeroOrOne: 1,
3350
+ ZeroOrMore: 2,
3351
+ One: 3,
3352
+ OneOrMore: 4
3353
+ };
3354
+ var isCaptureStep = /* @__PURE__ */ __name((step) => step.type === "capture", "isCaptureStep");
3355
+ var isStringStep = /* @__PURE__ */ __name((step) => step.type === "string", "isStringStep");
3356
+ var QueryErrorKind = {
3357
+ Syntax: 1,
3358
+ NodeName: 2,
3359
+ FieldName: 3,
3360
+ CaptureName: 4,
3361
+ PatternStructure: 5
3362
+ };
3363
+ var QueryError = class _QueryError extends Error {
3364
+ constructor(kind, info2, index, length) {
3365
+ super(_QueryError.formatMessage(kind, info2));
3366
+ this.kind = kind;
3367
+ this.info = info2;
3368
+ this.index = index;
3369
+ this.length = length;
3370
+ this.name = "QueryError";
3371
+ }
3372
+ static {
3373
+ __name(this, "QueryError");
3374
+ }
3375
+ /** Formats an error message based on the error kind and info */
3376
+ static formatMessage(kind, info2) {
3377
+ switch (kind) {
3378
+ case QueryErrorKind.NodeName:
3379
+ return `Bad node name '${info2.word}'`;
3380
+ case QueryErrorKind.FieldName:
3381
+ return `Bad field name '${info2.word}'`;
3382
+ case QueryErrorKind.CaptureName:
3383
+ return `Bad capture name @${info2.word}`;
3384
+ case QueryErrorKind.PatternStructure:
3385
+ return `Bad pattern structure at offset ${info2.suffix}`;
3386
+ case QueryErrorKind.Syntax:
3387
+ return `Bad syntax at offset ${info2.suffix}`;
3388
+ }
3389
+ }
3390
+ };
3391
+ function parseAnyPredicate(steps, index, operator, textPredicates) {
3392
+ if (steps.length !== 3) {
3393
+ throw new Error(
3394
+ `Wrong number of arguments to \`#${operator}\` predicate. Expected 2, got ${steps.length - 1}`
3395
+ );
3396
+ }
3397
+ if (!isCaptureStep(steps[1])) {
3398
+ throw new Error(
3399
+ `First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}"`
3400
+ );
3401
+ }
3402
+ const isPositive = operator === "eq?" || operator === "any-eq?";
3403
+ const matchAll = !operator.startsWith("any-");
3404
+ if (isCaptureStep(steps[2])) {
3405
+ const captureName1 = steps[1].name;
3406
+ const captureName2 = steps[2].name;
3407
+ textPredicates[index].push((captures) => {
3408
+ const nodes1 = [];
3409
+ const nodes2 = [];
3410
+ for (const c of captures) {
3411
+ if (c.name === captureName1) nodes1.push(c.node);
3412
+ if (c.name === captureName2) nodes2.push(c.node);
3413
+ }
3414
+ const compare = /* @__PURE__ */ __name((n1, n2, positive) => {
3415
+ return positive ? n1.text === n2.text : n1.text !== n2.text;
3416
+ }, "compare");
3417
+ return matchAll ? nodes1.every((n1) => nodes2.some((n2) => compare(n1, n2, isPositive))) : nodes1.some((n1) => nodes2.some((n2) => compare(n1, n2, isPositive)));
3418
+ });
3419
+ } else {
3420
+ const captureName = steps[1].name;
3421
+ const stringValue = steps[2].value;
3422
+ const matches = /* @__PURE__ */ __name((n) => n.text === stringValue, "matches");
3423
+ const doesNotMatch = /* @__PURE__ */ __name((n) => n.text !== stringValue, "doesNotMatch");
3424
+ textPredicates[index].push((captures) => {
3425
+ const nodes = [];
3426
+ for (const c of captures) {
3427
+ if (c.name === captureName) nodes.push(c.node);
3428
+ }
3429
+ const test = isPositive ? matches : doesNotMatch;
3430
+ return matchAll ? nodes.every(test) : nodes.some(test);
3431
+ });
3432
+ }
3433
+ }
3434
+ __name(parseAnyPredicate, "parseAnyPredicate");
3435
+ function parseMatchPredicate(steps, index, operator, textPredicates) {
3436
+ if (steps.length !== 3) {
3437
+ throw new Error(
3438
+ `Wrong number of arguments to \`#${operator}\` predicate. Expected 2, got ${steps.length - 1}.`
3439
+ );
3440
+ }
3441
+ if (steps[1].type !== "capture") {
3442
+ throw new Error(
3443
+ `First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}".`
3444
+ );
3445
+ }
3446
+ if (steps[2].type !== "string") {
3447
+ throw new Error(
3448
+ `Second argument of \`#${operator}\` predicate must be a string. Got @${steps[2].name}.`
3449
+ );
3450
+ }
3451
+ const isPositive = operator === "match?" || operator === "any-match?";
3452
+ const matchAll = !operator.startsWith("any-");
3453
+ const captureName = steps[1].name;
3454
+ const regex = new RegExp(steps[2].value);
3455
+ textPredicates[index].push((captures) => {
3456
+ const nodes = [];
3457
+ for (const c of captures) {
3458
+ if (c.name === captureName) nodes.push(c.node.text);
3459
+ }
3460
+ const test = /* @__PURE__ */ __name((text, positive) => {
3461
+ return positive ? regex.test(text) : !regex.test(text);
3462
+ }, "test");
3463
+ if (nodes.length === 0) return !isPositive;
3464
+ return matchAll ? nodes.every((text) => test(text, isPositive)) : nodes.some((text) => test(text, isPositive));
3465
+ });
3466
+ }
3467
+ __name(parseMatchPredicate, "parseMatchPredicate");
3468
+ function parseAnyOfPredicate(steps, index, operator, textPredicates) {
3469
+ if (steps.length < 2) {
3470
+ throw new Error(
3471
+ `Wrong number of arguments to \`#${operator}\` predicate. Expected at least 1. Got ${steps.length - 1}.`
3472
+ );
3473
+ }
3474
+ if (steps[1].type !== "capture") {
3475
+ throw new Error(
3476
+ `First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}".`
3477
+ );
3478
+ }
3479
+ const isPositive = operator === "any-of?";
3480
+ const captureName = steps[1].name;
3481
+ const stringSteps = steps.slice(2);
3482
+ if (!stringSteps.every(isStringStep)) {
3483
+ throw new Error(
3484
+ `Arguments to \`#${operator}\` predicate must be strings.".`
3485
+ );
3486
+ }
3487
+ const values = stringSteps.map((s) => s.value);
3488
+ textPredicates[index].push((captures) => {
3489
+ const nodes = [];
3490
+ for (const c of captures) {
3491
+ if (c.name === captureName) nodes.push(c.node.text);
3492
+ }
3493
+ if (nodes.length === 0) return !isPositive;
3494
+ return nodes.every((text) => values.includes(text)) === isPositive;
3495
+ });
3496
+ }
3497
+ __name(parseAnyOfPredicate, "parseAnyOfPredicate");
3498
+ function parseIsPredicate(steps, index, operator, assertedProperties, refutedProperties) {
3499
+ if (steps.length < 2 || steps.length > 3) {
3500
+ throw new Error(
3501
+ `Wrong number of arguments to \`#${operator}\` predicate. Expected 1 or 2. Got ${steps.length - 1}.`
3502
+ );
3503
+ }
3504
+ if (!steps.every(isStringStep)) {
3505
+ throw new Error(
3506
+ `Arguments to \`#${operator}\` predicate must be strings.".`
3507
+ );
3508
+ }
3509
+ const properties = operator === "is?" ? assertedProperties : refutedProperties;
3510
+ if (!properties[index]) properties[index] = {};
3511
+ properties[index][steps[1].value] = steps[2]?.value ?? null;
3512
+ }
3513
+ __name(parseIsPredicate, "parseIsPredicate");
3514
+ function parseSetDirective(steps, index, setProperties) {
3515
+ if (steps.length < 2 || steps.length > 3) {
3516
+ throw new Error(`Wrong number of arguments to \`#set!\` predicate. Expected 1 or 2. Got ${steps.length - 1}.`);
3517
+ }
3518
+ if (!steps.every(isStringStep)) {
3519
+ throw new Error(`Arguments to \`#set!\` predicate must be strings.".`);
3520
+ }
3521
+ if (!setProperties[index]) setProperties[index] = {};
3522
+ setProperties[index][steps[1].value] = steps[2]?.value ?? null;
3523
+ }
3524
+ __name(parseSetDirective, "parseSetDirective");
3525
+ function parsePattern(index, stepType, stepValueId, captureNames, stringValues, steps, textPredicates, predicates, setProperties, assertedProperties, refutedProperties) {
3526
+ if (stepType === PREDICATE_STEP_TYPE_CAPTURE) {
3527
+ const name2 = captureNames[stepValueId];
3528
+ steps.push({ type: "capture", name: name2 });
3529
+ } else if (stepType === PREDICATE_STEP_TYPE_STRING) {
3530
+ steps.push({ type: "string", value: stringValues[stepValueId] });
3531
+ } else if (steps.length > 0) {
3532
+ if (steps[0].type !== "string") {
3533
+ throw new Error("Predicates must begin with a literal value");
3534
+ }
3535
+ const operator = steps[0].value;
3536
+ switch (operator) {
3537
+ case "any-not-eq?":
3538
+ case "not-eq?":
3539
+ case "any-eq?":
3540
+ case "eq?":
3541
+ parseAnyPredicate(steps, index, operator, textPredicates);
3542
+ break;
3543
+ case "any-not-match?":
3544
+ case "not-match?":
3545
+ case "any-match?":
3546
+ case "match?":
3547
+ parseMatchPredicate(steps, index, operator, textPredicates);
3548
+ break;
3549
+ case "not-any-of?":
3550
+ case "any-of?":
3551
+ parseAnyOfPredicate(steps, index, operator, textPredicates);
3552
+ break;
3553
+ case "is?":
3554
+ case "is-not?":
3555
+ parseIsPredicate(steps, index, operator, assertedProperties, refutedProperties);
3556
+ break;
3557
+ case "set!":
3558
+ parseSetDirective(steps, index, setProperties);
3559
+ break;
3560
+ default:
3561
+ predicates[index].push({ operator, operands: steps.slice(1) });
3562
+ }
3563
+ steps.length = 0;
3564
+ }
3565
+ }
3566
+ __name(parsePattern, "parsePattern");
3567
+ var Query = class {
3568
+ static {
3569
+ __name(this, "Query");
3570
+ }
3571
+ /** @internal */
3572
+ [0] = 0;
3573
+ // Internal handle for Wasm
3574
+ /** @internal */
3575
+ exceededMatchLimit;
3576
+ /** @internal */
3577
+ textPredicates;
3578
+ /** The names of the captures used in the query. */
3579
+ captureNames;
3580
+ /** The quantifiers of the captures used in the query. */
3581
+ captureQuantifiers;
3582
+ /**
3583
+ * The other user-defined predicates associated with the given index.
3584
+ *
3585
+ * This includes predicates with operators other than:
3586
+ * - `match?`
3587
+ * - `eq?` and `not-eq?`
3588
+ * - `any-of?` and `not-any-of?`
3589
+ * - `is?` and `is-not?`
3590
+ * - `set!`
3591
+ */
3592
+ predicates;
3593
+ /** The properties for predicates with the operator `set!`. */
3594
+ setProperties;
3595
+ /** The properties for predicates with the operator `is?`. */
3596
+ assertedProperties;
3597
+ /** The properties for predicates with the operator `is-not?`. */
3598
+ refutedProperties;
3599
+ /** The maximum number of in-progress matches for this cursor. */
3600
+ matchLimit;
3601
+ /**
3602
+ * Create a new query from a string containing one or more S-expression
3603
+ * patterns.
3604
+ *
3605
+ * The query is associated with a particular language, and can only be run
3606
+ * on syntax nodes parsed with that language. References to Queries can be
3607
+ * shared between multiple threads.
3608
+ *
3609
+ * @link {@see https://tree-sitter.github.io/tree-sitter/using-parsers/queries}
3610
+ */
3611
+ constructor(language, source) {
3612
+ const sourceLength = C.lengthBytesUTF8(source);
3613
+ const sourceAddress = C._malloc(sourceLength + 1);
3614
+ C.stringToUTF8(source, sourceAddress, sourceLength + 1);
3615
+ const address = C._ts_query_new(
3616
+ language[0],
3617
+ sourceAddress,
3618
+ sourceLength,
3619
+ TRANSFER_BUFFER,
3620
+ TRANSFER_BUFFER + SIZE_OF_INT
3621
+ );
3622
+ if (!address) {
3623
+ const errorId = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
3624
+ const errorByte = C.getValue(TRANSFER_BUFFER, "i32");
3625
+ const errorIndex = C.UTF8ToString(sourceAddress, errorByte).length;
3626
+ const suffix = source.slice(errorIndex, errorIndex + 100).split("\n")[0];
3627
+ const word = suffix.match(QUERY_WORD_REGEX)?.[0] ?? "";
3628
+ C._free(sourceAddress);
3629
+ switch (errorId) {
3630
+ case QueryErrorKind.Syntax:
3631
+ throw new QueryError(QueryErrorKind.Syntax, { suffix: `${errorIndex}: '${suffix}'...` }, errorIndex, 0);
3632
+ case QueryErrorKind.NodeName:
3633
+ throw new QueryError(errorId, { word }, errorIndex, word.length);
3634
+ case QueryErrorKind.FieldName:
3635
+ throw new QueryError(errorId, { word }, errorIndex, word.length);
3636
+ case QueryErrorKind.CaptureName:
3637
+ throw new QueryError(errorId, { word }, errorIndex, word.length);
3638
+ case QueryErrorKind.PatternStructure:
3639
+ throw new QueryError(errorId, { suffix: `${errorIndex}: '${suffix}'...` }, errorIndex, 0);
3640
+ }
3641
+ }
3642
+ const stringCount = C._ts_query_string_count(address);
3643
+ const captureCount = C._ts_query_capture_count(address);
3644
+ const patternCount = C._ts_query_pattern_count(address);
3645
+ const captureNames = new Array(captureCount);
3646
+ const captureQuantifiers = new Array(patternCount);
3647
+ const stringValues = new Array(stringCount);
3648
+ for (let i2 = 0; i2 < captureCount; i2++) {
3649
+ const nameAddress = C._ts_query_capture_name_for_id(
3650
+ address,
3651
+ i2,
3652
+ TRANSFER_BUFFER
3653
+ );
3654
+ const nameLength = C.getValue(TRANSFER_BUFFER, "i32");
3655
+ captureNames[i2] = C.UTF8ToString(nameAddress, nameLength);
3656
+ }
3657
+ for (let i2 = 0; i2 < patternCount; i2++) {
3658
+ const captureQuantifiersArray = new Array(captureCount);
3659
+ for (let j = 0; j < captureCount; j++) {
3660
+ const quantifier = C._ts_query_capture_quantifier_for_id(address, i2, j);
3661
+ captureQuantifiersArray[j] = quantifier;
3662
+ }
3663
+ captureQuantifiers[i2] = captureQuantifiersArray;
3664
+ }
3665
+ for (let i2 = 0; i2 < stringCount; i2++) {
3666
+ const valueAddress = C._ts_query_string_value_for_id(
3667
+ address,
3668
+ i2,
3669
+ TRANSFER_BUFFER
3670
+ );
3671
+ const nameLength = C.getValue(TRANSFER_BUFFER, "i32");
3672
+ stringValues[i2] = C.UTF8ToString(valueAddress, nameLength);
3673
+ }
3674
+ const setProperties = new Array(patternCount);
3675
+ const assertedProperties = new Array(patternCount);
3676
+ const refutedProperties = new Array(patternCount);
3677
+ const predicates = new Array(patternCount);
3678
+ const textPredicates = new Array(patternCount);
3679
+ for (let i2 = 0; i2 < patternCount; i2++) {
3680
+ const predicatesAddress = C._ts_query_predicates_for_pattern(address, i2, TRANSFER_BUFFER);
3681
+ const stepCount = C.getValue(TRANSFER_BUFFER, "i32");
3682
+ predicates[i2] = [];
3683
+ textPredicates[i2] = [];
3684
+ const steps = new Array();
3685
+ let stepAddress = predicatesAddress;
3686
+ for (let j = 0; j < stepCount; j++) {
3687
+ const stepType = C.getValue(stepAddress, "i32");
3688
+ stepAddress += SIZE_OF_INT;
3689
+ const stepValueId = C.getValue(stepAddress, "i32");
3690
+ stepAddress += SIZE_OF_INT;
3691
+ parsePattern(
3692
+ i2,
3693
+ stepType,
3694
+ stepValueId,
3695
+ captureNames,
3696
+ stringValues,
3697
+ steps,
3698
+ textPredicates,
3699
+ predicates,
3700
+ setProperties,
3701
+ assertedProperties,
3702
+ refutedProperties
3703
+ );
3704
+ }
3705
+ Object.freeze(textPredicates[i2]);
3706
+ Object.freeze(predicates[i2]);
3707
+ Object.freeze(setProperties[i2]);
3708
+ Object.freeze(assertedProperties[i2]);
3709
+ Object.freeze(refutedProperties[i2]);
3710
+ }
3711
+ C._free(sourceAddress);
3712
+ this[0] = address;
3713
+ this.captureNames = captureNames;
3714
+ this.captureQuantifiers = captureQuantifiers;
3715
+ this.textPredicates = textPredicates;
3716
+ this.predicates = predicates;
3717
+ this.setProperties = setProperties;
3718
+ this.assertedProperties = assertedProperties;
3719
+ this.refutedProperties = refutedProperties;
3720
+ this.exceededMatchLimit = false;
3721
+ }
3722
+ /** Delete the query, freeing its resources. */
3723
+ delete() {
3724
+ C._ts_query_delete(this[0]);
3725
+ this[0] = 0;
3726
+ }
3727
+ /**
3728
+ * Iterate over all of the matches in the order that they were found.
3729
+ *
3730
+ * Each match contains the index of the pattern that matched, and a list of
3731
+ * captures. Because multiple patterns can match the same set of nodes,
3732
+ * one match may contain captures that appear *before* some of the
3733
+ * captures from a previous match.
3734
+ *
3735
+ * @param {Node} node - The node to execute the query on.
3736
+ *
3737
+ * @param {QueryOptions} options - Options for query execution.
3738
+ */
3739
+ matches(node, options = {}) {
3740
+ const startPosition = options.startPosition ?? ZERO_POINT;
3741
+ const endPosition = options.endPosition ?? ZERO_POINT;
3742
+ const startIndex = options.startIndex ?? 0;
3743
+ const endIndex = options.endIndex ?? 0;
3744
+ const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
3745
+ const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
3746
+ const startContainingIndex = options.startContainingIndex ?? 0;
3747
+ const endContainingIndex = options.endContainingIndex ?? 0;
3748
+ const matchLimit = options.matchLimit ?? 4294967295;
3749
+ const maxStartDepth = options.maxStartDepth ?? 4294967295;
3750
+ const progressCallback = options.progressCallback;
3751
+ if (typeof matchLimit !== "number") {
3752
+ throw new Error("Arguments must be numbers");
3753
+ }
3754
+ this.matchLimit = matchLimit;
3755
+ if (endIndex !== 0 && startIndex > endIndex) {
3756
+ throw new Error("`startIndex` cannot be greater than `endIndex`");
3757
+ }
3758
+ if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
3759
+ throw new Error("`startPosition` cannot be greater than `endPosition`");
3760
+ }
3761
+ if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
3762
+ throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
3763
+ }
3764
+ if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
3765
+ throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
3766
+ }
3767
+ if (progressCallback) {
3768
+ C.currentQueryProgressCallback = progressCallback;
3769
+ }
3770
+ marshalNode(node);
3771
+ C._ts_query_matches_wasm(
3772
+ this[0],
3773
+ node.tree[0],
3774
+ startPosition.row,
3775
+ startPosition.column,
3776
+ endPosition.row,
3777
+ endPosition.column,
3778
+ startIndex,
3779
+ endIndex,
3780
+ startContainingPosition.row,
3781
+ startContainingPosition.column,
3782
+ endContainingPosition.row,
3783
+ endContainingPosition.column,
3784
+ startContainingIndex,
3785
+ endContainingIndex,
3786
+ matchLimit,
3787
+ maxStartDepth
3788
+ );
3789
+ const rawCount = C.getValue(TRANSFER_BUFFER, "i32");
3790
+ const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
3791
+ const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
3792
+ const result = new Array(rawCount);
3793
+ this.exceededMatchLimit = Boolean(didExceedMatchLimit);
3794
+ let filteredCount = 0;
3795
+ let address = startAddress;
3796
+ for (let i2 = 0; i2 < rawCount; i2++) {
3797
+ const patternIndex = C.getValue(address, "i32");
3798
+ address += SIZE_OF_INT;
3799
+ const captureCount = C.getValue(address, "i32");
3800
+ address += SIZE_OF_INT;
3801
+ const captures = new Array(captureCount);
3802
+ address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
3803
+ if (this.textPredicates[patternIndex].every((p) => p(captures))) {
3804
+ result[filteredCount] = { patternIndex, captures };
3805
+ const setProperties = this.setProperties[patternIndex];
3806
+ result[filteredCount].setProperties = setProperties;
3807
+ const assertedProperties = this.assertedProperties[patternIndex];
3808
+ result[filteredCount].assertedProperties = assertedProperties;
3809
+ const refutedProperties = this.refutedProperties[patternIndex];
3810
+ result[filteredCount].refutedProperties = refutedProperties;
3811
+ filteredCount++;
3812
+ }
3813
+ }
3814
+ result.length = filteredCount;
3815
+ C._free(startAddress);
3816
+ C.currentQueryProgressCallback = null;
3817
+ return result;
3818
+ }
3819
+ /**
3820
+ * Iterate over all of the individual captures in the order that they
3821
+ * appear.
3822
+ *
3823
+ * This is useful if you don't care about which pattern matched, and just
3824
+ * want a single, ordered sequence of captures.
3825
+ *
3826
+ * @param {Node} node - The node to execute the query on.
3827
+ *
3828
+ * @param {QueryOptions} options - Options for query execution.
3829
+ */
3830
+ captures(node, options = {}) {
3831
+ const startPosition = options.startPosition ?? ZERO_POINT;
3832
+ const endPosition = options.endPosition ?? ZERO_POINT;
3833
+ const startIndex = options.startIndex ?? 0;
3834
+ const endIndex = options.endIndex ?? 0;
3835
+ const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
3836
+ const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
3837
+ const startContainingIndex = options.startContainingIndex ?? 0;
3838
+ const endContainingIndex = options.endContainingIndex ?? 0;
3839
+ const matchLimit = options.matchLimit ?? 4294967295;
3840
+ const maxStartDepth = options.maxStartDepth ?? 4294967295;
3841
+ const progressCallback = options.progressCallback;
3842
+ if (typeof matchLimit !== "number") {
3843
+ throw new Error("Arguments must be numbers");
3844
+ }
3845
+ this.matchLimit = matchLimit;
3846
+ if (endIndex !== 0 && startIndex > endIndex) {
3847
+ throw new Error("`startIndex` cannot be greater than `endIndex`");
3848
+ }
3849
+ if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
3850
+ throw new Error("`startPosition` cannot be greater than `endPosition`");
3851
+ }
3852
+ if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
3853
+ throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
3854
+ }
3855
+ if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
3856
+ throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
3857
+ }
3858
+ if (progressCallback) {
3859
+ C.currentQueryProgressCallback = progressCallback;
3860
+ }
3861
+ marshalNode(node);
3862
+ C._ts_query_captures_wasm(
3863
+ this[0],
3864
+ node.tree[0],
3865
+ startPosition.row,
3866
+ startPosition.column,
3867
+ endPosition.row,
3868
+ endPosition.column,
3869
+ startIndex,
3870
+ endIndex,
3871
+ startContainingPosition.row,
3872
+ startContainingPosition.column,
3873
+ endContainingPosition.row,
3874
+ endContainingPosition.column,
3875
+ startContainingIndex,
3876
+ endContainingIndex,
3877
+ matchLimit,
3878
+ maxStartDepth
3879
+ );
3880
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
3881
+ const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
3882
+ const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
3883
+ const result = new Array();
3884
+ this.exceededMatchLimit = Boolean(didExceedMatchLimit);
3885
+ const captures = new Array();
3886
+ let address = startAddress;
3887
+ for (let i2 = 0; i2 < count; i2++) {
3888
+ const patternIndex = C.getValue(address, "i32");
3889
+ address += SIZE_OF_INT;
3890
+ const captureCount = C.getValue(address, "i32");
3891
+ address += SIZE_OF_INT;
3892
+ const captureIndex = C.getValue(address, "i32");
3893
+ address += SIZE_OF_INT;
3894
+ captures.length = captureCount;
3895
+ address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
3896
+ if (this.textPredicates[patternIndex].every((p) => p(captures))) {
3897
+ const capture = captures[captureIndex];
3898
+ const setProperties = this.setProperties[patternIndex];
3899
+ capture.setProperties = setProperties;
3900
+ const assertedProperties = this.assertedProperties[patternIndex];
3901
+ capture.assertedProperties = assertedProperties;
3902
+ const refutedProperties = this.refutedProperties[patternIndex];
3903
+ capture.refutedProperties = refutedProperties;
3904
+ result.push(capture);
3905
+ }
3906
+ }
3907
+ C._free(startAddress);
3908
+ C.currentQueryProgressCallback = null;
3909
+ return result;
3910
+ }
3911
+ /** Get the predicates for a given pattern. */
3912
+ predicatesForPattern(patternIndex) {
3913
+ return this.predicates[patternIndex];
3914
+ }
3915
+ /**
3916
+ * Disable a certain capture within a query.
3917
+ *
3918
+ * This prevents the capture from being returned in matches, and also
3919
+ * avoids any resource usage associated with recording the capture.
3920
+ */
3921
+ disableCapture(captureName) {
3922
+ const captureNameLength = C.lengthBytesUTF8(captureName);
3923
+ const captureNameAddress = C._malloc(captureNameLength + 1);
3924
+ C.stringToUTF8(captureName, captureNameAddress, captureNameLength + 1);
3925
+ C._ts_query_disable_capture(this[0], captureNameAddress, captureNameLength);
3926
+ C._free(captureNameAddress);
3927
+ }
3928
+ /**
3929
+ * Disable a certain pattern within a query.
3930
+ *
3931
+ * This prevents the pattern from matching, and also avoids any resource
3932
+ * usage associated with the pattern. This throws an error if the pattern
3933
+ * index is out of bounds.
3934
+ */
3935
+ disablePattern(patternIndex) {
3936
+ if (patternIndex >= this.predicates.length) {
3937
+ throw new Error(
3938
+ `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
3939
+ );
3940
+ }
3941
+ C._ts_query_disable_pattern(this[0], patternIndex);
3942
+ }
3943
+ /**
3944
+ * Check if, on its last execution, this cursor exceeded its maximum number
3945
+ * of in-progress matches.
3946
+ */
3947
+ didExceedMatchLimit() {
3948
+ return this.exceededMatchLimit;
3949
+ }
3950
+ /** Get the byte offset where the given pattern starts in the query's source. */
3951
+ startIndexForPattern(patternIndex) {
3952
+ if (patternIndex >= this.predicates.length) {
3953
+ throw new Error(
3954
+ `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
3955
+ );
3956
+ }
3957
+ return C._ts_query_start_byte_for_pattern(this[0], patternIndex);
3958
+ }
3959
+ /** Get the byte offset where the given pattern ends in the query's source. */
3960
+ endIndexForPattern(patternIndex) {
3961
+ if (patternIndex >= this.predicates.length) {
3962
+ throw new Error(
3963
+ `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
3964
+ );
3965
+ }
3966
+ return C._ts_query_end_byte_for_pattern(this[0], patternIndex);
3967
+ }
3968
+ /** Get the number of patterns in the query. */
3969
+ patternCount() {
3970
+ return C._ts_query_pattern_count(this[0]);
3971
+ }
3972
+ /** Get the index for a given capture name. */
3973
+ captureIndexForName(captureName) {
3974
+ return this.captureNames.indexOf(captureName);
3975
+ }
3976
+ /** Check if a given pattern within a query has a single root node. */
3977
+ isPatternRooted(patternIndex) {
3978
+ return C._ts_query_is_pattern_rooted(this[0], patternIndex) === 1;
3979
+ }
3980
+ /** Check if a given pattern within a query has a single root node. */
3981
+ isPatternNonLocal(patternIndex) {
3982
+ return C._ts_query_is_pattern_non_local(this[0], patternIndex) === 1;
3983
+ }
3984
+ /**
3985
+ * Check if a given step in a query is 'definite'.
3986
+ *
3987
+ * A query step is 'definite' if its parent pattern will be guaranteed to
3988
+ * match successfully once it reaches the step.
3989
+ */
3990
+ isPatternGuaranteedAtStep(byteIndex) {
3991
+ return C._ts_query_is_pattern_guaranteed_at_step(this[0], byteIndex) === 1;
3992
+ }
3993
+ };
3994
+ export {
3995
+ CaptureQuantifier,
3996
+ Edit,
3997
+ LANGUAGE_VERSION,
3998
+ Language,
3999
+ LookaheadIterator,
4000
+ MIN_COMPATIBLE_VERSION,
4001
+ Node,
4002
+ Parser,
4003
+ Query,
4004
+ Tree,
4005
+ TreeCursor
4006
+ };
4007
+ //# sourceMappingURL=web-tree-sitter.js.map