diff --git a/docs/index.html b/docs/index.html index 43479e8..8d7306d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,83 +1,110 @@ - - - Tree Sitter HCL Playground - - - - + Taken from https://github.com/tree-sitter/tree-sitter/blob/master/docs/src/7-playground.md + --> - - + + -
-

Tree Sitter HCL Playground

-

Code

-
- - +

Tree Sitter HCL Playground

- - + + + + + + + + + + + \ No newline at end of file diff --git a/docs/playground.js b/docs/playground.js index a297500..2eee709 100644 --- a/docs/playground.js +++ b/docs/playground.js @@ -1,49 +1,146 @@ // This file is licensed under MIT license -// Copyright (c) 2018 Max Brunsfeld -// Taken from https://github.com/tree-sitter/tree-sitter/docs/assets/playground.js -let tree; +// Taken from https://github.com/tree-sitter/tree-sitter/docs/src/assets/js/playground.js + +function initializeLocalTheme() { + const themeToggle = document.getElementById('theme-toggle'); + if (!themeToggle) return; + + // Load saved theme or use system preference + const savedTheme = localStorage.getItem('theme'); + const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches; + const initialTheme = savedTheme || (prefersDark ? 'dark' : 'light'); + + // Set initial theme + document.documentElement.setAttribute('data-theme', initialTheme); + + themeToggle.addEventListener('click', () => { + const currentTheme = document.documentElement.getAttribute('data-theme'); + const newTheme = currentTheme === 'light' ? 'dark' : 'light'; + document.documentElement.setAttribute('data-theme', newTheme); + localStorage.setItem('theme', newTheme); + }); +} + +function initializeCustomSelect({ initialValue = null, addListeners = false }) { + const button = document.getElementById('language-button'); + const select = document.getElementById('language-select'); + if (!button || !select) return; + + const dropdown = button.nextElementSibling; + const selectedValue = button.querySelector('.selected-value'); + + if (initialValue) { + select.value = initialValue; + } + if (select.selectedIndex >= 0 && select.options[select.selectedIndex]) { + selectedValue.textContent = select.options[select.selectedIndex].text; + } else { + selectedValue.textContent = 'JavaScript'; + } + + if (addListeners) { + button.addEventListener('click', (e) => { + e.preventDefault(); // Prevent form submission + dropdown.classList.toggle('show'); + }); + + document.addEventListener('click', (e) => { + if (!button.contains(e.target)) { + dropdown.classList.remove('show'); + } + }); + + dropdown.querySelectorAll('.option').forEach(option => { + option.addEventListener('click', () => { + selectedValue.textContent = option.textContent; + select.value = option.dataset.value; + dropdown.classList.remove('show'); + + const event = new Event('change'); + select.dispatchEvent(event); + }); + }); + } +} + +window.initializePlayground = async (opts) => { + const { Parser, Language } = window.TreeSitter; + + const { local } = opts; + if (local) { + initializeLocalTheme(); + } + initializeCustomSelect({ addListeners: true }); + + let tree; -(async () => { const CAPTURE_REGEX = /@\s*([\w\._-]+)/g; - const COLORS_BY_INDEX = [ - "blue", - "chocolate", - "darkblue", - "darkcyan", - "darkgreen", - "darkred", - "darkslategray", - "dimgray", - "green", - "indigo", - "navy", - "red", - "sienna", + const LIGHT_COLORS = [ + "#0550ae", // blue + "#ab5000", // rust brown + "#116329", // forest green + "#844708", // warm brown + "#6639ba", // purple + "#7d4e00", // orange brown + "#0969da", // bright blue + "#1a7f37", // green + "#cf222e", // red + "#8250df", // violet + "#6e7781", // gray + "#953800", // dark orange + "#1b7c83" // teal ]; - const scriptURL = document.getElementById("playground-script").src; + const DARK_COLORS = [ + "#79c0ff", // light blue + "#ffa657", // orange + "#7ee787", // light green + "#ff7b72", // salmon + "#d2a8ff", // light purple + "#ffa198", // pink + "#a5d6ff", // pale blue + "#56d364", // bright green + "#ff9492", // light red + "#e0b8ff", // pale purple + "#9ca3af", // gray + "#ffb757", // yellow orange + "#80cbc4" // light teal + ]; const codeInput = document.getElementById("code-input"); + const languageSelect = document.getElementById("language-select"); const loggingCheckbox = document.getElementById("logging-checkbox"); + const anonymousNodes = document.getElementById('anonymous-nodes-checkbox'); const outputContainer = document.getElementById("output-container"); + const createIssueBtn = document.getElementById("create-issue-btn"); const outputContainerScroll = document.getElementById( "output-container-scroll", ); const playgroundContainer = document.getElementById("playground-container"); const queryCheckbox = document.getElementById("query-checkbox"); - const createIssueBtn = document.getElementById("create-issue-btn"); const queryContainer = document.getElementById("query-container"); const queryInput = document.getElementById("query-input"); + const accessibilityCheckbox = document.getElementById("accessibility-checkbox"); const updateTimeSpan = document.getElementById("update-time"); + const languagesByName = {}; loadState(); - await TreeSitter.init(); + await Parser.init(); + + const parser = new Parser(); + + console.log(parser, codeInput, queryInput); - const parser = new TreeSitter(); const codeEditor = CodeMirror.fromTextArea(codeInput, { lineNumbers: true, - showCursorWhenSelecting: true, + showCursorWhenSelecting: true + }); + + codeEditor.on('keydown', (_, event) => { + if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') { + event.stopPropagation(); // Prevent mdBook from going back/forward + } }); const queryEditor = CodeMirror.fromTextArea(queryInput, { @@ -51,6 +148,12 @@ let tree; showCursorWhenSelecting: true, }); + queryEditor.on('keydown', (_, event) => { + if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') { + event.stopPropagation(); // Prevent mdBook from going back/forward + } + }); + const cluster = new Clusterize({ rows: [], noDataText: null, @@ -61,7 +164,7 @@ let tree; const saveStateOnChange = debounce(saveState, 2000); const runTreeQueryOnChange = debounce(runTreeQuery, 50); - let languageName = "hcl"; + let languageName = languageSelect.value; let treeRows = null; let treeRowHighlightedIndex = -1; let parseCount = 0; @@ -74,20 +177,37 @@ let tree; queryEditor.on("changes", debounce(handleQueryChange, 150)); loggingCheckbox.addEventListener("change", handleLoggingChange); + anonymousNodes.addEventListener('change', renderTree); queryCheckbox.addEventListener("change", handleQueryEnableChange); + accessibilityCheckbox.addEventListener("change", handleQueryChange); + languageSelect.addEventListener("change", handleLanguageChange); outputContainer.addEventListener("click", handleTreeClick); createIssueBtn.addEventListener("click", handleCreateIssue); + handleQueryEnableChange(); - await loadLanguage(); + await handleLanguageChange(); playgroundContainer.style.visibility = "visible"; - async function loadLanguage() { - const query = new URL(scriptURL).search; - const url = `tree-sitter-hcl.wasm${query}`; - const language = await TreeSitter.Language.load(url); + async function handleLanguageChange() { + const newLanguageName = languageSelect.value; + if (!languagesByName[newLanguageName]) { + const url = `tree-sitter-${newLanguageName}.wasm`; + languageSelect.disabled = true; + try { + languagesByName[newLanguageName] = await Language.load(url); + } catch (e) { + console.error(e); + languageSelect.value = languageName; + return; + } finally { + languageSelect.disabled = false; + } + } + tree = null; - parser.setLanguage(language); + languageName = newLanguageName; + parser.setLanguage(languagesByName[newLanguageName]); handleCodeChange(); handleQueryChange(); } @@ -127,7 +247,7 @@ let tree; for (let i = 0; ; i++) { if (i > 0 && i % 10000 === 0) { - await new Promise(r => setTimeout(r, 0)); + await new Promise((r) => setTimeout(r, 0)); if (parseCount !== currentRenderCount) { cursor.delete(); isRendering--; @@ -137,9 +257,12 @@ let tree; let displayName; if (cursor.nodeIsMissing) { - displayName = `MISSING ${cursor.nodeType}`; + const nodeTypeText = cursor.nodeIsNamed ? cursor.nodeType : `"${cursor.nodeType}"`; + displayName = `MISSING ${nodeTypeText}`; } else if (cursor.nodeIsNamed) { displayName = cursor.nodeType; + } else if (anonymousNodes.checked) { + displayName = cursor.nodeType } if (visitedChildren) { @@ -165,19 +288,25 @@ let tree; const start = cursor.startPosition; const end = cursor.endPosition; const id = cursor.nodeId; - let fieldName = cursor.currentFieldName(); + let fieldName = cursor.currentFieldName; if (fieldName) { fieldName += ": "; } else { fieldName = ""; } - row = `
${" ".repeat( - indentLevel, - )}${fieldName}${displayName} [${ - start.row - }, ${start.column}] - [${end.row}, ${end.column}])`; + + const nodeClass = + displayName === 'ERROR' || displayName.startsWith('MISSING') + ? 'node-link error' + : cursor.nodeIsNamed + ? 'node-link named' + : 'node-link anonymous'; + + row = `
${" ".repeat(indentLevel)}${fieldName}` + + `` + + `${displayName} ` + + `[${start.row}, ${start.column}] - [${end.row}, ${end.column}]`; finishedRow = true; } @@ -201,6 +330,14 @@ let tree; handleCursorMovement(); } + function getCaptureCSS(name) { + if (accessibilityCheckbox.checked) { + return `color: white; background-color: ${colorForCaptureName(name)}`; + } else { + return `color: ${colorForCaptureName(name)}`; + } + } + function runTreeQuery(_, startRow, endRow) { if (endRow == null) { const viewport = codeEditor.getViewport(); @@ -210,7 +347,7 @@ let tree; codeEditor.operation(() => { const marks = codeEditor.getAllMarks(); - marks.forEach(m => m.clear()); + marks.forEach((m) => m.clear()); if (tree && query) { const captures = query.captures( @@ -229,7 +366,7 @@ let tree; { inclusiveLeft: true, inclusiveRight: true, - css: `color: ${colorForCaptureName(name)}`, + css: getCaptureCSS(name), }, ); } @@ -237,6 +374,21 @@ let tree; }); } + // When we change from a dark theme to a light theme (and vice versa), the colors of the + // captures need to be updated. + const observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + if (mutation.attributeName === 'class') { + handleQueryChange(); + } + }); + }); + + observer.observe(document.documentElement, { + attributes: true, + attributeFilter: ['class'] + }); + function handleQueryChange() { if (query) { query.delete(); @@ -245,17 +397,17 @@ let tree; } queryEditor.operation(() => { - queryEditor.getAllMarks().forEach(m => m.clear()); + queryEditor.getAllMarks().forEach((m) => m.clear()); if (!queryCheckbox.checked) return; const queryText = queryEditor.getValue(); try { - query = parser.getLanguage().query(queryText); + query = parser.language.query(queryText); let match; let row = 0; - queryEditor.eachLine(line => { + queryEditor.eachLine((line) => { while ((match = CAPTURE_REGEX.exec(line.text))) { queryEditor.markText( { line: row, ch: match.index }, @@ -322,7 +474,7 @@ let tree; "plain", ); } - treeRowHighlightedIndex = treeRows.findIndex(row => + treeRowHighlightedIndex = treeRows.findIndex((row) => row.includes(`data-id=${node.id}`), ); if (treeRowHighlightedIndex !== -1) { @@ -339,9 +491,9 @@ let tree; const containerHeight = outputContainerScroll.clientHeight; const offset = treeRowHighlightedIndex * lineHeight; if (scrollTop > offset - 20) { - $(outputContainerScroll).animate({ scrollTop: offset - 20 }, 150); + outputContainerScroll.animate({ scrollTop: offset - 20 }, 150); } else if (scrollTop < offset + lineHeight + 40 - containerHeight) { - $(outputContainerScroll).animate( + outputContainerScroll.animate( { scrollTop: offset - containerHeight + 40 }, 150, ); @@ -364,7 +516,7 @@ ${outputText} const queryParams = `title=${encodeURIComponent( title, )}&body=${encodeURIComponent(body)}`; - const url = `https://github.com/MichaHoffmann/tree-sitter-hcl/issues/new?${queryParams}`; + const url = `https://github.com/tree-sitter-grammars/tree-sitter-hcl/issues/new?${queryParams}`; window.open(url); } @@ -372,7 +524,7 @@ ${outputText} if (event.target.tagName === "A") { event.preventDefault(); const [startRow, startColumn, endRow, endColumn] = - event.target.dataset.range.split(",").map(n => parseInt(n)); + event.target.dataset.range.split(",").map((n) => parseInt(n)); codeEditor.focus(); codeEditor.setSelection( { line: startRow, ch: startColumn }, @@ -440,43 +592,40 @@ ${outputText} function colorForCaptureName(capture) { const id = query.captureNames.indexOf(capture); - return COLORS_BY_INDEX[id % COLORS_BY_INDEX.length]; - } + const isDark = document.querySelector('html').classList.contains('ayu') || + document.querySelector('html').classList.contains('coal') || + document.querySelector('html').classList.contains('navy'); - function storageGetItem(lookupKey) { - try { - return localStorage.getItem(lookupKey); - } catch { - return null; - } - } - - function storageSetItem(lookupKey, value) { - try { - return localStorage.setIem(lookupKey, value); - } catch {} + const colors = isDark ? DARK_COLORS : LIGHT_COLORS; + return colors[id % colors.length]; } function loadState() { - const language = storageGetItem("language"); - const sourceCode = storageGetItem("sourceCode"); - const query = storageGetItem("query"); - const queryEnabled = storageGetItem("queryEnabled"); + const language = localStorage.getItem("language"); + const sourceCode = localStorage.getItem("sourceCode"); + const anonNodes = localStorage.getItem("anonymousNodes"); + const query = localStorage.getItem("query"); + const queryEnabled = localStorage.getItem("queryEnabled"); if (language != null && sourceCode != null && query != null) { queryInput.value = query; codeInput.value = sourceCode; + languageSelect.value = language; + initializeCustomSelect({ initialValue: language }); + anonymousNodes.checked = anonNodes === "true"; queryCheckbox.checked = queryEnabled === "true"; } } function saveState() { - storageSetItem("sourceCode", codeEditor.getValue()); + localStorage.setItem("language", languageSelect.value); + localStorage.setItem("sourceCode", codeEditor.getValue()); + localStorage.setItem("anonymousNodes", anonymousNodes.checked); saveQueryState(); } function saveQueryState() { - storageSetItem("queryEnabled", queryCheckbox.checked); - storageSetItem("query", queryEditor.getValue()); + localStorage.setItem("queryEnabled", queryCheckbox.checked); + localStorage.setItem("query", queryEditor.getValue()); } function debounce(func, wait, immediate) { @@ -494,5 +643,4 @@ ${outputText} if (callNow) func.apply(context, args); }; } -})(); - +}; \ No newline at end of file diff --git a/docs/tree-sitter-hcl.wasm b/docs/tree-sitter-hcl.wasm index 024376f..e51f16a 100755 Binary files a/docs/tree-sitter-hcl.wasm and b/docs/tree-sitter-hcl.wasm differ diff --git a/docs/vendor/tree-sitter.js b/docs/vendor/tree-sitter.js deleted file mode 100644 index 81ee7f7..0000000 --- a/docs/vendor/tree-sitter.js +++ /dev/null @@ -1 +0,0 @@ -var Module=void 0!==Module?Module:{},TreeSitter=function(){var e,t="object"==typeof window?{currentScript:window.document.currentScript}:null;class Parser{constructor(){this.initialize()}initialize(){throw new Error("cannot construct a Parser before calling `init()`")}static init(r){return e||(Module=Object.assign({},Module,r),e=new Promise(e=>{var r,n={};for(r in Module)Module.hasOwnProperty(r)&&(n[r]=Module[r]);var s,o,_=[],a="./this.program",u=function(e,t){throw t},i=!1,l=!1;i="object"==typeof window,l="function"==typeof importScripts,s="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,o=!i&&!s&&!l;var d,c,m,f,p,h="";s?(h=l?require("path").dirname(h)+"/":__dirname+"/",d=function(e,t){return f||(f=require("fs")),p||(p=require("path")),e=p.normalize(e),f.readFileSync(e,t?null:"utf8")},m=function(e){var t=d(e,!0);return t.buffer||(t=new Uint8Array(t)),k(t.buffer),t},process.argv.length>1&&(a=process.argv[1].replace(/\\/g,"/")),_=process.argv.slice(2),"undefined"!=typeof module&&(module.exports=Module),u=function(e){process.exit(e)},Module.inspect=function(){return"[Emscripten Module object]"}):o?("undefined"!=typeof read&&(d=function(e){return read(e)}),m=function(e){var t;return"function"==typeof readbuffer?new Uint8Array(readbuffer(e)):(k("object"==typeof(t=read(e,"binary"))),t)},"undefined"!=typeof scriptArgs?_=scriptArgs:void 0!==arguments&&(_=arguments),"function"==typeof quit&&(u=function(e){quit(e)}),"undefined"!=typeof print&&("undefined"==typeof console&&(console={}),console.log=print,console.warn=console.error="undefined"!=typeof printErr?printErr:print)):(i||l)&&(l?h=self.location.href:void 0!==t&&t.currentScript&&(h=t.currentScript.src),h=0!==h.indexOf("blob:")?h.substr(0,h.lastIndexOf("/")+1):"",d=function(e){var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),t.responseText},l&&(m=function(e){var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),c=function(e,t,r){var n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=function(){200==n.status||0==n.status&&n.response?t(n.response):r()},n.onerror=r,n.send(null)});Module.print||console.log.bind(console);var g=Module.printErr||console.warn.bind(console);for(r in n)n.hasOwnProperty(r)&&(Module[r]=n[r]);n=null,Module.arguments&&(_=Module.arguments),Module.thisProgram&&(a=Module.thisProgram),Module.quit&&(u=Module.quit);var w=16;var y,M=[];function b(e,t){if(!y){y=new WeakMap;for(var r=0;r>0]=t;break;case"i16":L[e>>1]=t;break;case"i32":W[e>>2]=t;break;case"i64":ue=[t>>>0,(ae=t,+Math.abs(ae)>=1?ae>0?(0|Math.min(+Math.floor(ae/4294967296),4294967295))>>>0:~~+Math.ceil((ae-+(~~ae>>>0))/4294967296)>>>0:0)],W[e>>2]=ue[0],W[e+4>>2]=ue[1];break;case"float":O[e>>2]=t;break;case"double":Z[e>>3]=t;break;default:oe("invalid type for setValue: "+r)}}function N(e,t,r){switch("*"===(t=t||"i8").charAt(t.length-1)&&(t="i32"),t){case"i1":case"i8":return R[e>>0];case"i16":return L[e>>1];case"i32":case"i64":return W[e>>2];case"float":return O[e>>2];case"double":return Z[e>>3];default:oe("invalid type for getValue: "+t)}return null}"object"!=typeof WebAssembly&&oe("no native wasm support detected");var P=!1;function k(e,t){e||oe("Assertion failed: "+t)}var C=1;var q,R,T,L,W,O,Z,F="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function $(e,t,r){for(var n=t+r,s=t;e[s]&&!(s>=n);)++s;if(s-t>16&&e.subarray&&F)return F.decode(e.subarray(t,s));for(var o="";t>10,56320|1023&i)}}else o+=String.fromCharCode((31&_)<<6|a)}else o+=String.fromCharCode(_)}return o}function j(e,t){return e?$(T,e,t):""}function U(e,t,r,n){if(!(n>0))return 0;for(var s=r,o=r+n-1,_=0;_=55296&&a<=57343)a=65536+((1023&a)<<10)|1023&e.charCodeAt(++_);if(a<=127){if(r>=o)break;t[r++]=a}else if(a<=2047){if(r+1>=o)break;t[r++]=192|a>>6,t[r++]=128|63&a}else if(a<=65535){if(r+2>=o)break;t[r++]=224|a>>12,t[r++]=128|a>>6&63,t[r++]=128|63&a}else{if(r+3>=o)break;t[r++]=240|a>>18,t[r++]=128|a>>12&63,t[r++]=128|a>>6&63,t[r++]=128|63&a}}return t[r]=0,r-s}function D(e,t,r){return U(e,T,t,r)}function z(e){for(var t=0,r=0;r=55296&&n<=57343&&(n=65536+((1023&n)<<10)|1023&e.charCodeAt(++r)),n<=127?++t:t+=n<=2047?2:n<=65535?3:4}return t}function G(e){var t=z(e)+1,r=ze(t);return U(e,R,r,t),r}function H(e){q=e,Module.HEAP8=R=new Int8Array(e),Module.HEAP16=L=new Int16Array(e),Module.HEAP32=W=new Int32Array(e),Module.HEAPU8=T=new Uint8Array(e),Module.HEAPU16=new Uint16Array(e),Module.HEAPU32=new Uint32Array(e),Module.HEAPF32=O=new Float32Array(e),Module.HEAPF64=Z=new Float64Array(e)}var B=Module.INITIAL_MEMORY||33554432;(A=Module.wasmMemory?Module.wasmMemory:new WebAssembly.Memory({initial:B/65536,maximum:32768}))&&(q=A.buffer),B=q.byteLength,H(q);var K=new WebAssembly.Table({initial:17,element:"anyfunc"}),V=[],X=[],Q=[],J=[],Y=!1;var ee=0,te=null,re=null;function ne(e){ee++,Module.monitorRunDependencies&&Module.monitorRunDependencies(ee)}function se(e){if(ee--,Module.monitorRunDependencies&&Module.monitorRunDependencies(ee),0==ee&&(null!==te&&(clearInterval(te),te=null),re)){var t=re;re=null,t()}}function oe(e){throw Module.onAbort&&Module.onAbort(e),g(e+=""),P=!0,1,e="abort("+e+"). Build with -s ASSERTIONS=1 for more info.",new WebAssembly.RuntimeError(e)}Module.preloadedImages={},Module.preloadedAudios={},Module.preloadedWasm={};var _e,ae,ue,ie="data:application/octet-stream;base64,";function le(e){return e.startsWith(ie)}function de(e){return e.startsWith("file://")}function ce(e){try{if(e==_e&&v)return new Uint8Array(v);if(m)return m(e);throw"both async and sync fetching of the wasm failed"}catch(e){oe(e)}}le(_e="tree-sitter.wasm")||(_e=function(e){return Module.locateFile?Module.locateFile(e,h):h+e}(_e));var me={},fe={get:function(e,t){return me[t]||(me[t]=new WebAssembly.Global({value:"i32",mutable:!0})),me[t]}};function pe(e){for(;e.length>0;){var t=e.shift();if("function"!=typeof t){var r=t.func;"number"==typeof r?void 0===t.arg?K.get(r)():K.get(r)(t.arg):r(void 0===t.arg?null:t.arg)}else t(Module)}}function he(e){var t=0;function r(){for(var r=0,n=1;;){var s=e[t++];if(r+=(127&s)*n,n*=128,!(128&s))break}return r}if(e instanceof WebAssembly.Module){var n=WebAssembly.Module.customSections(e,"dylink");k(0!=n.length,"need dylink section"),e=new Int8Array(n[0])}else{k(1836278016==new Uint32Array(new Uint8Array(e.subarray(0,24)).buffer)[0],"need to see wasm magic number"),k(0===e[8],"need the dylink section to be first"),t=9,r(),k(6===e[t]),k(e[++t]==="d".charCodeAt(0)),k(e[++t]==="y".charCodeAt(0)),k(e[++t]==="l".charCodeAt(0)),k(e[++t]==="i".charCodeAt(0)),k(e[++t]==="n".charCodeAt(0)),k(e[++t]==="k".charCodeAt(0)),t++}var s={};s.memorySize=r(),s.memoryAlign=r(),s.tableSize=r(),s.tableAlign=r();var o=r();s.neededDynlibs=[];for(var _=0;_0}function ye(e){return 0==e.indexOf("dynCall_")||["stackAlloc","stackSave","stackRestore"].includes(e)?e:"_"+e}function Me(e,t){for(var r in e)if(e.hasOwnProperty(r)){Fe.hasOwnProperty(r)||(Fe[r]=e[r]);var n=ye(r);Module.hasOwnProperty(n)||(Module[n]=e[r])}}var be={nextHandle:1,loadedLibs:{},loadedLibNames:{}};function ve(e,t,r){return e.includes("j")?function(e,t,r){var n=Module["dynCall_"+e];return r&&r.length?n.apply(null,[t].concat(r)):n.call(null,t)}(e,t,r):K.get(t).apply(null,r)}var Ee=5250880;function Ie(e){return["__cpp_exception","__wasm_apply_data_relocs","__dso_handle","__set_stack_limits"].includes(e)}function Ae(e,t){var r={};for(var n in e){var s=e[n];"object"==typeof s&&(s=s.value),"number"==typeof s&&(s+=t),r[n]=s}return function(e){for(var t in e)if(!Ie(t)){var r=!1,n=e[t];t.startsWith("orig$")&&(t=t.split("$")[1],r=!0),me[t]||(me[t]=new WebAssembly.Global({value:"i32",mutable:!0})),(r||0==me[t].value)&&("function"==typeof n?me[t].value=b(n):"number"==typeof n?me[t].value=n:g("unhandled export type for `"+t+"`: "+typeof n))}}(r),r}function Se(e,t){var r,n;return t&&(r=Fe["orig$"+e]),r||(r=Fe[e]),r||(r=Module[ye(e)]),!r&&e.startsWith("invoke_")&&(n=e.split("_")[1],r=function(){var e=Ue();try{return ve(n,arguments[0],Array.prototype.slice.call(arguments,1))}catch(t){if(De(e),t!==t+0&&"longjmp"!==t)throw t;Ge(1,0)}}),r}function xe(e,t){var r=he(e);function n(){var n=Math.pow(2,r.memoryAlign);n=Math.max(n,w);var s,o,_,a=(s=function(e){if(Y)return $e(e);var t=Ee,r=t+e+15&-16;return Ee=r,me.__heap_base.value=r,t}(r.memorySize+n),(o=n)||(o=w),Math.ceil(s/o)*o),u=K.length;K.grow(r.tableSize);for(var i=a;i>2]=n,-1;r=ke()}return W[t>>2]=r/1e3|0,W[t+4>>2]=r%1e3*1e3*1e3|0,0}function Le(e){try{return A.grow(e-q.byteLength+65535>>>16),H(A.buffer),1}catch(e){}}function We(e){Ve(e)}function Oe(e){E(e)}Te.sig="iii",We.sig="vi",Oe.sig="vi";var Ze,Fe={__heap_base:Ee,__indirect_function_table:K,__memory_base:1024,__stack_pointer:Ce,__table_base:1,abort:qe,clock_gettime:Te,emscripten_memcpy_big:function(e,t,r){T.copyWithin(e,t,t+r)},emscripten_resize_heap:function(e){var t,r,n=T.length;if((e>>>=0)>2147483648)return!1;for(var s=1;s<=4;s*=2){var o=n*(1+.2/s);if(o=Math.min(o,e+100663296),Le(Math.min(2147483648,((t=Math.max(e,o))%(r=65536)>0&&(t+=r-t%r),t))))return!0}return!1},exit:We,memory:A,setTempRet0:Oe,tree_sitter_log_callback:function(e,t){if(ct){const r=j(t);ct(r,0!==e)}},tree_sitter_parse_callback:function(e,t,r,n,s){var o=dt(t,{row:r,column:n});"string"==typeof o?(x(s,o.length,"i32"),function(e,t,r){if(void 0===r&&(r=2147483647),r<2)return 0;for(var n=(r-=2)<2*e.length?r/2:e.length,s=0;s>1]=o,t+=2}L[t>>1]=0}(o,e,10240)):x(s,0,"i32")}},$e=(function(){var e={env:Fe,wasi_snapshot_preview1:Fe,"GOT.mem":new Proxy(Fe,fe),"GOT.func":new Proxy(Fe,fe)};function t(e,t){var r=e.exports;r=Ae(r,1024),Module.asm=r;var n,s=he(t);s.neededDynlibs&&(I=s.neededDynlibs.concat(I)),Me(r),n=Module.asm.__wasm_call_ctors,X.unshift(n),se()}function r(e){t(e.instance,e.module)}function n(t){return function(){if(!v&&(i||l)){if("function"==typeof fetch&&!de(_e))return fetch(_e,{credentials:"same-origin"}).then(function(e){if(!e.ok)throw"failed to load wasm binary file at '"+_e+"'";return e.arrayBuffer()}).catch(function(){return ce(_e)});if(c)return new Promise(function(e,t){c(_e,function(t){e(new Uint8Array(t))},t)})}return Promise.resolve().then(function(){return ce(_e)})}().then(function(t){return WebAssembly.instantiate(t,e)}).then(t,function(e){g("failed to asynchronously prepare wasm: "+e),oe(e)})}if(ne(),Module.instantiateWasm)try{return Module.instantiateWasm(e,t)}catch(e){return g("Module.instantiateWasm callback failed with error: "+e),!1}v||"function"!=typeof WebAssembly.instantiateStreaming||le(_e)||de(_e)||"function"!=typeof fetch?n(r):fetch(_e,{credentials:"same-origin"}).then(function(t){return WebAssembly.instantiateStreaming(t,e).then(r,function(e){return g("wasm streaming compile failed: "+e),g("falling back to ArrayBuffer instantiation"),n(r)})})}(),Module.___wasm_call_ctors=function(){return(Module.___wasm_call_ctors=Module.asm.__wasm_call_ctors).apply(null,arguments)},Module._malloc=function(){return($e=Module._malloc=Module.asm.malloc).apply(null,arguments)}),je=(Module._calloc=function(){return(Module._calloc=Module.asm.calloc).apply(null,arguments)},Module._realloc=function(){return(Module._realloc=Module.asm.realloc).apply(null,arguments)},Module._free=function(){return(Module._free=Module.asm.free).apply(null,arguments)},Module._ts_language_symbol_count=function(){return(Module._ts_language_symbol_count=Module.asm.ts_language_symbol_count).apply(null,arguments)},Module._ts_language_version=function(){return(Module._ts_language_version=Module.asm.ts_language_version).apply(null,arguments)},Module._ts_language_field_count=function(){return(Module._ts_language_field_count=Module.asm.ts_language_field_count).apply(null,arguments)},Module._ts_language_symbol_name=function(){return(Module._ts_language_symbol_name=Module.asm.ts_language_symbol_name).apply(null,arguments)},Module._ts_language_symbol_for_name=function(){return(Module._ts_language_symbol_for_name=Module.asm.ts_language_symbol_for_name).apply(null,arguments)},Module._ts_language_symbol_type=function(){return(Module._ts_language_symbol_type=Module.asm.ts_language_symbol_type).apply(null,arguments)},Module._ts_language_field_name_for_id=function(){return(Module._ts_language_field_name_for_id=Module.asm.ts_language_field_name_for_id).apply(null,arguments)},Module._memcpy=function(){return(Module._memcpy=Module.asm.memcpy).apply(null,arguments)},Module._ts_parser_delete=function(){return(Module._ts_parser_delete=Module.asm.ts_parser_delete).apply(null,arguments)},Module._ts_parser_reset=function(){return(Module._ts_parser_reset=Module.asm.ts_parser_reset).apply(null,arguments)},Module._ts_parser_set_language=function(){return(Module._ts_parser_set_language=Module.asm.ts_parser_set_language).apply(null,arguments)},Module._ts_parser_timeout_micros=function(){return(Module._ts_parser_timeout_micros=Module.asm.ts_parser_timeout_micros).apply(null,arguments)},Module._ts_parser_set_timeout_micros=function(){return(Module._ts_parser_set_timeout_micros=Module.asm.ts_parser_set_timeout_micros).apply(null,arguments)},Module._memmove=function(){return(Module._memmove=Module.asm.memmove).apply(null,arguments)},Module._memcmp=function(){return(Module._memcmp=Module.asm.memcmp).apply(null,arguments)},Module._ts_query_new=function(){return(Module._ts_query_new=Module.asm.ts_query_new).apply(null,arguments)},Module._ts_query_delete=function(){return(Module._ts_query_delete=Module.asm.ts_query_delete).apply(null,arguments)},Module._iswspace=function(){return(Module._iswspace=Module.asm.iswspace).apply(null,arguments)},Module._iswalnum=function(){return(Module._iswalnum=Module.asm.iswalnum).apply(null,arguments)},Module._ts_query_pattern_count=function(){return(Module._ts_query_pattern_count=Module.asm.ts_query_pattern_count).apply(null,arguments)},Module._ts_query_capture_count=function(){return(Module._ts_query_capture_count=Module.asm.ts_query_capture_count).apply(null,arguments)},Module._ts_query_string_count=function(){return(Module._ts_query_string_count=Module.asm.ts_query_string_count).apply(null,arguments)},Module._ts_query_capture_name_for_id=function(){return(Module._ts_query_capture_name_for_id=Module.asm.ts_query_capture_name_for_id).apply(null,arguments)},Module._ts_query_string_value_for_id=function(){return(Module._ts_query_string_value_for_id=Module.asm.ts_query_string_value_for_id).apply(null,arguments)},Module._ts_query_predicates_for_pattern=function(){return(Module._ts_query_predicates_for_pattern=Module.asm.ts_query_predicates_for_pattern).apply(null,arguments)},Module._ts_tree_copy=function(){return(Module._ts_tree_copy=Module.asm.ts_tree_copy).apply(null,arguments)},Module._ts_tree_delete=function(){return(Module._ts_tree_delete=Module.asm.ts_tree_delete).apply(null,arguments)},Module._ts_init=function(){return(Module._ts_init=Module.asm.ts_init).apply(null,arguments)},Module._ts_parser_new_wasm=function(){return(Module._ts_parser_new_wasm=Module.asm.ts_parser_new_wasm).apply(null,arguments)},Module._ts_parser_enable_logger_wasm=function(){return(Module._ts_parser_enable_logger_wasm=Module.asm.ts_parser_enable_logger_wasm).apply(null,arguments)},Module._ts_parser_parse_wasm=function(){return(Module._ts_parser_parse_wasm=Module.asm.ts_parser_parse_wasm).apply(null,arguments)},Module._ts_language_type_is_named_wasm=function(){return(Module._ts_language_type_is_named_wasm=Module.asm.ts_language_type_is_named_wasm).apply(null,arguments)},Module._ts_language_type_is_visible_wasm=function(){return(Module._ts_language_type_is_visible_wasm=Module.asm.ts_language_type_is_visible_wasm).apply(null,arguments)},Module._ts_tree_root_node_wasm=function(){return(Module._ts_tree_root_node_wasm=Module.asm.ts_tree_root_node_wasm).apply(null,arguments)},Module._ts_tree_edit_wasm=function(){return(Module._ts_tree_edit_wasm=Module.asm.ts_tree_edit_wasm).apply(null,arguments)},Module._ts_tree_get_changed_ranges_wasm=function(){return(Module._ts_tree_get_changed_ranges_wasm=Module.asm.ts_tree_get_changed_ranges_wasm).apply(null,arguments)},Module._ts_tree_cursor_new_wasm=function(){return(Module._ts_tree_cursor_new_wasm=Module.asm.ts_tree_cursor_new_wasm).apply(null,arguments)},Module._ts_tree_cursor_delete_wasm=function(){return(Module._ts_tree_cursor_delete_wasm=Module.asm.ts_tree_cursor_delete_wasm).apply(null,arguments)},Module._ts_tree_cursor_reset_wasm=function(){return(Module._ts_tree_cursor_reset_wasm=Module.asm.ts_tree_cursor_reset_wasm).apply(null,arguments)},Module._ts_tree_cursor_goto_first_child_wasm=function(){return(Module._ts_tree_cursor_goto_first_child_wasm=Module.asm.ts_tree_cursor_goto_first_child_wasm).apply(null,arguments)},Module._ts_tree_cursor_goto_next_sibling_wasm=function(){return(Module._ts_tree_cursor_goto_next_sibling_wasm=Module.asm.ts_tree_cursor_goto_next_sibling_wasm).apply(null,arguments)},Module._ts_tree_cursor_goto_parent_wasm=function(){return(Module._ts_tree_cursor_goto_parent_wasm=Module.asm.ts_tree_cursor_goto_parent_wasm).apply(null,arguments)},Module._ts_tree_cursor_current_node_type_id_wasm=function(){return(Module._ts_tree_cursor_current_node_type_id_wasm=Module.asm.ts_tree_cursor_current_node_type_id_wasm).apply(null,arguments)},Module._ts_tree_cursor_current_node_is_named_wasm=function(){return(Module._ts_tree_cursor_current_node_is_named_wasm=Module.asm.ts_tree_cursor_current_node_is_named_wasm).apply(null,arguments)},Module._ts_tree_cursor_current_node_is_missing_wasm=function(){return(Module._ts_tree_cursor_current_node_is_missing_wasm=Module.asm.ts_tree_cursor_current_node_is_missing_wasm).apply(null,arguments)},Module._ts_tree_cursor_current_node_id_wasm=function(){return(Module._ts_tree_cursor_current_node_id_wasm=Module.asm.ts_tree_cursor_current_node_id_wasm).apply(null,arguments)},Module._ts_tree_cursor_start_position_wasm=function(){return(Module._ts_tree_cursor_start_position_wasm=Module.asm.ts_tree_cursor_start_position_wasm).apply(null,arguments)},Module._ts_tree_cursor_end_position_wasm=function(){return(Module._ts_tree_cursor_end_position_wasm=Module.asm.ts_tree_cursor_end_position_wasm).apply(null,arguments)},Module._ts_tree_cursor_start_index_wasm=function(){return(Module._ts_tree_cursor_start_index_wasm=Module.asm.ts_tree_cursor_start_index_wasm).apply(null,arguments)},Module._ts_tree_cursor_end_index_wasm=function(){return(Module._ts_tree_cursor_end_index_wasm=Module.asm.ts_tree_cursor_end_index_wasm).apply(null,arguments)},Module._ts_tree_cursor_current_field_id_wasm=function(){return(Module._ts_tree_cursor_current_field_id_wasm=Module.asm.ts_tree_cursor_current_field_id_wasm).apply(null,arguments)},Module._ts_tree_cursor_current_node_wasm=function(){return(Module._ts_tree_cursor_current_node_wasm=Module.asm.ts_tree_cursor_current_node_wasm).apply(null,arguments)},Module._ts_node_symbol_wasm=function(){return(Module._ts_node_symbol_wasm=Module.asm.ts_node_symbol_wasm).apply(null,arguments)},Module._ts_node_child_count_wasm=function(){return(Module._ts_node_child_count_wasm=Module.asm.ts_node_child_count_wasm).apply(null,arguments)},Module._ts_node_named_child_count_wasm=function(){return(Module._ts_node_named_child_count_wasm=Module.asm.ts_node_named_child_count_wasm).apply(null,arguments)},Module._ts_node_child_wasm=function(){return(Module._ts_node_child_wasm=Module.asm.ts_node_child_wasm).apply(null,arguments)},Module._ts_node_named_child_wasm=function(){return(Module._ts_node_named_child_wasm=Module.asm.ts_node_named_child_wasm).apply(null,arguments)},Module._ts_node_child_by_field_id_wasm=function(){return(Module._ts_node_child_by_field_id_wasm=Module.asm.ts_node_child_by_field_id_wasm).apply(null,arguments)},Module._ts_node_next_sibling_wasm=function(){return(Module._ts_node_next_sibling_wasm=Module.asm.ts_node_next_sibling_wasm).apply(null,arguments)},Module._ts_node_prev_sibling_wasm=function(){return(Module._ts_node_prev_sibling_wasm=Module.asm.ts_node_prev_sibling_wasm).apply(null,arguments)},Module._ts_node_next_named_sibling_wasm=function(){return(Module._ts_node_next_named_sibling_wasm=Module.asm.ts_node_next_named_sibling_wasm).apply(null,arguments)},Module._ts_node_prev_named_sibling_wasm=function(){return(Module._ts_node_prev_named_sibling_wasm=Module.asm.ts_node_prev_named_sibling_wasm).apply(null,arguments)},Module._ts_node_parent_wasm=function(){return(Module._ts_node_parent_wasm=Module.asm.ts_node_parent_wasm).apply(null,arguments)},Module._ts_node_descendant_for_index_wasm=function(){return(Module._ts_node_descendant_for_index_wasm=Module.asm.ts_node_descendant_for_index_wasm).apply(null,arguments)},Module._ts_node_named_descendant_for_index_wasm=function(){return(Module._ts_node_named_descendant_for_index_wasm=Module.asm.ts_node_named_descendant_for_index_wasm).apply(null,arguments)},Module._ts_node_descendant_for_position_wasm=function(){return(Module._ts_node_descendant_for_position_wasm=Module.asm.ts_node_descendant_for_position_wasm).apply(null,arguments)},Module._ts_node_named_descendant_for_position_wasm=function(){return(Module._ts_node_named_descendant_for_position_wasm=Module.asm.ts_node_named_descendant_for_position_wasm).apply(null,arguments)},Module._ts_node_start_point_wasm=function(){return(Module._ts_node_start_point_wasm=Module.asm.ts_node_start_point_wasm).apply(null,arguments)},Module._ts_node_end_point_wasm=function(){return(Module._ts_node_end_point_wasm=Module.asm.ts_node_end_point_wasm).apply(null,arguments)},Module._ts_node_start_index_wasm=function(){return(Module._ts_node_start_index_wasm=Module.asm.ts_node_start_index_wasm).apply(null,arguments)},Module._ts_node_end_index_wasm=function(){return(Module._ts_node_end_index_wasm=Module.asm.ts_node_end_index_wasm).apply(null,arguments)},Module._ts_node_to_string_wasm=function(){return(Module._ts_node_to_string_wasm=Module.asm.ts_node_to_string_wasm).apply(null,arguments)},Module._ts_node_children_wasm=function(){return(Module._ts_node_children_wasm=Module.asm.ts_node_children_wasm).apply(null,arguments)},Module._ts_node_named_children_wasm=function(){return(Module._ts_node_named_children_wasm=Module.asm.ts_node_named_children_wasm).apply(null,arguments)},Module._ts_node_descendants_of_type_wasm=function(){return(Module._ts_node_descendants_of_type_wasm=Module.asm.ts_node_descendants_of_type_wasm).apply(null,arguments)},Module._ts_node_is_named_wasm=function(){return(Module._ts_node_is_named_wasm=Module.asm.ts_node_is_named_wasm).apply(null,arguments)},Module._ts_node_has_changes_wasm=function(){return(Module._ts_node_has_changes_wasm=Module.asm.ts_node_has_changes_wasm).apply(null,arguments)},Module._ts_node_has_error_wasm=function(){return(Module._ts_node_has_error_wasm=Module.asm.ts_node_has_error_wasm).apply(null,arguments)},Module._ts_node_is_missing_wasm=function(){return(Module._ts_node_is_missing_wasm=Module.asm.ts_node_is_missing_wasm).apply(null,arguments)},Module._ts_query_matches_wasm=function(){return(Module._ts_query_matches_wasm=Module.asm.ts_query_matches_wasm).apply(null,arguments)},Module._ts_query_captures_wasm=function(){return(Module._ts_query_captures_wasm=Module.asm.ts_query_captures_wasm).apply(null,arguments)},Module._iswdigit=function(){return(Module._iswdigit=Module.asm.iswdigit).apply(null,arguments)},Module._iswalpha=function(){return(Module._iswalpha=Module.asm.iswalpha).apply(null,arguments)},Module._iswlower=function(){return(Module._iswlower=Module.asm.iswlower).apply(null,arguments)},Module._towupper=function(){return(Module._towupper=Module.asm.towupper).apply(null,arguments)},Module.___errno_location=function(){return(je=Module.___errno_location=Module.asm.__errno_location).apply(null,arguments)}),Ue=(Module._memchr=function(){return(Module._memchr=Module.asm.memchr).apply(null,arguments)},Module._strlen=function(){return(Module._strlen=Module.asm.strlen).apply(null,arguments)},Module.stackSave=function(){return(Ue=Module.stackSave=Module.asm.stackSave).apply(null,arguments)}),De=Module.stackRestore=function(){return(De=Module.stackRestore=Module.asm.stackRestore).apply(null,arguments)},ze=Module.stackAlloc=function(){return(ze=Module.stackAlloc=Module.asm.stackAlloc).apply(null,arguments)},Ge=Module._setThrew=function(){return(Ge=Module._setThrew=Module.asm.setThrew).apply(null,arguments)};Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev=function(){return(Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev=Module.asm._ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev).apply(null,arguments)},Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__grow_byEmmmmmm=function(){return(Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__grow_byEmmmmmm=Module.asm._ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__grow_byEmmmmmm).apply(null,arguments)},Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm=function(){return(Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm=Module.asm._ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm).apply(null,arguments)},Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7reserveEm=function(){return(Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7reserveEm=Module.asm._ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7reserveEm).apply(null,arguments)},Module.__ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4copyEPcmm=function(){return(Module.__ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4copyEPcmm=Module.asm._ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4copyEPcmm).apply(null,arguments)},Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9push_backEc=function(){return(Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9push_backEc=Module.asm._ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9push_backEc).apply(null,arguments)},Module.__ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEED2Ev=function(){return(Module.__ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEED2Ev=Module.asm._ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEED2Ev).apply(null,arguments)},Module.__ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE9push_backEw=function(){return(Module.__ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE9push_backEw=Module.asm._ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE9push_backEw).apply(null,arguments)},Module.__Znwm=function(){return(Module.__Znwm=Module.asm._Znwm).apply(null,arguments)},Module.__ZdlPv=function(){return(Module.__ZdlPv=Module.asm._ZdlPv).apply(null,arguments)},Module.__ZNKSt3__220__vector_base_commonILb1EE20__throw_length_errorEv=function(){return(Module.__ZNKSt3__220__vector_base_commonILb1EE20__throw_length_errorEv=Module.asm._ZNKSt3__220__vector_base_commonILb1EE20__throw_length_errorEv).apply(null,arguments)},Module._orig$ts_parser_timeout_micros=function(){return(Module._orig$ts_parser_timeout_micros=Module.asm.orig$ts_parser_timeout_micros).apply(null,arguments)},Module._orig$ts_parser_set_timeout_micros=function(){return(Module._orig$ts_parser_set_timeout_micros=Module.asm.orig$ts_parser_set_timeout_micros).apply(null,arguments)};function He(e){this.name="ExitStatus",this.message="Program terminated with exit("+e+")",this.status=e}Module.allocate=function(e,t){var r;return r=t==C?ze(e.length):$e(e.length),e.subarray||e.slice?T.set(e,r):T.set(new Uint8Array(e),r),r};re=function e(){Ze||Ke(),Ze||(re=e)};var Be=!1;function Ke(e){function t(){Ze||(Ze=!0,Module.calledRun=!0,P||(Y=!0,pe(X),pe(Q),Module.onRuntimeInitialized&&Module.onRuntimeInitialized(),Xe&&function(e){var t=Module._main;if(t){var r=(e=e||[]).length+1,n=ze(4*(r+1));W[n>>2]=G(a);for(var s=1;s>2)+s]=G(e[s-1]);W[(n>>2)+r]=0;try{Ve(t(r,n),!0)}catch(e){if(e instanceof He)return;if("unwind"==e)return;var o=e;e&&"object"==typeof e&&e.stack&&(o=[e,e.stack]),g("exception thrown: "+o),u(1,e)}finally{!0}}}(e),function(){if(Module.postRun)for("function"==typeof Module.postRun&&(Module.postRun=[Module.postRun]);Module.postRun.length;)e=Module.postRun.shift(),J.unshift(e);var e;pe(J)}()))}e=e||_,ee>0||!Be&&(function(){if(I.length){if(!m)return ne(),void I.reduce(function(e,t){return e.then(function(){return Ne(t,{loadAsync:!0,global:!0,nodelete:!0,allowUndefined:!0})})},Promise.resolve()).then(function(){se(),Pe()});I.forEach(function(e){Ne(e,{global:!0,nodelete:!0,allowUndefined:!0})}),Pe()}else Pe()}(),Be=!0,ee>0)||(!function(){if(Module.preRun)for("function"==typeof Module.preRun&&(Module.preRun=[Module.preRun]);Module.preRun.length;)e=Module.preRun.shift(),V.unshift(e);var e;pe(V)}(),ee>0||(Module.setStatus?(Module.setStatus("Running..."),setTimeout(function(){setTimeout(function(){Module.setStatus("")},1),t()},1)):t()))}function Ve(e,t){e,t&&we()&&0===e||(we()||(!0,Module.onExit&&Module.onExit(e),P=!0),u(e,new He(e)))}if(Module.run=Ke,Module.preInit)for("function"==typeof Module.preInit&&(Module.preInit=[Module.preInit]);Module.preInit.length>0;)Module.preInit.pop()();var Xe=!0;Module.noInitialRun&&(Xe=!1),Ke();const Qe=Module,Je={},Ye=4,et=5*Ye,tt=2*Ye,rt=2*Ye+2*tt,nt={row:0,column:0},st=/[\w-.]*/g,ot=1,_t=2,at=/^_?tree_sitter_\w+/;var ut,it,lt,dt,ct;class ParserImpl{static init(){lt=Qe._ts_init(),ut=N(lt,"i32"),it=N(lt+Ye,"i32")}initialize(){Qe._ts_parser_new_wasm(),this[0]=N(lt,"i32"),this[1]=N(lt+Ye,"i32")}delete(){Qe._ts_parser_delete(this[0]),Qe._free(this[1]),this[0]=0,this[1]=0}setLanguage(e){let t;if(e){if(e.constructor!==Language)throw new Error("Argument must be a Language");{t=e[0];const r=Qe._ts_language_version(t);if(re.slice(t,n));else{if("function"!=typeof e)throw new Error("Argument must be a string or a function");dt=e}this.logCallback?(ct=this.logCallback,Qe._ts_parser_enable_logger_wasm(this[0],1)):(ct=null,Qe._ts_parser_enable_logger_wasm(this[0],0));let n=0,s=0;if(r&&r.includedRanges){n=r.includedRanges.length;let e=s=Qe._calloc(n,rt);for(let t=0;t0){let e=r;for(let r=0;r0){let r=t;for(let t=0;t0){let r=t;for(let t=0;t0){let e=a;for(let t=0;t<_;t++)u[t]=wt(this.tree,e),e+=et}return Qe._free(a),Qe._free(o),u}get nextSibling(){return gt(this),Qe._ts_node_next_sibling_wasm(this.tree[0]),wt(this.tree)}get previousSibling(){return gt(this),Qe._ts_node_prev_sibling_wasm(this.tree[0]),wt(this.tree)}get nextNamedSibling(){return gt(this),Qe._ts_node_next_named_sibling_wasm(this.tree[0]),wt(this.tree)}get previousNamedSibling(){return gt(this),Qe._ts_node_prev_named_sibling_wasm(this.tree[0]),wt(this.tree)}get parent(){return gt(this),Qe._ts_node_parent_wasm(this.tree[0]),wt(this.tree)}descendantForIndex(e,t=e){if("number"!=typeof e||"number"!=typeof t)throw new Error("Arguments must be numbers");gt(this);let r=lt+et;return x(r,e,"i32"),x(r+Ye,t,"i32"),Qe._ts_node_descendant_for_index_wasm(this.tree[0]),wt(this.tree)}namedDescendantForIndex(e,t=e){if("number"!=typeof e||"number"!=typeof t)throw new Error("Arguments must be numbers");gt(this);let r=lt+et;return x(r,e,"i32"),x(r+Ye,t,"i32"),Qe._ts_node_named_descendant_for_index_wasm(this.tree[0]),wt(this.tree)}descendantForPosition(e,t=e){if(!ht(e)||!ht(t))throw new Error("Arguments must be {row, column} objects");gt(this);let r=lt+et;return bt(r,e),bt(r+tt,t),Qe._ts_node_descendant_for_position_wasm(this.tree[0]),wt(this.tree)}namedDescendantForPosition(e,t=e){if(!ht(e)||!ht(t))throw new Error("Arguments must be {row, column} objects");gt(this);let r=lt+et;return bt(r,e),bt(r+tt,t),Qe._ts_node_named_descendant_for_position_wasm(this.tree[0]),wt(this.tree)}walk(){return gt(this),Qe._ts_tree_cursor_new_wasm(this.tree[0]),new TreeCursor(Je,this.tree)}toString(){gt(this);const e=Qe._ts_node_to_string_wasm(this.tree[0]),t=function(e){for(var t="";;){var r=T[e++>>0];if(!r)return t;t+=String.fromCharCode(r)}}(e);return Qe._free(e),t}}class TreeCursor{constructor(e,t){pt(e),this.tree=t,Mt(this)}delete(){yt(this),Qe._ts_tree_cursor_delete_wasm(this.tree[0]),this[0]=this[1]=this[2]=0}reset(e){gt(e),yt(this,lt+et),Qe._ts_tree_cursor_reset_wasm(this.tree[0]),Mt(this)}get nodeType(){return this.tree.language.types[this.nodeTypeId]||"ERROR"}get nodeTypeId(){return yt(this),Qe._ts_tree_cursor_current_node_type_id_wasm(this.tree[0])}get nodeId(){return yt(this),Qe._ts_tree_cursor_current_node_id_wasm(this.tree[0])}get nodeIsNamed(){return yt(this),1===Qe._ts_tree_cursor_current_node_is_named_wasm(this.tree[0])}get nodeIsMissing(){return yt(this),1===Qe._ts_tree_cursor_current_node_is_missing_wasm(this.tree[0])}get nodeText(){yt(this);const e=Qe._ts_tree_cursor_start_index_wasm(this.tree[0]),t=Qe._ts_tree_cursor_end_index_wasm(this.tree[0]);return mt(this.tree,e,t)}get startPosition(){return yt(this),Qe._ts_tree_cursor_start_position_wasm(this.tree[0]),vt(lt)}get endPosition(){return yt(this),Qe._ts_tree_cursor_end_position_wasm(this.tree[0]),vt(lt)}get startIndex(){return yt(this),Qe._ts_tree_cursor_start_index_wasm(this.tree[0])}get endIndex(){return yt(this),Qe._ts_tree_cursor_end_index_wasm(this.tree[0])}currentNode(){return yt(this),Qe._ts_tree_cursor_current_node_wasm(this.tree[0]),wt(this.tree)}currentFieldId(){return yt(this),Qe._ts_tree_cursor_current_field_id_wasm(this.tree[0])}currentFieldName(){return this.tree.language.fields[this.currentFieldId()]}gotoFirstChild(){yt(this);const e=Qe._ts_tree_cursor_goto_first_child_wasm(this.tree[0]);return Mt(this),1===e}gotoNextSibling(){yt(this);const e=Qe._ts_tree_cursor_goto_next_sibling_wasm(this.tree[0]);return Mt(this),1===e}gotoParent(){yt(this);const e=Qe._ts_tree_cursor_goto_parent_wasm(this.tree[0]);return Mt(this),1===e}}class Language{constructor(e,t){pt(e),this[0]=t,this.types=new Array(Qe._ts_language_symbol_count(this[0]));for(let e=0,t=this.types.length;e0){if("string"!==s[0].type)throw new Error("Predicates must begin with a literal value");const t=s[0].value;let r=!0;switch(t){case"not-eq?":r=!1;case"eq?":if(3!==s.length)throw new Error(`Wrong number of arguments to \`#eq?\` predicate. Expected 2, got ${s.length-1}`);if("capture"!==s[1].type)throw new Error(`First argument of \`#eq?\` predicate must be a capture. Got "${s[1].value}"`);if("capture"===s[2].type){const t=s[1].name,n=s[2].name;m[e].push(function(e){let s,o;for(const r of e)r.name===t&&(s=r.node),r.name===n&&(o=r.node);return void 0===s||void 0===o||s.text===o.text===r})}else{const t=s[1].name,n=s[2].value;m[e].push(function(e){for(const s of e)if(s.name===t)return s.node.text===n===r;return!0})}break;case"not-match?":r=!1;case"match?":if(3!==s.length)throw new Error(`Wrong number of arguments to \`#match?\` predicate. Expected 2, got ${s.length-1}.`);if("capture"!==s[1].type)throw new Error(`First argument of \`#match?\` predicate must be a capture. Got "${s[1].value}".`);if("string"!==s[2].type)throw new Error(`Second argument of \`#match?\` predicate must be a string. Got @${s[2].value}.`);const n=s[1].name,o=new RegExp(s[2].value);m[e].push(function(e){for(const t of e)if(t.name===n)return o.test(t.node.text)===r;return!0});break;case"set!":if(s.length<2||s.length>3)throw new Error(`Wrong number of arguments to \`#set!\` predicate. Expected 1 or 2. Got ${s.length-1}.`);if(s.some(e=>"string"!==e.type))throw new Error('Arguments to `#set!` predicate must be a strings.".');i[e]||(i[e]={}),i[e][s[1].value]=s[2]?s[2].value:null;break;case"is?":case"is-not?":if(s.length<2||s.length>3)throw new Error(`Wrong number of arguments to \`#${t}\` predicate. Expected 1 or 2. Got ${s.length-1}.`);if(s.some(e=>"string"!==e.type))throw new Error(`Arguments to \`#${t}\` predicate must be a strings.".`);const _="is?"===t?l:d;_[e]||(_[e]={}),_[e][s[1].value]=s[2]?s[2].value:null;break;default:c[e].push({operator:t,operands:s.slice(1)})}s.length=0}}Object.freeze(i[e]),Object.freeze(l[e]),Object.freeze(d[e])}return Qe._free(r),new Query(Je,n,a,m,c,Object.freeze(i),Object.freeze(l),Object.freeze(d))}static load(e){let t;if(e instanceof Uint8Array)t=Promise.resolve(e);else{const r=e;if("undefined"!=typeof process&&process.versions&&process.versions.node){const e=require("fs");t=Promise.resolve(e.readFileSync(r))}else t=fetch(r).then(e=>e.arrayBuffer().then(t=>{if(e.ok)return new Uint8Array(t);{const r=new TextDecoder("utf-8").decode(t);throw new Error(`Language.load failed with status ${e.status}.\n\n${r}`)}}))}const r="function"==typeof loadSideModule?loadSideModule:xe;return t.then(e=>r(e,{loadAsync:!0})).then(e=>{const t=Object.keys(e),r=t.find(e=>at.test(e)&&!e.includes("external_scanner_"));r||console.log(`Couldn't find language function in WASM file. Symbols:\n${JSON.stringify(t,null,2)}`);const n=e[r]();return new Language(Je,n)})}}class Query{constructor(e,t,r,n,s,o,_,a){pt(e),this[0]=t,this.captureNames=r,this.textPredicates=n,this.predicates=s,this.setProperties=o,this.assertedProperties=_,this.refutedProperties=a,this.exceededMatchLimit=!1}delete(){Qe._ts_query_delete(this[0]),this[0]=0}matches(e,t,r,n){t||(t=nt),r||(r=nt),n||(n={});let s=n.matchLimit;if(void 0===s)s=0;else if("number"!=typeof s)throw new Error("Arguments must be numbers");gt(e),Qe._ts_query_matches_wasm(this[0],e.tree[0],t.row,t.column,r.row,r.column,s);const o=N(lt,"i32"),_=N(lt+Ye,"i32"),a=N(lt+2*Ye,"i32"),u=new Array(o);this.exceededMatchLimit=!!a;let i=0,l=_;for(let t=0;te(s))){u[i++]={pattern:r,captures:s};const e=this.setProperties[r];e&&(u[t].setProperties=e);const n=this.assertedProperties[r];n&&(u[t].assertedProperties=n);const o=this.refutedProperties[r];o&&(u[t].refutedProperties=o)}}return u.length=i,Qe._free(_),u}captures(e,t,r,n){t||(t=nt),r||(r=nt),n||(n={});let s=n.matchLimit;if(void 0===s)s=0;else if("number"!=typeof s)throw new Error("Arguments must be numbers");gt(e),Qe._ts_query_captures_wasm(this[0],e.tree[0],t.row,t.column,r.row,r.column,s);const o=N(lt,"i32"),_=N(lt+Ye,"i32"),a=N(lt+2*Ye,"i32"),u=[];this.exceededMatchLimit=!!a;const i=[];let l=_;for(let t=0;te(i))){const e=i[n],r=this.setProperties[t];r&&(e.setProperties=r);const s=this.assertedProperties[t];s&&(e.assertedProperties=s);const o=this.refutedProperties[t];o&&(e.refutedProperties=o),u.push(e)}}return Qe._free(_),u}predicatesForPattern(e){return this.predicates[e]}didExceedMatchLimit(){return this.exceededMatchLimit}}function mt(e,t,r){const n=r-t;let s=e.textCallback(t,null,r);for(t+=s.length;t0))break;t+=n.length,s+=n}return t>r&&(s=s.slice(0,n)),s}function ft(e,t,r,n){for(let s=0,o=n.length;s{ParserImpl.init(),e()})}))}}return Parser}();"object"==typeof exports&&(module.exports=TreeSitter); diff --git a/docs/vendor/tree-sitter.wasm b/docs/vendor/tree-sitter.wasm index 84ac0a2..140b943 100644 Binary files a/docs/vendor/tree-sitter.wasm and b/docs/vendor/tree-sitter.wasm differ diff --git a/docs/vendor/web-tree-sitter.js b/docs/vendor/web-tree-sitter.js new file mode 100644 index 0000000..0ef48a4 --- /dev/null +++ b/docs/vendor/web-tree-sitter.js @@ -0,0 +1,4001 @@ +var __defProp = Object.defineProperty; +var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); +var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { + get: (a, b) => (typeof require !== "undefined" ? require : a)[b] +}) : x)(function(x) { + if (typeof require !== "undefined") return require.apply(this, arguments); + throw Error('Dynamic require of "' + x + '" is not supported'); +}); + +// src/constants.ts +var SIZE_OF_SHORT = 2; +var SIZE_OF_INT = 4; +var SIZE_OF_CURSOR = 4 * SIZE_OF_INT; +var SIZE_OF_NODE = 5 * SIZE_OF_INT; +var SIZE_OF_POINT = 2 * SIZE_OF_INT; +var SIZE_OF_RANGE = 2 * SIZE_OF_INT + 2 * SIZE_OF_POINT; +var ZERO_POINT = { row: 0, column: 0 }; +var INTERNAL = Symbol("INTERNAL"); +function assertInternal(x) { + if (x !== INTERNAL) throw new Error("Illegal constructor"); +} +__name(assertInternal, "assertInternal"); +function isPoint(point) { + return !!point && typeof point.row === "number" && typeof point.column === "number"; +} +__name(isPoint, "isPoint"); +function setModule(module2) { + C = module2; +} +__name(setModule, "setModule"); +var C; + +// src/lookahead_iterator.ts +var LookaheadIterator = class { + static { + __name(this, "LookaheadIterator"); + } + /** @internal */ + [0] = 0; + // Internal handle for WASM + /** @internal */ + language; + /** @internal */ + constructor(internal, address, language) { + assertInternal(internal); + this[0] = address; + this.language = language; + } + /** Get the current symbol of the lookahead iterator. */ + get currentTypeId() { + return C._ts_lookahead_iterator_current_symbol(this[0]); + } + /** Get the current symbol name of the lookahead iterator. */ + get currentType() { + return this.language.types[this.currentTypeId] || "ERROR"; + } + /** Delete the lookahead iterator, freeing its resources. */ + delete() { + C._ts_lookahead_iterator_delete(this[0]); + this[0] = 0; + } + /** + * Reset the lookahead iterator. + * + * This returns `true` if the language was set successfully and `false` + * otherwise. + */ + reset(language, stateId) { + if (C._ts_lookahead_iterator_reset(this[0], language[0], stateId)) { + this.language = language; + return true; + } + return false; + } + /** + * Reset the lookahead iterator to another state. + * + * This returns `true` if the iterator was reset to the given state and + * `false` otherwise. + */ + resetState(stateId) { + return Boolean(C._ts_lookahead_iterator_reset_state(this[0], stateId)); + } + /** + * Returns an iterator that iterates over the symbols of the lookahead iterator. + * + * The iterator will yield the current symbol name as a string for each step + * until there are no more symbols to iterate over. + */ + [Symbol.iterator]() { + return { + next: /* @__PURE__ */ __name(() => { + if (C._ts_lookahead_iterator_next(this[0])) { + return { done: false, value: this.currentType }; + } + return { done: true, value: "" }; + }, "next") + }; + } +}; + +// src/query.ts +var CaptureQuantifier = { + Zero: 0, + ZeroOrOne: 1, + ZeroOrMore: 2, + One: 3, + OneOrMore: 4 +}; +var Query = class { + static { + __name(this, "Query"); + } + /** @internal */ + [0] = 0; + // Internal handle for WASM + /** @internal */ + exceededMatchLimit; + /** @internal */ + textPredicates; + /** The names of the captures used in the query. */ + captureNames; + /** The quantifiers of the captures used in the query. */ + captureQuantifiers; + /** + * The other user-defined predicates associated with the given index. + * + * This includes predicates with operators other than: + * - `match?` + * - `eq?` and `not-eq?` + * - `any-of?` and `not-any-of?` + * - `is?` and `is-not?` + * - `set!` + */ + predicates; + /** The properties for predicates with the operator `set!`. */ + setProperties; + /** The properties for predicates with the operator `is?`. */ + assertedProperties; + /** The properties for predicates with the operator `is-not?`. */ + refutedProperties; + /** The maximum number of in-progress matches for this cursor. */ + matchLimit; + /** @internal */ + constructor(internal, address, captureNames, captureQuantifiers, textPredicates, predicates, setProperties, assertedProperties, refutedProperties) { + assertInternal(internal); + this[0] = address; + this.captureNames = captureNames; + this.captureQuantifiers = captureQuantifiers; + this.textPredicates = textPredicates; + this.predicates = predicates; + this.setProperties = setProperties; + this.assertedProperties = assertedProperties; + this.refutedProperties = refutedProperties; + this.exceededMatchLimit = false; + } + /** Delete the query, freeing its resources. */ + delete() { + C._ts_query_delete(this[0]); + this[0] = 0; + } + /** + * Iterate over all of the matches in the order that they were found. + * + * Each match contains the index of the pattern that matched, and a list of + * captures. Because multiple patterns can match the same set of nodes, + * one match may contain captures that appear *before* some of the + * captures from a previous match. + * + * @param {Node} node - The node to execute the query on. + * + * @param {QueryOptions} options - Options for query execution. + */ + matches(node, options = {}) { + const startPosition = options.startPosition ?? ZERO_POINT; + const endPosition = options.endPosition ?? ZERO_POINT; + const startIndex = options.startIndex ?? 0; + const endIndex = options.endIndex ?? 0; + const matchLimit = options.matchLimit ?? 4294967295; + const maxStartDepth = options.maxStartDepth ?? 4294967295; + const timeoutMicros = options.timeoutMicros ?? 0; + const progressCallback = options.progressCallback; + if (typeof matchLimit !== "number") { + throw new Error("Arguments must be numbers"); + } + this.matchLimit = matchLimit; + if (endIndex !== 0 && startIndex > endIndex) { + throw new Error("`startIndex` cannot be greater than `endIndex`"); + } + if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) { + throw new Error("`startPosition` cannot be greater than `endPosition`"); + } + if (progressCallback) { + C.currentQueryProgressCallback = progressCallback; + } + marshalNode(node); + C._ts_query_matches_wasm( + this[0], + node.tree[0], + startPosition.row, + startPosition.column, + endPosition.row, + endPosition.column, + startIndex, + endIndex, + matchLimit, + maxStartDepth, + timeoutMicros + ); + const rawCount = C.getValue(TRANSFER_BUFFER, "i32"); + const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32"); + const result = new Array(rawCount); + this.exceededMatchLimit = Boolean(didExceedMatchLimit); + let filteredCount = 0; + let address = startAddress; + for (let i2 = 0; i2 < rawCount; i2++) { + const pattern = C.getValue(address, "i32"); + address += SIZE_OF_INT; + const captureCount = C.getValue(address, "i32"); + address += SIZE_OF_INT; + const captures = new Array(captureCount); + address = unmarshalCaptures(this, node.tree, address, captures); + if (this.textPredicates[pattern].every((p) => p(captures))) { + result[filteredCount] = { pattern, captures }; + const setProperties = this.setProperties[pattern]; + result[filteredCount].setProperties = setProperties; + const assertedProperties = this.assertedProperties[pattern]; + result[filteredCount].assertedProperties = assertedProperties; + const refutedProperties = this.refutedProperties[pattern]; + result[filteredCount].refutedProperties = refutedProperties; + filteredCount++; + } + } + result.length = filteredCount; + C._free(startAddress); + C.currentQueryProgressCallback = null; + return result; + } + /** + * Iterate over all of the individual captures in the order that they + * appear. + * + * This is useful if you don't care about which pattern matched, and just + * want a single, ordered sequence of captures. + * + * @param {Node} node - The node to execute the query on. + * + * @param {QueryOptions} options - Options for query execution. + */ + captures(node, options = {}) { + const startPosition = options.startPosition ?? ZERO_POINT; + const endPosition = options.endPosition ?? ZERO_POINT; + const startIndex = options.startIndex ?? 0; + const endIndex = options.endIndex ?? 0; + const matchLimit = options.matchLimit ?? 4294967295; + const maxStartDepth = options.maxStartDepth ?? 4294967295; + const timeoutMicros = options.timeoutMicros ?? 0; + const progressCallback = options.progressCallback; + if (typeof matchLimit !== "number") { + throw new Error("Arguments must be numbers"); + } + this.matchLimit = matchLimit; + if (endIndex !== 0 && startIndex > endIndex) { + throw new Error("`startIndex` cannot be greater than `endIndex`"); + } + if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) { + throw new Error("`startPosition` cannot be greater than `endPosition`"); + } + if (progressCallback) { + C.currentQueryProgressCallback = progressCallback; + } + marshalNode(node); + C._ts_query_captures_wasm( + this[0], + node.tree[0], + startPosition.row, + startPosition.column, + endPosition.row, + endPosition.column, + startIndex, + endIndex, + matchLimit, + maxStartDepth, + timeoutMicros + ); + const count = C.getValue(TRANSFER_BUFFER, "i32"); + const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32"); + const result = new Array(); + this.exceededMatchLimit = Boolean(didExceedMatchLimit); + const captures = new Array(); + let address = startAddress; + for (let i2 = 0; i2 < count; i2++) { + const pattern = C.getValue(address, "i32"); + address += SIZE_OF_INT; + const captureCount = C.getValue(address, "i32"); + address += SIZE_OF_INT; + const captureIndex = C.getValue(address, "i32"); + address += SIZE_OF_INT; + captures.length = captureCount; + address = unmarshalCaptures(this, node.tree, address, captures); + if (this.textPredicates[pattern].every((p) => p(captures))) { + const capture = captures[captureIndex]; + const setProperties = this.setProperties[pattern]; + capture.setProperties = setProperties; + const assertedProperties = this.assertedProperties[pattern]; + capture.assertedProperties = assertedProperties; + const refutedProperties = this.refutedProperties[pattern]; + capture.refutedProperties = refutedProperties; + result.push(capture); + } + } + C._free(startAddress); + C.currentQueryProgressCallback = null; + return result; + } + /** Get the predicates for a given pattern. */ + predicatesForPattern(patternIndex) { + return this.predicates[patternIndex]; + } + /** + * Disable a certain capture within a query. + * + * This prevents the capture from being returned in matches, and also + * avoids any resource usage associated with recording the capture. + */ + disableCapture(captureName) { + const captureNameLength = C.lengthBytesUTF8(captureName); + const captureNameAddress = C._malloc(captureNameLength + 1); + C.stringToUTF8(captureName, captureNameAddress, captureNameLength + 1); + C._ts_query_disable_capture(this[0], captureNameAddress, captureNameLength); + C._free(captureNameAddress); + } + /** + * Disable a certain pattern within a query. + * + * This prevents the pattern from matching, and also avoids any resource + * usage associated with the pattern. This throws an error if the pattern + * index is out of bounds. + */ + disablePattern(patternIndex) { + if (patternIndex >= this.predicates.length) { + throw new Error( + `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}` + ); + } + C._ts_query_disable_pattern(this[0], patternIndex); + } + /** + * Check if, on its last execution, this cursor exceeded its maximum number + * of in-progress matches. + */ + didExceedMatchLimit() { + return this.exceededMatchLimit; + } + /** Get the byte offset where the given pattern starts in the query's source. */ + startIndexForPattern(patternIndex) { + if (patternIndex >= this.predicates.length) { + throw new Error( + `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}` + ); + } + return C._ts_query_start_byte_for_pattern(this[0], patternIndex); + } + /** Get the byte offset where the given pattern ends in the query's source. */ + endIndexForPattern(patternIndex) { + if (patternIndex >= this.predicates.length) { + throw new Error( + `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}` + ); + } + return C._ts_query_end_byte_for_pattern(this[0], patternIndex); + } + /** Get the number of patterns in the query. */ + patternCount() { + return C._ts_query_pattern_count(this[0]); + } + /** Get the index for a given capture name. */ + captureIndexForName(captureName) { + return this.captureNames.indexOf(captureName); + } + /** Check if a given pattern within a query has a single root node. */ + isPatternRooted(patternIndex) { + return C._ts_query_is_pattern_rooted(this[0], patternIndex) === 1; + } + /** Check if a given pattern within a query has a single root node. */ + isPatternNonLocal(patternIndex) { + return C._ts_query_is_pattern_non_local(this[0], patternIndex) === 1; + } + /** + * Check if a given step in a query is 'definite'. + * + * A query step is 'definite' if its parent pattern will be guaranteed to + * match successfully once it reaches the step. + */ + isPatternGuaranteedAtStep(byteIndex) { + return C._ts_query_is_pattern_guaranteed_at_step(this[0], byteIndex) === 1; + } +}; + +// src/language.ts +var PREDICATE_STEP_TYPE_CAPTURE = 1; +var PREDICATE_STEP_TYPE_STRING = 2; +var QUERY_WORD_REGEX = /[\w-]+/g; +var LANGUAGE_FUNCTION_REGEX = /^tree_sitter_\w+$/; +var Language = class _Language { + static { + __name(this, "Language"); + } + /** @internal */ + [0] = 0; + // Internal handle for WASM + /** + * A list of all node types in the language. The index of each type in this + * array is its node type id. + */ + types; + /** + * A list of all field names in the language. The index of each field name in + * this array is its field id. + */ + fields; + /** @internal */ + constructor(internal, address) { + assertInternal(internal); + this[0] = address; + this.types = new Array(C._ts_language_symbol_count(this[0])); + for (let i2 = 0, n = this.types.length; i2 < n; i2++) { + if (C._ts_language_symbol_type(this[0], i2) < 2) { + this.types[i2] = C.UTF8ToString(C._ts_language_symbol_name(this[0], i2)); + } + } + this.fields = new Array(C._ts_language_field_count(this[0]) + 1); + for (let i2 = 0, n = this.fields.length; i2 < n; i2++) { + const fieldName = C._ts_language_field_name_for_id(this[0], i2); + if (fieldName !== 0) { + this.fields[i2] = C.UTF8ToString(fieldName); + } else { + this.fields[i2] = null; + } + } + } + /** + * Gets the name of the language. + */ + get name() { + const ptr = C._ts_language_name(this[0]); + if (ptr === 0) return null; + return C.UTF8ToString(ptr); + } + /** + * Gets the version of the language. + */ + get version() { + return C._ts_language_version(this[0]); + } + /** + * Gets the number of fields in the language. + */ + get fieldCount() { + return this.fields.length - 1; + } + /** + * Gets the number of states in the language. + */ + get stateCount() { + return C._ts_language_state_count(this[0]); + } + /** + * Get the field id for a field name. + */ + fieldIdForName(fieldName) { + const result = this.fields.indexOf(fieldName); + return result !== -1 ? result : null; + } + /** + * Get the field name for a field id. + */ + fieldNameForId(fieldId) { + return this.fields[fieldId] ?? null; + } + /** + * Get the node type id for a node type name. + */ + idForNodeType(type, named) { + const typeLength = C.lengthBytesUTF8(type); + const typeAddress = C._malloc(typeLength + 1); + C.stringToUTF8(type, typeAddress, typeLength + 1); + const result = C._ts_language_symbol_for_name(this[0], typeAddress, typeLength, named ? 1 : 0); + C._free(typeAddress); + return result || null; + } + /** + * Gets the number of node types in the language. + */ + get nodeTypeCount() { + return C._ts_language_symbol_count(this[0]); + } + /** + * Get the node type name for a node type id. + */ + nodeTypeForId(typeId) { + const name2 = C._ts_language_symbol_name(this[0], typeId); + return name2 ? C.UTF8ToString(name2) : null; + } + /** + * Check if a node type is named. + * + * @see {@link https://tree-sitter.github.io/tree-sitter/using-parsers/2-basic-parsing.html#named-vs-anonymous-nodes} + */ + nodeTypeIsNamed(typeId) { + return C._ts_language_type_is_named_wasm(this[0], typeId) ? true : false; + } + /** + * Check if a node type is visible. + */ + nodeTypeIsVisible(typeId) { + return C._ts_language_type_is_visible_wasm(this[0], typeId) ? true : false; + } + /** + * Get the supertypes ids of this language. + * + * @see {@link https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types.html?highlight=supertype#supertype-nodes} + */ + get supertypes() { + C._ts_language_supertypes_wasm(this[0]); + const count = C.getValue(TRANSFER_BUFFER, "i32"); + const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + const result = new Array(count); + if (count > 0) { + let address = buffer; + for (let i2 = 0; i2 < count; i2++) { + result[i2] = C.getValue(address, "i16"); + address += SIZE_OF_SHORT; + } + } + return result; + } + /** + * Get the subtype ids for a given supertype node id. + */ + subtypes(supertype) { + C._ts_language_subtypes_wasm(this[0], supertype); + const count = C.getValue(TRANSFER_BUFFER, "i32"); + const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + const result = new Array(count); + if (count > 0) { + let address = buffer; + for (let i2 = 0; i2 < count; i2++) { + result[i2] = C.getValue(address, "i16"); + address += SIZE_OF_SHORT; + } + } + return result; + } + /** + * Get the next state id for a given state id and node type id. + */ + nextState(stateId, typeId) { + return C._ts_language_next_state(this[0], stateId, typeId); + } + /** + * Create a new lookahead iterator for this language and parse state. + * + * This returns `null` if state is invalid for this language. + * + * Iterating {@link LookaheadIterator} will yield valid symbols in the given + * parse state. Newly created lookahead iterators will return the `ERROR` + * symbol from {@link LookaheadIterator#currentType}. + * + * Lookahead iterators can be useful for generating suggestions and improving + * syntax error diagnostics. To get symbols valid in an `ERROR` node, use the + * lookahead iterator on its first leaf node state. For `MISSING` nodes, a + * lookahead iterator created on the previous non-extra leaf node may be + * appropriate. + */ + lookaheadIterator(stateId) { + const address = C._ts_lookahead_iterator_new(this[0], stateId); + if (address) return new LookaheadIterator(INTERNAL, address, this); + return null; + } + /** + * Create a new query from a string containing one or more S-expression + * patterns. + * + * The query is associated with a particular language, and can only be run + * on syntax nodes parsed with that language. References to Queries can be + * shared between multiple threads. + * + * @link {@see https://tree-sitter.github.io/tree-sitter/using-parsers/queries} + */ + query(source) { + const sourceLength = C.lengthBytesUTF8(source); + const sourceAddress = C._malloc(sourceLength + 1); + C.stringToUTF8(source, sourceAddress, sourceLength + 1); + const address = C._ts_query_new( + this[0], + sourceAddress, + sourceLength, + TRANSFER_BUFFER, + TRANSFER_BUFFER + SIZE_OF_INT + ); + if (!address) { + const errorId = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + const errorByte = C.getValue(TRANSFER_BUFFER, "i32"); + const errorIndex = C.UTF8ToString(sourceAddress, errorByte).length; + const suffix = source.slice(errorIndex, errorIndex + 100).split("\n")[0]; + let word = suffix.match(QUERY_WORD_REGEX)?.[0] ?? ""; + let error; + switch (errorId) { + case 2: + error = new RangeError(`Bad node name '${word}'`); + break; + case 3: + error = new RangeError(`Bad field name '${word}'`); + break; + case 4: + error = new RangeError(`Bad capture name @${word}`); + break; + case 5: + error = new TypeError(`Bad pattern structure at offset ${errorIndex}: '${suffix}'...`); + word = ""; + break; + default: + error = new SyntaxError(`Bad syntax at offset ${errorIndex}: '${suffix}'...`); + word = ""; + break; + } + error.index = errorIndex; + error.length = word.length; + C._free(sourceAddress); + throw error; + } + const stringCount = C._ts_query_string_count(address); + const captureCount = C._ts_query_capture_count(address); + const patternCount = C._ts_query_pattern_count(address); + const captureNames = new Array(captureCount); + const captureQuantifiers = new Array(patternCount); + const stringValues = new Array(stringCount); + for (let i2 = 0; i2 < captureCount; i2++) { + const nameAddress = C._ts_query_capture_name_for_id( + address, + i2, + TRANSFER_BUFFER + ); + const nameLength = C.getValue(TRANSFER_BUFFER, "i32"); + captureNames[i2] = C.UTF8ToString(nameAddress, nameLength); + } + for (let i2 = 0; i2 < patternCount; i2++) { + const captureQuantifiersArray = new Array(captureCount); + for (let j = 0; j < captureCount; j++) { + const quantifier = C._ts_query_capture_quantifier_for_id(address, i2, j); + captureQuantifiersArray[j] = quantifier; + } + captureQuantifiers[i2] = captureQuantifiersArray; + } + for (let i2 = 0; i2 < stringCount; i2++) { + const valueAddress = C._ts_query_string_value_for_id( + address, + i2, + TRANSFER_BUFFER + ); + const nameLength = C.getValue(TRANSFER_BUFFER, "i32"); + stringValues[i2] = C.UTF8ToString(valueAddress, nameLength); + } + const setProperties = new Array(patternCount); + const assertedProperties = new Array(patternCount); + const refutedProperties = new Array(patternCount); + const predicates = new Array(patternCount); + const textPredicates = new Array(patternCount); + for (let i2 = 0; i2 < patternCount; i2++) { + const predicatesAddress = C._ts_query_predicates_for_pattern( + address, + i2, + TRANSFER_BUFFER + ); + const stepCount = C.getValue(TRANSFER_BUFFER, "i32"); + predicates[i2] = []; + textPredicates[i2] = []; + const steps = new Array(); + const isStringStep = /* @__PURE__ */ __name((step) => { + return step.type === "string"; + }, "isStringStep"); + let stepAddress = predicatesAddress; + for (let j = 0; j < stepCount; j++) { + const stepType = C.getValue(stepAddress, "i32"); + stepAddress += SIZE_OF_INT; + const stepValueId = C.getValue(stepAddress, "i32"); + stepAddress += SIZE_OF_INT; + if (stepType === PREDICATE_STEP_TYPE_CAPTURE) { + const name2 = captureNames[stepValueId]; + steps.push({ type: "capture", name: name2 }); + } else if (stepType === PREDICATE_STEP_TYPE_STRING) { + steps.push({ type: "string", value: stringValues[stepValueId] }); + } else if (steps.length > 0) { + if (steps[0].type !== "string") { + throw new Error("Predicates must begin with a literal value"); + } + const operator = steps[0].value; + let isPositive = true; + let matchAll = true; + let captureName; + switch (operator) { + case "any-not-eq?": + case "not-eq?": + isPositive = false; + case "any-eq?": + case "eq?": { + if (steps.length !== 3) { + throw new Error( + `Wrong number of arguments to \`#${operator}\` predicate. Expected 2, got ${steps.length - 1}` + ); + } + if (steps[1].type !== "capture") { + throw new Error( + `First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}"` + ); + } + matchAll = !operator.startsWith("any-"); + if (steps[2].type === "capture") { + const captureName1 = steps[1].name; + const captureName2 = steps[2].name; + textPredicates[i2].push((captures) => { + const nodes1 = []; + const nodes2 = []; + for (const c of captures) { + if (c.name === captureName1) nodes1.push(c.node); + if (c.name === captureName2) nodes2.push(c.node); + } + const compare = /* @__PURE__ */ __name((n1, n2, positive) => { + return positive ? n1.text === n2.text : n1.text !== n2.text; + }, "compare"); + return matchAll ? nodes1.every((n1) => nodes2.some((n2) => compare(n1, n2, isPositive))) : nodes1.some((n1) => nodes2.some((n2) => compare(n1, n2, isPositive))); + }); + } else { + captureName = steps[1].name; + const stringValue = steps[2].value; + const matches = /* @__PURE__ */ __name((n) => n.text === stringValue, "matches"); + const doesNotMatch = /* @__PURE__ */ __name((n) => n.text !== stringValue, "doesNotMatch"); + textPredicates[i2].push((captures) => { + const nodes = []; + for (const c of captures) { + if (c.name === captureName) nodes.push(c.node); + } + const test = isPositive ? matches : doesNotMatch; + return matchAll ? nodes.every(test) : nodes.some(test); + }); + } + break; + } + case "any-not-match?": + case "not-match?": + isPositive = false; + case "any-match?": + case "match?": { + if (steps.length !== 3) { + throw new Error( + `Wrong number of arguments to \`#${operator}\` predicate. Expected 2, got ${steps.length - 1}.` + ); + } + if (steps[1].type !== "capture") { + throw new Error( + `First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}".` + ); + } + if (steps[2].type !== "string") { + throw new Error( + `Second argument of \`#${operator}\` predicate must be a string. Got @${steps[2].name}.` + ); + } + captureName = steps[1].name; + const regex = new RegExp(steps[2].value); + matchAll = !operator.startsWith("any-"); + textPredicates[i2].push((captures) => { + const nodes = []; + for (const c of captures) { + if (c.name === captureName) nodes.push(c.node.text); + } + const test = /* @__PURE__ */ __name((text, positive) => { + return positive ? regex.test(text) : !regex.test(text); + }, "test"); + if (nodes.length === 0) return !isPositive; + return matchAll ? nodes.every((text) => test(text, isPositive)) : nodes.some((text) => test(text, isPositive)); + }); + break; + } + case "set!": { + if (steps.length < 2 || steps.length > 3) { + throw new Error( + `Wrong number of arguments to \`#set!\` predicate. Expected 1 or 2. Got ${steps.length - 1}.` + ); + } + if (!steps.every(isStringStep)) { + throw new Error( + `Arguments to \`#set!\` predicate must be strings.".` + ); + } + if (!setProperties[i2]) setProperties[i2] = {}; + setProperties[i2][steps[1].value] = steps[2]?.value ?? null; + break; + } + case "is?": + case "is-not?": { + if (steps.length < 2 || steps.length > 3) { + throw new Error( + `Wrong number of arguments to \`#${operator}\` predicate. Expected 1 or 2. Got ${steps.length - 1}.` + ); + } + if (!steps.every(isStringStep)) { + throw new Error( + `Arguments to \`#${operator}\` predicate must be strings.".` + ); + } + const properties = operator === "is?" ? assertedProperties : refutedProperties; + if (!properties[i2]) properties[i2] = {}; + properties[i2][steps[1].value] = steps[2]?.value ?? null; + break; + } + case "not-any-of?": + isPositive = false; + case "any-of?": { + if (steps.length < 2) { + throw new Error( + `Wrong number of arguments to \`#${operator}\` predicate. Expected at least 1. Got ${steps.length - 1}.` + ); + } + if (steps[1].type !== "capture") { + throw new Error( + `First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}".` + ); + } + captureName = steps[1].name; + const stringSteps = steps.slice(2); + if (!stringSteps.every(isStringStep)) { + throw new Error( + `Arguments to \`#${operator}\` predicate must be strings.".` + ); + } + const values = stringSteps.map((s) => s.value); + textPredicates[i2].push((captures) => { + const nodes = []; + for (const c of captures) { + if (c.name === captureName) nodes.push(c.node.text); + } + if (nodes.length === 0) return !isPositive; + return nodes.every((text) => values.includes(text)) === isPositive; + }); + break; + } + default: + predicates[i2].push({ operator, operands: steps.slice(1) }); + } + steps.length = 0; + } + } + Object.freeze(setProperties[i2]); + Object.freeze(assertedProperties[i2]); + Object.freeze(refutedProperties[i2]); + } + C._free(sourceAddress); + return new Query( + INTERNAL, + address, + captureNames, + captureQuantifiers, + textPredicates, + predicates, + setProperties, + assertedProperties, + refutedProperties + ); + } + /** + * Load a language from a WebAssembly module. + * The module can be provided as a path to a file or as a buffer. + */ + static async load(input) { + let bytes; + if (input instanceof Uint8Array) { + bytes = Promise.resolve(input); + } else { + if (globalThis.process?.versions.node) { + const fs2 = __require("fs/promises"); + bytes = fs2.readFile(input); + } else { + bytes = fetch(input).then((response) => response.arrayBuffer().then((buffer) => { + if (response.ok) { + return new Uint8Array(buffer); + } else { + const body2 = new TextDecoder("utf-8").decode(buffer); + throw new Error(`Language.load failed with status ${response.status}. + +${body2}`); + } + })); + } + } + const mod = await C.loadWebAssemblyModule(await bytes, { loadAsync: true }); + const symbolNames = Object.keys(mod); + const functionName = symbolNames.find((key) => LANGUAGE_FUNCTION_REGEX.test(key) && !key.includes("external_scanner_")); + if (!functionName) { + console.log(`Couldn't find language function in WASM file. Symbols: +${JSON.stringify(symbolNames, null, 2)}`); + throw new Error("Language.load failed: no language function found in WASM file"); + } + const languageAddress = mod[functionName](); + return new _Language(INTERNAL, languageAddress); + } +}; + +// lib/tree-sitter.mjs +var Module2 = (() => { + var _scriptName = import.meta.url; + 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) { + const { createRequire } = await import("module"); + let dirname = import.meta.url; + if (dirname.startsWith("data:")) { + dirname = "/"; + } + var require = createRequire(dirname); + } + 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) { + var fs = require("fs"); + var nodePath = require("path"); + if (!import.meta.url.startsWith("data:")) { + scriptDirectory = nodePath.dirname(require("url").fileURLToPath(import.meta.url)) + "/"; + } + readBinary = /* @__PURE__ */ __name((filename) => { + filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename); + var ret = fs.readFileSync(filename); + return ret; + }, "readBinary"); + readAsync = /* @__PURE__ */ __name((filename, binary2 = true) => { + filename = isFileURI(filename) ? new URL(filename) : nodePath.normalize(filename); + return new Promise((resolve, reject) => { + fs.readFile(filename, binary2 ? void 0 : "utf8", (err2, data) => { + if (err2) reject(err2); + else resolve(binary2 ? data.buffer : data); + }); + }); + }, "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_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.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1); + } + { + 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((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); + }); + } + return fetch(url, { + credentials: "same-origin" + }).then((response) => { + if (response.ok) { + return response.arrayBuffer(); + } + return Promise.reject(new Error(response.status + " : " + response.url)); + }); + }, "readAsync"); + } + } else { + } + var out = Module["print"] || console.log.bind(console); + var err = Module["printErr"] || console.error.bind(console); + Object.assign(Module, moduleOverrides); + moduleOverrides = null; + if (Module["arguments"]) arguments_ = Module["arguments"]; + if (Module["thisProgram"]) thisProgram = Module["thisProgram"]; + var dynamicLibraries = Module["dynamicLibraries"] || []; + var wasmBinary = Module["wasmBinary"]; + var wasmMemory; + var ABORT = false; + var EXITSTATUS; + function assert(condition, text) { + if (!condition) { + abort(text); + } + } + __name(assert, "assert"); + var HEAP, HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64; + var HEAP_DATA_VIEW; + 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); + } + __name(updateMemoryViews, "updateMemoryViews"); + if (Module["wasmMemory"]) { + wasmMemory = Module["wasmMemory"]; + } else { + var INITIAL_MEMORY = Module["INITIAL_MEMORY"] || 33554432; + 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 __ATPRERUN__ = []; + var __ATINIT__ = []; + var __ATMAIN__ = []; + var __ATEXIT__ = []; + var __ATPOSTRUN__ = []; + var __RELOC_FUNCS__ = []; + var runtimeInitialized = false; + function preRun() { + if (Module["preRun"]) { + if (typeof Module["preRun"] == "function") Module["preRun"] = [Module["preRun"]]; + while (Module["preRun"].length) { + addOnPreRun(Module["preRun"].shift()); + } + } + callRuntimeCallbacks(__ATPRERUN__); + } + __name(preRun, "preRun"); + function initRuntime() { + runtimeInitialized = true; + callRuntimeCallbacks(__RELOC_FUNCS__); + callRuntimeCallbacks(__ATINIT__); + } + __name(initRuntime, "initRuntime"); + function preMain() { + callRuntimeCallbacks(__ATMAIN__); + } + __name(preMain, "preMain"); + function postRun() { + if (Module["postRun"]) { + if (typeof Module["postRun"] == "function") Module["postRun"] = [Module["postRun"]]; + while (Module["postRun"].length) { + addOnPostRun(Module["postRun"].shift()); + } + } + callRuntimeCallbacks(__ATPOSTRUN__); + } + __name(postRun, "postRun"); + function addOnPreRun(cb) { + __ATPRERUN__.unshift(cb); + } + __name(addOnPreRun, "addOnPreRun"); + function addOnInit(cb) { + __ATINIT__.unshift(cb); + } + __name(addOnInit, "addOnInit"); + function addOnPreMain(cb) { + __ATMAIN__.unshift(cb); + } + __name(addOnPreMain, "addOnPreMain"); + function addOnExit(cb) { + } + __name(addOnExit, "addOnExit"); + function addOnPostRun(cb) { + __ATPOSTRUN__.unshift(cb); + } + __name(addOnPostRun, "addOnPostRun"); + var runDependencies = 0; + var runDependencyWatcher = null; + var dependenciesFulfilled = null; + function getUniqueRunDependency(id) { + return id; + } + __name(getUniqueRunDependency, "getUniqueRunDependency"); + function addRunDependency(id) { + runDependencies++; + Module["monitorRunDependencies"]?.(runDependencies); + } + __name(addRunDependency, "addRunDependency"); + function removeRunDependency(id) { + runDependencies--; + Module["monitorRunDependencies"]?.(runDependencies); + 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; + what += ". Build with -sASSERTIONS for more info."; + var e = new WebAssembly.RuntimeError(what); + readyPromiseReject(e); + throw e; + } + __name(abort, "abort"); + var dataURIPrefix = "data:application/octet-stream;base64,"; + var isDataURI = /* @__PURE__ */ __name((filename) => filename.startsWith(dataURIPrefix), "isDataURI"); + var isFileURI = /* @__PURE__ */ __name((filename) => filename.startsWith("file://"), "isFileURI"); + function findWasmBinary() { + if (Module["locateFile"]) { + var f = "tree-sitter.wasm"; + if (!isDataURI(f)) { + return locateFile(f); + } + return f; + } + return new URL("tree-sitter.wasm", import.meta.url).href; + } + __name(findWasmBinary, "findWasmBinary"); + var wasmBinaryFile; + 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"); + function getBinaryPromise(binaryFile) { + if (!wasmBinary) { + return readAsync(binaryFile).then( + (response) => new Uint8Array( + /** @type{!ArrayBuffer} */ + response + ), + // Fall back to getBinarySync if readAsync fails + () => getBinarySync(binaryFile) + ); + } + return Promise.resolve().then(() => getBinarySync(binaryFile)); + } + __name(getBinaryPromise, "getBinaryPromise"); + function instantiateArrayBuffer(binaryFile, imports, receiver) { + return getBinaryPromise(binaryFile).then((binary2) => WebAssembly.instantiate(binary2, imports)).then(receiver, (reason) => { + err(`failed to asynchronously prepare wasm: ${reason}`); + abort(reason); + }); + } + __name(instantiateArrayBuffer, "instantiateArrayBuffer"); + function instantiateAsync(binary2, binaryFile, imports, callback) { + if (!binary2 && typeof WebAssembly.instantiateStreaming == "function" && !isDataURI(binaryFile) && // Don't use streaming for file:// delivered objects in a webview, fetch them synchronously. + !isFileURI(binaryFile) && // Avoid instantiateStreaming() on Node.js environment for now, as while + // Node.js v18.1.0 implements it, it does not have a full fetch() + // implementation yet. + // Reference: + // https://github.com/emscripten-core/emscripten/pull/16917 + !ENVIRONMENT_IS_NODE && typeof fetch == "function") { + return fetch(binaryFile, { + credentials: "same-origin" + }).then((response) => { + var result = WebAssembly.instantiateStreaming(response, imports); + return result.then(callback, function(reason) { + err(`wasm streaming compile failed: ${reason}`); + err("falling back to ArrayBuffer instantiation"); + return instantiateArrayBuffer(binaryFile, imports, callback); + }); + }); + } + return instantiateArrayBuffer(binaryFile, imports, callback); + } + __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"); + 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(); + addOnInit(wasmExports["__wasm_call_ctors"]); + __RELOC_FUNCS__.push(wasmExports["__wasm_apply_data_relocs"]); + removeRunDependency("wasm-instantiate"); + return wasmExports; + } + __name(receiveInstance, "receiveInstance"); + addRunDependency("wasm-instantiate"); + function receiveInstantiationResult(result) { + receiveInstance(result["instance"], result["module"]); + } + __name(receiveInstantiationResult, "receiveInstantiationResult"); + var info2 = getWasmImports(); + if (Module["instantiateWasm"]) { + try { + return Module["instantiateWasm"](info2, receiveInstance); + } catch (e) { + err(`Module.instantiateWasm callback failed with error: ${e}`); + readyPromiseReject(e); + } + } + wasmBinaryFile ??= findWasmBinary(); + instantiateAsync(wasmBinary, wasmBinaryFile, info2, receiveInstantiationResult).catch(readyPromiseReject); + return {}; + } + __name(createWasm, "createWasm"); + var tempDouble; + var tempI64; + 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 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 { + 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 { + offset += subsectionSize; + } + } + } + return customSection; + }, "getDylinkMetadata"); + function getValue(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": + abort("to do getValue(i64) use WASM_BIGINT"); + 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"); + 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() { + newDSO("__main__", 0, wasmImports); + } + }; + var ___heap_base = 78144; + var alignMemory = /* @__PURE__ */ __name((size, alignment) => 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); + ___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) => { + 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) { + 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) { + 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); + } + return func2; + }, "getWasmTableEntry"); + var updateTableMap = /* @__PURE__ */ __name((offset, count) => { + if (functionsInTableMap) { + for (var i2 = offset; i2 < offset + count; i2++) { + var item = getWasmTableEntry(i2); + if (item) { + functionsInTableMap.set(item, i2); + } + } + } + }, "updateTableMap"); + var functionsInTableMap; + var getFunctionAddress = /* @__PURE__ */ __name((func2) => { + if (!functionsInTableMap) { + functionsInTableMap = /* @__PURE__ */ new WeakMap(); + updateTableMap(0, wasmTable.length); + } + return functionsInTableMap.get(func2) || 0; + }, "getFunctionAddress"); + var freeTableIndexes = []; + var getEmptyTableSlot = /* @__PURE__ */ __name(() => { + if (freeTableIndexes.length) { + return freeTableIndexes.pop(); + } + try { + wasmTable.grow(1); + } catch (err2) { + if (!(err2 instanceof RangeError)) { + throw err2; + } + throw "Unable to grow wasm table. Set ALLOW_TABLE_GROWTH."; + } + return wasmTable.length - 1; + }, "getEmptyTableSlot"); + var setWasmTableEntry = /* @__PURE__ */ __name((idx, func2) => { + wasmTable.set(idx, func2); + wasmTableMirror[idx] = wasmTable.get(idx); + }, "setWasmTableEntry"); + var addFunction = /* @__PURE__ */ __name((func2, sig) => { + var rtn = getFunctionAddress(func2); + if (rtn) { + return rtn; + } + var ret = getEmptyTableSlot(); + try { + setWasmTableEntry(ret, func2); + } catch (err2) { + if (!(err2 instanceof TypeError)) { + throw err2; + } + var wrapped = convertJsFunctionToWasm(func2, sig); + setWasmTableEntry(ret, wrapped); + } + functionsInTableMap.set(func2, ret); + return ret; + }, "addFunction"); + var updateGOT = /* @__PURE__ */ __name((exports, replace) => { + for (var symName in exports) { + if (isInternalSym(symName)) { + continue; + } + var value = exports[symName]; + if (symName.startsWith("orig$")) { + symName = symName.split("$")[1]; + replace = true; + } + GOT[symName] ||= new WebAssembly.Global({ + "value": "i32", + "mutable": true + }); + if (replace || GOT[symName].value == 0) { + if (typeof value == "function") { + GOT[symName].value = addFunction(value); + } else if (typeof value == "number") { + GOT[symName].value = value; + } else { + err(`unhandled export type for '${symName}': ${typeof value}`); + } + } + } + }, "updateGOT"); + var relocateExports = /* @__PURE__ */ __name((exports, memoryBase2, replace) => { + var relocated = {}; + for (var e in exports) { + var value = exports[e]; + if (typeof value == "object") { + value = value.value; + } + if (typeof value == "number") { + value += memoryBase2; + } + relocated[e] = value; + } + updateGOT(relocated, replace); + return relocated; + }, "relocateExports"); + var isSymbolDefined = /* @__PURE__ */ __name((symName) => { + var existing = wasmImports[symName]; + if (!existing || existing.stub) { + return false; + } + return true; + }, "isSymbolDefined"); + var dynCallLegacy = /* @__PURE__ */ __name((sig, ptr, args2) => { + sig = sig.replace(/p/g, "i"); + var f = Module["dynCall_" + sig]; + return f(ptr, ...args2); + }, "dynCallLegacy"); + var dynCall = /* @__PURE__ */ __name((sig, ptr, args2 = []) => { + if (sig.includes("j")) { + return dynCallLegacy(sig, ptr, args2); + } + var rtn = getWasmTableEntry(ptr)(...args2); + return rtn; + }, "dynCall"); + var stackSave = /* @__PURE__ */ __name(() => _emscripten_stack_get_current(), "stackSave"); + var stackRestore = /* @__PURE__ */ __name((val) => __emscripten_stack_restore(val), "stackRestore"); + var createInvokeFunction = /* @__PURE__ */ __name((sig) => (ptr, ...args2) => { + var sp = stackSave(); + try { + return dynCall(sig, ptr, args2); + } catch (e) { + stackRestore(sp); + if (e !== e + 0) throw e; + _setThrew(1, 0); + } + }, "createInvokeFunction"); + var resolveGlobalSymbol = /* @__PURE__ */ __name((symName, direct = false) => { + var sym; + if (direct && "orig$" + symName in wasmImports) { + symName = "orig$" + symName; + } + if (isSymbolDefined(symName)) { + sym = wasmImports[symName]; + } else if (symName.startsWith("invoke_")) { + sym = wasmImports[symName] = createInvokeFunction(symName.split("_")[1]); + } + return { + sym, + name: symName + }; + }, "resolveGlobalSymbol"); + var UTF8ToString = /* @__PURE__ */ __name((ptr, maxBytesToRead) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "", "UTF8ToString"); + var loadWebAssemblyModule = /* @__PURE__ */ __name((binary, flags, libName, localScope, handle) => { + var metadata = getDylinkMetadata(binary); + currentModuleWeakSymbols = metadata.weakImports; + function loadModule() { + var firstLoad = !handle || !HEAP8[handle + 8]; + if (firstLoad) { + var memAlign = Math.pow(2, metadata.memoryAlign); + var memoryBase = metadata.memorySize ? alignMemory(getMemory(metadata.memorySize + memAlign), memAlign) : 0; + var tableBase = metadata.tableSize ? wasmTable.length : 0; + if (handle) { + HEAP8[handle + 8] = 1; + LE_HEAP_STORE_U32((handle + 12 >> 2) * 4, memoryBase); + LE_HEAP_STORE_I32((handle + 16 >> 2) * 4, metadata.memorySize); + LE_HEAP_STORE_U32((handle + 20 >> 2) * 4, tableBase); + LE_HEAP_STORE_I32((handle + 24 >> 2) * 4, metadata.tableSize); + } + } else { + memoryBase = LE_HEAP_LOAD_U32((handle + 12 >> 2) * 4); + tableBase = LE_HEAP_LOAD_U32((handle + 20 >> 2) * 4); + } + var tableGrowthNeeded = tableBase + metadata.tableSize - wasmTable.length; + if (tableGrowthNeeded > 0) { + wasmTable.grow(tableGrowthNeeded); + } + var moduleExports; + function resolveSymbol(sym) { + var resolved = resolveGlobalSymbol(sym).sym; + if (!resolved && localScope) { + resolved = localScope[sym]; + } + if (!resolved) { + resolved = moduleExports[sym]; + } + return resolved; + } + __name(resolveSymbol, "resolveSymbol"); + var proxyHandler = { + get(stubs, prop) { + switch (prop) { + case "__memory_base": + return memoryBase; + case "__table_base": + return tableBase; + } + if (prop in wasmImports && !wasmImports[prop].stub) { + return wasmImports[prop]; + } + if (!(prop in stubs)) { + var resolved; + stubs[prop] = (...args2) => { + resolved ||= resolveSymbol(prop); + return resolved(...args2); + }; + } + return stubs[prop]; + } + }; + var proxy = new Proxy({}, proxyHandler); + var info = { + "GOT.mem": new Proxy({}, GOTHandler), + "GOT.func": new Proxy({}, GOTHandler), + "env": proxy, + "wasi_snapshot_preview1": proxy + }; + function postInstantiation(module, instance) { + updateTableMap(tableBase, metadata.tableSize); + moduleExports = relocateExports(instance.exports, memoryBase); + if (!flags.allowUndefined) { + reportUndefinedSymbols(); + } + function addEmAsm(addr, body) { + var args = []; + var arity = 0; + for (; arity < 16; arity++) { + if (body.indexOf("$" + arity) != -1) { + args.push("$" + arity); + } else { + break; + } + } + args = args.join(","); + var func = `(${args}) => { ${body} };`; + ASM_CONSTS[start] = eval(func); + } + __name(addEmAsm, "addEmAsm"); + if ("__start_em_asm" in moduleExports) { + var start = moduleExports["__start_em_asm"]; + var stop = moduleExports["__stop_em_asm"]; + while (start < stop) { + var jsString = UTF8ToString(start); + addEmAsm(start, jsString); + start = HEAPU8.indexOf(0, start) + 1; + } + } + function addEmJs(name, cSig, body) { + var jsArgs = []; + cSig = cSig.slice(1, -1); + if (cSig != "void") { + cSig = cSig.split(","); + for (var i in cSig) { + var jsArg = cSig[i].split(" ").pop(); + jsArgs.push(jsArg.replace("*", "")); + } + } + var func = `(${jsArgs}) => ${body};`; + moduleExports[name] = eval(func); + } + __name(addEmJs, "addEmJs"); + for (var name in moduleExports) { + if (name.startsWith("__em_js__")) { + var start = moduleExports[name]; + var jsString = UTF8ToString(start); + var parts = jsString.split("<::>"); + addEmJs(name.replace("__em_js__", ""), parts[0], parts[1]); + delete moduleExports[name]; + } + } + var applyRelocs = moduleExports["__wasm_apply_data_relocs"]; + if (applyRelocs) { + if (runtimeInitialized) { + applyRelocs(); + } else { + __RELOC_FUNCS__.push(applyRelocs); + } + } + var init = moduleExports["__wasm_call_ctors"]; + if (init) { + if (runtimeInitialized) { + init(); + } else { + __ATINIT__.push(init); + } + } + return moduleExports; + } + __name(postInstantiation, "postInstantiation"); + if (flags.loadAsync) { + if (binary instanceof WebAssembly.Module) { + var instance = new WebAssembly.Instance(binary, info); + return Promise.resolve(postInstantiation(binary, instance)); + } + return WebAssembly.instantiate(binary, info).then((result) => postInstantiation(result.module, result.instance)); + } + var module = binary instanceof WebAssembly.Module ? binary : new WebAssembly.Module(binary); + var instance = new WebAssembly.Instance(module, info); + return postInstantiation(module, instance); + } + __name(loadModule, "loadModule"); + if (flags.loadAsync) { + return metadata.neededDynlibs.reduce((chain, dynNeeded) => chain.then(() => loadDynamicLibrary(dynNeeded, flags, localScope)), Promise.resolve()).then(loadModule); + } + metadata.neededDynlibs.forEach((needed) => loadDynamicLibrary(needed, flags, localScope)); + return loadModule(); + }, "loadWebAssemblyModule"); + var mergeLibSymbols = /* @__PURE__ */ __name((exports, libName2) => { + registerDynCallSymbols(exports); + for (var [sym, exp] of Object.entries(exports)) { + const setImport = /* @__PURE__ */ __name((target) => { + if (!isSymbolDefined(target)) { + wasmImports[target] = exp; + } + }, "setImport"); + setImport(sym); + const main_alias = "__main_argc_argv"; + if (sym == "main") { + setImport(main_alias); + } + if (sym == main_alias) { + setImport("main"); + } + } + }, "mergeLibSymbols"); + var asyncLoad = /* @__PURE__ */ __name((url, onload, onerror, noRunDep) => { + var dep = !noRunDep ? getUniqueRunDependency(`al ${url}`) : ""; + readAsync(url).then((arrayBuffer) => { + onload(new Uint8Array(arrayBuffer)); + if (dep) removeRunDependency(dep); + }, (err2) => { + if (onerror) { + onerror(); + } else { + throw `Loading data file "${url}" failed.`; + } + }); + if (dep) addRunDependency(dep); + }, "asyncLoad"); + var registerDynCallSymbols = /* @__PURE__ */ __name((exports) => { + for (var [sym, exp] of Object.entries(exports)) { + if (sym.startsWith("dynCall_") && !Module.hasOwnProperty(sym)) { + Module[sym] = exp; + } + } + }, "registerDynCallSymbols"); + function loadDynamicLibrary(libName2, flags2 = { + global: true, + nodelete: true + }, localScope2, handle2) { + var dso = LDSO.loadedLibsByName[libName2]; + if (dso) { + if (!flags2.global) { + if (localScope2) { + Object.assign(localScope2, dso.exports); + } + registerDynCallSymbols(dso.exports); + } else if (!dso.global) { + dso.global = true; + mergeLibSymbols(dso.exports, libName2); + } + if (flags2.nodelete && dso.refcount !== Infinity) { + dso.refcount = Infinity; + } + dso.refcount++; + if (handle2) { + LDSO.loadedLibsByHandle[handle2] = dso; + } + return flags2.loadAsync ? Promise.resolve(true) : true; + } + dso = newDSO(libName2, handle2, "loading"); + dso.refcount = flags2.nodelete ? Infinity : 1; + dso.global = flags2.global; + function loadLibData() { + if (handle2) { + var data = LE_HEAP_LOAD_U32((handle2 + 28 >> 2) * 4); + var dataSize = LE_HEAP_LOAD_U32((handle2 + 32 >> 2) * 4); + if (data && dataSize) { + var libData = HEAP8.slice(data, data + dataSize); + return flags2.loadAsync ? Promise.resolve(libData) : libData; + } + } + var libFile = locateFile(libName2); + if (flags2.loadAsync) { + return new Promise((resolve, reject) => asyncLoad(libFile, resolve, reject)); + } + if (!readBinary) { + throw new Error(`${libFile}: file not found, and synchronous loading of external files is not available`); + } + return readBinary(libFile); + } + __name(loadLibData, "loadLibData"); + function getExports() { + if (flags2.loadAsync) { + return loadLibData().then((libData) => loadWebAssemblyModule(libData, flags2, libName2, localScope2, handle2)); + } + return loadWebAssemblyModule(loadLibData(), flags2, libName2, localScope2, handle2); + } + __name(getExports, "getExports"); + function moduleLoaded(exports) { + if (dso.global) { + mergeLibSymbols(exports, libName2); + } else if (localScope2) { + Object.assign(localScope2, exports); + registerDynCallSymbols(exports); + } + dso.exports = exports; + } + __name(moduleLoaded, "moduleLoaded"); + if (flags2.loadAsync) { + return getExports().then((exports) => { + moduleLoaded(exports); + return true; + }); + } + moduleLoaded(getExports()); + return true; + } + __name(loadDynamicLibrary, "loadDynamicLibrary"); + var reportUndefinedSymbols = /* @__PURE__ */ __name(() => { + for (var [symName, entry] of Object.entries(GOT)) { + if (entry.value == 0) { + var value = resolveGlobalSymbol(symName, true).sym; + if (!value && !entry.required) { + continue; + } + if (typeof value == "function") { + entry.value = addFunction(value, value.sig); + } else if (typeof value == "number") { + entry.value = value; + } else { + throw new Error(`bad export type for '${symName}': ${typeof value}`); + } + } + } + }, "reportUndefinedSymbols"); + var loadDylibs = /* @__PURE__ */ __name(() => { + if (!dynamicLibraries.length) { + reportUndefinedSymbols(); + return; + } + addRunDependency("loadDylibs"); + dynamicLibraries.reduce((chain, lib) => chain.then(() => loadDynamicLibrary(lib, { + loadAsync: true, + global: true, + nodelete: true, + allowUndefined: true + })), Promise.resolve()).then(() => { + reportUndefinedSymbols(); + removeRunDependency("loadDylibs"); + }); + }, "loadDylibs"); + var noExitRuntime = Module["noExitRuntime"] || true; + function setValue(ptr, value, type = "i8") { + if (type.endsWith("*")) type = "*"; + switch (type) { + case "i1": + HEAP8[ptr] = value; + break; + case "i8": + HEAP8[ptr] = value; + break; + case "i16": + LE_HEAP_STORE_I16((ptr >> 1) * 2, value); + break; + case "i32": + LE_HEAP_STORE_I32((ptr >> 2) * 4, value); + break; + case "i64": + abort("to do setValue(i64) use WASM_BIGINT"); + case "float": + LE_HEAP_STORE_F32((ptr >> 2) * 4, value); + break; + case "double": + LE_HEAP_STORE_F64((ptr >> 3) * 8, value); + break; + case "*": + LE_HEAP_STORE_U32((ptr >> 2) * 4, value); + break; + default: + abort(`invalid type for setValue: ${type}`); + } + } + __name(setValue, "setValue"); + var ___memory_base = new WebAssembly.Global({ + "value": "i32", + "mutable": false + }, 1024); + var ___stack_pointer = new WebAssembly.Global({ + "value": "i32", + "mutable": true + }, 78144); + var ___table_base = new WebAssembly.Global({ + "value": "i32", + "mutable": false + }, 1); + var __abort_js = /* @__PURE__ */ __name(() => { + abort(""); + }, "__abort_js"); + __abort_js.sig = "v"; + var nowIsMonotonic = 1; + var __emscripten_get_now_is_monotonic = /* @__PURE__ */ __name(() => nowIsMonotonic, "__emscripten_get_now_is_monotonic"); + __emscripten_get_now_is_monotonic.sig = "i"; + var __emscripten_memcpy_js = /* @__PURE__ */ __name((dest, src, num) => HEAPU8.copyWithin(dest, src, src + num), "__emscripten_memcpy_js"); + __emscripten_memcpy_js.sig = "vppp"; + var _emscripten_date_now = /* @__PURE__ */ __name(() => Date.now(), "_emscripten_date_now"); + _emscripten_date_now.sig = "d"; + var _emscripten_get_now = /* @__PURE__ */ __name(() => performance.now(), "_emscripten_get_now"); + _emscripten_get_now.sig = "d"; + var getHeapMax = /* @__PURE__ */ __name(() => ( + // Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate + // full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side + // for any code that deals with heap sizes, which would require special + // casing all heap size related code to treat 0 specially. + 2147483648 + ), "getHeapMax"); + var growMemory = /* @__PURE__ */ __name((size) => { + var b = wasmMemory.buffer; + var pages = (size - b.byteLength + 65535) / 65536 | 0; + try { + wasmMemory.grow(pages); + updateMemoryViews(); + return 1; + } catch (e) { + } + }, "growMemory"); + var _emscripten_resize_heap = /* @__PURE__ */ __name((requestedSize) => { + var oldSize = HEAPU8.length; + requestedSize >>>= 0; + var maxHeapSize = getHeapMax(); + if (requestedSize > maxHeapSize) { + return false; + } + for (var cutDown = 1; cutDown <= 4; cutDown *= 2) { + var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown); + overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296); + var newSize = Math.min(maxHeapSize, alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536)); + var replacement = growMemory(newSize); + if (replacement) { + return true; + } + } + return false; + }, "_emscripten_resize_heap"); + _emscripten_resize_heap.sig = "ip"; + var _fd_close = /* @__PURE__ */ __name((fd) => 52, "_fd_close"); + _fd_close.sig = "ii"; + var convertI32PairToI53Checked = /* @__PURE__ */ __name((lo, hi) => hi + 2097152 >>> 0 < 4194305 - !!lo ? (lo >>> 0) + hi * 4294967296 : NaN, "convertI32PairToI53Checked"); + function _fd_seek(fd, offset_low, offset_high, whence, newOffset) { + var offset = convertI32PairToI53Checked(offset_low, offset_high); + return 70; + } + __name(_fd_seek, "_fd_seek"); + _fd_seek.sig = "iiiiip"; + var printCharBuffers = [null, [], []]; + var printChar = /* @__PURE__ */ __name((stream, curr) => { + var buffer = printCharBuffers[stream]; + if (curr === 0 || curr === 10) { + (stream === 1 ? out : err)(UTF8ArrayToString(buffer)); + buffer.length = 0; + } else { + buffer.push(curr); + } + }, "printChar"); + var flush_NO_FILESYSTEM = /* @__PURE__ */ __name(() => { + if (printCharBuffers[1].length) printChar(1, 10); + if (printCharBuffers[2].length) printChar(2, 10); + }, "flush_NO_FILESYSTEM"); + var SYSCALLS = { + varargs: void 0, + getStr(ptr) { + var ret = UTF8ToString(ptr); + return ret; + } + }; + var _fd_write = /* @__PURE__ */ __name((fd, iov, iovcnt, pnum) => { + var num = 0; + for (var i2 = 0; i2 < iovcnt; i2++) { + var ptr = LE_HEAP_LOAD_U32((iov >> 2) * 4); + var len = LE_HEAP_LOAD_U32((iov + 4 >> 2) * 4); + iov += 8; + for (var j = 0; j < len; j++) { + printChar(fd, HEAPU8[ptr + j]); + } + num += len; + } + LE_HEAP_STORE_U32((pnum >> 2) * 4, num); + return 0; + }, "_fd_write"); + _fd_write.sig = "iippp"; + function _tree_sitter_log_callback(isLexMessage, messageAddress) { + if (Module.currentLogCallback) { + const message = UTF8ToString(messageAddress); + Module.currentLogCallback(message, isLexMessage !== 0); + } + } + __name(_tree_sitter_log_callback, "_tree_sitter_log_callback"); + function _tree_sitter_parse_callback(inputBufferAddress, index, row, column, lengthAddress) { + const INPUT_BUFFER_SIZE = 10 * 1024; + const string = Module.currentParseCallback(index, { + row, + column + }); + if (typeof string === "string") { + setValue(lengthAddress, string.length, "i32"); + stringToUTF16(string, inputBufferAddress, INPUT_BUFFER_SIZE); + } else { + setValue(lengthAddress, 0, "i32"); + } + } + __name(_tree_sitter_parse_callback, "_tree_sitter_parse_callback"); + function _tree_sitter_progress_callback(currentOffset) { + if (Module.currentProgressCallback) { + return Module.currentProgressCallback({ + currentOffset + }); + } + return false; + } + __name(_tree_sitter_progress_callback, "_tree_sitter_progress_callback"); + function _tree_sitter_query_progress_callback(currentOffset) { + if (Module.currentQueryProgressCallback) { + return Module.currentQueryProgressCallback({ + currentOffset + }); + } + return false; + } + __name(_tree_sitter_query_progress_callback, "_tree_sitter_query_progress_callback"); + var runtimeKeepaliveCounter = 0; + var keepRuntimeAlive = /* @__PURE__ */ __name(() => noExitRuntime || runtimeKeepaliveCounter > 0, "keepRuntimeAlive"); + var _proc_exit = /* @__PURE__ */ __name((code) => { + EXITSTATUS = code; + if (!keepRuntimeAlive()) { + Module["onExit"]?.(code); + ABORT = true; + } + quit_(code, new ExitStatus(code)); + }, "_proc_exit"); + _proc_exit.sig = "vi"; + var exitJS = /* @__PURE__ */ __name((status, implicit) => { + EXITSTATUS = status; + _proc_exit(status); + }, "exitJS"); + var handleException = /* @__PURE__ */ __name((e) => { + if (e instanceof ExitStatus || e == "unwind") { + return EXITSTATUS; + } + quit_(1, e); + }, "handleException"); + var lengthBytesUTF8 = /* @__PURE__ */ __name((str) => { + var len = 0; + for (var i2 = 0; i2 < str.length; ++i2) { + var c = str.charCodeAt(i2); + if (c <= 127) { + len++; + } else if (c <= 2047) { + len += 2; + } else if (c >= 55296 && c <= 57343) { + len += 4; + ++i2; + } else { + len += 3; + } + } + return len; + }, "lengthBytesUTF8"); + var stringToUTF8Array = /* @__PURE__ */ __name((str, heap, outIdx, maxBytesToWrite) => { + if (!(maxBytesToWrite > 0)) return 0; + var startIdx = outIdx; + var endIdx = outIdx + maxBytesToWrite - 1; + for (var i2 = 0; i2 < str.length; ++i2) { + var u = str.charCodeAt(i2); + if (u >= 55296 && u <= 57343) { + var u1 = str.charCodeAt(++i2); + u = 65536 + ((u & 1023) << 10) | u1 & 1023; + } + if (u <= 127) { + if (outIdx >= endIdx) break; + heap[outIdx++] = u; + } else if (u <= 2047) { + if (outIdx + 1 >= endIdx) break; + heap[outIdx++] = 192 | u >> 6; + heap[outIdx++] = 128 | u & 63; + } else if (u <= 65535) { + if (outIdx + 2 >= endIdx) break; + heap[outIdx++] = 224 | u >> 12; + heap[outIdx++] = 128 | u >> 6 & 63; + heap[outIdx++] = 128 | u & 63; + } else { + if (outIdx + 3 >= endIdx) break; + heap[outIdx++] = 240 | u >> 18; + heap[outIdx++] = 128 | u >> 12 & 63; + heap[outIdx++] = 128 | u >> 6 & 63; + heap[outIdx++] = 128 | u & 63; + } + } + heap[outIdx] = 0; + return outIdx - startIdx; + }, "stringToUTF8Array"); + var stringToUTF8 = /* @__PURE__ */ __name((str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite), "stringToUTF8"); + var stackAlloc = /* @__PURE__ */ __name((sz) => __emscripten_stack_alloc(sz), "stackAlloc"); + var stringToUTF8OnStack = /* @__PURE__ */ __name((str) => { + var size = lengthBytesUTF8(str) + 1; + var ret = stackAlloc(size); + stringToUTF8(str, ret, size); + return ret; + }, "stringToUTF8OnStack"); + var AsciiToString = /* @__PURE__ */ __name((ptr) => { + var str = ""; + while (1) { + var ch = HEAPU8[ptr++]; + if (!ch) return str; + str += String.fromCharCode(ch); + } + }, "AsciiToString"); + var stringToUTF16 = /* @__PURE__ */ __name((str, outPtr, maxBytesToWrite) => { + maxBytesToWrite ??= 2147483647; + if (maxBytesToWrite < 2) return 0; + maxBytesToWrite -= 2; + var startPtr = outPtr; + var numCharsToWrite = maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length; + for (var i2 = 0; i2 < numCharsToWrite; ++i2) { + var codeUnit = str.charCodeAt(i2); + LE_HEAP_STORE_I16((outPtr >> 1) * 2, codeUnit); + outPtr += 2; + } + LE_HEAP_STORE_I16((outPtr >> 1) * 2, 0); + return outPtr - startPtr; + }, "stringToUTF16"); + var wasmImports = { + /** @export */ + __heap_base: ___heap_base, + /** @export */ + __indirect_function_table: wasmTable, + /** @export */ + __memory_base: ___memory_base, + /** @export */ + __stack_pointer: ___stack_pointer, + /** @export */ + __table_base: ___table_base, + /** @export */ + _abort_js: __abort_js, + /** @export */ + _emscripten_get_now_is_monotonic: __emscripten_get_now_is_monotonic, + /** @export */ + _emscripten_memcpy_js: __emscripten_memcpy_js, + /** @export */ + emscripten_date_now: _emscripten_date_now, + /** @export */ + emscripten_get_now: _emscripten_get_now, + /** @export */ + emscripten_resize_heap: _emscripten_resize_heap, + /** @export */ + fd_close: _fd_close, + /** @export */ + fd_seek: _fd_seek, + /** @export */ + fd_write: _fd_write, + /** @export */ + memory: wasmMemory, + /** @export */ + tree_sitter_log_callback: _tree_sitter_log_callback, + /** @export */ + tree_sitter_parse_callback: _tree_sitter_parse_callback, + /** @export */ + tree_sitter_progress_callback: _tree_sitter_progress_callback, + /** @export */ + tree_sitter_query_progress_callback: _tree_sitter_query_progress_callback + }; + var wasmExports = createWasm(); + var ___wasm_call_ctors = /* @__PURE__ */ __name(() => (___wasm_call_ctors = wasmExports["__wasm_call_ctors"])(), "___wasm_call_ctors"); + var _malloc = Module["_malloc"] = (a0) => (_malloc = Module["_malloc"] = wasmExports["malloc"])(a0); + var _calloc = Module["_calloc"] = (a0, a1) => (_calloc = Module["_calloc"] = wasmExports["calloc"])(a0, a1); + var _realloc = Module["_realloc"] = (a0, a1) => (_realloc = Module["_realloc"] = wasmExports["realloc"])(a0, a1); + var _free = Module["_free"] = (a0) => (_free = Module["_free"] = wasmExports["free"])(a0); + var _ts_language_symbol_count = Module["_ts_language_symbol_count"] = (a0) => (_ts_language_symbol_count = Module["_ts_language_symbol_count"] = wasmExports["ts_language_symbol_count"])(a0); + var _ts_language_state_count = Module["_ts_language_state_count"] = (a0) => (_ts_language_state_count = Module["_ts_language_state_count"] = wasmExports["ts_language_state_count"])(a0); + var _ts_language_version = Module["_ts_language_version"] = (a0) => (_ts_language_version = Module["_ts_language_version"] = wasmExports["ts_language_version"])(a0); + var _ts_language_name = Module["_ts_language_name"] = (a0) => (_ts_language_name = Module["_ts_language_name"] = wasmExports["ts_language_name"])(a0); + var _ts_language_field_count = Module["_ts_language_field_count"] = (a0) => (_ts_language_field_count = Module["_ts_language_field_count"] = wasmExports["ts_language_field_count"])(a0); + var _ts_language_next_state = Module["_ts_language_next_state"] = (a0, a1, a2) => (_ts_language_next_state = Module["_ts_language_next_state"] = wasmExports["ts_language_next_state"])(a0, a1, a2); + var _ts_language_symbol_name = Module["_ts_language_symbol_name"] = (a0, a1) => (_ts_language_symbol_name = Module["_ts_language_symbol_name"] = wasmExports["ts_language_symbol_name"])(a0, a1); + var _ts_language_symbol_for_name = Module["_ts_language_symbol_for_name"] = (a0, a1, a2, a3) => (_ts_language_symbol_for_name = Module["_ts_language_symbol_for_name"] = wasmExports["ts_language_symbol_for_name"])(a0, a1, a2, a3); + var _strncmp = Module["_strncmp"] = (a0, a1, a2) => (_strncmp = Module["_strncmp"] = wasmExports["strncmp"])(a0, a1, a2); + var _ts_language_symbol_type = Module["_ts_language_symbol_type"] = (a0, a1) => (_ts_language_symbol_type = Module["_ts_language_symbol_type"] = wasmExports["ts_language_symbol_type"])(a0, a1); + var _ts_language_field_name_for_id = Module["_ts_language_field_name_for_id"] = (a0, a1) => (_ts_language_field_name_for_id = Module["_ts_language_field_name_for_id"] = wasmExports["ts_language_field_name_for_id"])(a0, a1); + var _ts_lookahead_iterator_new = Module["_ts_lookahead_iterator_new"] = (a0, a1) => (_ts_lookahead_iterator_new = Module["_ts_lookahead_iterator_new"] = wasmExports["ts_lookahead_iterator_new"])(a0, a1); + var _ts_lookahead_iterator_delete = Module["_ts_lookahead_iterator_delete"] = (a0) => (_ts_lookahead_iterator_delete = Module["_ts_lookahead_iterator_delete"] = wasmExports["ts_lookahead_iterator_delete"])(a0); + var _ts_lookahead_iterator_reset_state = Module["_ts_lookahead_iterator_reset_state"] = (a0, a1) => (_ts_lookahead_iterator_reset_state = Module["_ts_lookahead_iterator_reset_state"] = wasmExports["ts_lookahead_iterator_reset_state"])(a0, a1); + var _ts_lookahead_iterator_reset = Module["_ts_lookahead_iterator_reset"] = (a0, a1, a2) => (_ts_lookahead_iterator_reset = Module["_ts_lookahead_iterator_reset"] = wasmExports["ts_lookahead_iterator_reset"])(a0, a1, a2); + var _ts_lookahead_iterator_next = Module["_ts_lookahead_iterator_next"] = (a0) => (_ts_lookahead_iterator_next = Module["_ts_lookahead_iterator_next"] = wasmExports["ts_lookahead_iterator_next"])(a0); + var _ts_lookahead_iterator_current_symbol = Module["_ts_lookahead_iterator_current_symbol"] = (a0) => (_ts_lookahead_iterator_current_symbol = Module["_ts_lookahead_iterator_current_symbol"] = wasmExports["ts_lookahead_iterator_current_symbol"])(a0); + var _memset = Module["_memset"] = (a0, a1, a2) => (_memset = Module["_memset"] = wasmExports["memset"])(a0, a1, a2); + var _memcpy = Module["_memcpy"] = (a0, a1, a2) => (_memcpy = Module["_memcpy"] = wasmExports["memcpy"])(a0, a1, a2); + var _ts_parser_delete = Module["_ts_parser_delete"] = (a0) => (_ts_parser_delete = Module["_ts_parser_delete"] = wasmExports["ts_parser_delete"])(a0); + var _ts_parser_reset = Module["_ts_parser_reset"] = (a0) => (_ts_parser_reset = Module["_ts_parser_reset"] = wasmExports["ts_parser_reset"])(a0); + var _ts_parser_set_language = Module["_ts_parser_set_language"] = (a0, a1) => (_ts_parser_set_language = Module["_ts_parser_set_language"] = wasmExports["ts_parser_set_language"])(a0, a1); + var _ts_parser_timeout_micros = Module["_ts_parser_timeout_micros"] = (a0) => (_ts_parser_timeout_micros = Module["_ts_parser_timeout_micros"] = wasmExports["ts_parser_timeout_micros"])(a0); + var _ts_parser_set_timeout_micros = Module["_ts_parser_set_timeout_micros"] = (a0, a1, a2) => (_ts_parser_set_timeout_micros = Module["_ts_parser_set_timeout_micros"] = wasmExports["ts_parser_set_timeout_micros"])(a0, a1, a2); + var _ts_parser_set_included_ranges = Module["_ts_parser_set_included_ranges"] = (a0, a1, a2) => (_ts_parser_set_included_ranges = Module["_ts_parser_set_included_ranges"] = wasmExports["ts_parser_set_included_ranges"])(a0, a1, a2); + var _memmove = Module["_memmove"] = (a0, a1, a2) => (_memmove = Module["_memmove"] = wasmExports["memmove"])(a0, a1, a2); + var _memcmp = Module["_memcmp"] = (a0, a1, a2) => (_memcmp = Module["_memcmp"] = wasmExports["memcmp"])(a0, a1, a2); + var _ts_query_new = Module["_ts_query_new"] = (a0, a1, a2, a3, a4) => (_ts_query_new = Module["_ts_query_new"] = wasmExports["ts_query_new"])(a0, a1, a2, a3, a4); + var _ts_query_delete = Module["_ts_query_delete"] = (a0) => (_ts_query_delete = Module["_ts_query_delete"] = wasmExports["ts_query_delete"])(a0); + var _iswspace = Module["_iswspace"] = (a0) => (_iswspace = Module["_iswspace"] = wasmExports["iswspace"])(a0); + var _iswalnum = Module["_iswalnum"] = (a0) => (_iswalnum = Module["_iswalnum"] = wasmExports["iswalnum"])(a0); + var _ts_query_pattern_count = Module["_ts_query_pattern_count"] = (a0) => (_ts_query_pattern_count = Module["_ts_query_pattern_count"] = wasmExports["ts_query_pattern_count"])(a0); + var _ts_query_capture_count = Module["_ts_query_capture_count"] = (a0) => (_ts_query_capture_count = Module["_ts_query_capture_count"] = wasmExports["ts_query_capture_count"])(a0); + var _ts_query_string_count = Module["_ts_query_string_count"] = (a0) => (_ts_query_string_count = Module["_ts_query_string_count"] = wasmExports["ts_query_string_count"])(a0); + var _ts_query_capture_name_for_id = Module["_ts_query_capture_name_for_id"] = (a0, a1, a2) => (_ts_query_capture_name_for_id = Module["_ts_query_capture_name_for_id"] = wasmExports["ts_query_capture_name_for_id"])(a0, a1, a2); + var _ts_query_capture_quantifier_for_id = Module["_ts_query_capture_quantifier_for_id"] = (a0, a1, a2) => (_ts_query_capture_quantifier_for_id = Module["_ts_query_capture_quantifier_for_id"] = wasmExports["ts_query_capture_quantifier_for_id"])(a0, a1, a2); + var _ts_query_string_value_for_id = Module["_ts_query_string_value_for_id"] = (a0, a1, a2) => (_ts_query_string_value_for_id = Module["_ts_query_string_value_for_id"] = wasmExports["ts_query_string_value_for_id"])(a0, a1, a2); + var _ts_query_predicates_for_pattern = Module["_ts_query_predicates_for_pattern"] = (a0, a1, a2) => (_ts_query_predicates_for_pattern = Module["_ts_query_predicates_for_pattern"] = wasmExports["ts_query_predicates_for_pattern"])(a0, a1, a2); + var _ts_query_start_byte_for_pattern = Module["_ts_query_start_byte_for_pattern"] = (a0, a1) => (_ts_query_start_byte_for_pattern = Module["_ts_query_start_byte_for_pattern"] = wasmExports["ts_query_start_byte_for_pattern"])(a0, a1); + var _ts_query_end_byte_for_pattern = Module["_ts_query_end_byte_for_pattern"] = (a0, a1) => (_ts_query_end_byte_for_pattern = Module["_ts_query_end_byte_for_pattern"] = wasmExports["ts_query_end_byte_for_pattern"])(a0, a1); + var _ts_query_is_pattern_rooted = Module["_ts_query_is_pattern_rooted"] = (a0, a1) => (_ts_query_is_pattern_rooted = Module["_ts_query_is_pattern_rooted"] = wasmExports["ts_query_is_pattern_rooted"])(a0, a1); + var _ts_query_is_pattern_non_local = Module["_ts_query_is_pattern_non_local"] = (a0, a1) => (_ts_query_is_pattern_non_local = Module["_ts_query_is_pattern_non_local"] = wasmExports["ts_query_is_pattern_non_local"])(a0, a1); + var _ts_query_is_pattern_guaranteed_at_step = Module["_ts_query_is_pattern_guaranteed_at_step"] = (a0, a1) => (_ts_query_is_pattern_guaranteed_at_step = Module["_ts_query_is_pattern_guaranteed_at_step"] = wasmExports["ts_query_is_pattern_guaranteed_at_step"])(a0, a1); + var _ts_query_disable_capture = Module["_ts_query_disable_capture"] = (a0, a1, a2) => (_ts_query_disable_capture = Module["_ts_query_disable_capture"] = wasmExports["ts_query_disable_capture"])(a0, a1, a2); + var _ts_query_disable_pattern = Module["_ts_query_disable_pattern"] = (a0, a1) => (_ts_query_disable_pattern = Module["_ts_query_disable_pattern"] = wasmExports["ts_query_disable_pattern"])(a0, a1); + var _ts_tree_copy = Module["_ts_tree_copy"] = (a0) => (_ts_tree_copy = Module["_ts_tree_copy"] = wasmExports["ts_tree_copy"])(a0); + var _ts_tree_delete = Module["_ts_tree_delete"] = (a0) => (_ts_tree_delete = Module["_ts_tree_delete"] = wasmExports["ts_tree_delete"])(a0); + var _ts_init = Module["_ts_init"] = () => (_ts_init = Module["_ts_init"] = wasmExports["ts_init"])(); + var _ts_parser_new_wasm = Module["_ts_parser_new_wasm"] = () => (_ts_parser_new_wasm = Module["_ts_parser_new_wasm"] = wasmExports["ts_parser_new_wasm"])(); + var _ts_parser_enable_logger_wasm = Module["_ts_parser_enable_logger_wasm"] = (a0, a1) => (_ts_parser_enable_logger_wasm = Module["_ts_parser_enable_logger_wasm"] = wasmExports["ts_parser_enable_logger_wasm"])(a0, a1); + var _ts_parser_parse_wasm = Module["_ts_parser_parse_wasm"] = (a0, a1, a2, a3, a4) => (_ts_parser_parse_wasm = Module["_ts_parser_parse_wasm"] = wasmExports["ts_parser_parse_wasm"])(a0, a1, a2, a3, a4); + var _ts_parser_included_ranges_wasm = Module["_ts_parser_included_ranges_wasm"] = (a0) => (_ts_parser_included_ranges_wasm = Module["_ts_parser_included_ranges_wasm"] = wasmExports["ts_parser_included_ranges_wasm"])(a0); + var _ts_language_type_is_named_wasm = Module["_ts_language_type_is_named_wasm"] = (a0, a1) => (_ts_language_type_is_named_wasm = Module["_ts_language_type_is_named_wasm"] = wasmExports["ts_language_type_is_named_wasm"])(a0, a1); + var _ts_language_type_is_visible_wasm = Module["_ts_language_type_is_visible_wasm"] = (a0, a1) => (_ts_language_type_is_visible_wasm = Module["_ts_language_type_is_visible_wasm"] = wasmExports["ts_language_type_is_visible_wasm"])(a0, a1); + var _ts_language_supertypes_wasm = Module["_ts_language_supertypes_wasm"] = (a0) => (_ts_language_supertypes_wasm = Module["_ts_language_supertypes_wasm"] = wasmExports["ts_language_supertypes_wasm"])(a0); + var _ts_language_subtypes_wasm = Module["_ts_language_subtypes_wasm"] = (a0, a1) => (_ts_language_subtypes_wasm = Module["_ts_language_subtypes_wasm"] = wasmExports["ts_language_subtypes_wasm"])(a0, a1); + var _ts_tree_root_node_wasm = Module["_ts_tree_root_node_wasm"] = (a0) => (_ts_tree_root_node_wasm = Module["_ts_tree_root_node_wasm"] = wasmExports["ts_tree_root_node_wasm"])(a0); + var _ts_tree_root_node_with_offset_wasm = Module["_ts_tree_root_node_with_offset_wasm"] = (a0) => (_ts_tree_root_node_with_offset_wasm = Module["_ts_tree_root_node_with_offset_wasm"] = wasmExports["ts_tree_root_node_with_offset_wasm"])(a0); + var _ts_tree_edit_wasm = Module["_ts_tree_edit_wasm"] = (a0) => (_ts_tree_edit_wasm = Module["_ts_tree_edit_wasm"] = wasmExports["ts_tree_edit_wasm"])(a0); + var _ts_tree_included_ranges_wasm = Module["_ts_tree_included_ranges_wasm"] = (a0) => (_ts_tree_included_ranges_wasm = Module["_ts_tree_included_ranges_wasm"] = wasmExports["ts_tree_included_ranges_wasm"])(a0); + var _ts_tree_get_changed_ranges_wasm = Module["_ts_tree_get_changed_ranges_wasm"] = (a0, a1) => (_ts_tree_get_changed_ranges_wasm = Module["_ts_tree_get_changed_ranges_wasm"] = wasmExports["ts_tree_get_changed_ranges_wasm"])(a0, a1); + var _ts_tree_cursor_new_wasm = Module["_ts_tree_cursor_new_wasm"] = (a0) => (_ts_tree_cursor_new_wasm = Module["_ts_tree_cursor_new_wasm"] = wasmExports["ts_tree_cursor_new_wasm"])(a0); + var _ts_tree_cursor_copy_wasm = Module["_ts_tree_cursor_copy_wasm"] = (a0) => (_ts_tree_cursor_copy_wasm = Module["_ts_tree_cursor_copy_wasm"] = wasmExports["ts_tree_cursor_copy_wasm"])(a0); + var _ts_tree_cursor_delete_wasm = Module["_ts_tree_cursor_delete_wasm"] = (a0) => (_ts_tree_cursor_delete_wasm = Module["_ts_tree_cursor_delete_wasm"] = wasmExports["ts_tree_cursor_delete_wasm"])(a0); + var _ts_tree_cursor_reset_wasm = Module["_ts_tree_cursor_reset_wasm"] = (a0) => (_ts_tree_cursor_reset_wasm = Module["_ts_tree_cursor_reset_wasm"] = wasmExports["ts_tree_cursor_reset_wasm"])(a0); + var _ts_tree_cursor_reset_to_wasm = Module["_ts_tree_cursor_reset_to_wasm"] = (a0, a1) => (_ts_tree_cursor_reset_to_wasm = Module["_ts_tree_cursor_reset_to_wasm"] = wasmExports["ts_tree_cursor_reset_to_wasm"])(a0, a1); + var _ts_tree_cursor_goto_first_child_wasm = Module["_ts_tree_cursor_goto_first_child_wasm"] = (a0) => (_ts_tree_cursor_goto_first_child_wasm = Module["_ts_tree_cursor_goto_first_child_wasm"] = wasmExports["ts_tree_cursor_goto_first_child_wasm"])(a0); + var _ts_tree_cursor_goto_last_child_wasm = Module["_ts_tree_cursor_goto_last_child_wasm"] = (a0) => (_ts_tree_cursor_goto_last_child_wasm = Module["_ts_tree_cursor_goto_last_child_wasm"] = wasmExports["ts_tree_cursor_goto_last_child_wasm"])(a0); + var _ts_tree_cursor_goto_first_child_for_index_wasm = Module["_ts_tree_cursor_goto_first_child_for_index_wasm"] = (a0) => (_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"])(a0); + var _ts_tree_cursor_goto_first_child_for_position_wasm = Module["_ts_tree_cursor_goto_first_child_for_position_wasm"] = (a0) => (_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"])(a0); + var _ts_tree_cursor_goto_next_sibling_wasm = Module["_ts_tree_cursor_goto_next_sibling_wasm"] = (a0) => (_ts_tree_cursor_goto_next_sibling_wasm = Module["_ts_tree_cursor_goto_next_sibling_wasm"] = wasmExports["ts_tree_cursor_goto_next_sibling_wasm"])(a0); + var _ts_tree_cursor_goto_previous_sibling_wasm = Module["_ts_tree_cursor_goto_previous_sibling_wasm"] = (a0) => (_ts_tree_cursor_goto_previous_sibling_wasm = Module["_ts_tree_cursor_goto_previous_sibling_wasm"] = wasmExports["ts_tree_cursor_goto_previous_sibling_wasm"])(a0); + var _ts_tree_cursor_goto_descendant_wasm = Module["_ts_tree_cursor_goto_descendant_wasm"] = (a0, a1) => (_ts_tree_cursor_goto_descendant_wasm = Module["_ts_tree_cursor_goto_descendant_wasm"] = wasmExports["ts_tree_cursor_goto_descendant_wasm"])(a0, a1); + var _ts_tree_cursor_goto_parent_wasm = Module["_ts_tree_cursor_goto_parent_wasm"] = (a0) => (_ts_tree_cursor_goto_parent_wasm = Module["_ts_tree_cursor_goto_parent_wasm"] = wasmExports["ts_tree_cursor_goto_parent_wasm"])(a0); + var _ts_tree_cursor_current_node_type_id_wasm = Module["_ts_tree_cursor_current_node_type_id_wasm"] = (a0) => (_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"])(a0); + var _ts_tree_cursor_current_node_state_id_wasm = Module["_ts_tree_cursor_current_node_state_id_wasm"] = (a0) => (_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"])(a0); + var _ts_tree_cursor_current_node_is_named_wasm = Module["_ts_tree_cursor_current_node_is_named_wasm"] = (a0) => (_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"])(a0); + var _ts_tree_cursor_current_node_is_missing_wasm = Module["_ts_tree_cursor_current_node_is_missing_wasm"] = (a0) => (_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"])(a0); + var _ts_tree_cursor_current_node_id_wasm = Module["_ts_tree_cursor_current_node_id_wasm"] = (a0) => (_ts_tree_cursor_current_node_id_wasm = Module["_ts_tree_cursor_current_node_id_wasm"] = wasmExports["ts_tree_cursor_current_node_id_wasm"])(a0); + var _ts_tree_cursor_start_position_wasm = Module["_ts_tree_cursor_start_position_wasm"] = (a0) => (_ts_tree_cursor_start_position_wasm = Module["_ts_tree_cursor_start_position_wasm"] = wasmExports["ts_tree_cursor_start_position_wasm"])(a0); + var _ts_tree_cursor_end_position_wasm = Module["_ts_tree_cursor_end_position_wasm"] = (a0) => (_ts_tree_cursor_end_position_wasm = Module["_ts_tree_cursor_end_position_wasm"] = wasmExports["ts_tree_cursor_end_position_wasm"])(a0); + var _ts_tree_cursor_start_index_wasm = Module["_ts_tree_cursor_start_index_wasm"] = (a0) => (_ts_tree_cursor_start_index_wasm = Module["_ts_tree_cursor_start_index_wasm"] = wasmExports["ts_tree_cursor_start_index_wasm"])(a0); + var _ts_tree_cursor_end_index_wasm = Module["_ts_tree_cursor_end_index_wasm"] = (a0) => (_ts_tree_cursor_end_index_wasm = Module["_ts_tree_cursor_end_index_wasm"] = wasmExports["ts_tree_cursor_end_index_wasm"])(a0); + var _ts_tree_cursor_current_field_id_wasm = Module["_ts_tree_cursor_current_field_id_wasm"] = (a0) => (_ts_tree_cursor_current_field_id_wasm = Module["_ts_tree_cursor_current_field_id_wasm"] = wasmExports["ts_tree_cursor_current_field_id_wasm"])(a0); + var _ts_tree_cursor_current_depth_wasm = Module["_ts_tree_cursor_current_depth_wasm"] = (a0) => (_ts_tree_cursor_current_depth_wasm = Module["_ts_tree_cursor_current_depth_wasm"] = wasmExports["ts_tree_cursor_current_depth_wasm"])(a0); + var _ts_tree_cursor_current_descendant_index_wasm = Module["_ts_tree_cursor_current_descendant_index_wasm"] = (a0) => (_ts_tree_cursor_current_descendant_index_wasm = Module["_ts_tree_cursor_current_descendant_index_wasm"] = wasmExports["ts_tree_cursor_current_descendant_index_wasm"])(a0); + var _ts_tree_cursor_current_node_wasm = Module["_ts_tree_cursor_current_node_wasm"] = (a0) => (_ts_tree_cursor_current_node_wasm = Module["_ts_tree_cursor_current_node_wasm"] = wasmExports["ts_tree_cursor_current_node_wasm"])(a0); + var _ts_node_symbol_wasm = Module["_ts_node_symbol_wasm"] = (a0) => (_ts_node_symbol_wasm = Module["_ts_node_symbol_wasm"] = wasmExports["ts_node_symbol_wasm"])(a0); + var _ts_node_field_name_for_child_wasm = Module["_ts_node_field_name_for_child_wasm"] = (a0, a1) => (_ts_node_field_name_for_child_wasm = Module["_ts_node_field_name_for_child_wasm"] = wasmExports["ts_node_field_name_for_child_wasm"])(a0, a1); + var _ts_node_field_name_for_named_child_wasm = Module["_ts_node_field_name_for_named_child_wasm"] = (a0, a1) => (_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"])(a0, a1); + var _ts_node_children_by_field_id_wasm = Module["_ts_node_children_by_field_id_wasm"] = (a0, a1) => (_ts_node_children_by_field_id_wasm = Module["_ts_node_children_by_field_id_wasm"] = wasmExports["ts_node_children_by_field_id_wasm"])(a0, a1); + var _ts_node_first_child_for_byte_wasm = Module["_ts_node_first_child_for_byte_wasm"] = (a0) => (_ts_node_first_child_for_byte_wasm = Module["_ts_node_first_child_for_byte_wasm"] = wasmExports["ts_node_first_child_for_byte_wasm"])(a0); + var _ts_node_first_named_child_for_byte_wasm = Module["_ts_node_first_named_child_for_byte_wasm"] = (a0) => (_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"])(a0); + var _ts_node_grammar_symbol_wasm = Module["_ts_node_grammar_symbol_wasm"] = (a0) => (_ts_node_grammar_symbol_wasm = Module["_ts_node_grammar_symbol_wasm"] = wasmExports["ts_node_grammar_symbol_wasm"])(a0); + var _ts_node_child_count_wasm = Module["_ts_node_child_count_wasm"] = (a0) => (_ts_node_child_count_wasm = Module["_ts_node_child_count_wasm"] = wasmExports["ts_node_child_count_wasm"])(a0); + var _ts_node_named_child_count_wasm = Module["_ts_node_named_child_count_wasm"] = (a0) => (_ts_node_named_child_count_wasm = Module["_ts_node_named_child_count_wasm"] = wasmExports["ts_node_named_child_count_wasm"])(a0); + var _ts_node_child_wasm = Module["_ts_node_child_wasm"] = (a0, a1) => (_ts_node_child_wasm = Module["_ts_node_child_wasm"] = wasmExports["ts_node_child_wasm"])(a0, a1); + var _ts_node_named_child_wasm = Module["_ts_node_named_child_wasm"] = (a0, a1) => (_ts_node_named_child_wasm = Module["_ts_node_named_child_wasm"] = wasmExports["ts_node_named_child_wasm"])(a0, a1); + var _ts_node_child_by_field_id_wasm = Module["_ts_node_child_by_field_id_wasm"] = (a0, a1) => (_ts_node_child_by_field_id_wasm = Module["_ts_node_child_by_field_id_wasm"] = wasmExports["ts_node_child_by_field_id_wasm"])(a0, a1); + var _ts_node_next_sibling_wasm = Module["_ts_node_next_sibling_wasm"] = (a0) => (_ts_node_next_sibling_wasm = Module["_ts_node_next_sibling_wasm"] = wasmExports["ts_node_next_sibling_wasm"])(a0); + var _ts_node_prev_sibling_wasm = Module["_ts_node_prev_sibling_wasm"] = (a0) => (_ts_node_prev_sibling_wasm = Module["_ts_node_prev_sibling_wasm"] = wasmExports["ts_node_prev_sibling_wasm"])(a0); + var _ts_node_next_named_sibling_wasm = Module["_ts_node_next_named_sibling_wasm"] = (a0) => (_ts_node_next_named_sibling_wasm = Module["_ts_node_next_named_sibling_wasm"] = wasmExports["ts_node_next_named_sibling_wasm"])(a0); + var _ts_node_prev_named_sibling_wasm = Module["_ts_node_prev_named_sibling_wasm"] = (a0) => (_ts_node_prev_named_sibling_wasm = Module["_ts_node_prev_named_sibling_wasm"] = wasmExports["ts_node_prev_named_sibling_wasm"])(a0); + var _ts_node_descendant_count_wasm = Module["_ts_node_descendant_count_wasm"] = (a0) => (_ts_node_descendant_count_wasm = Module["_ts_node_descendant_count_wasm"] = wasmExports["ts_node_descendant_count_wasm"])(a0); + var _ts_node_parent_wasm = Module["_ts_node_parent_wasm"] = (a0) => (_ts_node_parent_wasm = Module["_ts_node_parent_wasm"] = wasmExports["ts_node_parent_wasm"])(a0); + var _ts_node_child_with_descendant_wasm = Module["_ts_node_child_with_descendant_wasm"] = (a0) => (_ts_node_child_with_descendant_wasm = Module["_ts_node_child_with_descendant_wasm"] = wasmExports["ts_node_child_with_descendant_wasm"])(a0); + var _ts_node_descendant_for_index_wasm = Module["_ts_node_descendant_for_index_wasm"] = (a0) => (_ts_node_descendant_for_index_wasm = Module["_ts_node_descendant_for_index_wasm"] = wasmExports["ts_node_descendant_for_index_wasm"])(a0); + var _ts_node_named_descendant_for_index_wasm = Module["_ts_node_named_descendant_for_index_wasm"] = (a0) => (_ts_node_named_descendant_for_index_wasm = Module["_ts_node_named_descendant_for_index_wasm"] = wasmExports["ts_node_named_descendant_for_index_wasm"])(a0); + var _ts_node_descendant_for_position_wasm = Module["_ts_node_descendant_for_position_wasm"] = (a0) => (_ts_node_descendant_for_position_wasm = Module["_ts_node_descendant_for_position_wasm"] = wasmExports["ts_node_descendant_for_position_wasm"])(a0); + var _ts_node_named_descendant_for_position_wasm = Module["_ts_node_named_descendant_for_position_wasm"] = (a0) => (_ts_node_named_descendant_for_position_wasm = Module["_ts_node_named_descendant_for_position_wasm"] = wasmExports["ts_node_named_descendant_for_position_wasm"])(a0); + var _ts_node_start_point_wasm = Module["_ts_node_start_point_wasm"] = (a0) => (_ts_node_start_point_wasm = Module["_ts_node_start_point_wasm"] = wasmExports["ts_node_start_point_wasm"])(a0); + var _ts_node_end_point_wasm = Module["_ts_node_end_point_wasm"] = (a0) => (_ts_node_end_point_wasm = Module["_ts_node_end_point_wasm"] = wasmExports["ts_node_end_point_wasm"])(a0); + var _ts_node_start_index_wasm = Module["_ts_node_start_index_wasm"] = (a0) => (_ts_node_start_index_wasm = Module["_ts_node_start_index_wasm"] = wasmExports["ts_node_start_index_wasm"])(a0); + var _ts_node_end_index_wasm = Module["_ts_node_end_index_wasm"] = (a0) => (_ts_node_end_index_wasm = Module["_ts_node_end_index_wasm"] = wasmExports["ts_node_end_index_wasm"])(a0); + var _ts_node_to_string_wasm = Module["_ts_node_to_string_wasm"] = (a0) => (_ts_node_to_string_wasm = Module["_ts_node_to_string_wasm"] = wasmExports["ts_node_to_string_wasm"])(a0); + var _ts_node_children_wasm = Module["_ts_node_children_wasm"] = (a0) => (_ts_node_children_wasm = Module["_ts_node_children_wasm"] = wasmExports["ts_node_children_wasm"])(a0); + var _ts_node_named_children_wasm = Module["_ts_node_named_children_wasm"] = (a0) => (_ts_node_named_children_wasm = Module["_ts_node_named_children_wasm"] = wasmExports["ts_node_named_children_wasm"])(a0); + var _ts_node_descendants_of_type_wasm = Module["_ts_node_descendants_of_type_wasm"] = (a0, a1, a2, a3, a4, a5, a6) => (_ts_node_descendants_of_type_wasm = Module["_ts_node_descendants_of_type_wasm"] = wasmExports["ts_node_descendants_of_type_wasm"])(a0, a1, a2, a3, a4, a5, a6); + var _ts_node_is_named_wasm = Module["_ts_node_is_named_wasm"] = (a0) => (_ts_node_is_named_wasm = Module["_ts_node_is_named_wasm"] = wasmExports["ts_node_is_named_wasm"])(a0); + var _ts_node_has_changes_wasm = Module["_ts_node_has_changes_wasm"] = (a0) => (_ts_node_has_changes_wasm = Module["_ts_node_has_changes_wasm"] = wasmExports["ts_node_has_changes_wasm"])(a0); + var _ts_node_has_error_wasm = Module["_ts_node_has_error_wasm"] = (a0) => (_ts_node_has_error_wasm = Module["_ts_node_has_error_wasm"] = wasmExports["ts_node_has_error_wasm"])(a0); + var _ts_node_is_error_wasm = Module["_ts_node_is_error_wasm"] = (a0) => (_ts_node_is_error_wasm = Module["_ts_node_is_error_wasm"] = wasmExports["ts_node_is_error_wasm"])(a0); + var _ts_node_is_missing_wasm = Module["_ts_node_is_missing_wasm"] = (a0) => (_ts_node_is_missing_wasm = Module["_ts_node_is_missing_wasm"] = wasmExports["ts_node_is_missing_wasm"])(a0); + var _ts_node_is_extra_wasm = Module["_ts_node_is_extra_wasm"] = (a0) => (_ts_node_is_extra_wasm = Module["_ts_node_is_extra_wasm"] = wasmExports["ts_node_is_extra_wasm"])(a0); + var _ts_node_parse_state_wasm = Module["_ts_node_parse_state_wasm"] = (a0) => (_ts_node_parse_state_wasm = Module["_ts_node_parse_state_wasm"] = wasmExports["ts_node_parse_state_wasm"])(a0); + var _ts_node_next_parse_state_wasm = Module["_ts_node_next_parse_state_wasm"] = (a0) => (_ts_node_next_parse_state_wasm = Module["_ts_node_next_parse_state_wasm"] = wasmExports["ts_node_next_parse_state_wasm"])(a0); + var _ts_query_matches_wasm = Module["_ts_query_matches_wasm"] = (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) => (_ts_query_matches_wasm = Module["_ts_query_matches_wasm"] = wasmExports["ts_query_matches_wasm"])(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); + var _ts_query_captures_wasm = Module["_ts_query_captures_wasm"] = (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) => (_ts_query_captures_wasm = Module["_ts_query_captures_wasm"] = wasmExports["ts_query_captures_wasm"])(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); + var _iswalpha = Module["_iswalpha"] = (a0) => (_iswalpha = Module["_iswalpha"] = wasmExports["iswalpha"])(a0); + var _iswblank = Module["_iswblank"] = (a0) => (_iswblank = Module["_iswblank"] = wasmExports["iswblank"])(a0); + var _iswdigit = Module["_iswdigit"] = (a0) => (_iswdigit = Module["_iswdigit"] = wasmExports["iswdigit"])(a0); + var _iswlower = Module["_iswlower"] = (a0) => (_iswlower = Module["_iswlower"] = wasmExports["iswlower"])(a0); + var _iswupper = Module["_iswupper"] = (a0) => (_iswupper = Module["_iswupper"] = wasmExports["iswupper"])(a0); + var _iswxdigit = Module["_iswxdigit"] = (a0) => (_iswxdigit = Module["_iswxdigit"] = wasmExports["iswxdigit"])(a0); + var _memchr = Module["_memchr"] = (a0, a1, a2) => (_memchr = Module["_memchr"] = wasmExports["memchr"])(a0, a1, a2); + var _strlen = Module["_strlen"] = (a0) => (_strlen = Module["_strlen"] = wasmExports["strlen"])(a0); + var _strcmp = Module["_strcmp"] = (a0, a1) => (_strcmp = Module["_strcmp"] = wasmExports["strcmp"])(a0, a1); + var _strncat = Module["_strncat"] = (a0, a1, a2) => (_strncat = Module["_strncat"] = wasmExports["strncat"])(a0, a1, a2); + var _strncpy = Module["_strncpy"] = (a0, a1, a2) => (_strncpy = Module["_strncpy"] = wasmExports["strncpy"])(a0, a1, a2); + var _towlower = Module["_towlower"] = (a0) => (_towlower = Module["_towlower"] = wasmExports["towlower"])(a0); + var _towupper = Module["_towupper"] = (a0) => (_towupper = Module["_towupper"] = wasmExports["towupper"])(a0); + var _setThrew = /* @__PURE__ */ __name((a0, a1) => (_setThrew = wasmExports["setThrew"])(a0, a1), "_setThrew"); + var __emscripten_stack_restore = /* @__PURE__ */ __name((a0) => (__emscripten_stack_restore = wasmExports["_emscripten_stack_restore"])(a0), "__emscripten_stack_restore"); + var __emscripten_stack_alloc = /* @__PURE__ */ __name((a0) => (__emscripten_stack_alloc = wasmExports["_emscripten_stack_alloc"])(a0), "__emscripten_stack_alloc"); + var _emscripten_stack_get_current = /* @__PURE__ */ __name(() => (_emscripten_stack_get_current = wasmExports["emscripten_stack_get_current"])(), "_emscripten_stack_get_current"); + var ___wasm_apply_data_relocs = /* @__PURE__ */ __name(() => (___wasm_apply_data_relocs = wasmExports["__wasm_apply_data_relocs"])(), "___wasm_apply_data_relocs"); + var dynCall_jiji = Module["dynCall_jiji"] = (a0, a1, a2, a3, a4) => (dynCall_jiji = Module["dynCall_jiji"] = wasmExports["dynCall_jiji"])(a0, a1, a2, a3, a4); + var _orig$ts_parser_timeout_micros = Module["_orig$ts_parser_timeout_micros"] = (a0) => (_orig$ts_parser_timeout_micros = Module["_orig$ts_parser_timeout_micros"] = wasmExports["orig$ts_parser_timeout_micros"])(a0); + var _orig$ts_parser_set_timeout_micros = Module["_orig$ts_parser_set_timeout_micros"] = (a0, a1) => (_orig$ts_parser_set_timeout_micros = Module["_orig$ts_parser_set_timeout_micros"] = wasmExports["orig$ts_parser_set_timeout_micros"])(a0, a1); + Module["setValue"] = setValue; + Module["getValue"] = getValue; + Module["UTF8ToString"] = UTF8ToString; + Module["stringToUTF8"] = stringToUTF8; + Module["lengthBytesUTF8"] = lengthBytesUTF8; + Module["AsciiToString"] = AsciiToString; + Module["stringToUTF16"] = stringToUTF16; + Module["loadWebAssemblyModule"] = loadWebAssemblyModule; + var calledRun; + dependenciesFulfilled = /* @__PURE__ */ __name(function runCaller() { + if (!calledRun) run(); + if (!calledRun) dependenciesFulfilled = runCaller; + }, "runCaller"); + function callMain(args2 = []) { + var entryFunction = resolveGlobalSymbol("main").sym; + if (!entryFunction) return; + args2.unshift(thisProgram); + var argc = args2.length; + var argv = stackAlloc((argc + 1) * 4); + var argv_ptr = argv; + args2.forEach((arg) => { + LE_HEAP_STORE_U32((argv_ptr >> 2) * 4, stringToUTF8OnStack(arg)); + argv_ptr += 4; + }); + LE_HEAP_STORE_U32((argv_ptr >> 2) * 4, 0); + try { + var ret = entryFunction(argc, argv); + exitJS( + ret, + /* implicit = */ + true + ); + return ret; + } catch (e) { + return handleException(e); + } + } + __name(callMain, "callMain"); + function run(args2 = arguments_) { + if (runDependencies > 0) { + return; + } + preRun(); + if (runDependencies > 0) { + return; + } + function doRun() { + if (calledRun) return; + calledRun = true; + Module["calledRun"] = true; + if (ABORT) return; + initRuntime(); + preMain(); + readyPromiseResolve(Module); + Module["onRuntimeInitialized"]?.(); + if (shouldRunNow) callMain(args2); + postRun(); + } + __name(doRun, "doRun"); + if (Module["setStatus"]) { + Module["setStatus"]("Running..."); + setTimeout(() => { + setTimeout(() => Module["setStatus"](""), 1); + doRun(); + }, 1); + } else { + doRun(); + } + } + __name(run, "run"); + if (Module["preInit"]) { + if (typeof Module["preInit"] == "function") Module["preInit"] = [Module["preInit"]]; + while (Module["preInit"].length > 0) { + Module["preInit"].pop()(); + } + } + var shouldRunNow = true; + if (Module["noInitialRun"]) shouldRunNow = false; + run(); + moduleRtn = readyPromise; + return moduleRtn; + }; +})(); +var tree_sitter_default = Module2; + +// src/bindings.ts +var Module3 = null; +async function initializeBinding(moduleOptions) { + if (!Module3) { + Module3 = await tree_sitter_default(moduleOptions); + } + return Module3; +} +__name(initializeBinding, "initializeBinding"); +function checkModule() { + return !!Module3; +} +__name(checkModule, "checkModule"); + +// src/parser.ts +var TRANSFER_BUFFER; +var LANGUAGE_VERSION; +var MIN_COMPATIBLE_VERSION; +var Parser = class { + static { + __name(this, "Parser"); + } + /** @internal */ + [0] = 0; + // Internal handle for WASM + /** @internal */ + [1] = 0; + // Internal handle for WASM + /** @internal */ + logCallback = null; + /** The parser's current language. */ + language = null; + /** + * This must always be called before creating a Parser. + * + * You can optionally pass in options to configure the WASM module, the most common + * one being `locateFile` to help the module find the `.wasm` file. + */ + static async init(moduleOptions) { + setModule(await initializeBinding(moduleOptions)); + TRANSFER_BUFFER = C._ts_init(); + LANGUAGE_VERSION = C.getValue(TRANSFER_BUFFER, "i32"); + MIN_COMPATIBLE_VERSION = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + } + /** + * Create a new parser. + */ + constructor() { + this.initialize(); + } + /** @internal */ + initialize() { + if (!checkModule()) { + throw new Error("cannot construct a Parser before calling `init()`"); + } + C._ts_parser_new_wasm(); + this[0] = C.getValue(TRANSFER_BUFFER, "i32"); + this[1] = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + } + /** Delete the parser, freeing its resources. */ + delete() { + C._ts_parser_delete(this[0]); + C._free(this[1]); + this[0] = 0; + this[1] = 0; + } + /** + * Set the language that the parser should use for parsing. + * + * If the language was not successfully assigned, an error will be thrown. + * This happens if the language was generated with an incompatible + * version of the Tree-sitter CLI. Check the language's version using + * {@link Language#version} and compare it to this library's + * {@link LANGUAGE_VERSION} and {@link MIN_COMPATIBLE_VERSION} constants. + */ + setLanguage(language) { + let address; + if (!language) { + address = 0; + this.language = null; + } else if (language.constructor === Language) { + address = language[0]; + const version = C._ts_language_version(address); + if (version < MIN_COMPATIBLE_VERSION || LANGUAGE_VERSION < version) { + throw new Error( + `Incompatible language version ${version}. Compatibility range ${MIN_COMPATIBLE_VERSION} through ${LANGUAGE_VERSION}.` + ); + } + this.language = language; + } else { + throw new Error("Argument must be a Language"); + } + C._ts_parser_set_language(this[0], address); + return this; + } + /** + * Parse a slice of UTF8 text. + * + * @param {string | ParseCallback} callback - The UTF8-encoded text to parse or a callback function. + * + * @param {Tree | null} [oldTree] - A previous syntax tree parsed from the same document. If the text of the + * document has changed since `oldTree` was created, then you must edit `oldTree` to match + * the new text using {@link Tree#edit}. + * + * @param {ParseOptions} [options] - Options for parsing the text. + * This can be used to set the included ranges, or a progress callback. + * + * @returns {Tree | null} A {@link Tree} if parsing succeeded, or `null` if: + * - The parser has not yet had a language assigned with {@link Parser#setLanguage}. + * - The progress callback returned true. + */ + parse(callback, oldTree, options) { + if (typeof callback === "string") { + C.currentParseCallback = (index) => callback.slice(index); + } else if (typeof callback === "function") { + C.currentParseCallback = callback; + } else { + throw new Error("Argument must be a string or a function"); + } + if (options?.progressCallback) { + C.currentProgressCallback = options.progressCallback; + } else { + C.currentProgressCallback = null; + } + if (this.logCallback) { + C.currentLogCallback = this.logCallback; + C._ts_parser_enable_logger_wasm(this[0], 1); + } else { + C.currentLogCallback = null; + C._ts_parser_enable_logger_wasm(this[0], 0); + } + let rangeCount = 0; + let rangeAddress = 0; + if (options?.includedRanges) { + rangeCount = options.includedRanges.length; + rangeAddress = C._calloc(rangeCount, SIZE_OF_RANGE); + let address = rangeAddress; + for (let i2 = 0; i2 < rangeCount; i2++) { + marshalRange(address, options.includedRanges[i2]); + address += SIZE_OF_RANGE; + } + } + const treeAddress = C._ts_parser_parse_wasm( + this[0], + this[1], + oldTree ? oldTree[0] : 0, + rangeAddress, + rangeCount + ); + if (!treeAddress) { + C.currentParseCallback = null; + C.currentLogCallback = null; + C.currentProgressCallback = null; + return null; + } + if (!this.language) { + throw new Error("Parser must have a language to parse"); + } + const result = new Tree(INTERNAL, treeAddress, this.language, C.currentParseCallback); + C.currentParseCallback = null; + C.currentLogCallback = null; + C.currentProgressCallback = null; + return result; + } + /** + * Instruct the parser to start the next parse from the beginning. + * + * If the parser previously failed because of a timeout, cancellation, + * or callback, then by default, it will resume where it left off on the + * next call to {@link Parser#parse} or other parsing functions. + * If you don't want to resume, and instead intend to use this parser to + * parse some other document, you must call `reset` first. + */ + reset() { + C._ts_parser_reset(this[0]); + } + /** Get the ranges of text that the parser will include when parsing. */ + getIncludedRanges() { + C._ts_parser_included_ranges_wasm(this[0]); + const count = C.getValue(TRANSFER_BUFFER, "i32"); + const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + const result = new Array(count); + if (count > 0) { + let address = buffer; + for (let i2 = 0; i2 < count; i2++) { + result[i2] = unmarshalRange(address); + address += SIZE_OF_RANGE; + } + C._free(buffer); + } + return result; + } + /** + * @deprecated since version 0.25.0, prefer passing a progress callback to {@link Parser#parse} + * + * Get the duration in microseconds that parsing is allowed to take. + * + * This is set via {@link Parser#setTimeoutMicros}. + */ + getTimeoutMicros() { + return C._ts_parser_timeout_micros(this[0]); + } + /** + * @deprecated since version 0.25.0, prefer passing a progress callback to {@link Parser#parse} + * + * Set the maximum duration in microseconds that parsing should be allowed + * to take before halting. + * + * If parsing takes longer than this, it will halt early, returning `null`. + * See {@link Parser#parse} for more information. + */ + setTimeoutMicros(timeout) { + C._ts_parser_set_timeout_micros(this[0], 0, timeout); + } + /** Set the logging callback that a parser should use during parsing. */ + setLogger(callback) { + if (!callback) { + this.logCallback = null; + } else if (typeof callback !== "function") { + throw new Error("Logger callback must be a function"); + } else { + this.logCallback = callback; + } + return this; + } + /** Get the parser's current logger. */ + getLogger() { + return this.logCallback; + } +}; + +// src/tree.ts +function getText(tree, startIndex, endIndex, startPosition) { + const length = endIndex - startIndex; + let result = tree.textCallback(startIndex, startPosition); + if (result) { + startIndex += result.length; + while (startIndex < endIndex) { + const string = tree.textCallback(startIndex, startPosition); + if (string && string.length > 0) { + startIndex += string.length; + result += string; + } else { + break; + } + } + if (startIndex > endIndex) { + result = result.slice(0, length); + } + } + return result ?? ""; +} +__name(getText, "getText"); +var Tree = class _Tree { + static { + __name(this, "Tree"); + } + /** @internal */ + [0] = 0; + // Internal handle for WASM + /** @internal */ + textCallback; + /** The language that was used to parse the syntax tree. */ + language; + /** @internal */ + constructor(internal, address, language, textCallback) { + assertInternal(internal); + this[0] = address; + this.language = language; + this.textCallback = textCallback; + } + /** Create a shallow copy of the syntax tree. This is very fast. */ + copy() { + const address = C._ts_tree_copy(this[0]); + return new _Tree(INTERNAL, address, this.language, this.textCallback); + } + /** Delete the syntax tree, freeing its resources. */ + delete() { + C._ts_tree_delete(this[0]); + this[0] = 0; + } + /** Get the root node of the syntax tree. */ + get rootNode() { + C._ts_tree_root_node_wasm(this[0]); + return unmarshalNode(this); + } + /** + * Get the root node of the syntax tree, but with its position shifted + * forward by the given offset. + */ + rootNodeWithOffset(offsetBytes, offsetExtent) { + const address = TRANSFER_BUFFER + SIZE_OF_NODE; + C.setValue(address, offsetBytes, "i32"); + marshalPoint(address + SIZE_OF_INT, offsetExtent); + C._ts_tree_root_node_with_offset_wasm(this[0]); + return unmarshalNode(this); + } + /** + * Edit the syntax tree to keep it in sync with source code that has been + * edited. + * + * You must describe the edit both in terms of byte offsets and in terms of + * row/column coordinates. + */ + edit(edit) { + marshalEdit(edit); + C._ts_tree_edit_wasm(this[0]); + } + /** Create a new {@link TreeCursor} starting from the root of the tree. */ + walk() { + return this.rootNode.walk(); + } + /** + * Compare this old edited syntax tree to a new syntax tree representing + * the same document, returning a sequence of ranges whose syntactic + * structure has changed. + * + * For this to work correctly, this syntax tree must have been edited such + * that its ranges match up to the new tree. Generally, you'll want to + * call this method right after calling one of the [`Parser::parse`] + * functions. Call it on the old tree that was passed to parse, and + * pass the new tree that was returned from `parse`. + */ + getChangedRanges(other) { + if (!(other instanceof _Tree)) { + throw new TypeError("Argument must be a Tree"); + } + C._ts_tree_get_changed_ranges_wasm(this[0], other[0]); + const count = C.getValue(TRANSFER_BUFFER, "i32"); + const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + const result = new Array(count); + if (count > 0) { + let address = buffer; + for (let i2 = 0; i2 < count; i2++) { + result[i2] = unmarshalRange(address); + address += SIZE_OF_RANGE; + } + C._free(buffer); + } + return result; + } + /** Get the included ranges that were used to parse the syntax tree. */ + getIncludedRanges() { + C._ts_tree_included_ranges_wasm(this[0]); + const count = C.getValue(TRANSFER_BUFFER, "i32"); + const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + const result = new Array(count); + if (count > 0) { + let address = buffer; + for (let i2 = 0; i2 < count; i2++) { + result[i2] = unmarshalRange(address); + address += SIZE_OF_RANGE; + } + C._free(buffer); + } + return result; + } +}; + +// src/tree_cursor.ts +var TreeCursor = class _TreeCursor { + static { + __name(this, "TreeCursor"); + } + /** @internal */ + [0] = 0; + // Internal handle for WASM + /** @internal */ + [1] = 0; + // Internal handle for WASM + /** @internal */ + [2] = 0; + // Internal handle for WASM + /** @internal */ + [3] = 0; + // Internal handle for WASM + /** @internal */ + tree; + /** @internal */ + constructor(internal, tree) { + assertInternal(internal); + this.tree = tree; + unmarshalTreeCursor(this); + } + /** Creates a deep copy of the tree cursor. This allocates new memory. */ + copy() { + const copy = new _TreeCursor(INTERNAL, this.tree); + C._ts_tree_cursor_copy_wasm(this.tree[0]); + unmarshalTreeCursor(copy); + return copy; + } + /** Delete the tree cursor, freeing its resources. */ + delete() { + marshalTreeCursor(this); + C._ts_tree_cursor_delete_wasm(this.tree[0]); + this[0] = this[1] = this[2] = 0; + } + /** Get the tree cursor's current {@link Node}. */ + get currentNode() { + marshalTreeCursor(this); + C._ts_tree_cursor_current_node_wasm(this.tree[0]); + return unmarshalNode(this.tree); + } + /** + * Get the numerical field id of this tree cursor's current node. + * + * See also {@link TreeCursor#currentFieldName}. + */ + get currentFieldId() { + marshalTreeCursor(this); + return C._ts_tree_cursor_current_field_id_wasm(this.tree[0]); + } + /** Get the field name of this tree cursor's current node. */ + get currentFieldName() { + return this.tree.language.fields[this.currentFieldId]; + } + /** + * Get the depth of the cursor's current node relative to the original + * node that the cursor was constructed with. + */ + get currentDepth() { + marshalTreeCursor(this); + return C._ts_tree_cursor_current_depth_wasm(this.tree[0]); + } + /** + * Get the index of the cursor's current node out of all of the + * descendants of the original node that the cursor was constructed with. + */ + get currentDescendantIndex() { + marshalTreeCursor(this); + return C._ts_tree_cursor_current_descendant_index_wasm(this.tree[0]); + } + /** Get the type of the cursor's current node. */ + get nodeType() { + return this.tree.language.types[this.nodeTypeId] || "ERROR"; + } + /** Get the type id of the cursor's current node. */ + get nodeTypeId() { + marshalTreeCursor(this); + return C._ts_tree_cursor_current_node_type_id_wasm(this.tree[0]); + } + /** Get the state id of the cursor's current node. */ + get nodeStateId() { + marshalTreeCursor(this); + return C._ts_tree_cursor_current_node_state_id_wasm(this.tree[0]); + } + /** Get the id of the cursor's current node. */ + get nodeId() { + marshalTreeCursor(this); + return C._ts_tree_cursor_current_node_id_wasm(this.tree[0]); + } + /** + * Check if the cursor's current node is *named*. + * + * Named nodes correspond to named rules in the grammar, whereas + * *anonymous* nodes correspond to string literals in the grammar. + */ + get nodeIsNamed() { + marshalTreeCursor(this); + return C._ts_tree_cursor_current_node_is_named_wasm(this.tree[0]) === 1; + } + /** + * Check if the cursor's current node is *missing*. + * + * Missing nodes are inserted by the parser in order to recover from + * certain kinds of syntax errors. + */ + get nodeIsMissing() { + marshalTreeCursor(this); + return C._ts_tree_cursor_current_node_is_missing_wasm(this.tree[0]) === 1; + } + /** Get the string content of the cursor's current node. */ + get nodeText() { + marshalTreeCursor(this); + const startIndex = C._ts_tree_cursor_start_index_wasm(this.tree[0]); + const endIndex = C._ts_tree_cursor_end_index_wasm(this.tree[0]); + C._ts_tree_cursor_start_position_wasm(this.tree[0]); + const startPosition = unmarshalPoint(TRANSFER_BUFFER); + return getText(this.tree, startIndex, endIndex, startPosition); + } + /** Get the start position of the cursor's current node. */ + get startPosition() { + marshalTreeCursor(this); + C._ts_tree_cursor_start_position_wasm(this.tree[0]); + return unmarshalPoint(TRANSFER_BUFFER); + } + /** Get the end position of the cursor's current node. */ + get endPosition() { + marshalTreeCursor(this); + C._ts_tree_cursor_end_position_wasm(this.tree[0]); + return unmarshalPoint(TRANSFER_BUFFER); + } + /** Get the start index of the cursor's current node. */ + get startIndex() { + marshalTreeCursor(this); + return C._ts_tree_cursor_start_index_wasm(this.tree[0]); + } + /** Get the end index of the cursor's current node. */ + get endIndex() { + marshalTreeCursor(this); + return C._ts_tree_cursor_end_index_wasm(this.tree[0]); + } + /** + * Move this cursor to the first child of its current node. + * + * This returns `true` if the cursor successfully moved, and returns + * `false` if there were no children. + */ + gotoFirstChild() { + marshalTreeCursor(this); + const result = C._ts_tree_cursor_goto_first_child_wasm(this.tree[0]); + unmarshalTreeCursor(this); + return result === 1; + } + /** + * Move this cursor to the last child of its current node. + * + * This returns `true` if the cursor successfully moved, and returns + * `false` if there were no children. + * + * Note that this function may be slower than + * {@link TreeCursor#gotoFirstChild} because it needs to + * iterate through all the children to compute the child's position. + */ + gotoLastChild() { + marshalTreeCursor(this); + const result = C._ts_tree_cursor_goto_last_child_wasm(this.tree[0]); + unmarshalTreeCursor(this); + return result === 1; + } + /** + * Move this cursor to the parent of its current node. + * + * This returns `true` if the cursor successfully moved, and returns + * `false` if there was no parent node (the cursor was already on the + * root node). + * + * Note that the node the cursor was constructed with is considered the root + * of the cursor, and the cursor cannot walk outside this node. + */ + gotoParent() { + marshalTreeCursor(this); + const result = C._ts_tree_cursor_goto_parent_wasm(this.tree[0]); + unmarshalTreeCursor(this); + return result === 1; + } + /** + * Move this cursor to the next sibling of its current node. + * + * This returns `true` if the cursor successfully moved, and returns + * `false` if there was no next sibling node. + * + * Note that the node the cursor was constructed with is considered the root + * of the cursor, and the cursor cannot walk outside this node. + */ + gotoNextSibling() { + marshalTreeCursor(this); + const result = C._ts_tree_cursor_goto_next_sibling_wasm(this.tree[0]); + unmarshalTreeCursor(this); + return result === 1; + } + /** + * Move this cursor to the previous sibling of its current node. + * + * This returns `true` if the cursor successfully moved, and returns + * `false` if there was no previous sibling node. + * + * Note that this function may be slower than + * {@link TreeCursor#gotoNextSibling} due to how node + * positions are stored. In the worst case, this will need to iterate + * through all the children up to the previous sibling node to recalculate + * its position. Also note that the node the cursor was constructed with is + * considered the root of the cursor, and the cursor cannot walk outside this node. + */ + gotoPreviousSibling() { + marshalTreeCursor(this); + const result = C._ts_tree_cursor_goto_previous_sibling_wasm(this.tree[0]); + unmarshalTreeCursor(this); + return result === 1; + } + /** + * Move the cursor to the node that is the nth descendant of + * the original node that the cursor was constructed with, where + * zero represents the original node itself. + */ + gotoDescendant(goalDescendantIndex) { + marshalTreeCursor(this); + C._ts_tree_cursor_goto_descendant_wasm(this.tree[0], goalDescendantIndex); + unmarshalTreeCursor(this); + } + /** + * Move this cursor to the first child of its current node that contains or + * starts after the given byte offset. + * + * This returns `true` if the cursor successfully moved to a child node, and returns + * `false` if no such child was found. + */ + gotoFirstChildForIndex(goalIndex) { + marshalTreeCursor(this); + C.setValue(TRANSFER_BUFFER + SIZE_OF_CURSOR, goalIndex, "i32"); + const result = C._ts_tree_cursor_goto_first_child_for_index_wasm(this.tree[0]); + unmarshalTreeCursor(this); + return result === 1; + } + /** + * Move this cursor to the first child of its current node that contains or + * starts after the given byte offset. + * + * This returns the index of the child node if one was found, and returns + * `null` if no such child was found. + */ + gotoFirstChildForPosition(goalPosition) { + marshalTreeCursor(this); + marshalPoint(TRANSFER_BUFFER + SIZE_OF_CURSOR, goalPosition); + const result = C._ts_tree_cursor_goto_first_child_for_position_wasm(this.tree[0]); + unmarshalTreeCursor(this); + return result === 1; + } + /** + * Re-initialize this tree cursor to start at the original node that the + * cursor was constructed with. + */ + reset(node) { + marshalNode(node); + marshalTreeCursor(this, TRANSFER_BUFFER + SIZE_OF_NODE); + C._ts_tree_cursor_reset_wasm(this.tree[0]); + unmarshalTreeCursor(this); + } + /** + * Re-initialize a tree cursor to the same position as another cursor. + * + * Unlike {@link TreeCursor#reset}, this will not lose parent + * information and allows reusing already created cursors. + */ + resetTo(cursor) { + marshalTreeCursor(this, TRANSFER_BUFFER); + marshalTreeCursor(cursor, TRANSFER_BUFFER + SIZE_OF_CURSOR); + C._ts_tree_cursor_reset_to_wasm(this.tree[0], cursor.tree[0]); + unmarshalTreeCursor(this); + } +}; + +// src/node.ts +var Node = class { + static { + __name(this, "Node"); + } + /** @internal */ + [0] = 0; + // Internal handle for WASM + /** @internal */ + _children; + /** @internal */ + _namedChildren; + /** @internal */ + constructor(internal, { + id, + tree, + startIndex, + startPosition, + other + }) { + assertInternal(internal); + this[0] = other; + this.id = id; + this.tree = tree; + this.startIndex = startIndex; + this.startPosition = startPosition; + } + /** + * The numeric id for this node that is unique. + * + * Within a given syntax tree, no two nodes have the same id. However: + * + * * If a new tree is created based on an older tree, and a node from the old tree is reused in + * the process, then that node will have the same id in both trees. + * + * * A node not marked as having changes does not guarantee it was reused. + * + * * If a node is marked as having changed in the old tree, it will not be reused. + */ + id; + /** The byte index where this node starts. */ + startIndex; + /** The position where this node starts. */ + startPosition; + /** The tree that this node belongs to. */ + tree; + /** Get this node's type as a numerical id. */ + get typeId() { + marshalNode(this); + return C._ts_node_symbol_wasm(this.tree[0]); + } + /** + * Get the node's type as a numerical id as it appears in the grammar, + * ignoring aliases. + */ + get grammarId() { + marshalNode(this); + return C._ts_node_grammar_symbol_wasm(this.tree[0]); + } + /** Get this node's type as a string. */ + get type() { + return this.tree.language.types[this.typeId] || "ERROR"; + } + /** + * Get this node's symbol name as it appears in the grammar, ignoring + * aliases as a string. + */ + get grammarType() { + return this.tree.language.types[this.grammarId] || "ERROR"; + } + /** + * Check if this node is *named*. + * + * Named nodes correspond to named rules in the grammar, whereas + * *anonymous* nodes correspond to string literals in the grammar. + */ + get isNamed() { + marshalNode(this); + return C._ts_node_is_named_wasm(this.tree[0]) === 1; + } + /** + * Check if this node is *extra*. + * + * Extra nodes represent things like comments, which are not required + * by the grammar, but can appear anywhere. + */ + get isExtra() { + marshalNode(this); + return C._ts_node_is_extra_wasm(this.tree[0]) === 1; + } + /** + * Check if this node represents a syntax error. + * + * Syntax errors represent parts of the code that could not be incorporated + * into a valid syntax tree. + */ + get isError() { + marshalNode(this); + return C._ts_node_is_error_wasm(this.tree[0]) === 1; + } + /** + * Check if this node is *missing*. + * + * Missing nodes are inserted by the parser in order to recover from + * certain kinds of syntax errors. + */ + get isMissing() { + marshalNode(this); + return C._ts_node_is_missing_wasm(this.tree[0]) === 1; + } + /** Check if this node has been edited. */ + get hasChanges() { + marshalNode(this); + return C._ts_node_has_changes_wasm(this.tree[0]) === 1; + } + /** + * Check if this node represents a syntax error or contains any syntax + * errors anywhere within it. + */ + get hasError() { + marshalNode(this); + return C._ts_node_has_error_wasm(this.tree[0]) === 1; + } + /** Get the byte index where this node ends. */ + get endIndex() { + marshalNode(this); + return C._ts_node_end_index_wasm(this.tree[0]); + } + /** Get the position where this node ends. */ + get endPosition() { + marshalNode(this); + C._ts_node_end_point_wasm(this.tree[0]); + return unmarshalPoint(TRANSFER_BUFFER); + } + /** Get the string content of this node. */ + get text() { + return getText(this.tree, this.startIndex, this.endIndex, this.startPosition); + } + /** Get this node's parse state. */ + get parseState() { + marshalNode(this); + return C._ts_node_parse_state_wasm(this.tree[0]); + } + /** Get the parse state after this node. */ + get nextParseState() { + marshalNode(this); + return C._ts_node_next_parse_state_wasm(this.tree[0]); + } + /** Check if this node is equal to another node. */ + equals(other) { + return this.tree === other.tree && this.id === other.id; + } + /** + * Get the node's child at the given index, where zero represents the first child. + * + * This method is fairly fast, but its cost is technically log(n), so if + * you might be iterating over a long list of children, you should use + * {@link Node#children} instead. + */ + child(index) { + marshalNode(this); + C._ts_node_child_wasm(this.tree[0], index); + return unmarshalNode(this.tree); + } + /** + * Get this node's *named* child at the given index. + * + * See also {@link Node#isNamed}. + * This method is fairly fast, but its cost is technically log(n), so if + * you might be iterating over a long list of children, you should use + * {@link Node#namedChildren} instead. + */ + namedChild(index) { + marshalNode(this); + C._ts_node_named_child_wasm(this.tree[0], index); + return unmarshalNode(this.tree); + } + /** + * Get this node's child with the given numerical field id. + * + * See also {@link Node#childForFieldName}. You can + * convert a field name to an id using {@link Language#fieldIdForName}. + */ + childForFieldId(fieldId) { + marshalNode(this); + C._ts_node_child_by_field_id_wasm(this.tree[0], fieldId); + return unmarshalNode(this.tree); + } + /** + * Get the first child with the given field name. + * + * If multiple children may have the same field name, access them using + * {@link Node#childrenForFieldName}. + */ + childForFieldName(fieldName) { + const fieldId = this.tree.language.fields.indexOf(fieldName); + if (fieldId !== -1) return this.childForFieldId(fieldId); + return null; + } + /** Get the field name of this node's child at the given index. */ + fieldNameForChild(index) { + marshalNode(this); + const address = C._ts_node_field_name_for_child_wasm(this.tree[0], index); + if (!address) return null; + return C.AsciiToString(address); + } + /** Get the field name of this node's named child at the given index. */ + fieldNameForNamedChild(index) { + marshalNode(this); + const address = C._ts_node_field_name_for_named_child_wasm(this.tree[0], index); + if (!address) return null; + return C.AsciiToString(address); + } + /** + * Get an array of this node's children with a given field name. + * + * See also {@link Node#children}. + */ + childrenForFieldName(fieldName) { + const fieldId = this.tree.language.fields.indexOf(fieldName); + if (fieldId !== -1 && fieldId !== 0) return this.childrenForFieldId(fieldId); + return []; + } + /** + * Get an array of this node's children with a given field id. + * + * See also {@link Node#childrenForFieldName}. + */ + childrenForFieldId(fieldId) { + marshalNode(this); + C._ts_node_children_by_field_id_wasm(this.tree[0], fieldId); + const count = C.getValue(TRANSFER_BUFFER, "i32"); + const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + const result = new Array(count); + if (count > 0) { + let address = buffer; + for (let i2 = 0; i2 < count; i2++) { + result[i2] = unmarshalNode(this.tree, address); + address += SIZE_OF_NODE; + } + C._free(buffer); + } + return result; + } + /** Get the node's first child that contains or starts after the given byte offset. */ + firstChildForIndex(index) { + marshalNode(this); + const address = TRANSFER_BUFFER + SIZE_OF_NODE; + C.setValue(address, index, "i32"); + C._ts_node_first_child_for_byte_wasm(this.tree[0]); + return unmarshalNode(this.tree); + } + /** Get the node's first named child that contains or starts after the given byte offset. */ + firstNamedChildForIndex(index) { + marshalNode(this); + const address = TRANSFER_BUFFER + SIZE_OF_NODE; + C.setValue(address, index, "i32"); + C._ts_node_first_named_child_for_byte_wasm(this.tree[0]); + return unmarshalNode(this.tree); + } + /** Get this node's number of children. */ + get childCount() { + marshalNode(this); + return C._ts_node_child_count_wasm(this.tree[0]); + } + /** + * Get this node's number of *named* children. + * + * See also {@link Node#isNamed}. + */ + get namedChildCount() { + marshalNode(this); + return C._ts_node_named_child_count_wasm(this.tree[0]); + } + /** Get this node's first child. */ + get firstChild() { + return this.child(0); + } + /** + * Get this node's first named child. + * + * See also {@link Node#isNamed}. + */ + get firstNamedChild() { + return this.namedChild(0); + } + /** Get this node's last child. */ + get lastChild() { + return this.child(this.childCount - 1); + } + /** + * Get this node's last named child. + * + * See also {@link Node#isNamed}. + */ + get lastNamedChild() { + return this.namedChild(this.namedChildCount - 1); + } + /** + * Iterate over this node's children. + * + * If you're walking the tree recursively, you may want to use the + * {@link TreeCursor} APIs directly instead. + */ + get children() { + if (!this._children) { + marshalNode(this); + C._ts_node_children_wasm(this.tree[0]); + const count = C.getValue(TRANSFER_BUFFER, "i32"); + const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + this._children = new Array(count); + if (count > 0) { + let address = buffer; + for (let i2 = 0; i2 < count; i2++) { + this._children[i2] = unmarshalNode(this.tree, address); + address += SIZE_OF_NODE; + } + C._free(buffer); + } + } + return this._children; + } + /** + * Iterate over this node's named children. + * + * See also {@link Node#children}. + */ + get namedChildren() { + if (!this._namedChildren) { + marshalNode(this); + C._ts_node_named_children_wasm(this.tree[0]); + const count = C.getValue(TRANSFER_BUFFER, "i32"); + const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + this._namedChildren = new Array(count); + if (count > 0) { + let address = buffer; + for (let i2 = 0; i2 < count; i2++) { + this._namedChildren[i2] = unmarshalNode(this.tree, address); + address += SIZE_OF_NODE; + } + C._free(buffer); + } + } + return this._namedChildren; + } + /** + * Get the descendants of this node that are the given type, or in the given types array. + * + * The types array should contain node type strings, which can be retrieved from {@link Language#types}. + * + * Additionally, a `startPosition` and `endPosition` can be passed in to restrict the search to a byte range. + */ + descendantsOfType(types, startPosition = ZERO_POINT, endPosition = ZERO_POINT) { + if (!Array.isArray(types)) types = [types]; + const symbols = []; + const typesBySymbol = this.tree.language.types; + for (let i2 = 0, n = typesBySymbol.length; i2 < n; i2++) { + if (types.includes(typesBySymbol[i2])) { + symbols.push(i2); + } + } + const symbolsAddress = C._malloc(SIZE_OF_INT * symbols.length); + for (let i2 = 0, n = symbols.length; i2 < n; i2++) { + C.setValue(symbolsAddress + i2 * SIZE_OF_INT, symbols[i2], "i32"); + } + marshalNode(this); + C._ts_node_descendants_of_type_wasm( + this.tree[0], + symbolsAddress, + symbols.length, + startPosition.row, + startPosition.column, + endPosition.row, + endPosition.column + ); + const descendantCount = C.getValue(TRANSFER_BUFFER, "i32"); + const descendantAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32"); + const result = new Array(descendantCount); + if (descendantCount > 0) { + let address = descendantAddress; + for (let i2 = 0; i2 < descendantCount; i2++) { + result[i2] = unmarshalNode(this.tree, address); + address += SIZE_OF_NODE; + } + } + C._free(descendantAddress); + C._free(symbolsAddress); + return result; + } + /** Get this node's next sibling. */ + get nextSibling() { + marshalNode(this); + C._ts_node_next_sibling_wasm(this.tree[0]); + return unmarshalNode(this.tree); + } + /** Get this node's previous sibling. */ + get previousSibling() { + marshalNode(this); + C._ts_node_prev_sibling_wasm(this.tree[0]); + return unmarshalNode(this.tree); + } + /** + * Get this node's next *named* sibling. + * + * See also {@link Node#isNamed}. + */ + get nextNamedSibling() { + marshalNode(this); + C._ts_node_next_named_sibling_wasm(this.tree[0]); + return unmarshalNode(this.tree); + } + /** + * Get this node's previous *named* sibling. + * + * See also {@link Node#isNamed}. + */ + get previousNamedSibling() { + marshalNode(this); + C._ts_node_prev_named_sibling_wasm(this.tree[0]); + return unmarshalNode(this.tree); + } + /** Get the node's number of descendants, including one for the node itself. */ + get descendantCount() { + marshalNode(this); + return C._ts_node_descendant_count_wasm(this.tree[0]); + } + /** + * Get this node's immediate parent. + * Prefer {@link Node#childWithDescendant} for iterating over this node's ancestors. + */ + get parent() { + marshalNode(this); + C._ts_node_parent_wasm(this.tree[0]); + return unmarshalNode(this.tree); + } + /** + * Get the node that contains `descendant`. + * + * Note that this can return `descendant` itself. + */ + childWithDescendant(descendant) { + marshalNode(this); + marshalNode(descendant); + C._ts_node_child_with_descendant_wasm(this.tree[0]); + return unmarshalNode(this.tree); + } + /** Get the smallest node within this node that spans the given byte range. */ + descendantForIndex(start2, end = start2) { + if (typeof start2 !== "number" || typeof end !== "number") { + throw new Error("Arguments must be numbers"); + } + marshalNode(this); + const address = TRANSFER_BUFFER + SIZE_OF_NODE; + C.setValue(address, start2, "i32"); + C.setValue(address + SIZE_OF_INT, end, "i32"); + C._ts_node_descendant_for_index_wasm(this.tree[0]); + return unmarshalNode(this.tree); + } + /** Get the smallest named node within this node that spans the given byte range. */ + namedDescendantForIndex(start2, end = start2) { + if (typeof start2 !== "number" || typeof end !== "number") { + throw new Error("Arguments must be numbers"); + } + marshalNode(this); + const address = TRANSFER_BUFFER + SIZE_OF_NODE; + C.setValue(address, start2, "i32"); + C.setValue(address + SIZE_OF_INT, end, "i32"); + C._ts_node_named_descendant_for_index_wasm(this.tree[0]); + return unmarshalNode(this.tree); + } + /** Get the smallest node within this node that spans the given point range. */ + descendantForPosition(start2, end = start2) { + if (!isPoint(start2) || !isPoint(end)) { + throw new Error("Arguments must be {row, column} objects"); + } + marshalNode(this); + const address = TRANSFER_BUFFER + SIZE_OF_NODE; + marshalPoint(address, start2); + marshalPoint(address + SIZE_OF_POINT, end); + C._ts_node_descendant_for_position_wasm(this.tree[0]); + return unmarshalNode(this.tree); + } + /** Get the smallest named node within this node that spans the given point range. */ + namedDescendantForPosition(start2, end = start2) { + if (!isPoint(start2) || !isPoint(end)) { + throw new Error("Arguments must be {row, column} objects"); + } + marshalNode(this); + const address = TRANSFER_BUFFER + SIZE_OF_NODE; + marshalPoint(address, start2); + marshalPoint(address + SIZE_OF_POINT, end); + C._ts_node_named_descendant_for_position_wasm(this.tree[0]); + return unmarshalNode(this.tree); + } + /** + * Create a new {@link TreeCursor} starting from this node. + * + * Note that the given node is considered the root of the cursor, + * and the cursor cannot walk outside this node. + */ + walk() { + marshalNode(this); + C._ts_tree_cursor_new_wasm(this.tree[0]); + return new TreeCursor(INTERNAL, this.tree); + } + /** + * Edit this node to keep it in-sync with source code that has been edited. + * + * This function is only rarely needed. When you edit a syntax tree with + * the {@link Tree#edit} method, all of the nodes that you retrieve from + * the tree afterward will already reflect the edit. You only need to + * use {@link Node#edit} when you have a specific {@link Node} instance that + * you want to keep and continue to use after an edit. + */ + edit(edit) { + if (this.startIndex >= edit.oldEndIndex) { + this.startIndex = edit.newEndIndex + (this.startIndex - edit.oldEndIndex); + let subbedPointRow; + let subbedPointColumn; + if (this.startPosition.row > edit.oldEndPosition.row) { + subbedPointRow = this.startPosition.row - edit.oldEndPosition.row; + subbedPointColumn = this.startPosition.column; + } else { + subbedPointRow = 0; + subbedPointColumn = this.startPosition.column; + if (this.startPosition.column >= edit.oldEndPosition.column) { + subbedPointColumn = this.startPosition.column - edit.oldEndPosition.column; + } + } + if (subbedPointRow > 0) { + this.startPosition.row += subbedPointRow; + this.startPosition.column = subbedPointColumn; + } else { + this.startPosition.column += subbedPointColumn; + } + } else if (this.startIndex > edit.startIndex) { + this.startIndex = edit.newEndIndex; + this.startPosition.row = edit.newEndPosition.row; + this.startPosition.column = edit.newEndPosition.column; + } + } + /** Get the S-expression representation of this node. */ + toString() { + marshalNode(this); + const address = C._ts_node_to_string_wasm(this.tree[0]); + const result = C.AsciiToString(address); + C._free(address); + return result; + } +}; + +// src/marshal.ts +function unmarshalCaptures(query, tree, address, result) { + for (let i2 = 0, n = result.length; i2 < n; i2++) { + const captureIndex = C.getValue(address, "i32"); + address += SIZE_OF_INT; + const node = unmarshalNode(tree, address); + address += SIZE_OF_NODE; + result[i2] = { name: query.captureNames[captureIndex], node }; + } + return address; +} +__name(unmarshalCaptures, "unmarshalCaptures"); +function marshalNode(node) { + let address = TRANSFER_BUFFER; + C.setValue(address, node.id, "i32"); + address += SIZE_OF_INT; + C.setValue(address, node.startIndex, "i32"); + address += SIZE_OF_INT; + C.setValue(address, node.startPosition.row, "i32"); + address += SIZE_OF_INT; + C.setValue(address, node.startPosition.column, "i32"); + address += SIZE_OF_INT; + C.setValue(address, node[0], "i32"); +} +__name(marshalNode, "marshalNode"); +function unmarshalNode(tree, address = TRANSFER_BUFFER) { + const id = C.getValue(address, "i32"); + address += SIZE_OF_INT; + if (id === 0) return null; + const index = C.getValue(address, "i32"); + address += SIZE_OF_INT; + const row = C.getValue(address, "i32"); + address += SIZE_OF_INT; + const column = C.getValue(address, "i32"); + address += SIZE_OF_INT; + const other = C.getValue(address, "i32"); + const result = new Node(INTERNAL, { + id, + tree, + startIndex: index, + startPosition: { row, column }, + other + }); + return result; +} +__name(unmarshalNode, "unmarshalNode"); +function marshalTreeCursor(cursor, address = TRANSFER_BUFFER) { + C.setValue(address + 0 * SIZE_OF_INT, cursor[0], "i32"); + C.setValue(address + 1 * SIZE_OF_INT, cursor[1], "i32"); + C.setValue(address + 2 * SIZE_OF_INT, cursor[2], "i32"); + C.setValue(address + 3 * SIZE_OF_INT, cursor[3], "i32"); +} +__name(marshalTreeCursor, "marshalTreeCursor"); +function unmarshalTreeCursor(cursor) { + cursor[0] = C.getValue(TRANSFER_BUFFER + 0 * SIZE_OF_INT, "i32"); + cursor[1] = C.getValue(TRANSFER_BUFFER + 1 * SIZE_OF_INT, "i32"); + cursor[2] = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32"); + cursor[3] = C.getValue(TRANSFER_BUFFER + 3 * SIZE_OF_INT, "i32"); +} +__name(unmarshalTreeCursor, "unmarshalTreeCursor"); +function marshalPoint(address, point) { + C.setValue(address, point.row, "i32"); + C.setValue(address + SIZE_OF_INT, point.column, "i32"); +} +__name(marshalPoint, "marshalPoint"); +function unmarshalPoint(address) { + const result = { + row: C.getValue(address, "i32") >>> 0, + column: C.getValue(address + SIZE_OF_INT, "i32") >>> 0 + }; + return result; +} +__name(unmarshalPoint, "unmarshalPoint"); +function marshalRange(address, range) { + marshalPoint(address, range.startPosition); + address += SIZE_OF_POINT; + marshalPoint(address, range.endPosition); + address += SIZE_OF_POINT; + C.setValue(address, range.startIndex, "i32"); + address += SIZE_OF_INT; + C.setValue(address, range.endIndex, "i32"); + address += SIZE_OF_INT; +} +__name(marshalRange, "marshalRange"); +function unmarshalRange(address) { + const result = {}; + result.startPosition = unmarshalPoint(address); + address += SIZE_OF_POINT; + result.endPosition = unmarshalPoint(address); + address += SIZE_OF_POINT; + result.startIndex = C.getValue(address, "i32") >>> 0; + address += SIZE_OF_INT; + result.endIndex = C.getValue(address, "i32") >>> 0; + return result; +} +__name(unmarshalRange, "unmarshalRange"); +function marshalEdit(edit, address = TRANSFER_BUFFER) { + marshalPoint(address, edit.startPosition); + address += SIZE_OF_POINT; + marshalPoint(address, edit.oldEndPosition); + address += SIZE_OF_POINT; + marshalPoint(address, edit.newEndPosition); + address += SIZE_OF_POINT; + C.setValue(address, edit.startIndex, "i32"); + address += SIZE_OF_INT; + C.setValue(address, edit.oldEndIndex, "i32"); + address += SIZE_OF_INT; + C.setValue(address, edit.newEndIndex, "i32"); + address += SIZE_OF_INT; +} +__name(marshalEdit, "marshalEdit"); +export { + C, + CaptureQuantifier, + INTERNAL, + LANGUAGE_VERSION, + Language, + LookaheadIterator, + MIN_COMPATIBLE_VERSION, + Node, + Parser, + Query, + SIZE_OF_CURSOR, + SIZE_OF_INT, + SIZE_OF_NODE, + SIZE_OF_POINT, + SIZE_OF_RANGE, + SIZE_OF_SHORT, + TRANSFER_BUFFER, + Tree, + TreeCursor, + ZERO_POINT, + assertInternal, + getText, + isPoint, + marshalEdit, + marshalNode, + marshalPoint, + marshalRange, + marshalTreeCursor, + setModule, + unmarshalCaptures, + unmarshalNode, + unmarshalPoint, + unmarshalRange, + unmarshalTreeCursor +}; +//# sourceMappingURL=tree-sitter.js.map