@levnikolaevich/hex-line-mcp 1.3.4 → 1.3.5

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