UNPKG

web-tree-sitter

Version:
1,098 lines (1,097 loc) 195 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name2 in all) __defProp(target, name2, { get: all[name2], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // lib/tree-sitter.cjs var require_tree_sitter = __commonJS({ "lib/tree-sitter.cjs"(exports, module) { "use strict"; var Module = (() => { var _scriptName = typeof document != "undefined" ? document.currentScript?.src : void 0; if (typeof __filename != "undefined") _scriptName = _scriptName || __filename; return async function(moduleArg = {}) { var moduleRtn; var Module = moduleArg; var readyPromiseResolve, readyPromiseReject; var readyPromise = new Promise((resolve, reject) => { readyPromiseResolve = resolve; readyPromiseReject = reject; }); var ENVIRONMENT_IS_WEB = typeof window == "object"; var ENVIRONMENT_IS_WORKER = typeof WorkerGlobalScope != "undefined"; var ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string" && process.type != "renderer"; var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER; if (ENVIRONMENT_IS_NODE) { } Module.currentQueryProgressCallback = null; Module.currentProgressCallback = null; Module.currentLogCallback = null; Module.currentParseCallback = null; var moduleOverrides = Object.assign({}, Module); var arguments_ = []; var thisProgram = "./this.program"; var quit_ = /* @__PURE__ */ __name((status, toThrow) => { throw toThrow; }, "quit_"); var scriptDirectory = ""; function locateFile(path) { if (Module["locateFile"]) { return Module["locateFile"](path, scriptDirectory); } return scriptDirectory + path; } __name(locateFile, "locateFile"); var readAsync, readBinary; if (ENVIRONMENT_IS_NODE) { if (typeof process == "undefined" || !process.release || process.release.name !== "node") throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)"); var nodeVersion = process.versions.node; var numericVersion = nodeVersion.split(".").slice(0, 3); numericVersion = numericVersion[0] * 1e4 + numericVersion[1] * 100 + numericVersion[2].split("-")[0] * 1; var minVersion = 16e4; if (numericVersion < 16e4) { throw new Error("This emscripten-generated code requires node v16.0.0 (detected v" + nodeVersion + ")"); } var fs = require("fs"); var nodePath = require("path"); scriptDirectory = __dirname + "/"; readBinary = /* @__PURE__ */ __name((filename) => { filename = isFileURI(filename) ? new URL(filename) : filename; var ret = fs.readFileSync(filename); assert(Buffer.isBuffer(ret)); return ret; }, "readBinary"); readAsync = /* @__PURE__ */ __name(async (filename, binary2 = true) => { filename = isFileURI(filename) ? new URL(filename) : filename; var ret = fs.readFileSync(filename, binary2 ? void 0 : "utf8"); assert(binary2 ? Buffer.isBuffer(ret) : typeof ret == "string"); return ret; }, "readAsync"); if (!Module["thisProgram"] && process.argv.length > 1) { thisProgram = process.argv[1].replace(/\\/g, "/"); } arguments_ = process.argv.slice(2); quit_ = /* @__PURE__ */ __name((status, toThrow) => { process.exitCode = status; throw toThrow; }, "quit_"); } else if (ENVIRONMENT_IS_SHELL) { if (typeof process == "object" && typeof require === "function" || typeof window == "object" || typeof WorkerGlobalScope != "undefined") throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)"); } else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { if (ENVIRONMENT_IS_WORKER) { scriptDirectory = self.location.href; } else if (typeof document != "undefined" && document.currentScript) { scriptDirectory = document.currentScript.src; } if (_scriptName) { scriptDirectory = _scriptName; } if (scriptDirectory.startsWith("blob:")) { scriptDirectory = ""; } else { scriptDirectory = scriptDirectory.slice(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1); } if (!(typeof window == "object" || typeof WorkerGlobalScope != "undefined")) throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)"); { if (ENVIRONMENT_IS_WORKER) { readBinary = /* @__PURE__ */ __name((url) => { var xhr = new XMLHttpRequest(); xhr.open("GET", url, false); xhr.responseType = "arraybuffer"; xhr.send(null); return new Uint8Array( /** @type{!ArrayBuffer} */ xhr.response ); }, "readBinary"); } readAsync = /* @__PURE__ */ __name(async (url) => { if (isFileURI(url)) { return new Promise((resolve, reject) => { var xhr = new XMLHttpRequest(); xhr.open("GET", url, true); xhr.responseType = "arraybuffer"; xhr.onload = () => { if (xhr.status == 200 || xhr.status == 0 && xhr.response) { resolve(xhr.response); return; } reject(xhr.status); }; xhr.onerror = reject; xhr.send(null); }); } var response = await fetch(url, { credentials: "same-origin" }); if (response.ok) { return response.arrayBuffer(); } throw new Error(response.status + " : " + response.url); }, "readAsync"); } } else { throw new Error("environment detection error"); } var out = Module["print"] || console.log.bind(console); var err = Module["printErr"] || console.error.bind(console); Object.assign(Module, moduleOverrides); moduleOverrides = null; checkIncomingModuleAPI(); if (Module["arguments"]) arguments_ = Module["arguments"]; legacyModuleProp("arguments", "arguments_"); if (Module["thisProgram"]) thisProgram = Module["thisProgram"]; legacyModuleProp("thisProgram", "thisProgram"); assert(typeof Module["memoryInitializerPrefixURL"] == "undefined", "Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead"); assert(typeof Module["pthreadMainPrefixURL"] == "undefined", "Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead"); assert(typeof Module["cdInitializerPrefixURL"] == "undefined", "Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead"); assert(typeof Module["filePackagePrefixURL"] == "undefined", "Module.filePackagePrefixURL option was removed, use Module.locateFile instead"); assert(typeof Module["read"] == "undefined", "Module.read option was removed"); assert(typeof Module["readAsync"] == "undefined", "Module.readAsync option was removed (modify readAsync in JS)"); assert(typeof Module["readBinary"] == "undefined", "Module.readBinary option was removed (modify readBinary in JS)"); assert(typeof Module["setWindowTitle"] == "undefined", "Module.setWindowTitle option was removed (modify emscripten_set_window_title in JS)"); assert(typeof Module["TOTAL_MEMORY"] == "undefined", "Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY"); legacyModuleProp("asm", "wasmExports"); legacyModuleProp("readAsync", "readAsync"); legacyModuleProp("readBinary", "readBinary"); legacyModuleProp("setWindowTitle", "setWindowTitle"); var IDBFS = "IDBFS is no longer included by default; build with -lidbfs.js"; var PROXYFS = "PROXYFS is no longer included by default; build with -lproxyfs.js"; var WORKERFS = "WORKERFS is no longer included by default; build with -lworkerfs.js"; var FETCHFS = "FETCHFS is no longer included by default; build with -lfetchfs.js"; var ICASEFS = "ICASEFS is no longer included by default; build with -licasefs.js"; var JSFILEFS = "JSFILEFS is no longer included by default; build with -ljsfilefs.js"; var OPFS = "OPFS is no longer included by default; build with -lopfs.js"; var NODEFS = "NODEFS is no longer included by default; build with -lnodefs.js"; assert(!ENVIRONMENT_IS_SHELL, "shell environment detected but not enabled at build time. Add `shell` to `-sENVIRONMENT` to enable."); var dynamicLibraries = Module["dynamicLibraries"] || []; var wasmBinary = Module["wasmBinary"]; legacyModuleProp("wasmBinary", "wasmBinary"); if (typeof WebAssembly != "object") { err("no native wasm support detected"); } var wasmMemory; var ABORT = false; var EXITSTATUS; function assert(condition, text) { if (!condition) { abort("Assertion failed" + (text ? ": " + text : "")); } } __name(assert, "assert"); var HEAP, HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAP64, HEAPU64, HEAPF64; var HEAP_DATA_VIEW; var runtimeInitialized = false; var isFileURI = /* @__PURE__ */ __name((filename) => filename.startsWith("file://"), "isFileURI"); function writeStackCookie() { var max = _emscripten_stack_get_end(); assert((max & 3) == 0); if (max == 0) { max += 4; } LE_HEAP_STORE_U32((max >> 2) * 4, 34821223); LE_HEAP_STORE_U32((max + 4 >> 2) * 4, 2310721022); } __name(writeStackCookie, "writeStackCookie"); function checkStackCookie() { if (ABORT) return; var max = _emscripten_stack_get_end(); if (max == 0) { max += 4; } var cookie1 = LE_HEAP_LOAD_U32((max >> 2) * 4); var cookie2 = LE_HEAP_LOAD_U32((max + 4 >> 2) * 4); if (cookie1 != 34821223 || cookie2 != 2310721022) { abort(`Stack overflow! Stack cookie has been overwritten at ${ptrToString(max)}, expected hex dwords 0x89BACDFE and 0x2135467, but received ${ptrToString(cookie2)} ${ptrToString(cookie1)}`); } } __name(checkStackCookie, "checkStackCookie"); if (Module["ENVIRONMENT"]) { throw new Error("Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -sENVIRONMENT=web or -sENVIRONMENT=node)"); } function legacyModuleProp(prop, newName, incoming = true) { if (!Object.getOwnPropertyDescriptor(Module, prop)) { Object.defineProperty(Module, prop, { configurable: true, get() { let extra = incoming ? " (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)" : ""; abort(`\`Module.${prop}\` has been replaced by \`${newName}\`` + extra); } }); } } __name(legacyModuleProp, "legacyModuleProp"); function consumedModuleProp(prop) { if (!Object.getOwnPropertyDescriptor(Module, prop)) { Object.defineProperty(Module, prop, { configurable: true, set() { abort(`Attempt to set \`Module.${prop}\` after it has already been processed. This can happen, for example, when code is injected via '--post-js' rather than '--pre-js'`); } }); } } __name(consumedModuleProp, "consumedModuleProp"); function ignoredModuleProp(prop) { if (Object.getOwnPropertyDescriptor(Module, prop)) { abort(`\`Module.${prop}\` was supplied but \`${prop}\` not included in INCOMING_MODULE_JS_API`); } } __name(ignoredModuleProp, "ignoredModuleProp"); function isExportedByForceFilesystem(name2) { return name2 === "FS_createPath" || name2 === "FS_createDataFile" || name2 === "FS_createPreloadedFile" || name2 === "FS_unlink" || name2 === "addRunDependency" || // The old FS has some functionality that WasmFS lacks. name2 === "FS_createLazyFile" || name2 === "FS_createDevice" || name2 === "removeRunDependency"; } __name(isExportedByForceFilesystem, "isExportedByForceFilesystem"); function hookGlobalSymbolAccess(sym, func2) { } __name(hookGlobalSymbolAccess, "hookGlobalSymbolAccess"); function missingGlobal(sym, msg) { hookGlobalSymbolAccess(sym, () => { warnOnce(`\`${sym}\` is not longer defined by emscripten. ${msg}`); }); } __name(missingGlobal, "missingGlobal"); missingGlobal("buffer", "Please use HEAP8.buffer or wasmMemory.buffer"); missingGlobal("asm", "Please use wasmExports instead"); function missingLibrarySymbol(sym) { hookGlobalSymbolAccess(sym, () => { var msg = `\`${sym}\` is a library symbol and not included by default; add it to your library.js __deps or to DEFAULT_LIBRARY_FUNCS_TO_INCLUDE on the command line`; var librarySymbol = sym; if (!librarySymbol.startsWith("_")) { librarySymbol = "$" + sym; } msg += ` (e.g. -sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE='${librarySymbol}')`; if (isExportedByForceFilesystem(sym)) { msg += ". Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you"; } warnOnce(msg); }); unexportedRuntimeSymbol(sym); } __name(missingLibrarySymbol, "missingLibrarySymbol"); function unexportedRuntimeSymbol(sym) { if (!Object.getOwnPropertyDescriptor(Module, sym)) { Object.defineProperty(Module, sym, { configurable: true, get() { var msg = `'${sym}' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)`; if (isExportedByForceFilesystem(sym)) { msg += ". Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you"; } abort(msg); } }); } } __name(unexportedRuntimeSymbol, "unexportedRuntimeSymbol"); function dbg(...args2) { console.warn(...args2); } __name(dbg, "dbg"); function getSafeHeapType(bytes, isFloat) { switch (bytes) { case 1: return "i8"; case 2: return "i16"; case 4: return isFloat ? "float" : "i32"; case 8: return isFloat ? "double" : "i64"; default: abort(`getSafeHeapType() invalid bytes=${bytes}`); } } __name(getSafeHeapType, "getSafeHeapType"); function SAFE_HEAP_STORE(dest, value, bytes, isFloat) { if (dest <= 0) abort(`segmentation fault storing ${bytes} bytes to address ${dest}`); if (dest % bytes !== 0) abort(`alignment error storing to address ${dest}, which was expected to be aligned to a multiple of ${bytes}`); if (runtimeInitialized) { var brk = _sbrk(0); if (dest + bytes > brk) abort(`segmentation fault, exceeded the top of the available dynamic heap when storing ${bytes} bytes to address ${dest}. DYNAMICTOP=${brk}`); if (brk < _emscripten_stack_get_base()) abort(`brk >= _emscripten_stack_get_base() (brk=${brk}, _emscripten_stack_get_base()=${_emscripten_stack_get_base()})`); if (brk > wasmMemory.buffer.byteLength) abort(`brk <= wasmMemory.buffer.byteLength (brk=${brk}, wasmMemory.buffer.byteLength=${wasmMemory.buffer.byteLength})`); } setValue_safe(dest, value, getSafeHeapType(bytes, isFloat)); return value; } __name(SAFE_HEAP_STORE, "SAFE_HEAP_STORE"); function SAFE_HEAP_STORE_D(dest, value, bytes) { return SAFE_HEAP_STORE(dest, value, bytes, true); } __name(SAFE_HEAP_STORE_D, "SAFE_HEAP_STORE_D"); function SAFE_HEAP_LOAD(dest, bytes, unsigned, isFloat) { if (dest <= 0) abort(`segmentation fault loading ${bytes} bytes from address ${dest}`); if (dest % bytes !== 0) abort(`alignment error loading from address ${dest}, which was expected to be aligned to a multiple of ${bytes}`); if (runtimeInitialized) { var brk = _sbrk(0); if (dest + bytes > brk) abort(`segmentation fault, exceeded the top of the available dynamic heap when loading ${bytes} bytes from address ${dest}. DYNAMICTOP=${brk}`); if (brk < _emscripten_stack_get_base()) abort(`brk >= _emscripten_stack_get_base() (brk=${brk}, _emscripten_stack_get_base()=${_emscripten_stack_get_base()})`); if (brk > wasmMemory.buffer.byteLength) abort(`brk <= wasmMemory.buffer.byteLength (brk=${brk}, wasmMemory.buffer.byteLength=${wasmMemory.buffer.byteLength})`); } var type = getSafeHeapType(bytes, isFloat); var ret = getValue_safe(dest, type); if (unsigned) ret = unSign(ret, parseInt(type.slice(1), 10)); return ret; } __name(SAFE_HEAP_LOAD, "SAFE_HEAP_LOAD"); function SAFE_HEAP_LOAD_D(dest, bytes, unsigned) { return SAFE_HEAP_LOAD(dest, bytes, unsigned, true); } __name(SAFE_HEAP_LOAD_D, "SAFE_HEAP_LOAD_D"); function SAFE_FT_MASK(value, mask) { var ret = value & mask; if (ret !== value) { abort(`Function table mask error: function pointer is ${value} which is masked by ${mask}, the likely cause of this is that the function pointer is being called by the wrong type.`); } return ret; } __name(SAFE_FT_MASK, "SAFE_FT_MASK"); function segfault() { abort("segmentation fault"); } __name(segfault, "segfault"); function alignfault() { abort("alignment fault"); } __name(alignfault, "alignfault"); function updateMemoryViews() { var b = wasmMemory.buffer; Module["HEAP_DATA_VIEW"] = HEAP_DATA_VIEW = new DataView(b); Module["HEAP8"] = HEAP8 = new Int8Array(b); Module["HEAP16"] = HEAP16 = new Int16Array(b); Module["HEAPU8"] = HEAPU8 = new Uint8Array(b); Module["HEAPU16"] = HEAPU16 = new Uint16Array(b); Module["HEAP32"] = HEAP32 = new Int32Array(b); Module["HEAPU32"] = HEAPU32 = new Uint32Array(b); Module["HEAPF32"] = HEAPF32 = new Float32Array(b); Module["HEAPF64"] = HEAPF64 = new Float64Array(b); Module["HEAP64"] = HEAP64 = new BigInt64Array(b); Module["HEAPU64"] = HEAPU64 = new BigUint64Array(b); } __name(updateMemoryViews, "updateMemoryViews"); assert(!Module["STACK_SIZE"], "STACK_SIZE can no longer be set at runtime. Use -sSTACK_SIZE at link time"); assert(typeof Int32Array != "undefined" && typeof Float64Array !== "undefined" && Int32Array.prototype.subarray != void 0 && Int32Array.prototype.set != void 0, "JS engine does not provide full typed array support"); if (Module["wasmMemory"]) { wasmMemory = Module["wasmMemory"]; } else { var INITIAL_MEMORY = Module["INITIAL_MEMORY"] || 33554432; legacyModuleProp("INITIAL_MEMORY", "INITIAL_MEMORY"); assert(INITIAL_MEMORY >= 65536, "INITIAL_MEMORY should be larger than STACK_SIZE, was " + INITIAL_MEMORY + "! (STACK_SIZE=65536)"); wasmMemory = new WebAssembly.Memory({ "initial": INITIAL_MEMORY / 65536, // In theory we should not need to emit the maximum if we want "unlimited" // or 4GB of memory, but VMs error on that atm, see // https://github.com/emscripten-core/emscripten/issues/14130 // And in the pthreads case we definitely need to emit a maximum. So // always emit one. "maximum": 32768 }); } updateMemoryViews(); var __RELOC_FUNCS__ = []; function preRun() { if (Module["preRun"]) { if (typeof Module["preRun"] == "function") Module["preRun"] = [Module["preRun"]]; while (Module["preRun"].length) { addOnPreRun(Module["preRun"].shift()); } } consumedModuleProp("preRun"); callRuntimeCallbacks(onPreRuns); } __name(preRun, "preRun"); function initRuntime() { assert(!runtimeInitialized); runtimeInitialized = true; checkStackCookie(); callRuntimeCallbacks(__RELOC_FUNCS__); wasmExports["__wasm_call_ctors"](); callRuntimeCallbacks(onPostCtors); } __name(initRuntime, "initRuntime"); function preMain() { checkStackCookie(); } __name(preMain, "preMain"); function postRun() { checkStackCookie(); if (Module["postRun"]) { if (typeof Module["postRun"] == "function") Module["postRun"] = [Module["postRun"]]; while (Module["postRun"].length) { addOnPostRun(Module["postRun"].shift()); } } consumedModuleProp("postRun"); callRuntimeCallbacks(onPostRuns); } __name(postRun, "postRun"); var runDependencies = 0; var dependenciesFulfilled = null; var runDependencyTracking = {}; var runDependencyWatcher = null; function getUniqueRunDependency(id) { var orig = id; while (1) { if (!runDependencyTracking[id]) return id; id = orig + Math.random(); } } __name(getUniqueRunDependency, "getUniqueRunDependency"); function addRunDependency(id) { runDependencies++; Module["monitorRunDependencies"]?.(runDependencies); if (id) { assert(!runDependencyTracking[id]); runDependencyTracking[id] = 1; if (runDependencyWatcher === null && typeof setInterval != "undefined") { runDependencyWatcher = setInterval(() => { if (ABORT) { clearInterval(runDependencyWatcher); runDependencyWatcher = null; return; } var shown = false; for (var dep in runDependencyTracking) { if (!shown) { shown = true; err("still waiting on run dependencies:"); } err(`dependency: ${dep}`); } if (shown) { err("(end of list)"); } }, 1e4); } } else { err("warning: run dependency added without ID"); } } __name(addRunDependency, "addRunDependency"); function removeRunDependency(id) { runDependencies--; Module["monitorRunDependencies"]?.(runDependencies); if (id) { assert(runDependencyTracking[id]); delete runDependencyTracking[id]; } else { err("warning: run dependency removed without ID"); } if (runDependencies == 0) { if (runDependencyWatcher !== null) { clearInterval(runDependencyWatcher); runDependencyWatcher = null; } if (dependenciesFulfilled) { var callback = dependenciesFulfilled; dependenciesFulfilled = null; callback(); } } } __name(removeRunDependency, "removeRunDependency"); function abort(what) { Module["onAbort"]?.(what); what = "Aborted(" + what + ")"; err(what); ABORT = true; var e = new WebAssembly.RuntimeError(what); readyPromiseReject(e); throw e; } __name(abort, "abort"); var FS = { error() { abort("Filesystem support (FS) was not included. The problem is that you are using files from JS, but files were not used from C/C++, so filesystem support was not auto-included. You can force-include filesystem support with -sFORCE_FILESYSTEM"); }, init() { FS.error(); }, createDataFile() { FS.error(); }, createPreloadedFile() { FS.error(); }, createLazyFile() { FS.error(); }, open() { FS.error(); }, mkdev() { FS.error(); }, registerDevice() { FS.error(); }, analyzePath() { FS.error(); }, ErrnoError() { FS.error(); } }; Module["FS_createDataFile"] = FS.createDataFile; Module["FS_createPreloadedFile"] = FS.createPreloadedFile; function createExportWrapper(name2, nargs) { return (...args2) => { assert(runtimeInitialized, `native function \`${name2}\` called before runtime initialization`); var f = wasmExports[name2]; assert(f, `exported native function \`${name2}\` not found`); assert(args2.length <= nargs, `native function \`${name2}\` called with ${args2.length} args but expects ${nargs}`); return f(...args2); }; } __name(createExportWrapper, "createExportWrapper"); var wasmBinaryFile; function findWasmBinary() { return locateFile("tree-sitter.wasm"); } __name(findWasmBinary, "findWasmBinary"); function getBinarySync(file) { if (file == wasmBinaryFile && wasmBinary) { return new Uint8Array(wasmBinary); } if (readBinary) { return readBinary(file); } throw "both async and sync fetching of the wasm failed"; } __name(getBinarySync, "getBinarySync"); async function getWasmBinary(binaryFile) { if (!wasmBinary) { try { var response = await readAsync(binaryFile); return new Uint8Array(response); } catch { } } return getBinarySync(binaryFile); } __name(getWasmBinary, "getWasmBinary"); async function instantiateArrayBuffer(binaryFile, imports) { try { var binary2 = await getWasmBinary(binaryFile); var instance2 = await WebAssembly.instantiate(binary2, imports); return instance2; } catch (reason) { err(`failed to asynchronously prepare wasm: ${reason}`); if (isFileURI(wasmBinaryFile)) { err(`warning: Loading from a file URI (${wasmBinaryFile}) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing`); } abort(reason); } } __name(instantiateArrayBuffer, "instantiateArrayBuffer"); async function instantiateAsync(binary2, binaryFile, imports) { if (!binary2 && typeof WebAssembly.instantiateStreaming == "function" && !isFileURI(binaryFile) && !ENVIRONMENT_IS_NODE) { try { var response = fetch(binaryFile, { credentials: "same-origin" }); var instantiationResult = await WebAssembly.instantiateStreaming(response, imports); return instantiationResult; } catch (reason) { err(`wasm streaming compile failed: ${reason}`); err("falling back to ArrayBuffer instantiation"); } } return instantiateArrayBuffer(binaryFile, imports); } __name(instantiateAsync, "instantiateAsync"); function getWasmImports() { return { "env": wasmImports, "wasi_snapshot_preview1": wasmImports, "GOT.mem": new Proxy(wasmImports, GOTHandler), "GOT.func": new Proxy(wasmImports, GOTHandler) }; } __name(getWasmImports, "getWasmImports"); async function createWasm() { function receiveInstance(instance2, module2) { wasmExports = instance2.exports; wasmExports = relocateExports(wasmExports, 1024); var metadata2 = getDylinkMetadata(module2); if (metadata2.neededDynlibs) { dynamicLibraries = metadata2.neededDynlibs.concat(dynamicLibraries); } mergeLibSymbols(wasmExports, "main"); LDSO.init(); loadDylibs(); __RELOC_FUNCS__.push(wasmExports["__wasm_apply_data_relocs"]); removeRunDependency("wasm-instantiate"); return wasmExports; } __name(receiveInstance, "receiveInstance"); addRunDependency("wasm-instantiate"); var trueModule = Module; function receiveInstantiationResult(result2) { assert(Module === trueModule, "the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?"); trueModule = null; return receiveInstance(result2["instance"], result2["module"]); } __name(receiveInstantiationResult, "receiveInstantiationResult"); var info2 = getWasmImports(); if (Module["instantiateWasm"]) { return new Promise((resolve, reject) => { try { Module["instantiateWasm"](info2, (mod, inst) => { receiveInstance(mod, inst); resolve(mod.exports); }); } catch (e) { err(`Module.instantiateWasm callback failed with error: ${e}`); reject(e); } }); } wasmBinaryFile ??= findWasmBinary(); try { var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info2); var exports2 = receiveInstantiationResult(result); return exports2; } catch (e) { readyPromiseReject(e); return Promise.reject(e); } } __name(createWasm, "createWasm"); var ASM_CONSTS = {}; class ExitStatus { static { __name(this, "ExitStatus"); } name = "ExitStatus"; constructor(status) { this.message = `Program terminated with exit(${status})`; this.status = status; } } var GOT = {}; var currentModuleWeakSymbols = /* @__PURE__ */ new Set([]); var GOTHandler = { get(obj, symName) { var rtn = GOT[symName]; if (!rtn) { rtn = GOT[symName] = new WebAssembly.Global({ "value": "i32", "mutable": true }); } if (!currentModuleWeakSymbols.has(symName)) { rtn.required = true; } return rtn; } }; var LE_HEAP_LOAD_F32 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getFloat32(byteOffset, true), "LE_HEAP_LOAD_F32"); var LE_HEAP_LOAD_F64 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getFloat64(byteOffset, true), "LE_HEAP_LOAD_F64"); var LE_HEAP_LOAD_I16 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getInt16(byteOffset, true), "LE_HEAP_LOAD_I16"); var LE_HEAP_LOAD_I32 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getInt32(byteOffset, true), "LE_HEAP_LOAD_I32"); var LE_HEAP_LOAD_U16 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getUint16(byteOffset, true), "LE_HEAP_LOAD_U16"); var LE_HEAP_LOAD_U32 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getUint32(byteOffset, true), "LE_HEAP_LOAD_U32"); var LE_HEAP_STORE_F32 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setFloat32(byteOffset, value, true), "LE_HEAP_STORE_F32"); var LE_HEAP_STORE_F64 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setFloat64(byteOffset, value, true), "LE_HEAP_STORE_F64"); var LE_HEAP_STORE_I16 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setInt16(byteOffset, value, true), "LE_HEAP_STORE_I16"); var LE_HEAP_STORE_I32 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setInt32(byteOffset, value, true), "LE_HEAP_STORE_I32"); var LE_HEAP_STORE_U16 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setUint16(byteOffset, value, true), "LE_HEAP_STORE_U16"); var LE_HEAP_STORE_U32 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setUint32(byteOffset, value, true), "LE_HEAP_STORE_U32"); var callRuntimeCallbacks = /* @__PURE__ */ __name((callbacks) => { while (callbacks.length > 0) { callbacks.shift()(Module); } }, "callRuntimeCallbacks"); var onPostRuns = []; var addOnPostRun = /* @__PURE__ */ __name((cb) => onPostRuns.unshift(cb), "addOnPostRun"); var onPreRuns = []; var addOnPreRun = /* @__PURE__ */ __name((cb) => onPreRuns.unshift(cb), "addOnPreRun"); var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder() : void 0; var UTF8ArrayToString = /* @__PURE__ */ __name((heapOrArray, idx = 0, maxBytesToRead = NaN) => { var endIdx = idx + maxBytesToRead; var endPtr = idx; while (heapOrArray[endPtr] && !(endPtr >= endIdx)) ++endPtr; if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) { return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr)); } var str = ""; while (idx < endPtr) { var u0 = heapOrArray[idx++]; if (!(u0 & 128)) { str += String.fromCharCode(u0); continue; } var u1 = heapOrArray[idx++] & 63; if ((u0 & 224) == 192) { str += String.fromCharCode((u0 & 31) << 6 | u1); continue; } var u2 = heapOrArray[idx++] & 63; if ((u0 & 240) == 224) { u0 = (u0 & 15) << 12 | u1 << 6 | u2; } else { if ((u0 & 248) != 240) warnOnce("Invalid UTF-8 leading byte " + ptrToString(u0) + " encountered when deserializing a UTF-8 string in wasm memory to a JS string!"); u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heapOrArray[idx++] & 63; } if (u0 < 65536) { str += String.fromCharCode(u0); } else { var ch = u0 - 65536; str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023); } } return str; }, "UTF8ArrayToString"); var getDylinkMetadata = /* @__PURE__ */ __name((binary2) => { var offset = 0; var end = 0; function getU8() { return binary2[offset++]; } __name(getU8, "getU8"); function getLEB() { var ret = 0; var mul = 1; while (1) { var byte = binary2[offset++]; ret += (byte & 127) * mul; mul *= 128; if (!(byte & 128)) break; } return ret; } __name(getLEB, "getLEB"); function getString() { var len = getLEB(); offset += len; return UTF8ArrayToString(binary2, offset - len, len); } __name(getString, "getString"); function failIf(condition, message) { if (condition) throw new Error(message); } __name(failIf, "failIf"); var name2 = "dylink.0"; if (binary2 instanceof WebAssembly.Module) { var dylinkSection = WebAssembly.Module.customSections(binary2, name2); if (dylinkSection.length === 0) { name2 = "dylink"; dylinkSection = WebAssembly.Module.customSections(binary2, name2); } failIf(dylinkSection.length === 0, "need dylink section"); binary2 = new Uint8Array(dylinkSection[0]); end = binary2.length; } else { var int32View = new Uint32Array(new Uint8Array(binary2.subarray(0, 24)).buffer); var magicNumberFound = int32View[0] == 1836278016 || int32View[0] == 6386541; failIf(!magicNumberFound, "need to see wasm magic number"); failIf(binary2[8] !== 0, "need the dylink section to be first"); offset = 9; var section_size = getLEB(); end = offset + section_size; name2 = getString(); } var customSection = { neededDynlibs: [], tlsExports: /* @__PURE__ */ new Set(), weakImports: /* @__PURE__ */ new Set() }; if (name2 == "dylink") { customSection.memorySize = getLEB(); customSection.memoryAlign = getLEB(); customSection.tableSize = getLEB(); customSection.tableAlign = getLEB(); var neededDynlibsCount = getLEB(); for (var i2 = 0; i2 < neededDynlibsCount; ++i2) { var libname = getString(); customSection.neededDynlibs.push(libname); } } else { failIf(name2 !== "dylink.0"); var WASM_DYLINK_MEM_INFO = 1; var WASM_DYLINK_NEEDED = 2; var WASM_DYLINK_EXPORT_INFO = 3; var WASM_DYLINK_IMPORT_INFO = 4; var WASM_SYMBOL_TLS = 256; var WASM_SYMBOL_BINDING_MASK = 3; var WASM_SYMBOL_BINDING_WEAK = 1; while (offset < end) { var subsectionType = getU8(); var subsectionSize = getLEB(); if (subsectionType === WASM_DYLINK_MEM_INFO) { customSection.memorySize = getLEB(); customSection.memoryAlign = getLEB(); customSection.tableSize = getLEB(); customSection.tableAlign = getLEB(); } else if (subsectionType === WASM_DYLINK_NEEDED) { var neededDynlibsCount = getLEB(); for (var i2 = 0; i2 < neededDynlibsCount; ++i2) { libname = getString(); customSection.neededDynlibs.push(libname); } } else if (subsectionType === WASM_DYLINK_EXPORT_INFO) { var count = getLEB(); while (count--) { var symname = getString(); var flags2 = getLEB(); if (flags2 & WASM_SYMBOL_TLS) { customSection.tlsExports.add(symname); } } } else if (subsectionType === WASM_DYLINK_IMPORT_INFO) { var count = getLEB(); while (count--) { var modname = getString(); var symname = getString(); var flags2 = getLEB(); if ((flags2 & WASM_SYMBOL_BINDING_MASK) == WASM_SYMBOL_BINDING_WEAK) { customSection.weakImports.add(symname); } } } else { err(`unknown dylink.0 subsection: ${subsectionType}`); offset += subsectionSize; } } } var tableAlign = Math.pow(2, customSection.tableAlign); assert(tableAlign === 1, `invalid tableAlign ${tableAlign}`); assert(offset == end); return customSection; }, "getDylinkMetadata"); function getValue(ptr, type = "i8") { if (type.endsWith("*")) type = "*"; switch (type) { case "i1": return SAFE_HEAP_LOAD(ptr, 1, 0); case "i8": return SAFE_HEAP_LOAD(ptr, 1, 0); case "i16": return LE_HEAP_LOAD_I16((ptr >> 1) * 2); case "i32": return LE_HEAP_LOAD_I32((ptr >> 2) * 4); case "i64": return HEAP64[ptr >> 3]; case "float": return LE_HEAP_LOAD_F32((ptr >> 2) * 4); case "double": return LE_HEAP_LOAD_F64((ptr >> 3) * 8); case "*": return LE_HEAP_LOAD_U32((ptr >> 2) * 4); default: abort(`invalid type for getValue: ${type}`); } } __name(getValue, "getValue"); function getValue_safe(ptr, type = "i8") { if (type.endsWith("*")) type = "*"; switch (type) { case "i1": return HEAP8[ptr]; case "i8": return HEAP8[ptr]; case "i16": return LE_HEAP_LOAD_I16((ptr >> 1) * 2); case "i32": return LE_HEAP_LOAD_I32((ptr >> 2) * 4); case "i64": return HEAP64[ptr >> 3]; case "float": return LE_HEAP_LOAD_F32((ptr >> 2) * 4); case "double": return LE_HEAP_LOAD_F64((ptr >> 3) * 8); case "*": return LE_HEAP_LOAD_U32((ptr >> 2) * 4); default: abort(`invalid type for getValue: ${type}`); } } __name(getValue_safe, "getValue_safe"); var newDSO = /* @__PURE__ */ __name((name2, handle2, syms) => { var dso = { refcount: Infinity, name: name2, exports: syms, global: true }; LDSO.loadedLibsByName[name2] = dso; if (handle2 != void 0) { LDSO.loadedLibsByHandle[handle2] = dso; } return dso; }, "newDSO"); var LDSO = { loadedLibsByName: {}, loadedLibsByHandle: {}, init() { assert(wasmImports); newDSO("__main__", 0, wasmImports); } }; var ___heap_base = 78208; var alignMemory = /* @__PURE__ */ __name((size, alignment) => { assert(alignment, "alignment argument is required"); return Math.ceil(size / alignment) * alignment; }, "alignMemory"); var getMemory = /* @__PURE__ */ __name((size) => { if (runtimeInitialized) { return _calloc(size, 1); } var ret = ___heap_base; var end = ret + alignMemory(size, 16); assert(end <= HEAP8.length, "failure to getMemory - memory growth etc. is not supported there, call malloc/sbrk directly or increase INITIAL_MEMORY"); ___heap_base = end; GOT["__heap_base"].value = end; return ret; }, "getMemory"); 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"); var uleb128Encode = /* @__PURE__ */ __name((n, target) => { assert(n < 16384); if (n < 128) { target.push(n); } else { target.push(n % 128 | 128, n >> 7); } }, "uleb128Encode"); var sigToWasmTypes = /* @__PURE__ */ __name((sig) => { var typeNames = { "i": "i32", "j": "i64", "f": "f32", "d": "f64", "e": "externref", "p": "i32" }; var type = { parameters: [], results: sig[0] == "v" ? [] : [typeNames[sig[0]]] }; for (var i2 = 1; i2 < sig.length; ++i2) { assert(sig[i2] in typeNames, "invalid signature char: " + sig[i2]); type.parameters.push(typeNames[sig[i2]]); } return type; }, "sigToWasmTypes"); var generateFuncType = /* @__PURE__ */ __name((sig, target) => { var sigRet = sig.slice(0, 1); var sigParam = sig.slice(1); var typeCodes = { "i": 127, // i32 "p": 127, // i32 "j": 126, // i64 "f": 125, // f32 "d": 124, // f64 "e": 111 }; target.push(96); uleb128Encode(sigParam.length, target); for (var i2 = 0; i2 < sigParam.length; ++i2) { assert(sigParam[i2] in typeCodes, "invalid signature char: " + sigParam[i2]); target.push(typeCodes[sigParam[i2]]); } if (sigRet == "v") { target.push(0); } else { target.push(1, typeCodes[sigRet]); } }, "generateFuncType"); var convertJsFunctionToWasm = /* @__PURE__ */ __name((func2, sig) => { if (typeof WebAssembly.Function == "function") { return new WebAssembly.Function(sigToWasmTypes(sig), func2); } var typeSectionBody = [1]; generateFuncType(sig, typeSectionBody); var bytes = [ 0, 97, 115, 109, // magic ("\0asm") 1, 0, 0, 0, // version: 1 1 ]; uleb128Encode(typeSectionBody.length, bytes); bytes.push(...typeSectionBody); bytes.push( 2, 7, // import section // (import "e" "f" (func 0 (type 0))) 1, 1, 101, 1, 102, 0, 0, 7, 5, // export section // (export "f" (func 0 (type 0))) 1, 1, 102, 0, 0 ); var module2 = new WebAssembly.Module(new Uint8Array(bytes)); var instance2 = new WebAssembly.Instance(module2, { "e": { "f": func2 } }); var wrappedFunc = instance2.exports["f"]; return wrappedFunc; }, "convertJsFunctionToWasm"); var wasmTableMirror = []; var wasmTable = new WebAssembly.Table({ "initial": 31, "element": "anyfunc" }); var getWasmTableEntry = /* @__PURE__ */ __name((funcPtr) => { var func2 = wasmTableMirror[funcPtr]; if (!func2) { if (funcPtr >= wasmTableMirror.length) wasmTableMirror.length = funcPtr + 1; wasmTableMirror[funcPtr] = func2 = wasmTable.get(funcPtr); } assert(wasmTable.get(funcPtr) == func2, "JavaScr