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