@mnemonik/cli 0.0.0 → 7.99.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/LICENSE +38 -0
  2. package/dist/auth/credentials.d.ts +38 -0
  3. package/dist/auth/credentials.d.ts.map +1 -0
  4. package/dist/auth/credentials.js +7464 -0
  5. package/dist/auth/credentials.js.map +1 -0
  6. package/dist/auth/device.d.ts +23 -0
  7. package/dist/auth/device.d.ts.map +1 -0
  8. package/dist/auth/device.js +108 -0
  9. package/dist/auth/device.js.map +1 -0
  10. package/dist/auth/index.d.ts +34 -0
  11. package/dist/auth/index.d.ts.map +1 -0
  12. package/dist/auth/index.js +5048 -0
  13. package/dist/auth/index.js.map +1 -0
  14. package/dist/auth/installSession.d.ts +22 -0
  15. package/dist/auth/installSession.d.ts.map +1 -0
  16. package/dist/auth/installSession.js +4717 -0
  17. package/dist/auth/installSession.js.map +1 -0
  18. package/dist/auth/pkce.d.ts +35 -0
  19. package/dist/auth/pkce.d.ts.map +1 -0
  20. package/dist/auth/pkce.js +182 -0
  21. package/dist/auth/pkce.js.map +1 -0
  22. package/dist/auth/status.d.ts +30 -0
  23. package/dist/auth/status.d.ts.map +1 -0
  24. package/dist/auth/status.js +4799 -0
  25. package/dist/auth/status.js.map +1 -0
  26. package/dist/bin.d.ts +3 -0
  27. package/dist/bin.d.ts.map +1 -0
  28. package/dist/bin.js +28 -0
  29. package/dist/bin.js.map +1 -0
  30. package/dist/diagnostics.d.ts +42 -0
  31. package/dist/diagnostics.d.ts.map +1 -0
  32. package/dist/diagnostics.js +7405 -0
  33. package/dist/diagnostics.js.map +1 -0
  34. package/dist/digests.json +175 -0
  35. package/dist/identity/migrate.d.ts +62 -0
  36. package/dist/identity/migrate.d.ts.map +1 -0
  37. package/dist/identity/migrate.js +5416 -0
  38. package/dist/identity/migrate.js.map +1 -0
  39. package/dist/index.d.ts +9 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +11 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/install/adapters.d.ts +65 -0
  44. package/dist/install/adapters.d.ts.map +1 -0
  45. package/dist/install/adapters.js +91 -0
  46. package/dist/install/adapters.js.map +1 -0
  47. package/dist/install/hosts.d.ts +83 -0
  48. package/dist/install/hosts.d.ts.map +1 -0
  49. package/dist/install/hosts.js +5733 -0
  50. package/dist/install/hosts.js.map +1 -0
  51. package/dist/install/journal.d.ts +113 -0
  52. package/dist/install/journal.d.ts.map +1 -0
  53. package/dist/install/journal.js +6836 -0
  54. package/dist/install/journal.js.map +1 -0
  55. package/dist/install/journey.d.ts +11 -0
  56. package/dist/install/journey.d.ts.map +1 -0
  57. package/dist/install/journey.js +5594 -0
  58. package/dist/install/journey.js.map +1 -0
  59. package/dist/install/ownership.d.ts +55 -0
  60. package/dist/install/ownership.d.ts.map +1 -0
  61. package/dist/install/ownership.js +4942 -0
  62. package/dist/install/ownership.js.map +1 -0
  63. package/dist/install/transaction.d.ts +71 -0
  64. package/dist/install/transaction.d.ts.map +1 -0
  65. package/dist/install/transaction.js +5254 -0
  66. package/dist/install/transaction.js.map +1 -0
  67. package/dist/install/ui.d.ts +14 -0
  68. package/dist/install/ui.d.ts.map +1 -0
  69. package/dist/install/ui.js +4925 -0
  70. package/dist/install/ui.js.map +1 -0
  71. package/dist/installSession.d.ts +33 -0
  72. package/dist/installSession.d.ts.map +1 -0
  73. package/dist/installSession.js +4893 -0
  74. package/dist/installSession.js.map +1 -0
  75. package/dist/installation.d.ts +11 -0
  76. package/dist/installation.d.ts.map +1 -0
  77. package/dist/installation.js +6618 -0
  78. package/dist/installation.js.map +1 -0
  79. package/dist/launcher.d.ts +27 -0
  80. package/dist/launcher.d.ts.map +1 -0
  81. package/dist/launcher.js +6862 -0
  82. package/dist/launcher.js.map +1 -0
  83. package/dist/output.d.ts +22 -0
  84. package/dist/output.d.ts.map +1 -0
  85. package/dist/output.js +68 -0
  86. package/dist/output.js.map +1 -0
  87. package/dist/preflight.d.ts +43 -0
  88. package/dist/preflight.d.ts.map +1 -0
  89. package/dist/preflight.js +5265 -0
  90. package/dist/preflight.js.map +1 -0
  91. package/dist/project/eligibility.d.ts +19 -0
  92. package/dist/project/eligibility.d.ts.map +1 -0
  93. package/dist/project/eligibility.js +4835 -0
  94. package/dist/project/eligibility.js.map +1 -0
  95. package/dist/project/records.d.ts +14 -0
  96. package/dist/project/records.d.ts.map +1 -0
  97. package/dist/project/records.js +6598 -0
  98. package/dist/project/records.js.map +1 -0
  99. package/dist/project.d.ts +127 -0
  100. package/dist/project.d.ts.map +1 -0
  101. package/dist/project.js +7857 -0
  102. package/dist/project.js.map +1 -0
  103. package/dist/router.d.ts +63 -0
  104. package/dist/router.d.ts.map +1 -0
  105. package/dist/router.js +6168 -0
  106. package/dist/router.js.map +1 -0
  107. package/dist/runtime/bootstrap.d.ts +31 -0
  108. package/dist/runtime/bootstrap.d.ts.map +1 -0
  109. package/dist/runtime/bootstrap.js +386 -0
  110. package/dist/runtime/bootstrap.js.map +1 -0
  111. package/dist/runtime/releaseSource.d.ts +26 -0
  112. package/dist/runtime/releaseSource.d.ts.map +1 -0
  113. package/dist/runtime/releaseSource.js +4992 -0
  114. package/dist/runtime/releaseSource.js.map +1 -0
  115. package/dist/runtime/selfUpdate.d.ts +12 -0
  116. package/dist/runtime/selfUpdate.d.ts.map +1 -0
  117. package/dist/runtime/selfUpdate.js +4943 -0
  118. package/dist/runtime/selfUpdate.js.map +1 -0
  119. package/dist/runtime/signers.d.ts +2 -0
  120. package/dist/runtime/signers.d.ts.map +1 -0
  121. package/dist/runtime/signers.js +1697 -0
  122. package/dist/runtime/signers.js.map +1 -0
  123. package/dist/runtime/store.d.ts +30 -0
  124. package/dist/runtime/store.d.ts.map +1 -0
  125. package/dist/runtime/store.js +977 -0
  126. package/dist/runtime/store.js.map +1 -0
  127. package/dist/sbom.json +308 -0
  128. package/dist/scanner/control.d.ts +38 -0
  129. package/dist/scanner/control.d.ts.map +1 -0
  130. package/dist/scanner/control.js +6568 -0
  131. package/dist/scanner/control.js.map +1 -0
  132. package/dist/scanner/data.d.ts +9 -0
  133. package/dist/scanner/data.d.ts.map +1 -0
  134. package/dist/scanner/data.js +4715 -0
  135. package/dist/scanner/data.js.map +1 -0
  136. package/dist/scanner/discover.d.ts +35 -0
  137. package/dist/scanner/discover.d.ts.map +1 -0
  138. package/dist/scanner/discover.js +5266 -0
  139. package/dist/scanner/discover.js.map +1 -0
  140. package/dist/scanner/enable.d.ts +69 -0
  141. package/dist/scanner/enable.d.ts.map +1 -0
  142. package/dist/scanner/enable.js +6923 -0
  143. package/dist/scanner/enable.js.map +1 -0
  144. package/dist/scanner/picker.d.ts +58 -0
  145. package/dist/scanner/picker.d.ts.map +1 -0
  146. package/dist/scanner/picker.js +4993 -0
  147. package/dist/scanner/picker.js.map +1 -0
  148. package/dist/scanner/service.d.ts +49 -0
  149. package/dist/scanner/service.d.ts.map +1 -0
  150. package/dist/scanner/service.js +4888 -0
  151. package/dist/scanner/service.js.map +1 -0
  152. package/dist/scanner/update.d.ts +4 -0
  153. package/dist/scanner/update.d.ts.map +1 -0
  154. package/dist/scanner/update.js +6569 -0
  155. package/dist/scanner/update.js.map +1 -0
  156. package/dist/scanner-release.json +129 -0
  157. package/dist/screens/journey.d.ts +23 -0
  158. package/dist/screens/journey.d.ts.map +1 -0
  159. package/dist/screens/journey.js +110 -0
  160. package/dist/screens/journey.js.map +1 -0
  161. package/dist/screens.d.ts +18 -0
  162. package/dist/screens.d.ts.map +1 -0
  163. package/dist/screens.js +79 -0
  164. package/dist/screens.js.map +1 -0
  165. package/dist/status.d.ts +64 -0
  166. package/dist/status.d.ts.map +1 -0
  167. package/dist/status.js +5281 -0
  168. package/dist/status.js.map +1 -0
  169. package/dist/transport/server.d.ts +79 -0
  170. package/dist/transport/server.d.ts.map +1 -0
  171. package/dist/transport/server.js +136 -0
  172. package/dist/transport/server.js.map +1 -0
  173. package/dist/vendor/local-setup.js +6971 -0
  174. package/dist/vendor/shared/runtimeReader.js +408 -0
  175. package/dist/vendor/shared/runtimeSigners.js +512 -0
  176. package/package.json +258 -7
  177. package/README.md +0 -3
@@ -0,0 +1,4835 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res, err2) => function __init() {
9
+ if (err2) throw err2[0];
10
+ try {
11
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
+ } catch (e) {
13
+ throw err2 = [e], e;
14
+ }
15
+ };
16
+ var __commonJS = (cb, mod) => function __require() {
17
+ try {
18
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
19
+ } catch (e) {
20
+ throw mod = 0, e;
21
+ }
22
+ };
23
+ var __copyProps = (to, from, except, desc) => {
24
+ if (from && typeof from === "object" || typeof from === "function") {
25
+ for (let key of __getOwnPropNames(from))
26
+ if (!__hasOwnProp.call(to, key) && key !== except)
27
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
28
+ }
29
+ return to;
30
+ };
31
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
+ // If the importer is in node compatibility mode or this is not an ESM
33
+ // file that has been converted to a CommonJS file using a Babel-
34
+ // compatible transform (i.e. "__esModule" has not been set), then set
35
+ // "default" to the CommonJS "module.exports" for node compatibility.
36
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
+ mod
38
+ ));
39
+
40
+ // node_modules/ignore/index.js
41
+ var require_ignore = __commonJS({
42
+ "node_modules/ignore/index.js"(exports, module2) {
43
+ function makeArray(subject) {
44
+ return Array.isArray(subject) ? subject : [subject];
45
+ }
46
+ var UNDEFINED = void 0;
47
+ var EMPTY = "";
48
+ var SPACE = " ";
49
+ var ESCAPE = "\\";
50
+ var REGEX_TEST_BLANK_LINE = /^\s+$/;
51
+ var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
52
+ var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
53
+ var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
54
+ var REGEX_SPLITALL_CRLF = /\r?\n/g;
55
+ var REGEX_TEST_INVALID_PATH = /^\.{0,2}\/|^\.{1,2}$/;
56
+ var REGEX_TEST_TRAILING_SLASH = /\/$/;
57
+ var SLASH = "/";
58
+ var TMP_KEY_IGNORE = "node-ignore";
59
+ if (typeof Symbol !== "undefined") {
60
+ TMP_KEY_IGNORE = /* @__PURE__ */ Symbol.for("node-ignore");
61
+ }
62
+ var KEY_IGNORE = TMP_KEY_IGNORE;
63
+ var define = (object, key, value) => {
64
+ Object.defineProperty(object, key, { value });
65
+ return value;
66
+ };
67
+ var REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
68
+ var RETURN_FALSE = () => false;
69
+ var sanitizeRange = (range) => range.replace(
70
+ REGEX_REGEXP_RANGE,
71
+ (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0) ? match : EMPTY
72
+ );
73
+ var negateRange = (range) => range.startsWith("!") || range.startsWith("\\^") ? `^${range.slice(range[0] === "!" ? 1 : 2)}` : range;
74
+ var cleanRangeBackSlash = (slashes) => {
75
+ const { length } = slashes;
76
+ return slashes.slice(0, length - length % 2);
77
+ };
78
+ var REPLACERS = [
79
+ [
80
+ // Remove BOM
81
+ // TODO:
82
+ // Other similar zero-width characters?
83
+ /^\uFEFF/,
84
+ () => EMPTY
85
+ ],
86
+ // > Trailing spaces are ignored unless they are quoted with backslash ("\")
87
+ [
88
+ // (a\ ) -> (a )
89
+ // (a ) -> (a)
90
+ // (a ) -> (a)
91
+ // (a \ ) -> (a )
92
+ /((?:\\\\)*?)(\\?\s+)$/,
93
+ (_, m1, m2) => m1 + (m2.indexOf("\\") === 0 ? SPACE : EMPTY)
94
+ ],
95
+ // Replace (\ ) with ' '
96
+ // (\ ) -> ' '
97
+ // (\\ ) -> '\\ '
98
+ // (\\\ ) -> '\\ '
99
+ [
100
+ /(\\+?)\s/g,
101
+ (_, m1) => {
102
+ const { length } = m1;
103
+ return m1.slice(0, length - length % 2) + SPACE;
104
+ }
105
+ ],
106
+ // Escape metacharacters
107
+ // which is written down by users but means special for regular expressions.
108
+ // > There are 12 characters with special meanings:
109
+ // > - the backslash \,
110
+ // > - the caret ^,
111
+ // > - the dollar sign $,
112
+ // > - the period or dot .,
113
+ // > - the vertical bar or pipe symbol |,
114
+ // > - the question mark ?,
115
+ // > - the asterisk or star *,
116
+ // > - the plus sign +,
117
+ // > - the opening parenthesis (,
118
+ // > - the closing parenthesis ),
119
+ // > - and the opening square bracket [,
120
+ // > - the opening curly brace {,
121
+ // > These special characters are often called "metacharacters".
122
+ [
123
+ /[\\$.|*+(){^]/g,
124
+ (match) => `\\${match}`
125
+ ],
126
+ [
127
+ // > a question mark (?) matches a single character
128
+ /(?!\\)\?/g,
129
+ () => "[^/]"
130
+ ],
131
+ // leading slash
132
+ [
133
+ // > A leading slash matches the beginning of the pathname.
134
+ // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
135
+ // A leading slash matches the beginning of the pathname
136
+ /^\//,
137
+ () => "^"
138
+ ],
139
+ // replace special metacharacter slash after the leading slash
140
+ [
141
+ /\//g,
142
+ () => "\\/"
143
+ ],
144
+ [
145
+ // > A leading "**" followed by a slash means match in all directories.
146
+ // > For example, "**/foo" matches file or directory "foo" anywhere,
147
+ // > the same as pattern "foo".
148
+ // > "**/foo/bar" matches file or directory "bar" anywhere that is directly
149
+ // > under directory "foo".
150
+ // Notice that the '*'s have been replaced as '\\*'
151
+ /^\^*(?:\\\*\\\*\\\/)+/,
152
+ // '**/foo' <-> 'foo'
153
+ () => "^(?:.*\\/)?"
154
+ ],
155
+ // starting
156
+ [
157
+ // there will be no leading '/'
158
+ // (which has been replaced by section "leading slash")
159
+ // If starts with '**', adding a '^' to the regular expression also works
160
+ /^(?=[^^])/,
161
+ function startingReplacer() {
162
+ return !/\/(?!$)/.test(this) ? "(?:^|\\/)" : "^";
163
+ }
164
+ ],
165
+ // two globstars
166
+ [
167
+ // Use lookahead assertions so that we could match more than one `'/**'`
168
+ /\\\/\\\*\\\*(?=\\\/|$)/g,
169
+ // Zero, one or several directories
170
+ // should not use '*', or it will be replaced by the next replacer
171
+ // Check if it is not the last `'/**'`
172
+ (_, index, str) => index + 6 < str.length ? "(?:\\/[^\\/]+)*" : "\\/.+"
173
+ ],
174
+ // normal intermediate wildcards
175
+ [
176
+ // Never replace escaped '*'
177
+ // ignore rule '\*' will match the path '*'
178
+ // 'abc.*/' -> go
179
+ // 'abc.*' -> skip this rule,
180
+ // coz trailing single wildcard will be handed by [trailing wildcard]
181
+ /(^|[^\\]+)(\\\*)+(?=.+)/g,
182
+ // '*.js' matches '.js'
183
+ // '*.js' doesn't match 'abc'
184
+ (_, p1, p2) => {
185
+ const unescaped = p2.replace(/\\\*/g, "[^\\/]*");
186
+ return p1 + unescaped;
187
+ }
188
+ ],
189
+ [
190
+ // unescape, revert step 3 except for back slash
191
+ // For example, if a user escape a '\\*',
192
+ // after step 3, the result will be '\\\\\\*'
193
+ /\\\\\\(?=[$.|*+(){^])/g,
194
+ () => ESCAPE
195
+ ],
196
+ [
197
+ // '\\\\' -> '\\'
198
+ /\\\\/g,
199
+ () => ESCAPE
200
+ ],
201
+ [
202
+ // > The range notation, e.g. [a-zA-Z],
203
+ // > can be used to match one of the characters in a range.
204
+ // `\` is escaped by step 3
205
+ /(\\)?\[([^\]/]*?)(\\*)($|\])/g,
206
+ (match, leadEscape, range, endEscape, close) => leadEscape === ESCAPE ? `\\[${range}${cleanRangeBackSlash(endEscape)}${close}` : close === "]" ? endEscape.length % 2 === 0 ? `[${negateRange(sanitizeRange(range))}${endEscape}]` : "[]" : "[]"
207
+ ],
208
+ // ending
209
+ [
210
+ // 'js' will not match 'js.'
211
+ // 'ab' will not match 'abc'
212
+ /(?:[^*])$/,
213
+ // WTF!
214
+ // https://git-scm.com/docs/gitignore
215
+ // changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
216
+ // which re-fixes #24, #38
217
+ // > If there is a separator at the end of the pattern then the pattern
218
+ // > will only match directories, otherwise the pattern can match both
219
+ // > files and directories.
220
+ // 'js*' will not match 'a.js'
221
+ // 'js/' will not match 'a.js'
222
+ // 'js' will match 'a.js' and 'a.js/'
223
+ (match) => /\/$/.test(match) ? `${match}$` : `${match}(?=$|\\/$)`
224
+ ]
225
+ ];
226
+ var REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\\\*$/;
227
+ var MODE_IGNORE = "regex";
228
+ var MODE_CHECK_IGNORE = "checkRegex";
229
+ var UNDERSCORE = "_";
230
+ var TRAILING_WILD_CARD_REPLACERS = {
231
+ [MODE_IGNORE](_, p1) {
232
+ const prefix = p1 ? `${p1}[^/]+` : "[^/]*";
233
+ return `${prefix}(?=$|\\/$)`;
234
+ },
235
+ [MODE_CHECK_IGNORE](_, p1) {
236
+ const prefix = p1 ? `${p1}[^/]*` : "[^/]*";
237
+ return `${prefix}(?=$|\\/$)`;
238
+ }
239
+ };
240
+ var makeRegexPrefix = (pattern) => REPLACERS.reduce(
241
+ (prev, [matcher, replacer]) => prev.replace(matcher, replacer.bind(pattern)),
242
+ pattern
243
+ );
244
+ var isString = (subject) => typeof subject === "string";
245
+ var checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) && pattern.indexOf("#") !== 0;
246
+ var splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
247
+ var IgnoreRule = class {
248
+ constructor(pattern, mark, body2, ignoreCase, negative, prefix) {
249
+ this.pattern = pattern;
250
+ this.mark = mark;
251
+ this.negative = negative;
252
+ define(this, "body", body2);
253
+ define(this, "ignoreCase", ignoreCase);
254
+ define(this, "regexPrefix", prefix);
255
+ }
256
+ get regex() {
257
+ const key = UNDERSCORE + MODE_IGNORE;
258
+ if (this[key]) {
259
+ return this[key];
260
+ }
261
+ return this._make(MODE_IGNORE, key);
262
+ }
263
+ get checkRegex() {
264
+ const key = UNDERSCORE + MODE_CHECK_IGNORE;
265
+ if (this[key]) {
266
+ return this[key];
267
+ }
268
+ return this._make(MODE_CHECK_IGNORE, key);
269
+ }
270
+ _make(mode, key) {
271
+ const str = this.regexPrefix.replace(
272
+ REGEX_REPLACE_TRAILING_WILDCARD,
273
+ // It does not need to bind pattern
274
+ TRAILING_WILD_CARD_REPLACERS[mode]
275
+ );
276
+ const regex = this.ignoreCase ? new RegExp(str, "i") : new RegExp(str);
277
+ return define(this, key, regex);
278
+ }
279
+ };
280
+ var createRule = ({
281
+ pattern,
282
+ mark
283
+ }, ignoreCase) => {
284
+ let negative = false;
285
+ let body2 = pattern;
286
+ if (body2.indexOf("!") === 0) {
287
+ negative = true;
288
+ body2 = body2.substr(1);
289
+ }
290
+ body2 = body2.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, "!").replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, "#");
291
+ const regexPrefix = makeRegexPrefix(body2);
292
+ return new IgnoreRule(
293
+ pattern,
294
+ mark,
295
+ body2,
296
+ ignoreCase,
297
+ negative,
298
+ regexPrefix
299
+ );
300
+ };
301
+ var RuleManager = class {
302
+ constructor(ignoreCase) {
303
+ this._ignoreCase = ignoreCase;
304
+ this._rules = [];
305
+ }
306
+ _add(pattern) {
307
+ if (pattern && pattern[KEY_IGNORE]) {
308
+ this._rules = this._rules.concat(pattern._rules._rules);
309
+ this._added = true;
310
+ return;
311
+ }
312
+ if (isString(pattern)) {
313
+ pattern = {
314
+ pattern
315
+ };
316
+ }
317
+ if (checkPattern(pattern.pattern)) {
318
+ const rule = createRule(pattern, this._ignoreCase);
319
+ this._added = true;
320
+ this._rules.push(rule);
321
+ }
322
+ }
323
+ // @param {Array<string> | string | Ignore} pattern
324
+ add(pattern) {
325
+ this._added = false;
326
+ makeArray(
327
+ isString(pattern) ? splitPattern(pattern) : pattern
328
+ ).forEach(this._add, this);
329
+ return this._added;
330
+ }
331
+ // Test one single path without recursively checking parent directories
332
+ //
333
+ // - checkUnignored `boolean` whether should check if the path is unignored,
334
+ // setting `checkUnignored` to `false` could reduce additional
335
+ // path matching.
336
+ // - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
337
+ // @returns {TestResult} true if a file is ignored
338
+ test(path, checkUnignored, mode) {
339
+ let ignored = false;
340
+ let unignored = false;
341
+ let matchedRule;
342
+ this._rules.forEach((rule) => {
343
+ const { negative } = rule;
344
+ if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
345
+ return;
346
+ }
347
+ const matched = rule[mode].test(path);
348
+ if (!matched) {
349
+ return;
350
+ }
351
+ ignored = !negative;
352
+ unignored = negative;
353
+ matchedRule = negative ? UNDEFINED : rule;
354
+ });
355
+ const ret = {
356
+ ignored,
357
+ unignored
358
+ };
359
+ if (matchedRule) {
360
+ ret.rule = matchedRule;
361
+ }
362
+ return ret;
363
+ }
364
+ };
365
+ var throwError = (message, Ctor) => {
366
+ throw new Ctor(message);
367
+ };
368
+ var checkPath = (path, originalPath, doThrow) => {
369
+ if (!isString(path)) {
370
+ return doThrow(
371
+ `path must be a string, but got \`${originalPath}\``,
372
+ TypeError
373
+ );
374
+ }
375
+ if (!path) {
376
+ return doThrow(`path must not be empty`, TypeError);
377
+ }
378
+ if (checkPath.isNotRelative(path)) {
379
+ const r = "`path.relative()`d";
380
+ return doThrow(
381
+ `path should be a ${r} string, but got "${originalPath}"`,
382
+ RangeError
383
+ );
384
+ }
385
+ return true;
386
+ };
387
+ var isNotRelative = (path) => REGEX_TEST_INVALID_PATH.test(path);
388
+ checkPath.isNotRelative = isNotRelative;
389
+ checkPath.convert = (p) => p;
390
+ var Ignore = class {
391
+ constructor({
392
+ ignorecase = true,
393
+ ignoreCase = ignorecase,
394
+ allowRelativePaths = false
395
+ } = {}) {
396
+ define(this, KEY_IGNORE, true);
397
+ this._rules = new RuleManager(ignoreCase);
398
+ this._strictPathCheck = !allowRelativePaths;
399
+ this._initCache();
400
+ }
401
+ _initCache() {
402
+ this._ignoreCache = /* @__PURE__ */ Object.create(null);
403
+ this._testCache = /* @__PURE__ */ Object.create(null);
404
+ }
405
+ add(pattern) {
406
+ if (this._rules.add(pattern)) {
407
+ this._initCache();
408
+ }
409
+ return this;
410
+ }
411
+ // legacy
412
+ addPattern(pattern) {
413
+ return this.add(pattern);
414
+ }
415
+ // @returns {TestResult}
416
+ _test(originalPath, cache, checkUnignored, slices) {
417
+ const path = originalPath && checkPath.convert(originalPath);
418
+ checkPath(
419
+ path,
420
+ originalPath,
421
+ this._strictPathCheck ? throwError : RETURN_FALSE
422
+ );
423
+ return this._t(path, cache, checkUnignored, slices);
424
+ }
425
+ checkIgnore(path) {
426
+ if (!REGEX_TEST_TRAILING_SLASH.test(path)) {
427
+ return this.test(path);
428
+ }
429
+ const slices = path.split(SLASH).filter(Boolean);
430
+ slices.pop();
431
+ if (slices.length) {
432
+ const parent = this._t(
433
+ slices.join(SLASH) + SLASH,
434
+ this._testCache,
435
+ true,
436
+ slices
437
+ );
438
+ if (parent.ignored) {
439
+ return parent;
440
+ }
441
+ }
442
+ return this._rules.test(path, false, MODE_CHECK_IGNORE);
443
+ }
444
+ _t(path, cache, checkUnignored, slices) {
445
+ if (path in cache) {
446
+ return cache[path];
447
+ }
448
+ if (!slices) {
449
+ slices = path.split(SLASH).filter(Boolean);
450
+ }
451
+ slices.pop();
452
+ if (!slices.length) {
453
+ return cache[path] = this._rules.test(path, checkUnignored, MODE_IGNORE);
454
+ }
455
+ const parent = this._t(
456
+ slices.join(SLASH) + SLASH,
457
+ cache,
458
+ checkUnignored,
459
+ slices
460
+ );
461
+ return cache[path] = parent.ignored ? parent : this._rules.test(path, checkUnignored, MODE_IGNORE);
462
+ }
463
+ ignores(path) {
464
+ return this._test(path, this._ignoreCache, false).ignored;
465
+ }
466
+ createFilter() {
467
+ return (path) => !this.ignores(path);
468
+ }
469
+ filter(paths) {
470
+ return makeArray(paths).filter(this.createFilter());
471
+ }
472
+ // @returns {TestResult}
473
+ test(path) {
474
+ return this._test(path, this._testCache, true);
475
+ }
476
+ };
477
+ var factory = (options) => new Ignore(options);
478
+ var isPathValid = (path) => checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
479
+ var setupWindows = () => {
480
+ const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
481
+ checkPath.convert = makePosix;
482
+ const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
483
+ checkPath.isNotRelative = (path) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
484
+ };
485
+ if (
486
+ // Detect `process` so that it can run in browsers.
487
+ typeof process !== "undefined" && process.platform === "win32"
488
+ ) {
489
+ setupWindows();
490
+ }
491
+ module2.exports = factory;
492
+ factory.default = factory;
493
+ module2.exports.isPathValid = isPathValid;
494
+ define(module2.exports, /* @__PURE__ */ Symbol.for("setupWindows"), setupWindows);
495
+ }
496
+ });
497
+
498
+ // packages/shared/dist/runtimeSigners.js
499
+ var ttl;
500
+ var init_runtimeSigners = __esm({
501
+ "packages/shared/dist/runtimeSigners.js"() {
502
+ "use strict";
503
+ ttl = 10 * 6e4;
504
+ }
505
+ });
506
+
507
+ // packages/shared/dist/repositoryFingerprint.js
508
+ var REPOSITORY_PROVIDER_RULES, controls;
509
+ var init_repositoryFingerprint = __esm({
510
+ "packages/shared/dist/repositoryFingerprint.js"() {
511
+ "use strict";
512
+ REPOSITORY_PROVIDER_RULES = Object.freeze([
513
+ Object.freeze({ name: "github", host: "github.com", sshUser: "git", removeTerminalDotGit: true })
514
+ ]);
515
+ controls = new RegExp("\\p{Cc}", "u");
516
+ }
517
+ });
518
+
519
+ // packages/shared/dist/projectIdentityFile.js
520
+ var init_projectIdentityFile = __esm({
521
+ "packages/shared/dist/projectIdentityFile.js"() {
522
+ "use strict";
523
+ }
524
+ });
525
+
526
+ // packages/shared/dist/repositoryRoot.js
527
+ var init_repositoryRoot = __esm({
528
+ "packages/shared/dist/repositoryRoot.js"() {
529
+ "use strict";
530
+ init_projectIdentityFile();
531
+ }
532
+ });
533
+
534
+ // packages/shared/dist/runtimeReader.js
535
+ var init_runtimeReader = __esm({
536
+ "packages/shared/dist/runtimeReader.js"() {
537
+ "use strict";
538
+ init_runtimeSigners();
539
+ init_runtimeSigners();
540
+ }
541
+ });
542
+
543
+ // packages/shared/dist/projectSetupHandoff.js
544
+ var init_projectSetupHandoff = __esm({
545
+ "packages/shared/dist/projectSetupHandoff.js"() {
546
+ "use strict";
547
+ init_runtimeSigners();
548
+ init_runtimeReader();
549
+ }
550
+ });
551
+
552
+ // packages/shared/dist/hookRuntime.js
553
+ var init_hookRuntime = __esm({
554
+ "packages/shared/dist/hookRuntime.js"() {
555
+ "use strict";
556
+ init_runtimeSigners();
557
+ init_repositoryRoot();
558
+ init_runtimeReader();
559
+ init_runtimeSigners();
560
+ init_projectSetupHandoff();
561
+ }
562
+ });
563
+
564
+ // packages/cli/src/project/eligibility.ts
565
+ import { lstat, readdir, realpath } from "node:fs/promises";
566
+ import { homedir as homedir2, tmpdir } from "node:os";
567
+ import { join as join3, posix as posix2, win32 as win322 } from "node:path";
568
+
569
+ // packages/shared/dist/instructions.js
570
+ var INSTRUCTIONS_CONTENT = `Mnemonik provides persistent project memory: decisions, rationale, tasks, and policies across sessions. If no block begins "PROJECT_CONTEXT schemaVersion=", session_bootstrap({ cwd }) loads project context when cwd is the real absolute path of the project root; a placeholder or relative path fails. With that block, context is loaded and no session_bootstrap call is needed. Code and docs show current artifacts, git shows changes, and memory carries the why; memory_search recalls rationale or intent, then Grep or Read verifies current source.
571
+
572
+ memory_discover supplies exact schemas and examples for unfamiliar or action-based methods; memory_tools runs their async JavaScript.
573
+
574
+ Retrieval pages use hydrated for complete records, index for pointer rows, extent for totals, and cursor for continuation. Relevant IDs can be selected before exact originals are hydrated; a refined query or cursor reveals more without paging full bodies merely to discover what exists.
575
+
576
+ Project work items live in tasks. A pending list requires action:"list" and status:"pending". Each page is { hydrated, index, extent, cursor }; a complete listing combines hydrated and index and follows cursor until null.
577
+
578
+ Which tool for what:
579
+ - memory_get: hydrates exact originals by id.
580
+ - memory_add: saves a discrete decision or root cause.
581
+ - memory_state: corrects wrong, outdated, or conflicting memory.
582
+ - memory_info: explains confidence or origin when memory looks suspect.
583
+ - memory_links: connects related decisions so they surface together.
584
+ - assist: measures coverage when search results are thin or empty.
585
+ - search_summaries: finds past work by topic or date across sessions.
586
+ - policy: stores durable enforced rules or preferences, not memories.
587
+ - tasks: creates follow-up work and closes completed work.
588
+ - code_search: finds conceptual code when source wording differs.
589
+ - memory_search: finds rationale, intent, decisions, and prior work.`;
590
+ function getMcpInstructions() {
591
+ const process2 = globalThis.process;
592
+ if (!process2?.env) {
593
+ return INSTRUCTIONS_CONTENT;
594
+ }
595
+ if (process2.env.MNEMONIK_INSTRUCTIONS_ENABLED === "false") {
596
+ return "";
597
+ }
598
+ return INSTRUCTIONS_CONTENT;
599
+ }
600
+ var MCP_INSTRUCTIONS = getMcpInstructions();
601
+
602
+ // packages/shared/dist/codeScanner.js
603
+ var import_ignore = __toESM(require_ignore(), 1);
604
+
605
+ // node_modules/web-tree-sitter/web-tree-sitter.js
606
+ var __defProp2 = Object.defineProperty;
607
+ var __name = (target, value) => __defProp2(target, "name", { value, configurable: true });
608
+ var Edit = class {
609
+ static {
610
+ __name(this, "Edit");
611
+ }
612
+ /** The start position of the change. */
613
+ startPosition;
614
+ /** The end position of the change before the edit. */
615
+ oldEndPosition;
616
+ /** The end position of the change after the edit. */
617
+ newEndPosition;
618
+ /** The start index of the change. */
619
+ startIndex;
620
+ /** The end index of the change before the edit. */
621
+ oldEndIndex;
622
+ /** The end index of the change after the edit. */
623
+ newEndIndex;
624
+ constructor({
625
+ startIndex,
626
+ oldEndIndex,
627
+ newEndIndex,
628
+ startPosition,
629
+ oldEndPosition,
630
+ newEndPosition
631
+ }) {
632
+ this.startIndex = startIndex >>> 0;
633
+ this.oldEndIndex = oldEndIndex >>> 0;
634
+ this.newEndIndex = newEndIndex >>> 0;
635
+ this.startPosition = startPosition;
636
+ this.oldEndPosition = oldEndPosition;
637
+ this.newEndPosition = newEndPosition;
638
+ }
639
+ /**
640
+ * Edit a point and index to keep it in-sync with source code that has been edited.
641
+ *
642
+ * This function updates a single point's byte offset and row/column position
643
+ * based on an edit operation. This is useful for editing points without
644
+ * requiring a tree or node instance.
645
+ */
646
+ editPoint(point, index) {
647
+ let newIndex = index;
648
+ const newPoint = { ...point };
649
+ if (index >= this.oldEndIndex) {
650
+ newIndex = this.newEndIndex + (index - this.oldEndIndex);
651
+ const originalRow = point.row;
652
+ newPoint.row = this.newEndPosition.row + (point.row - this.oldEndPosition.row);
653
+ newPoint.column = originalRow === this.oldEndPosition.row ? this.newEndPosition.column + (point.column - this.oldEndPosition.column) : point.column;
654
+ } else if (index > this.startIndex) {
655
+ newIndex = this.newEndIndex;
656
+ newPoint.row = this.newEndPosition.row;
657
+ newPoint.column = this.newEndPosition.column;
658
+ }
659
+ return { point: newPoint, index: newIndex };
660
+ }
661
+ /**
662
+ * Edit a range to keep it in-sync with source code that has been edited.
663
+ *
664
+ * This function updates a range's start and end positions based on an edit
665
+ * operation. This is useful for editing ranges without requiring a tree
666
+ * or node instance.
667
+ */
668
+ editRange(range) {
669
+ const newRange = {
670
+ startIndex: range.startIndex,
671
+ startPosition: { ...range.startPosition },
672
+ endIndex: range.endIndex,
673
+ endPosition: { ...range.endPosition }
674
+ };
675
+ if (range.endIndex >= this.oldEndIndex) {
676
+ if (range.endIndex !== Number.MAX_SAFE_INTEGER) {
677
+ newRange.endIndex = this.newEndIndex + (range.endIndex - this.oldEndIndex);
678
+ newRange.endPosition = {
679
+ row: this.newEndPosition.row + (range.endPosition.row - this.oldEndPosition.row),
680
+ column: range.endPosition.row === this.oldEndPosition.row ? this.newEndPosition.column + (range.endPosition.column - this.oldEndPosition.column) : range.endPosition.column
681
+ };
682
+ if (newRange.endIndex < this.newEndIndex) {
683
+ newRange.endIndex = Number.MAX_SAFE_INTEGER;
684
+ newRange.endPosition = { row: Number.MAX_SAFE_INTEGER, column: Number.MAX_SAFE_INTEGER };
685
+ }
686
+ }
687
+ } else if (range.endIndex > this.startIndex) {
688
+ newRange.endIndex = this.startIndex;
689
+ newRange.endPosition = { ...this.startPosition };
690
+ }
691
+ if (range.startIndex >= this.oldEndIndex) {
692
+ newRange.startIndex = this.newEndIndex + (range.startIndex - this.oldEndIndex);
693
+ newRange.startPosition = {
694
+ row: this.newEndPosition.row + (range.startPosition.row - this.oldEndPosition.row),
695
+ column: range.startPosition.row === this.oldEndPosition.row ? this.newEndPosition.column + (range.startPosition.column - this.oldEndPosition.column) : range.startPosition.column
696
+ };
697
+ if (newRange.startIndex < this.newEndIndex) {
698
+ newRange.startIndex = Number.MAX_SAFE_INTEGER;
699
+ newRange.startPosition = { row: Number.MAX_SAFE_INTEGER, column: Number.MAX_SAFE_INTEGER };
700
+ }
701
+ } else if (range.startIndex > this.startIndex) {
702
+ newRange.startIndex = this.startIndex;
703
+ newRange.startPosition = { ...this.startPosition };
704
+ }
705
+ return newRange;
706
+ }
707
+ };
708
+ var SIZE_OF_SHORT = 2;
709
+ var SIZE_OF_INT = 4;
710
+ var SIZE_OF_CURSOR = 4 * SIZE_OF_INT;
711
+ var SIZE_OF_NODE = 5 * SIZE_OF_INT;
712
+ var SIZE_OF_POINT = 2 * SIZE_OF_INT;
713
+ var SIZE_OF_RANGE = 2 * SIZE_OF_INT + 2 * SIZE_OF_POINT;
714
+ var ZERO_POINT = { row: 0, column: 0 };
715
+ var INTERNAL = /* @__PURE__ */ Symbol("INTERNAL");
716
+ function assertInternal(x) {
717
+ if (x !== INTERNAL) throw new Error("Illegal constructor");
718
+ }
719
+ __name(assertInternal, "assertInternal");
720
+ function isPoint(point) {
721
+ return !!point && typeof point.row === "number" && typeof point.column === "number";
722
+ }
723
+ __name(isPoint, "isPoint");
724
+ function setModule(module2) {
725
+ C = module2;
726
+ }
727
+ __name(setModule, "setModule");
728
+ var C;
729
+ var LookaheadIterator = class {
730
+ static {
731
+ __name(this, "LookaheadIterator");
732
+ }
733
+ /** @internal */
734
+ [0] = 0;
735
+ // Internal handle for Wasm
736
+ /** @internal */
737
+ language;
738
+ /** @internal */
739
+ constructor(internal, address, language) {
740
+ assertInternal(internal);
741
+ this[0] = address;
742
+ this.language = language;
743
+ }
744
+ /** Get the current symbol of the lookahead iterator. */
745
+ get currentTypeId() {
746
+ return C._ts_lookahead_iterator_current_symbol(this[0]);
747
+ }
748
+ /** Get the current symbol name of the lookahead iterator. */
749
+ get currentType() {
750
+ return this.language.types[this.currentTypeId] || "ERROR";
751
+ }
752
+ /** Delete the lookahead iterator, freeing its resources. */
753
+ delete() {
754
+ C._ts_lookahead_iterator_delete(this[0]);
755
+ this[0] = 0;
756
+ }
757
+ /**
758
+ * Reset the lookahead iterator.
759
+ *
760
+ * This returns `true` if the language was set successfully and `false`
761
+ * otherwise.
762
+ */
763
+ reset(language, stateId) {
764
+ if (C._ts_lookahead_iterator_reset(this[0], language[0], stateId)) {
765
+ this.language = language;
766
+ return true;
767
+ }
768
+ return false;
769
+ }
770
+ /**
771
+ * Reset the lookahead iterator to another state.
772
+ *
773
+ * This returns `true` if the iterator was reset to the given state and
774
+ * `false` otherwise.
775
+ */
776
+ resetState(stateId) {
777
+ return Boolean(C._ts_lookahead_iterator_reset_state(this[0], stateId));
778
+ }
779
+ /**
780
+ * Returns an iterator that iterates over the symbols of the lookahead iterator.
781
+ *
782
+ * The iterator will yield the current symbol name as a string for each step
783
+ * until there are no more symbols to iterate over.
784
+ */
785
+ [Symbol.iterator]() {
786
+ return {
787
+ next: /* @__PURE__ */ __name(() => {
788
+ if (C._ts_lookahead_iterator_next(this[0])) {
789
+ return { done: false, value: this.currentType };
790
+ }
791
+ return { done: true, value: "" };
792
+ }, "next")
793
+ };
794
+ }
795
+ };
796
+ function getText(tree, startIndex, endIndex, startPosition) {
797
+ const length = endIndex - startIndex;
798
+ let result = tree.textCallback(startIndex, startPosition);
799
+ if (result) {
800
+ startIndex += result.length;
801
+ while (startIndex < endIndex) {
802
+ const string = tree.textCallback(startIndex, startPosition);
803
+ if (string && string.length > 0) {
804
+ startIndex += string.length;
805
+ result += string;
806
+ } else {
807
+ break;
808
+ }
809
+ }
810
+ if (startIndex > endIndex) {
811
+ result = result.slice(0, length);
812
+ }
813
+ }
814
+ return result ?? "";
815
+ }
816
+ __name(getText, "getText");
817
+ var Tree = class _Tree {
818
+ static {
819
+ __name(this, "Tree");
820
+ }
821
+ /** @internal */
822
+ [0] = 0;
823
+ // Internal handle for Wasm
824
+ /** @internal */
825
+ textCallback;
826
+ /** The language that was used to parse the syntax tree. */
827
+ language;
828
+ /** @internal */
829
+ constructor(internal, address, language, textCallback) {
830
+ assertInternal(internal);
831
+ this[0] = address;
832
+ this.language = language;
833
+ this.textCallback = textCallback;
834
+ }
835
+ /** Create a shallow copy of the syntax tree. This is very fast. */
836
+ copy() {
837
+ const address = C._ts_tree_copy(this[0]);
838
+ return new _Tree(INTERNAL, address, this.language, this.textCallback);
839
+ }
840
+ /** Delete the syntax tree, freeing its resources. */
841
+ delete() {
842
+ C._ts_tree_delete(this[0]);
843
+ this[0] = 0;
844
+ }
845
+ /** Get the root node of the syntax tree. */
846
+ get rootNode() {
847
+ C._ts_tree_root_node_wasm(this[0]);
848
+ return unmarshalNode(this);
849
+ }
850
+ /**
851
+ * Get the root node of the syntax tree, but with its position shifted
852
+ * forward by the given offset.
853
+ */
854
+ rootNodeWithOffset(offsetBytes, offsetExtent) {
855
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
856
+ C.setValue(address, offsetBytes, "i32");
857
+ marshalPoint(address + SIZE_OF_INT, offsetExtent);
858
+ C._ts_tree_root_node_with_offset_wasm(this[0]);
859
+ return unmarshalNode(this);
860
+ }
861
+ /**
862
+ * Edit the syntax tree to keep it in sync with source code that has been
863
+ * edited.
864
+ *
865
+ * You must describe the edit both in terms of byte offsets and in terms of
866
+ * row/column coordinates.
867
+ */
868
+ edit(edit) {
869
+ marshalEdit(edit);
870
+ C._ts_tree_edit_wasm(this[0]);
871
+ }
872
+ /** Create a new {@link TreeCursor} starting from the root of the tree. */
873
+ walk() {
874
+ return this.rootNode.walk();
875
+ }
876
+ /**
877
+ * Compare this old edited syntax tree to a new syntax tree representing
878
+ * the same document, returning a sequence of ranges whose syntactic
879
+ * structure has changed.
880
+ *
881
+ * For this to work correctly, this syntax tree must have been edited such
882
+ * that its ranges match up to the new tree. Generally, you'll want to
883
+ * call this method right after calling one of the [`Parser::parse`]
884
+ * functions. Call it on the old tree that was passed to parse, and
885
+ * pass the new tree that was returned from `parse`.
886
+ */
887
+ getChangedRanges(other) {
888
+ if (!(other instanceof _Tree)) {
889
+ throw new TypeError("Argument must be a Tree");
890
+ }
891
+ C._ts_tree_get_changed_ranges_wasm(this[0], other[0]);
892
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
893
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
894
+ const result = new Array(count);
895
+ if (count > 0) {
896
+ let address = buffer;
897
+ for (let i2 = 0; i2 < count; i2++) {
898
+ result[i2] = unmarshalRange(address);
899
+ address += SIZE_OF_RANGE;
900
+ }
901
+ C._free(buffer);
902
+ }
903
+ return result;
904
+ }
905
+ /** Get the included ranges that were used to parse the syntax tree. */
906
+ getIncludedRanges() {
907
+ C._ts_tree_included_ranges_wasm(this[0]);
908
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
909
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
910
+ const result = new Array(count);
911
+ if (count > 0) {
912
+ let address = buffer;
913
+ for (let i2 = 0; i2 < count; i2++) {
914
+ result[i2] = unmarshalRange(address);
915
+ address += SIZE_OF_RANGE;
916
+ }
917
+ C._free(buffer);
918
+ }
919
+ return result;
920
+ }
921
+ };
922
+ var TreeCursor = class _TreeCursor {
923
+ static {
924
+ __name(this, "TreeCursor");
925
+ }
926
+ /** @internal */
927
+ // @ts-expect-error: never read
928
+ [0] = 0;
929
+ // Internal handle for Wasm
930
+ /** @internal */
931
+ // @ts-expect-error: never read
932
+ [1] = 0;
933
+ // Internal handle for Wasm
934
+ /** @internal */
935
+ // @ts-expect-error: never read
936
+ [2] = 0;
937
+ // Internal handle for Wasm
938
+ /** @internal */
939
+ // @ts-expect-error: never read
940
+ [3] = 0;
941
+ // Internal handle for Wasm
942
+ /** @internal */
943
+ tree;
944
+ /** @internal */
945
+ constructor(internal, tree) {
946
+ assertInternal(internal);
947
+ this.tree = tree;
948
+ unmarshalTreeCursor(this);
949
+ }
950
+ /** Creates a deep copy of the tree cursor. This allocates new memory. */
951
+ copy() {
952
+ const copy = new _TreeCursor(INTERNAL, this.tree);
953
+ C._ts_tree_cursor_copy_wasm(this.tree[0]);
954
+ unmarshalTreeCursor(copy);
955
+ return copy;
956
+ }
957
+ /** Delete the tree cursor, freeing its resources. */
958
+ delete() {
959
+ marshalTreeCursor(this);
960
+ C._ts_tree_cursor_delete_wasm(this.tree[0]);
961
+ this[0] = this[1] = this[2] = 0;
962
+ }
963
+ /** Get the tree cursor's current {@link Node}. */
964
+ get currentNode() {
965
+ marshalTreeCursor(this);
966
+ C._ts_tree_cursor_current_node_wasm(this.tree[0]);
967
+ return unmarshalNode(this.tree);
968
+ }
969
+ /**
970
+ * Get the numerical field id of this tree cursor's current node.
971
+ *
972
+ * See also {@link TreeCursor#currentFieldName}.
973
+ */
974
+ get currentFieldId() {
975
+ marshalTreeCursor(this);
976
+ return C._ts_tree_cursor_current_field_id_wasm(this.tree[0]);
977
+ }
978
+ /** Get the field name of this tree cursor's current node. */
979
+ get currentFieldName() {
980
+ return this.tree.language.fields[this.currentFieldId];
981
+ }
982
+ /**
983
+ * Get the depth of the cursor's current node relative to the original
984
+ * node that the cursor was constructed with.
985
+ */
986
+ get currentDepth() {
987
+ marshalTreeCursor(this);
988
+ return C._ts_tree_cursor_current_depth_wasm(this.tree[0]);
989
+ }
990
+ /**
991
+ * Get the index of the cursor's current node out of all of the
992
+ * descendants of the original node that the cursor was constructed with.
993
+ */
994
+ get currentDescendantIndex() {
995
+ marshalTreeCursor(this);
996
+ return C._ts_tree_cursor_current_descendant_index_wasm(this.tree[0]);
997
+ }
998
+ /** Get the type of the cursor's current node. */
999
+ get nodeType() {
1000
+ return this.tree.language.types[this.nodeTypeId] || "ERROR";
1001
+ }
1002
+ /** Get the type id of the cursor's current node. */
1003
+ get nodeTypeId() {
1004
+ marshalTreeCursor(this);
1005
+ return C._ts_tree_cursor_current_node_type_id_wasm(this.tree[0]);
1006
+ }
1007
+ /** Get the state id of the cursor's current node. */
1008
+ get nodeStateId() {
1009
+ marshalTreeCursor(this);
1010
+ return C._ts_tree_cursor_current_node_state_id_wasm(this.tree[0]);
1011
+ }
1012
+ /** Get the id of the cursor's current node. */
1013
+ get nodeId() {
1014
+ marshalTreeCursor(this);
1015
+ return C._ts_tree_cursor_current_node_id_wasm(this.tree[0]);
1016
+ }
1017
+ /**
1018
+ * Check if the cursor's current node is *named*.
1019
+ *
1020
+ * Named nodes correspond to named rules in the grammar, whereas
1021
+ * *anonymous* nodes correspond to string literals in the grammar.
1022
+ */
1023
+ get nodeIsNamed() {
1024
+ marshalTreeCursor(this);
1025
+ return C._ts_tree_cursor_current_node_is_named_wasm(this.tree[0]) === 1;
1026
+ }
1027
+ /**
1028
+ * Check if the cursor's current node is *missing*.
1029
+ *
1030
+ * Missing nodes are inserted by the parser in order to recover from
1031
+ * certain kinds of syntax errors.
1032
+ */
1033
+ get nodeIsMissing() {
1034
+ marshalTreeCursor(this);
1035
+ return C._ts_tree_cursor_current_node_is_missing_wasm(this.tree[0]) === 1;
1036
+ }
1037
+ /** Get the string content of the cursor's current node. */
1038
+ get nodeText() {
1039
+ marshalTreeCursor(this);
1040
+ const startIndex = C._ts_tree_cursor_start_index_wasm(this.tree[0]);
1041
+ const endIndex = C._ts_tree_cursor_end_index_wasm(this.tree[0]);
1042
+ C._ts_tree_cursor_start_position_wasm(this.tree[0]);
1043
+ const startPosition = unmarshalPoint(TRANSFER_BUFFER);
1044
+ return getText(this.tree, startIndex, endIndex, startPosition);
1045
+ }
1046
+ /** Get the start position of the cursor's current node. */
1047
+ get startPosition() {
1048
+ marshalTreeCursor(this);
1049
+ C._ts_tree_cursor_start_position_wasm(this.tree[0]);
1050
+ return unmarshalPoint(TRANSFER_BUFFER);
1051
+ }
1052
+ /** Get the end position of the cursor's current node. */
1053
+ get endPosition() {
1054
+ marshalTreeCursor(this);
1055
+ C._ts_tree_cursor_end_position_wasm(this.tree[0]);
1056
+ return unmarshalPoint(TRANSFER_BUFFER);
1057
+ }
1058
+ /** Get the start index of the cursor's current node. */
1059
+ get startIndex() {
1060
+ marshalTreeCursor(this);
1061
+ return C._ts_tree_cursor_start_index_wasm(this.tree[0]);
1062
+ }
1063
+ /** Get the end index of the cursor's current node. */
1064
+ get endIndex() {
1065
+ marshalTreeCursor(this);
1066
+ return C._ts_tree_cursor_end_index_wasm(this.tree[0]);
1067
+ }
1068
+ /**
1069
+ * Move this cursor to the first child of its current node.
1070
+ *
1071
+ * This returns `true` if the cursor successfully moved, and returns
1072
+ * `false` if there were no children.
1073
+ */
1074
+ gotoFirstChild() {
1075
+ marshalTreeCursor(this);
1076
+ const result = C._ts_tree_cursor_goto_first_child_wasm(this.tree[0]);
1077
+ unmarshalTreeCursor(this);
1078
+ return result === 1;
1079
+ }
1080
+ /**
1081
+ * Move this cursor to the last child of its current node.
1082
+ *
1083
+ * This returns `true` if the cursor successfully moved, and returns
1084
+ * `false` if there were no children.
1085
+ *
1086
+ * Note that this function may be slower than
1087
+ * {@link TreeCursor#gotoFirstChild} because it needs to
1088
+ * iterate through all the children to compute the child's position.
1089
+ */
1090
+ gotoLastChild() {
1091
+ marshalTreeCursor(this);
1092
+ const result = C._ts_tree_cursor_goto_last_child_wasm(this.tree[0]);
1093
+ unmarshalTreeCursor(this);
1094
+ return result === 1;
1095
+ }
1096
+ /**
1097
+ * Move this cursor to the parent of its current node.
1098
+ *
1099
+ * This returns `true` if the cursor successfully moved, and returns
1100
+ * `false` if there was no parent node (the cursor was already on the
1101
+ * root node).
1102
+ *
1103
+ * Note that the node the cursor was constructed with is considered the root
1104
+ * of the cursor, and the cursor cannot walk outside this node.
1105
+ */
1106
+ gotoParent() {
1107
+ marshalTreeCursor(this);
1108
+ const result = C._ts_tree_cursor_goto_parent_wasm(this.tree[0]);
1109
+ unmarshalTreeCursor(this);
1110
+ return result === 1;
1111
+ }
1112
+ /**
1113
+ * Move this cursor to the next sibling of its current node.
1114
+ *
1115
+ * This returns `true` if the cursor successfully moved, and returns
1116
+ * `false` if there was no next sibling node.
1117
+ *
1118
+ * Note that the node the cursor was constructed with is considered the root
1119
+ * of the cursor, and the cursor cannot walk outside this node.
1120
+ */
1121
+ gotoNextSibling() {
1122
+ marshalTreeCursor(this);
1123
+ const result = C._ts_tree_cursor_goto_next_sibling_wasm(this.tree[0]);
1124
+ unmarshalTreeCursor(this);
1125
+ return result === 1;
1126
+ }
1127
+ /**
1128
+ * Move this cursor to the previous sibling of its current node.
1129
+ *
1130
+ * This returns `true` if the cursor successfully moved, and returns
1131
+ * `false` if there was no previous sibling node.
1132
+ *
1133
+ * Note that this function may be slower than
1134
+ * {@link TreeCursor#gotoNextSibling} due to how node
1135
+ * positions are stored. In the worst case, this will need to iterate
1136
+ * through all the children up to the previous sibling node to recalculate
1137
+ * its position. Also note that the node the cursor was constructed with is
1138
+ * considered the root of the cursor, and the cursor cannot walk outside this node.
1139
+ */
1140
+ gotoPreviousSibling() {
1141
+ marshalTreeCursor(this);
1142
+ const result = C._ts_tree_cursor_goto_previous_sibling_wasm(this.tree[0]);
1143
+ unmarshalTreeCursor(this);
1144
+ return result === 1;
1145
+ }
1146
+ /**
1147
+ * Move the cursor to the node that is the nth descendant of
1148
+ * the original node that the cursor was constructed with, where
1149
+ * zero represents the original node itself.
1150
+ */
1151
+ gotoDescendant(goalDescendantIndex) {
1152
+ marshalTreeCursor(this);
1153
+ C._ts_tree_cursor_goto_descendant_wasm(this.tree[0], goalDescendantIndex);
1154
+ unmarshalTreeCursor(this);
1155
+ }
1156
+ /**
1157
+ * Move this cursor to the first child of its current node that contains or
1158
+ * starts after the given byte offset.
1159
+ *
1160
+ * This returns `true` if the cursor successfully moved to a child node, and returns
1161
+ * `false` if no such child was found.
1162
+ */
1163
+ gotoFirstChildForIndex(goalIndex) {
1164
+ marshalTreeCursor(this);
1165
+ C.setValue(TRANSFER_BUFFER + SIZE_OF_CURSOR, goalIndex, "i32");
1166
+ const result = C._ts_tree_cursor_goto_first_child_for_index_wasm(this.tree[0]);
1167
+ unmarshalTreeCursor(this);
1168
+ return result === 1;
1169
+ }
1170
+ /**
1171
+ * Move this cursor to the first child of its current node that contains or
1172
+ * starts after the given byte offset.
1173
+ *
1174
+ * This returns the index of the child node if one was found, and returns
1175
+ * `null` if no such child was found.
1176
+ */
1177
+ gotoFirstChildForPosition(goalPosition) {
1178
+ marshalTreeCursor(this);
1179
+ marshalPoint(TRANSFER_BUFFER + SIZE_OF_CURSOR, goalPosition);
1180
+ const result = C._ts_tree_cursor_goto_first_child_for_position_wasm(this.tree[0]);
1181
+ unmarshalTreeCursor(this);
1182
+ return result === 1;
1183
+ }
1184
+ /**
1185
+ * Re-initialize this tree cursor to start at the original node that the
1186
+ * cursor was constructed with.
1187
+ */
1188
+ reset(node) {
1189
+ marshalNode(node);
1190
+ marshalTreeCursor(this, TRANSFER_BUFFER + SIZE_OF_NODE);
1191
+ C._ts_tree_cursor_reset_wasm(this.tree[0]);
1192
+ unmarshalTreeCursor(this);
1193
+ }
1194
+ /**
1195
+ * Re-initialize a tree cursor to the same position as another cursor.
1196
+ *
1197
+ * Unlike {@link TreeCursor#reset}, this will not lose parent
1198
+ * information and allows reusing already created cursors.
1199
+ */
1200
+ resetTo(cursor) {
1201
+ marshalTreeCursor(this, TRANSFER_BUFFER);
1202
+ marshalTreeCursor(cursor, TRANSFER_BUFFER + SIZE_OF_CURSOR);
1203
+ C._ts_tree_cursor_reset_to_wasm(this.tree[0], cursor.tree[0]);
1204
+ unmarshalTreeCursor(this);
1205
+ }
1206
+ };
1207
+ var Node = class {
1208
+ static {
1209
+ __name(this, "Node");
1210
+ }
1211
+ /** @internal */
1212
+ // @ts-expect-error: never read
1213
+ [0] = 0;
1214
+ // Internal handle for Wasm
1215
+ /** @internal */
1216
+ _children;
1217
+ /** @internal */
1218
+ _namedChildren;
1219
+ /** @internal */
1220
+ constructor(internal, {
1221
+ id,
1222
+ tree,
1223
+ startIndex,
1224
+ startPosition,
1225
+ other
1226
+ }) {
1227
+ assertInternal(internal);
1228
+ this[0] = other;
1229
+ this.id = id;
1230
+ this.tree = tree;
1231
+ this.startIndex = startIndex;
1232
+ this.startPosition = startPosition;
1233
+ }
1234
+ /**
1235
+ * The numeric id for this node that is unique.
1236
+ *
1237
+ * Within a given syntax tree, no two nodes have the same id. However:
1238
+ *
1239
+ * * If a new tree is created based on an older tree, and a node from the old tree is reused in
1240
+ * the process, then that node will have the same id in both trees.
1241
+ *
1242
+ * * A node not marked as having changes does not guarantee it was reused.
1243
+ *
1244
+ * * If a node is marked as having changed in the old tree, it will not be reused.
1245
+ */
1246
+ id;
1247
+ /** The byte index where this node starts. */
1248
+ startIndex;
1249
+ /** The position where this node starts. */
1250
+ startPosition;
1251
+ /** The tree that this node belongs to. */
1252
+ tree;
1253
+ /** Get this node's type as a numerical id. */
1254
+ get typeId() {
1255
+ marshalNode(this);
1256
+ return C._ts_node_symbol_wasm(this.tree[0]);
1257
+ }
1258
+ /**
1259
+ * Get the node's type as a numerical id as it appears in the grammar,
1260
+ * ignoring aliases.
1261
+ */
1262
+ get grammarId() {
1263
+ marshalNode(this);
1264
+ return C._ts_node_grammar_symbol_wasm(this.tree[0]);
1265
+ }
1266
+ /** Get this node's type as a string. */
1267
+ get type() {
1268
+ return this.tree.language.types[this.typeId] || "ERROR";
1269
+ }
1270
+ /**
1271
+ * Get this node's symbol name as it appears in the grammar, ignoring
1272
+ * aliases as a string.
1273
+ */
1274
+ get grammarType() {
1275
+ return this.tree.language.types[this.grammarId] || "ERROR";
1276
+ }
1277
+ /**
1278
+ * Check if this node is *named*.
1279
+ *
1280
+ * Named nodes correspond to named rules in the grammar, whereas
1281
+ * *anonymous* nodes correspond to string literals in the grammar.
1282
+ */
1283
+ get isNamed() {
1284
+ marshalNode(this);
1285
+ return C._ts_node_is_named_wasm(this.tree[0]) === 1;
1286
+ }
1287
+ /**
1288
+ * Check if this node is *extra*.
1289
+ *
1290
+ * Extra nodes represent things like comments, which are not required
1291
+ * by the grammar, but can appear anywhere.
1292
+ */
1293
+ get isExtra() {
1294
+ marshalNode(this);
1295
+ return C._ts_node_is_extra_wasm(this.tree[0]) === 1;
1296
+ }
1297
+ /**
1298
+ * Check if this node represents a syntax error.
1299
+ *
1300
+ * Syntax errors represent parts of the code that could not be incorporated
1301
+ * into a valid syntax tree.
1302
+ */
1303
+ get isError() {
1304
+ marshalNode(this);
1305
+ return C._ts_node_is_error_wasm(this.tree[0]) === 1;
1306
+ }
1307
+ /**
1308
+ * Check if this node is *missing*.
1309
+ *
1310
+ * Missing nodes are inserted by the parser in order to recover from
1311
+ * certain kinds of syntax errors.
1312
+ */
1313
+ get isMissing() {
1314
+ marshalNode(this);
1315
+ return C._ts_node_is_missing_wasm(this.tree[0]) === 1;
1316
+ }
1317
+ /** Check if this node has been edited. */
1318
+ get hasChanges() {
1319
+ marshalNode(this);
1320
+ return C._ts_node_has_changes_wasm(this.tree[0]) === 1;
1321
+ }
1322
+ /**
1323
+ * Check if this node represents a syntax error or contains any syntax
1324
+ * errors anywhere within it.
1325
+ */
1326
+ get hasError() {
1327
+ marshalNode(this);
1328
+ return C._ts_node_has_error_wasm(this.tree[0]) === 1;
1329
+ }
1330
+ /** Get the byte index where this node ends. */
1331
+ get endIndex() {
1332
+ marshalNode(this);
1333
+ return C._ts_node_end_index_wasm(this.tree[0]);
1334
+ }
1335
+ /** Get the position where this node ends. */
1336
+ get endPosition() {
1337
+ marshalNode(this);
1338
+ C._ts_node_end_point_wasm(this.tree[0]);
1339
+ return unmarshalPoint(TRANSFER_BUFFER);
1340
+ }
1341
+ /** Get the string content of this node. */
1342
+ get text() {
1343
+ return getText(this.tree, this.startIndex, this.endIndex, this.startPosition);
1344
+ }
1345
+ /** Get this node's parse state. */
1346
+ get parseState() {
1347
+ marshalNode(this);
1348
+ return C._ts_node_parse_state_wasm(this.tree[0]);
1349
+ }
1350
+ /** Get the parse state after this node. */
1351
+ get nextParseState() {
1352
+ marshalNode(this);
1353
+ return C._ts_node_next_parse_state_wasm(this.tree[0]);
1354
+ }
1355
+ /** Check if this node is equal to another node. */
1356
+ equals(other) {
1357
+ return this.tree === other.tree && this.id === other.id;
1358
+ }
1359
+ /**
1360
+ * Get the node's child at the given index, where zero represents the first child.
1361
+ *
1362
+ * This method is fairly fast, but its cost is technically log(n), so if
1363
+ * you might be iterating over a long list of children, you should use
1364
+ * {@link Node#children} instead.
1365
+ */
1366
+ child(index) {
1367
+ marshalNode(this);
1368
+ C._ts_node_child_wasm(this.tree[0], index);
1369
+ return unmarshalNode(this.tree);
1370
+ }
1371
+ /**
1372
+ * Get this node's *named* child at the given index.
1373
+ *
1374
+ * See also {@link Node#isNamed}.
1375
+ * This method is fairly fast, but its cost is technically log(n), so if
1376
+ * you might be iterating over a long list of children, you should use
1377
+ * {@link Node#namedChildren} instead.
1378
+ */
1379
+ namedChild(index) {
1380
+ marshalNode(this);
1381
+ C._ts_node_named_child_wasm(this.tree[0], index);
1382
+ return unmarshalNode(this.tree);
1383
+ }
1384
+ /**
1385
+ * Get this node's child with the given numerical field id.
1386
+ *
1387
+ * See also {@link Node#childForFieldName}. You can
1388
+ * convert a field name to an id using {@link Language#fieldIdForName}.
1389
+ */
1390
+ childForFieldId(fieldId) {
1391
+ marshalNode(this);
1392
+ C._ts_node_child_by_field_id_wasm(this.tree[0], fieldId);
1393
+ return unmarshalNode(this.tree);
1394
+ }
1395
+ /**
1396
+ * Get the first child with the given field name.
1397
+ *
1398
+ * If multiple children may have the same field name, access them using
1399
+ * {@link Node#childrenForFieldName}.
1400
+ */
1401
+ childForFieldName(fieldName) {
1402
+ const fieldId = this.tree.language.fields.indexOf(fieldName);
1403
+ if (fieldId !== -1) return this.childForFieldId(fieldId);
1404
+ return null;
1405
+ }
1406
+ /** Get the field name of this node's child at the given index. */
1407
+ fieldNameForChild(index) {
1408
+ marshalNode(this);
1409
+ const address = C._ts_node_field_name_for_child_wasm(this.tree[0], index);
1410
+ if (!address) return null;
1411
+ return C.AsciiToString(address);
1412
+ }
1413
+ /** Get the field name of this node's named child at the given index. */
1414
+ fieldNameForNamedChild(index) {
1415
+ marshalNode(this);
1416
+ const address = C._ts_node_field_name_for_named_child_wasm(this.tree[0], index);
1417
+ if (!address) return null;
1418
+ return C.AsciiToString(address);
1419
+ }
1420
+ /**
1421
+ * Get an array of this node's children with a given field name.
1422
+ *
1423
+ * See also {@link Node#children}.
1424
+ */
1425
+ childrenForFieldName(fieldName) {
1426
+ const fieldId = this.tree.language.fields.indexOf(fieldName);
1427
+ if (fieldId !== -1 && fieldId !== 0) return this.childrenForFieldId(fieldId);
1428
+ return [];
1429
+ }
1430
+ /**
1431
+ * Get an array of this node's children with a given field id.
1432
+ *
1433
+ * See also {@link Node#childrenForFieldName}.
1434
+ */
1435
+ childrenForFieldId(fieldId) {
1436
+ marshalNode(this);
1437
+ C._ts_node_children_by_field_id_wasm(this.tree[0], fieldId);
1438
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
1439
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
1440
+ const result = new Array(count);
1441
+ if (count > 0) {
1442
+ let address = buffer;
1443
+ for (let i2 = 0; i2 < count; i2++) {
1444
+ result[i2] = unmarshalNode(this.tree, address);
1445
+ address += SIZE_OF_NODE;
1446
+ }
1447
+ C._free(buffer);
1448
+ }
1449
+ return result;
1450
+ }
1451
+ /** Get the node's first child that contains or starts after the given byte offset. */
1452
+ firstChildForIndex(index) {
1453
+ marshalNode(this);
1454
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
1455
+ C.setValue(address, index, "i32");
1456
+ C._ts_node_first_child_for_byte_wasm(this.tree[0]);
1457
+ return unmarshalNode(this.tree);
1458
+ }
1459
+ /** Get the node's first named child that contains or starts after the given byte offset. */
1460
+ firstNamedChildForIndex(index) {
1461
+ marshalNode(this);
1462
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
1463
+ C.setValue(address, index, "i32");
1464
+ C._ts_node_first_named_child_for_byte_wasm(this.tree[0]);
1465
+ return unmarshalNode(this.tree);
1466
+ }
1467
+ /** Get this node's number of children. */
1468
+ get childCount() {
1469
+ marshalNode(this);
1470
+ return C._ts_node_child_count_wasm(this.tree[0]);
1471
+ }
1472
+ /**
1473
+ * Get this node's number of *named* children.
1474
+ *
1475
+ * See also {@link Node#isNamed}.
1476
+ */
1477
+ get namedChildCount() {
1478
+ marshalNode(this);
1479
+ return C._ts_node_named_child_count_wasm(this.tree[0]);
1480
+ }
1481
+ /** Get this node's first child. */
1482
+ get firstChild() {
1483
+ return this.child(0);
1484
+ }
1485
+ /**
1486
+ * Get this node's first named child.
1487
+ *
1488
+ * See also {@link Node#isNamed}.
1489
+ */
1490
+ get firstNamedChild() {
1491
+ return this.namedChild(0);
1492
+ }
1493
+ /** Get this node's last child. */
1494
+ get lastChild() {
1495
+ return this.child(this.childCount - 1);
1496
+ }
1497
+ /**
1498
+ * Get this node's last named child.
1499
+ *
1500
+ * See also {@link Node#isNamed}.
1501
+ */
1502
+ get lastNamedChild() {
1503
+ return this.namedChild(this.namedChildCount - 1);
1504
+ }
1505
+ /**
1506
+ * Iterate over this node's children.
1507
+ *
1508
+ * If you're walking the tree recursively, you may want to use the
1509
+ * {@link TreeCursor} APIs directly instead.
1510
+ */
1511
+ get children() {
1512
+ if (!this._children) {
1513
+ marshalNode(this);
1514
+ C._ts_node_children_wasm(this.tree[0]);
1515
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
1516
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
1517
+ this._children = new Array(count);
1518
+ if (count > 0) {
1519
+ let address = buffer;
1520
+ for (let i2 = 0; i2 < count; i2++) {
1521
+ this._children[i2] = unmarshalNode(this.tree, address);
1522
+ address += SIZE_OF_NODE;
1523
+ }
1524
+ C._free(buffer);
1525
+ }
1526
+ }
1527
+ return this._children;
1528
+ }
1529
+ /**
1530
+ * Iterate over this node's named children.
1531
+ *
1532
+ * See also {@link Node#children}.
1533
+ */
1534
+ get namedChildren() {
1535
+ if (!this._namedChildren) {
1536
+ marshalNode(this);
1537
+ C._ts_node_named_children_wasm(this.tree[0]);
1538
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
1539
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
1540
+ this._namedChildren = new Array(count);
1541
+ if (count > 0) {
1542
+ let address = buffer;
1543
+ for (let i2 = 0; i2 < count; i2++) {
1544
+ this._namedChildren[i2] = unmarshalNode(this.tree, address);
1545
+ address += SIZE_OF_NODE;
1546
+ }
1547
+ C._free(buffer);
1548
+ }
1549
+ }
1550
+ return this._namedChildren;
1551
+ }
1552
+ /**
1553
+ * Get the descendants of this node that are the given type, or in the given types array.
1554
+ *
1555
+ * The types array should contain node type strings, which can be retrieved from {@link Language#types}.
1556
+ *
1557
+ * Additionally, a `startPosition` and `endPosition` can be passed in to restrict the search to a byte range.
1558
+ */
1559
+ descendantsOfType(types, startPosition = ZERO_POINT, endPosition = ZERO_POINT) {
1560
+ if (!Array.isArray(types)) types = [types];
1561
+ const symbols = [];
1562
+ const typesBySymbol = this.tree.language.types;
1563
+ for (const node_type of types) {
1564
+ if (node_type == "ERROR") {
1565
+ symbols.push(65535);
1566
+ }
1567
+ }
1568
+ for (let i2 = 0, n = typesBySymbol.length; i2 < n; i2++) {
1569
+ if (types.includes(typesBySymbol[i2])) {
1570
+ symbols.push(i2);
1571
+ }
1572
+ }
1573
+ const symbolsAddress = C._malloc(SIZE_OF_INT * symbols.length);
1574
+ for (let i2 = 0, n = symbols.length; i2 < n; i2++) {
1575
+ C.setValue(symbolsAddress + i2 * SIZE_OF_INT, symbols[i2], "i32");
1576
+ }
1577
+ marshalNode(this);
1578
+ C._ts_node_descendants_of_type_wasm(
1579
+ this.tree[0],
1580
+ symbolsAddress,
1581
+ symbols.length,
1582
+ startPosition.row,
1583
+ startPosition.column,
1584
+ endPosition.row,
1585
+ endPosition.column
1586
+ );
1587
+ const descendantCount = C.getValue(TRANSFER_BUFFER, "i32");
1588
+ const descendantAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
1589
+ const result = new Array(descendantCount);
1590
+ if (descendantCount > 0) {
1591
+ let address = descendantAddress;
1592
+ for (let i2 = 0; i2 < descendantCount; i2++) {
1593
+ result[i2] = unmarshalNode(this.tree, address);
1594
+ address += SIZE_OF_NODE;
1595
+ }
1596
+ }
1597
+ C._free(descendantAddress);
1598
+ C._free(symbolsAddress);
1599
+ return result;
1600
+ }
1601
+ /** Get this node's next sibling. */
1602
+ get nextSibling() {
1603
+ marshalNode(this);
1604
+ C._ts_node_next_sibling_wasm(this.tree[0]);
1605
+ return unmarshalNode(this.tree);
1606
+ }
1607
+ /** Get this node's previous sibling. */
1608
+ get previousSibling() {
1609
+ marshalNode(this);
1610
+ C._ts_node_prev_sibling_wasm(this.tree[0]);
1611
+ return unmarshalNode(this.tree);
1612
+ }
1613
+ /**
1614
+ * Get this node's next *named* sibling.
1615
+ *
1616
+ * See also {@link Node#isNamed}.
1617
+ */
1618
+ get nextNamedSibling() {
1619
+ marshalNode(this);
1620
+ C._ts_node_next_named_sibling_wasm(this.tree[0]);
1621
+ return unmarshalNode(this.tree);
1622
+ }
1623
+ /**
1624
+ * Get this node's previous *named* sibling.
1625
+ *
1626
+ * See also {@link Node#isNamed}.
1627
+ */
1628
+ get previousNamedSibling() {
1629
+ marshalNode(this);
1630
+ C._ts_node_prev_named_sibling_wasm(this.tree[0]);
1631
+ return unmarshalNode(this.tree);
1632
+ }
1633
+ /** Get the node's number of descendants, including one for the node itself. */
1634
+ get descendantCount() {
1635
+ marshalNode(this);
1636
+ return C._ts_node_descendant_count_wasm(this.tree[0]);
1637
+ }
1638
+ /**
1639
+ * Get this node's immediate parent.
1640
+ * Prefer {@link Node#childWithDescendant} for iterating over this node's ancestors.
1641
+ */
1642
+ get parent() {
1643
+ marshalNode(this);
1644
+ C._ts_node_parent_wasm(this.tree[0]);
1645
+ return unmarshalNode(this.tree);
1646
+ }
1647
+ /**
1648
+ * Get the node that contains `descendant`.
1649
+ *
1650
+ * Note that this can return `descendant` itself.
1651
+ */
1652
+ childWithDescendant(descendant) {
1653
+ marshalNode(this);
1654
+ marshalNode(descendant, 1);
1655
+ C._ts_node_child_with_descendant_wasm(this.tree[0]);
1656
+ return unmarshalNode(this.tree);
1657
+ }
1658
+ /** Get the smallest node within this node that spans the given byte range. */
1659
+ descendantForIndex(start2, end = start2) {
1660
+ if (typeof start2 !== "number" || typeof end !== "number") {
1661
+ throw new Error("Arguments must be numbers");
1662
+ }
1663
+ marshalNode(this);
1664
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
1665
+ C.setValue(address, start2, "i32");
1666
+ C.setValue(address + SIZE_OF_INT, end, "i32");
1667
+ C._ts_node_descendant_for_index_wasm(this.tree[0]);
1668
+ return unmarshalNode(this.tree);
1669
+ }
1670
+ /** Get the smallest named node within this node that spans the given byte range. */
1671
+ namedDescendantForIndex(start2, end = start2) {
1672
+ if (typeof start2 !== "number" || typeof end !== "number") {
1673
+ throw new Error("Arguments must be numbers");
1674
+ }
1675
+ marshalNode(this);
1676
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
1677
+ C.setValue(address, start2, "i32");
1678
+ C.setValue(address + SIZE_OF_INT, end, "i32");
1679
+ C._ts_node_named_descendant_for_index_wasm(this.tree[0]);
1680
+ return unmarshalNode(this.tree);
1681
+ }
1682
+ /** Get the smallest node within this node that spans the given point range. */
1683
+ descendantForPosition(start2, end = start2) {
1684
+ if (!isPoint(start2) || !isPoint(end)) {
1685
+ throw new Error("Arguments must be {row, column} objects");
1686
+ }
1687
+ marshalNode(this);
1688
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
1689
+ marshalPoint(address, start2);
1690
+ marshalPoint(address + SIZE_OF_POINT, end);
1691
+ C._ts_node_descendant_for_position_wasm(this.tree[0]);
1692
+ return unmarshalNode(this.tree);
1693
+ }
1694
+ /** Get the smallest named node within this node that spans the given point range. */
1695
+ namedDescendantForPosition(start2, end = start2) {
1696
+ if (!isPoint(start2) || !isPoint(end)) {
1697
+ throw new Error("Arguments must be {row, column} objects");
1698
+ }
1699
+ marshalNode(this);
1700
+ const address = TRANSFER_BUFFER + SIZE_OF_NODE;
1701
+ marshalPoint(address, start2);
1702
+ marshalPoint(address + SIZE_OF_POINT, end);
1703
+ C._ts_node_named_descendant_for_position_wasm(this.tree[0]);
1704
+ return unmarshalNode(this.tree);
1705
+ }
1706
+ /**
1707
+ * Create a new {@link TreeCursor} starting from this node.
1708
+ *
1709
+ * Note that the given node is considered the root of the cursor,
1710
+ * and the cursor cannot walk outside this node.
1711
+ */
1712
+ walk() {
1713
+ marshalNode(this);
1714
+ C._ts_tree_cursor_new_wasm(this.tree[0]);
1715
+ return new TreeCursor(INTERNAL, this.tree);
1716
+ }
1717
+ /**
1718
+ * Edit this node to keep it in-sync with source code that has been edited.
1719
+ *
1720
+ * This function is only rarely needed. When you edit a syntax tree with
1721
+ * the {@link Tree#edit} method, all of the nodes that you retrieve from
1722
+ * the tree afterward will already reflect the edit. You only need to
1723
+ * use {@link Node#edit} when you have a specific {@link Node} instance that
1724
+ * you want to keep and continue to use after an edit.
1725
+ */
1726
+ edit(edit) {
1727
+ if (this.startIndex >= edit.oldEndIndex) {
1728
+ this.startIndex = edit.newEndIndex + (this.startIndex - edit.oldEndIndex);
1729
+ let subbedPointRow;
1730
+ let subbedPointColumn;
1731
+ if (this.startPosition.row > edit.oldEndPosition.row) {
1732
+ subbedPointRow = this.startPosition.row - edit.oldEndPosition.row;
1733
+ subbedPointColumn = this.startPosition.column;
1734
+ } else {
1735
+ subbedPointRow = 0;
1736
+ subbedPointColumn = this.startPosition.column;
1737
+ if (this.startPosition.column >= edit.oldEndPosition.column) {
1738
+ subbedPointColumn = this.startPosition.column - edit.oldEndPosition.column;
1739
+ }
1740
+ }
1741
+ if (subbedPointRow > 0) {
1742
+ this.startPosition.row += subbedPointRow;
1743
+ this.startPosition.column = subbedPointColumn;
1744
+ } else {
1745
+ this.startPosition.column += subbedPointColumn;
1746
+ }
1747
+ } else if (this.startIndex > edit.startIndex) {
1748
+ this.startIndex = edit.newEndIndex;
1749
+ this.startPosition.row = edit.newEndPosition.row;
1750
+ this.startPosition.column = edit.newEndPosition.column;
1751
+ }
1752
+ }
1753
+ /** Get the S-expression representation of this node. */
1754
+ toString() {
1755
+ marshalNode(this);
1756
+ const address = C._ts_node_to_string_wasm(this.tree[0]);
1757
+ const result = C.AsciiToString(address);
1758
+ C._free(address);
1759
+ return result;
1760
+ }
1761
+ };
1762
+ function unmarshalCaptures(query, tree, address, patternIndex, result) {
1763
+ for (let i2 = 0, n = result.length; i2 < n; i2++) {
1764
+ const captureIndex = C.getValue(address, "i32");
1765
+ address += SIZE_OF_INT;
1766
+ const node = unmarshalNode(tree, address);
1767
+ address += SIZE_OF_NODE;
1768
+ result[i2] = { patternIndex, name: query.captureNames[captureIndex], node };
1769
+ }
1770
+ return address;
1771
+ }
1772
+ __name(unmarshalCaptures, "unmarshalCaptures");
1773
+ function marshalNode(node, index = 0) {
1774
+ let address = TRANSFER_BUFFER + index * SIZE_OF_NODE;
1775
+ C.setValue(address, node.id, "i32");
1776
+ address += SIZE_OF_INT;
1777
+ C.setValue(address, node.startIndex, "i32");
1778
+ address += SIZE_OF_INT;
1779
+ C.setValue(address, node.startPosition.row, "i32");
1780
+ address += SIZE_OF_INT;
1781
+ C.setValue(address, node.startPosition.column, "i32");
1782
+ address += SIZE_OF_INT;
1783
+ C.setValue(address, node[0], "i32");
1784
+ }
1785
+ __name(marshalNode, "marshalNode");
1786
+ function unmarshalNode(tree, address = TRANSFER_BUFFER) {
1787
+ const id = C.getValue(address, "i32");
1788
+ address += SIZE_OF_INT;
1789
+ if (id === 0) return null;
1790
+ const index = C.getValue(address, "i32");
1791
+ address += SIZE_OF_INT;
1792
+ const row = C.getValue(address, "i32");
1793
+ address += SIZE_OF_INT;
1794
+ const column = C.getValue(address, "i32");
1795
+ address += SIZE_OF_INT;
1796
+ const other = C.getValue(address, "i32");
1797
+ const result = new Node(INTERNAL, {
1798
+ id,
1799
+ tree,
1800
+ startIndex: index,
1801
+ startPosition: { row, column },
1802
+ other
1803
+ });
1804
+ return result;
1805
+ }
1806
+ __name(unmarshalNode, "unmarshalNode");
1807
+ function marshalTreeCursor(cursor, address = TRANSFER_BUFFER) {
1808
+ C.setValue(address + 0 * SIZE_OF_INT, cursor[0], "i32");
1809
+ C.setValue(address + 1 * SIZE_OF_INT, cursor[1], "i32");
1810
+ C.setValue(address + 2 * SIZE_OF_INT, cursor[2], "i32");
1811
+ C.setValue(address + 3 * SIZE_OF_INT, cursor[3], "i32");
1812
+ }
1813
+ __name(marshalTreeCursor, "marshalTreeCursor");
1814
+ function unmarshalTreeCursor(cursor) {
1815
+ cursor[0] = C.getValue(TRANSFER_BUFFER + 0 * SIZE_OF_INT, "i32");
1816
+ cursor[1] = C.getValue(TRANSFER_BUFFER + 1 * SIZE_OF_INT, "i32");
1817
+ cursor[2] = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
1818
+ cursor[3] = C.getValue(TRANSFER_BUFFER + 3 * SIZE_OF_INT, "i32");
1819
+ }
1820
+ __name(unmarshalTreeCursor, "unmarshalTreeCursor");
1821
+ function marshalPoint(address, point) {
1822
+ C.setValue(address, point.row, "i32");
1823
+ C.setValue(address + SIZE_OF_INT, point.column, "i32");
1824
+ }
1825
+ __name(marshalPoint, "marshalPoint");
1826
+ function unmarshalPoint(address) {
1827
+ const result = {
1828
+ row: C.getValue(address, "i32") >>> 0,
1829
+ column: C.getValue(address + SIZE_OF_INT, "i32") >>> 0
1830
+ };
1831
+ return result;
1832
+ }
1833
+ __name(unmarshalPoint, "unmarshalPoint");
1834
+ function marshalRange(address, range) {
1835
+ marshalPoint(address, range.startPosition);
1836
+ address += SIZE_OF_POINT;
1837
+ marshalPoint(address, range.endPosition);
1838
+ address += SIZE_OF_POINT;
1839
+ C.setValue(address, range.startIndex, "i32");
1840
+ address += SIZE_OF_INT;
1841
+ C.setValue(address, range.endIndex, "i32");
1842
+ address += SIZE_OF_INT;
1843
+ }
1844
+ __name(marshalRange, "marshalRange");
1845
+ function unmarshalRange(address) {
1846
+ const result = {};
1847
+ result.startPosition = unmarshalPoint(address);
1848
+ address += SIZE_OF_POINT;
1849
+ result.endPosition = unmarshalPoint(address);
1850
+ address += SIZE_OF_POINT;
1851
+ result.startIndex = C.getValue(address, "i32") >>> 0;
1852
+ address += SIZE_OF_INT;
1853
+ result.endIndex = C.getValue(address, "i32") >>> 0;
1854
+ return result;
1855
+ }
1856
+ __name(unmarshalRange, "unmarshalRange");
1857
+ function marshalEdit(edit, address = TRANSFER_BUFFER) {
1858
+ marshalPoint(address, edit.startPosition);
1859
+ address += SIZE_OF_POINT;
1860
+ marshalPoint(address, edit.oldEndPosition);
1861
+ address += SIZE_OF_POINT;
1862
+ marshalPoint(address, edit.newEndPosition);
1863
+ address += SIZE_OF_POINT;
1864
+ C.setValue(address, edit.startIndex, "i32");
1865
+ address += SIZE_OF_INT;
1866
+ C.setValue(address, edit.oldEndIndex, "i32");
1867
+ address += SIZE_OF_INT;
1868
+ C.setValue(address, edit.newEndIndex, "i32");
1869
+ address += SIZE_OF_INT;
1870
+ }
1871
+ __name(marshalEdit, "marshalEdit");
1872
+ function unmarshalLanguageMetadata(address) {
1873
+ const major_version = C.getValue(address, "i32");
1874
+ const minor_version = C.getValue(address += SIZE_OF_INT, "i32");
1875
+ const patch_version = C.getValue(address += SIZE_OF_INT, "i32");
1876
+ return { major_version, minor_version, patch_version };
1877
+ }
1878
+ __name(unmarshalLanguageMetadata, "unmarshalLanguageMetadata");
1879
+ var LANGUAGE_FUNCTION_REGEX = /^tree_sitter_\w+$/;
1880
+ var Language = class _Language {
1881
+ static {
1882
+ __name(this, "Language");
1883
+ }
1884
+ /** @internal */
1885
+ [0] = 0;
1886
+ // Internal handle for Wasm
1887
+ /**
1888
+ * A list of all node types in the language. The index of each type in this
1889
+ * array is its node type id.
1890
+ */
1891
+ types;
1892
+ /**
1893
+ * A list of all field names in the language. The index of each field name in
1894
+ * this array is its field id.
1895
+ */
1896
+ fields;
1897
+ /** @internal */
1898
+ constructor(internal, address) {
1899
+ assertInternal(internal);
1900
+ this[0] = address;
1901
+ this.types = new Array(C._ts_language_symbol_count(this[0]));
1902
+ for (let i2 = 0, n = this.types.length; i2 < n; i2++) {
1903
+ if (C._ts_language_symbol_type(this[0], i2) < 2) {
1904
+ this.types[i2] = C.UTF8ToString(C._ts_language_symbol_name(this[0], i2));
1905
+ }
1906
+ }
1907
+ this.fields = new Array(C._ts_language_field_count(this[0]) + 1);
1908
+ for (let i2 = 0, n = this.fields.length; i2 < n; i2++) {
1909
+ const fieldName = C._ts_language_field_name_for_id(this[0], i2);
1910
+ if (fieldName !== 0) {
1911
+ this.fields[i2] = C.UTF8ToString(fieldName);
1912
+ } else {
1913
+ this.fields[i2] = null;
1914
+ }
1915
+ }
1916
+ }
1917
+ /**
1918
+ * Gets the name of the language.
1919
+ */
1920
+ get name() {
1921
+ const ptr = C._ts_language_name(this[0]);
1922
+ if (ptr === 0) return null;
1923
+ return C.UTF8ToString(ptr);
1924
+ }
1925
+ /**
1926
+ * Gets the ABI version of the language.
1927
+ */
1928
+ get abiVersion() {
1929
+ return C._ts_language_abi_version(this[0]);
1930
+ }
1931
+ /**
1932
+ * Get the metadata for this language. This information is generated by the
1933
+ * CLI, and relies on the language author providing the correct metadata in
1934
+ * the language's `tree-sitter.json` file.
1935
+ */
1936
+ get metadata() {
1937
+ C._ts_language_metadata_wasm(this[0]);
1938
+ const length = C.getValue(TRANSFER_BUFFER, "i32");
1939
+ if (length === 0) return null;
1940
+ return unmarshalLanguageMetadata(TRANSFER_BUFFER + SIZE_OF_INT);
1941
+ }
1942
+ /**
1943
+ * Gets the number of fields in the language.
1944
+ */
1945
+ get fieldCount() {
1946
+ return this.fields.length - 1;
1947
+ }
1948
+ /**
1949
+ * Gets the number of states in the language.
1950
+ */
1951
+ get stateCount() {
1952
+ return C._ts_language_state_count(this[0]);
1953
+ }
1954
+ /**
1955
+ * Get the field id for a field name.
1956
+ */
1957
+ fieldIdForName(fieldName) {
1958
+ const result = this.fields.indexOf(fieldName);
1959
+ return result !== -1 ? result : null;
1960
+ }
1961
+ /**
1962
+ * Get the field name for a field id.
1963
+ */
1964
+ fieldNameForId(fieldId) {
1965
+ return this.fields[fieldId] ?? null;
1966
+ }
1967
+ /**
1968
+ * Get the node type id for a node type name.
1969
+ */
1970
+ idForNodeType(type, named) {
1971
+ const typeLength = C.lengthBytesUTF8(type);
1972
+ const typeAddress = C._malloc(typeLength + 1);
1973
+ C.stringToUTF8(type, typeAddress, typeLength + 1);
1974
+ const result = C._ts_language_symbol_for_name(this[0], typeAddress, typeLength, named ? 1 : 0);
1975
+ C._free(typeAddress);
1976
+ return result || null;
1977
+ }
1978
+ /**
1979
+ * Gets the number of node types in the language.
1980
+ */
1981
+ get nodeTypeCount() {
1982
+ return C._ts_language_symbol_count(this[0]);
1983
+ }
1984
+ /**
1985
+ * Get the node type name for a node type id.
1986
+ */
1987
+ nodeTypeForId(typeId) {
1988
+ const name2 = C._ts_language_symbol_name(this[0], typeId);
1989
+ return name2 ? C.UTF8ToString(name2) : null;
1990
+ }
1991
+ /**
1992
+ * Check if a node type is named.
1993
+ *
1994
+ * @see {@link https://tree-sitter.github.io/tree-sitter/using-parsers/2-basic-parsing.html#named-vs-anonymous-nodes}
1995
+ */
1996
+ nodeTypeIsNamed(typeId) {
1997
+ return C._ts_language_type_is_named_wasm(this[0], typeId) ? true : false;
1998
+ }
1999
+ /**
2000
+ * Check if a node type is visible.
2001
+ */
2002
+ nodeTypeIsVisible(typeId) {
2003
+ return C._ts_language_type_is_visible_wasm(this[0], typeId) ? true : false;
2004
+ }
2005
+ /**
2006
+ * Get the supertypes ids of this language.
2007
+ *
2008
+ * @see {@link https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types.html?highlight=supertype#supertype-nodes}
2009
+ */
2010
+ get supertypes() {
2011
+ C._ts_language_supertypes_wasm(this[0]);
2012
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
2013
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
2014
+ const result = new Array(count);
2015
+ if (count > 0) {
2016
+ let address = buffer;
2017
+ for (let i2 = 0; i2 < count; i2++) {
2018
+ result[i2] = C.getValue(address, "i16");
2019
+ address += SIZE_OF_SHORT;
2020
+ }
2021
+ }
2022
+ return result;
2023
+ }
2024
+ /**
2025
+ * Get the subtype ids for a given supertype node id.
2026
+ */
2027
+ subtypes(supertype) {
2028
+ C._ts_language_subtypes_wasm(this[0], supertype);
2029
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
2030
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
2031
+ const result = new Array(count);
2032
+ if (count > 0) {
2033
+ let address = buffer;
2034
+ for (let i2 = 0; i2 < count; i2++) {
2035
+ result[i2] = C.getValue(address, "i16");
2036
+ address += SIZE_OF_SHORT;
2037
+ }
2038
+ }
2039
+ return result;
2040
+ }
2041
+ /**
2042
+ * Get the next state id for a given state id and node type id.
2043
+ */
2044
+ nextState(stateId, typeId) {
2045
+ return C._ts_language_next_state(this[0], stateId, typeId);
2046
+ }
2047
+ /**
2048
+ * Create a new lookahead iterator for this language and parse state.
2049
+ *
2050
+ * This returns `null` if state is invalid for this language.
2051
+ *
2052
+ * Iterating {@link LookaheadIterator} will yield valid symbols in the given
2053
+ * parse state. Newly created lookahead iterators will return the `ERROR`
2054
+ * symbol from {@link LookaheadIterator#currentType}.
2055
+ *
2056
+ * Lookahead iterators can be useful for generating suggestions and improving
2057
+ * syntax error diagnostics. To get symbols valid in an `ERROR` node, use the
2058
+ * lookahead iterator on its first leaf node state. For `MISSING` nodes, a
2059
+ * lookahead iterator created on the previous non-extra leaf node may be
2060
+ * appropriate.
2061
+ */
2062
+ lookaheadIterator(stateId) {
2063
+ const address = C._ts_lookahead_iterator_new(this[0], stateId);
2064
+ if (address) return new LookaheadIterator(INTERNAL, address, this);
2065
+ return null;
2066
+ }
2067
+ /**
2068
+ * Load a language from a WebAssembly module.
2069
+ * The module can be provided as a path to a file or as a buffer.
2070
+ */
2071
+ static async load(input) {
2072
+ let binary2;
2073
+ if (input instanceof Uint8Array) {
2074
+ binary2 = input;
2075
+ } else if (globalThis.process?.versions.node) {
2076
+ const fs2 = await import("fs/promises");
2077
+ binary2 = await fs2.readFile(input);
2078
+ } else {
2079
+ const response = await fetch(input);
2080
+ if (!response.ok) {
2081
+ const body2 = await response.text();
2082
+ throw new Error(`Language.load failed with status ${response.status}.
2083
+
2084
+ ${body2}`);
2085
+ }
2086
+ const retryResp = response.clone();
2087
+ try {
2088
+ binary2 = await WebAssembly.compileStreaming(response);
2089
+ } catch (reason) {
2090
+ console.error("wasm streaming compile failed:", reason);
2091
+ console.error("falling back to ArrayBuffer instantiation");
2092
+ binary2 = new Uint8Array(await retryResp.arrayBuffer());
2093
+ }
2094
+ }
2095
+ const mod = await C.loadWebAssemblyModule(binary2, { loadAsync: true });
2096
+ const symbolNames = Object.keys(mod);
2097
+ const functionName = symbolNames.find((key) => LANGUAGE_FUNCTION_REGEX.test(key) && !key.includes("external_scanner_"));
2098
+ if (!functionName) {
2099
+ console.log(`Couldn't find language function in Wasm file. Symbols:
2100
+ ${JSON.stringify(symbolNames, null, 2)}`);
2101
+ throw new Error("Language.load failed: no language function found in Wasm file");
2102
+ }
2103
+ const languageAddress = mod[functionName]();
2104
+ return new _Language(INTERNAL, languageAddress);
2105
+ }
2106
+ };
2107
+ async function Module2(moduleArg = {}) {
2108
+ var moduleRtn;
2109
+ var Module = moduleArg;
2110
+ var ENVIRONMENT_IS_WEB = typeof window == "object";
2111
+ var ENVIRONMENT_IS_WORKER = typeof WorkerGlobalScope != "undefined";
2112
+ var ENVIRONMENT_IS_NODE = typeof process == "object" && process.versions?.node && process.type != "renderer";
2113
+ if (ENVIRONMENT_IS_NODE) {
2114
+ const { createRequire } = await import("module");
2115
+ var require = createRequire(import.meta.url);
2116
+ }
2117
+ Module.currentQueryProgressCallback = null;
2118
+ Module.currentProgressCallback = null;
2119
+ Module.currentLogCallback = null;
2120
+ Module.currentParseCallback = null;
2121
+ var arguments_ = [];
2122
+ var thisProgram = "./this.program";
2123
+ var quit_ = /* @__PURE__ */ __name((status, toThrow) => {
2124
+ throw toThrow;
2125
+ }, "quit_");
2126
+ var _scriptName = import.meta.url;
2127
+ var scriptDirectory = "";
2128
+ function locateFile(path) {
2129
+ if (Module["locateFile"]) {
2130
+ return Module["locateFile"](path, scriptDirectory);
2131
+ }
2132
+ return scriptDirectory + path;
2133
+ }
2134
+ __name(locateFile, "locateFile");
2135
+ var readAsync, readBinary;
2136
+ if (ENVIRONMENT_IS_NODE) {
2137
+ var fs = require("fs");
2138
+ if (_scriptName.startsWith("file:")) {
2139
+ scriptDirectory = require("path").dirname(require("url").fileURLToPath(_scriptName)) + "/";
2140
+ }
2141
+ readBinary = /* @__PURE__ */ __name((filename) => {
2142
+ filename = isFileURI(filename) ? new URL(filename) : filename;
2143
+ var ret = fs.readFileSync(filename);
2144
+ return ret;
2145
+ }, "readBinary");
2146
+ readAsync = /* @__PURE__ */ __name(async (filename, binary2 = true) => {
2147
+ filename = isFileURI(filename) ? new URL(filename) : filename;
2148
+ var ret = fs.readFileSync(filename, binary2 ? void 0 : "utf8");
2149
+ return ret;
2150
+ }, "readAsync");
2151
+ if (process.argv.length > 1) {
2152
+ thisProgram = process.argv[1].replace(/\\/g, "/");
2153
+ }
2154
+ arguments_ = process.argv.slice(2);
2155
+ quit_ = /* @__PURE__ */ __name((status, toThrow) => {
2156
+ process.exitCode = status;
2157
+ throw toThrow;
2158
+ }, "quit_");
2159
+ } else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
2160
+ try {
2161
+ scriptDirectory = new URL(".", _scriptName).href;
2162
+ } catch {
2163
+ }
2164
+ {
2165
+ if (ENVIRONMENT_IS_WORKER) {
2166
+ readBinary = /* @__PURE__ */ __name((url) => {
2167
+ var xhr = new XMLHttpRequest();
2168
+ xhr.open("GET", url, false);
2169
+ xhr.responseType = "arraybuffer";
2170
+ xhr.send(null);
2171
+ return new Uint8Array(
2172
+ /** @type{!ArrayBuffer} */
2173
+ xhr.response
2174
+ );
2175
+ }, "readBinary");
2176
+ }
2177
+ readAsync = /* @__PURE__ */ __name(async (url) => {
2178
+ if (isFileURI(url)) {
2179
+ return new Promise((resolve, reject) => {
2180
+ var xhr = new XMLHttpRequest();
2181
+ xhr.open("GET", url, true);
2182
+ xhr.responseType = "arraybuffer";
2183
+ xhr.onload = () => {
2184
+ if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
2185
+ resolve(xhr.response);
2186
+ return;
2187
+ }
2188
+ reject(xhr.status);
2189
+ };
2190
+ xhr.onerror = reject;
2191
+ xhr.send(null);
2192
+ });
2193
+ }
2194
+ var response = await fetch(url, {
2195
+ credentials: "same-origin"
2196
+ });
2197
+ if (response.ok) {
2198
+ return response.arrayBuffer();
2199
+ }
2200
+ throw new Error(response.status + " : " + response.url);
2201
+ }, "readAsync");
2202
+ }
2203
+ } else {
2204
+ }
2205
+ var out = console.log.bind(console);
2206
+ var err = console.error.bind(console);
2207
+ var dynamicLibraries = [];
2208
+ var wasmBinary;
2209
+ var ABORT = false;
2210
+ var EXITSTATUS;
2211
+ var isFileURI = /* @__PURE__ */ __name((filename) => filename.startsWith("file://"), "isFileURI");
2212
+ var readyPromiseResolve, readyPromiseReject;
2213
+ var wasmMemory;
2214
+ var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
2215
+ var HEAP64, HEAPU64;
2216
+ var HEAP_DATA_VIEW;
2217
+ var runtimeInitialized = false;
2218
+ function updateMemoryViews() {
2219
+ var b = wasmMemory.buffer;
2220
+ Module["HEAP8"] = HEAP8 = new Int8Array(b);
2221
+ Module["HEAP16"] = HEAP16 = new Int16Array(b);
2222
+ Module["HEAPU8"] = HEAPU8 = new Uint8Array(b);
2223
+ Module["HEAPU16"] = HEAPU16 = new Uint16Array(b);
2224
+ Module["HEAP32"] = HEAP32 = new Int32Array(b);
2225
+ Module["HEAPU32"] = HEAPU32 = new Uint32Array(b);
2226
+ Module["HEAPF32"] = HEAPF32 = new Float32Array(b);
2227
+ Module["HEAPF64"] = HEAPF64 = new Float64Array(b);
2228
+ Module["HEAP64"] = HEAP64 = new BigInt64Array(b);
2229
+ Module["HEAPU64"] = HEAPU64 = new BigUint64Array(b);
2230
+ Module["HEAP_DATA_VIEW"] = HEAP_DATA_VIEW = new DataView(b);
2231
+ LE_HEAP_UPDATE();
2232
+ }
2233
+ __name(updateMemoryViews, "updateMemoryViews");
2234
+ function initMemory() {
2235
+ if (Module["wasmMemory"]) {
2236
+ wasmMemory = Module["wasmMemory"];
2237
+ } else {
2238
+ var INITIAL_MEMORY = Module["INITIAL_MEMORY"] || 33554432;
2239
+ wasmMemory = new WebAssembly.Memory({
2240
+ "initial": INITIAL_MEMORY / 65536,
2241
+ // In theory we should not need to emit the maximum if we want "unlimited"
2242
+ // or 4GB of memory, but VMs error on that atm, see
2243
+ // https://github.com/emscripten-core/emscripten/issues/14130
2244
+ // And in the pthreads case we definitely need to emit a maximum. So
2245
+ // always emit one.
2246
+ "maximum": 32768
2247
+ });
2248
+ }
2249
+ updateMemoryViews();
2250
+ }
2251
+ __name(initMemory, "initMemory");
2252
+ var __RELOC_FUNCS__ = [];
2253
+ function preRun() {
2254
+ if (Module["preRun"]) {
2255
+ if (typeof Module["preRun"] == "function") Module["preRun"] = [Module["preRun"]];
2256
+ while (Module["preRun"].length) {
2257
+ addOnPreRun(Module["preRun"].shift());
2258
+ }
2259
+ }
2260
+ callRuntimeCallbacks(onPreRuns);
2261
+ }
2262
+ __name(preRun, "preRun");
2263
+ function initRuntime() {
2264
+ runtimeInitialized = true;
2265
+ callRuntimeCallbacks(__RELOC_FUNCS__);
2266
+ wasmExports["__wasm_call_ctors"]();
2267
+ callRuntimeCallbacks(onPostCtors);
2268
+ }
2269
+ __name(initRuntime, "initRuntime");
2270
+ function preMain() {
2271
+ }
2272
+ __name(preMain, "preMain");
2273
+ function postRun() {
2274
+ if (Module["postRun"]) {
2275
+ if (typeof Module["postRun"] == "function") Module["postRun"] = [Module["postRun"]];
2276
+ while (Module["postRun"].length) {
2277
+ addOnPostRun(Module["postRun"].shift());
2278
+ }
2279
+ }
2280
+ callRuntimeCallbacks(onPostRuns);
2281
+ }
2282
+ __name(postRun, "postRun");
2283
+ function abort(what) {
2284
+ Module["onAbort"]?.(what);
2285
+ what = "Aborted(" + what + ")";
2286
+ err(what);
2287
+ ABORT = true;
2288
+ what += ". Build with -sASSERTIONS for more info.";
2289
+ var e = new WebAssembly.RuntimeError(what);
2290
+ readyPromiseReject?.(e);
2291
+ throw e;
2292
+ }
2293
+ __name(abort, "abort");
2294
+ var wasmBinaryFile;
2295
+ function findWasmBinary() {
2296
+ if (Module["locateFile"]) {
2297
+ return locateFile("web-tree-sitter.wasm");
2298
+ }
2299
+ return new URL("web-tree-sitter.wasm", import.meta.url).href;
2300
+ }
2301
+ __name(findWasmBinary, "findWasmBinary");
2302
+ function getBinarySync(file) {
2303
+ if (file == wasmBinaryFile && wasmBinary) {
2304
+ return new Uint8Array(wasmBinary);
2305
+ }
2306
+ if (readBinary) {
2307
+ return readBinary(file);
2308
+ }
2309
+ throw "both async and sync fetching of the wasm failed";
2310
+ }
2311
+ __name(getBinarySync, "getBinarySync");
2312
+ async function getWasmBinary(binaryFile) {
2313
+ if (!wasmBinary) {
2314
+ try {
2315
+ var response = await readAsync(binaryFile);
2316
+ return new Uint8Array(response);
2317
+ } catch {
2318
+ }
2319
+ }
2320
+ return getBinarySync(binaryFile);
2321
+ }
2322
+ __name(getWasmBinary, "getWasmBinary");
2323
+ async function instantiateArrayBuffer(binaryFile, imports) {
2324
+ try {
2325
+ var binary2 = await getWasmBinary(binaryFile);
2326
+ var instance2 = await WebAssembly.instantiate(binary2, imports);
2327
+ return instance2;
2328
+ } catch (reason) {
2329
+ err(`failed to asynchronously prepare wasm: ${reason}`);
2330
+ abort(reason);
2331
+ }
2332
+ }
2333
+ __name(instantiateArrayBuffer, "instantiateArrayBuffer");
2334
+ async function instantiateAsync(binary2, binaryFile, imports) {
2335
+ if (!binary2 && !isFileURI(binaryFile) && !ENVIRONMENT_IS_NODE) {
2336
+ try {
2337
+ var response = fetch(binaryFile, {
2338
+ credentials: "same-origin"
2339
+ });
2340
+ var instantiationResult = await WebAssembly.instantiateStreaming(response, imports);
2341
+ return instantiationResult;
2342
+ } catch (reason) {
2343
+ err(`wasm streaming compile failed: ${reason}`);
2344
+ err("falling back to ArrayBuffer instantiation");
2345
+ }
2346
+ }
2347
+ return instantiateArrayBuffer(binaryFile, imports);
2348
+ }
2349
+ __name(instantiateAsync, "instantiateAsync");
2350
+ function getWasmImports() {
2351
+ return {
2352
+ "env": wasmImports,
2353
+ "wasi_snapshot_preview1": wasmImports,
2354
+ "GOT.mem": new Proxy(wasmImports, GOTHandler),
2355
+ "GOT.func": new Proxy(wasmImports, GOTHandler)
2356
+ };
2357
+ }
2358
+ __name(getWasmImports, "getWasmImports");
2359
+ async function createWasm() {
2360
+ function receiveInstance(instance2, module2) {
2361
+ wasmExports = instance2.exports;
2362
+ wasmExports = relocateExports(wasmExports, 1024);
2363
+ var metadata2 = getDylinkMetadata(module2);
2364
+ if (metadata2.neededDynlibs) {
2365
+ dynamicLibraries = metadata2.neededDynlibs.concat(dynamicLibraries);
2366
+ }
2367
+ mergeLibSymbols(wasmExports, "main");
2368
+ LDSO.init();
2369
+ loadDylibs();
2370
+ __RELOC_FUNCS__.push(wasmExports["__wasm_apply_data_relocs"]);
2371
+ assignWasmExports(wasmExports);
2372
+ return wasmExports;
2373
+ }
2374
+ __name(receiveInstance, "receiveInstance");
2375
+ function receiveInstantiationResult(result2) {
2376
+ return receiveInstance(result2["instance"], result2["module"]);
2377
+ }
2378
+ __name(receiveInstantiationResult, "receiveInstantiationResult");
2379
+ var info22 = getWasmImports();
2380
+ if (Module["instantiateWasm"]) {
2381
+ return new Promise((resolve, reject) => {
2382
+ Module["instantiateWasm"](info22, (mod, inst) => {
2383
+ resolve(receiveInstance(mod, inst));
2384
+ });
2385
+ });
2386
+ }
2387
+ wasmBinaryFile ??= findWasmBinary();
2388
+ var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info22);
2389
+ var exports = receiveInstantiationResult(result);
2390
+ return exports;
2391
+ }
2392
+ __name(createWasm, "createWasm");
2393
+ class ExitStatus {
2394
+ static {
2395
+ __name(this, "ExitStatus");
2396
+ }
2397
+ name = "ExitStatus";
2398
+ constructor(status) {
2399
+ this.message = `Program terminated with exit(${status})`;
2400
+ this.status = status;
2401
+ }
2402
+ }
2403
+ var GOT = {};
2404
+ var currentModuleWeakSymbols = /* @__PURE__ */ new Set([]);
2405
+ var GOTHandler = {
2406
+ get(obj, symName) {
2407
+ var rtn = GOT[symName];
2408
+ if (!rtn) {
2409
+ rtn = GOT[symName] = new WebAssembly.Global({
2410
+ "value": "i32",
2411
+ "mutable": true
2412
+ });
2413
+ }
2414
+ if (!currentModuleWeakSymbols.has(symName)) {
2415
+ rtn.required = true;
2416
+ }
2417
+ return rtn;
2418
+ }
2419
+ };
2420
+ var LE_ATOMICS_NATIVE_BYTE_ORDER = [];
2421
+ var LE_HEAP_LOAD_F32 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getFloat32(byteOffset, true), "LE_HEAP_LOAD_F32");
2422
+ var LE_HEAP_LOAD_F64 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getFloat64(byteOffset, true), "LE_HEAP_LOAD_F64");
2423
+ var LE_HEAP_LOAD_I16 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getInt16(byteOffset, true), "LE_HEAP_LOAD_I16");
2424
+ var LE_HEAP_LOAD_I32 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getInt32(byteOffset, true), "LE_HEAP_LOAD_I32");
2425
+ var LE_HEAP_LOAD_I64 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getBigInt64(byteOffset, true), "LE_HEAP_LOAD_I64");
2426
+ var LE_HEAP_LOAD_U32 = /* @__PURE__ */ __name((byteOffset) => HEAP_DATA_VIEW.getUint32(byteOffset, true), "LE_HEAP_LOAD_U32");
2427
+ var LE_HEAP_STORE_F32 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setFloat32(byteOffset, value, true), "LE_HEAP_STORE_F32");
2428
+ var LE_HEAP_STORE_F64 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setFloat64(byteOffset, value, true), "LE_HEAP_STORE_F64");
2429
+ var LE_HEAP_STORE_I16 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setInt16(byteOffset, value, true), "LE_HEAP_STORE_I16");
2430
+ var LE_HEAP_STORE_I32 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setInt32(byteOffset, value, true), "LE_HEAP_STORE_I32");
2431
+ var LE_HEAP_STORE_I64 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setBigInt64(byteOffset, value, true), "LE_HEAP_STORE_I64");
2432
+ var LE_HEAP_STORE_U32 = /* @__PURE__ */ __name((byteOffset, value) => HEAP_DATA_VIEW.setUint32(byteOffset, value, true), "LE_HEAP_STORE_U32");
2433
+ var callRuntimeCallbacks = /* @__PURE__ */ __name((callbacks) => {
2434
+ while (callbacks.length > 0) {
2435
+ callbacks.shift()(Module);
2436
+ }
2437
+ }, "callRuntimeCallbacks");
2438
+ var onPostRuns = [];
2439
+ var addOnPostRun = /* @__PURE__ */ __name((cb) => onPostRuns.push(cb), "addOnPostRun");
2440
+ var onPreRuns = [];
2441
+ var addOnPreRun = /* @__PURE__ */ __name((cb) => onPreRuns.push(cb), "addOnPreRun");
2442
+ var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder() : void 0;
2443
+ var findStringEnd = /* @__PURE__ */ __name((heapOrArray, idx, maxBytesToRead, ignoreNul) => {
2444
+ var maxIdx = idx + maxBytesToRead;
2445
+ if (ignoreNul) return maxIdx;
2446
+ while (heapOrArray[idx] && !(idx >= maxIdx)) ++idx;
2447
+ return idx;
2448
+ }, "findStringEnd");
2449
+ var UTF8ArrayToString = /* @__PURE__ */ __name((heapOrArray, idx = 0, maxBytesToRead, ignoreNul) => {
2450
+ var endPtr = findStringEnd(heapOrArray, idx, maxBytesToRead, ignoreNul);
2451
+ if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
2452
+ return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
2453
+ }
2454
+ var str = "";
2455
+ while (idx < endPtr) {
2456
+ var u0 = heapOrArray[idx++];
2457
+ if (!(u0 & 128)) {
2458
+ str += String.fromCharCode(u0);
2459
+ continue;
2460
+ }
2461
+ var u1 = heapOrArray[idx++] & 63;
2462
+ if ((u0 & 224) == 192) {
2463
+ str += String.fromCharCode((u0 & 31) << 6 | u1);
2464
+ continue;
2465
+ }
2466
+ var u2 = heapOrArray[idx++] & 63;
2467
+ if ((u0 & 240) == 224) {
2468
+ u0 = (u0 & 15) << 12 | u1 << 6 | u2;
2469
+ } else {
2470
+ u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heapOrArray[idx++] & 63;
2471
+ }
2472
+ if (u0 < 65536) {
2473
+ str += String.fromCharCode(u0);
2474
+ } else {
2475
+ var ch = u0 - 65536;
2476
+ str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023);
2477
+ }
2478
+ }
2479
+ return str;
2480
+ }, "UTF8ArrayToString");
2481
+ var getDylinkMetadata = /* @__PURE__ */ __name((binary2) => {
2482
+ var offset = 0;
2483
+ var end = 0;
2484
+ function getU8() {
2485
+ return binary2[offset++];
2486
+ }
2487
+ __name(getU8, "getU8");
2488
+ function getLEB() {
2489
+ var ret = 0;
2490
+ var mul = 1;
2491
+ while (1) {
2492
+ var byte = binary2[offset++];
2493
+ ret += (byte & 127) * mul;
2494
+ mul *= 128;
2495
+ if (!(byte & 128)) break;
2496
+ }
2497
+ return ret;
2498
+ }
2499
+ __name(getLEB, "getLEB");
2500
+ function getString() {
2501
+ var len = getLEB();
2502
+ offset += len;
2503
+ return UTF8ArrayToString(binary2, offset - len, len);
2504
+ }
2505
+ __name(getString, "getString");
2506
+ function getStringList() {
2507
+ var count2 = getLEB();
2508
+ var rtn = [];
2509
+ while (count2--) rtn.push(getString());
2510
+ return rtn;
2511
+ }
2512
+ __name(getStringList, "getStringList");
2513
+ function failIf(condition, message) {
2514
+ if (condition) throw new Error(message);
2515
+ }
2516
+ __name(failIf, "failIf");
2517
+ if (binary2 instanceof WebAssembly.Module) {
2518
+ var dylinkSection = WebAssembly.Module.customSections(binary2, "dylink.0");
2519
+ failIf(dylinkSection.length === 0, "need dylink section");
2520
+ binary2 = new Uint8Array(dylinkSection[0]);
2521
+ end = binary2.length;
2522
+ } else {
2523
+ var int32View = new Uint32Array(new Uint8Array(binary2.subarray(0, 24)).buffer);
2524
+ var magicNumberFound = int32View[0] == 1836278016 || int32View[0] == 6386541;
2525
+ failIf(!magicNumberFound, "need to see wasm magic number");
2526
+ failIf(binary2[8] !== 0, "need the dylink section to be first");
2527
+ offset = 9;
2528
+ var section_size = getLEB();
2529
+ end = offset + section_size;
2530
+ var name2 = getString();
2531
+ failIf(name2 !== "dylink.0");
2532
+ }
2533
+ var customSection = {
2534
+ neededDynlibs: [],
2535
+ tlsExports: /* @__PURE__ */ new Set(),
2536
+ weakImports: /* @__PURE__ */ new Set(),
2537
+ runtimePaths: []
2538
+ };
2539
+ var WASM_DYLINK_MEM_INFO = 1;
2540
+ var WASM_DYLINK_NEEDED = 2;
2541
+ var WASM_DYLINK_EXPORT_INFO = 3;
2542
+ var WASM_DYLINK_IMPORT_INFO = 4;
2543
+ var WASM_DYLINK_RUNTIME_PATH = 5;
2544
+ var WASM_SYMBOL_TLS = 256;
2545
+ var WASM_SYMBOL_BINDING_MASK = 3;
2546
+ var WASM_SYMBOL_BINDING_WEAK = 1;
2547
+ while (offset < end) {
2548
+ var subsectionType = getU8();
2549
+ var subsectionSize = getLEB();
2550
+ if (subsectionType === WASM_DYLINK_MEM_INFO) {
2551
+ customSection.memorySize = getLEB();
2552
+ customSection.memoryAlign = getLEB();
2553
+ customSection.tableSize = getLEB();
2554
+ customSection.tableAlign = getLEB();
2555
+ } else if (subsectionType === WASM_DYLINK_NEEDED) {
2556
+ customSection.neededDynlibs = getStringList();
2557
+ } else if (subsectionType === WASM_DYLINK_EXPORT_INFO) {
2558
+ var count = getLEB();
2559
+ while (count--) {
2560
+ var symname = getString();
2561
+ var flags2 = getLEB();
2562
+ if (flags2 & WASM_SYMBOL_TLS) {
2563
+ customSection.tlsExports.add(symname);
2564
+ }
2565
+ }
2566
+ } else if (subsectionType === WASM_DYLINK_IMPORT_INFO) {
2567
+ var count = getLEB();
2568
+ while (count--) {
2569
+ var modname = getString();
2570
+ var symname = getString();
2571
+ var flags2 = getLEB();
2572
+ if ((flags2 & WASM_SYMBOL_BINDING_MASK) == WASM_SYMBOL_BINDING_WEAK) {
2573
+ customSection.weakImports.add(symname);
2574
+ }
2575
+ }
2576
+ } else if (subsectionType === WASM_DYLINK_RUNTIME_PATH) {
2577
+ customSection.runtimePaths = getStringList();
2578
+ } else {
2579
+ offset += subsectionSize;
2580
+ }
2581
+ }
2582
+ return customSection;
2583
+ }, "getDylinkMetadata");
2584
+ function getValue(ptr, type = "i8") {
2585
+ if (type.endsWith("*")) type = "*";
2586
+ switch (type) {
2587
+ case "i1":
2588
+ return HEAP8[ptr];
2589
+ case "i8":
2590
+ return HEAP8[ptr];
2591
+ case "i16":
2592
+ return LE_HEAP_LOAD_I16((ptr >> 1) * 2);
2593
+ case "i32":
2594
+ return LE_HEAP_LOAD_I32((ptr >> 2) * 4);
2595
+ case "i64":
2596
+ return LE_HEAP_LOAD_I64((ptr >> 3) * 8);
2597
+ case "float":
2598
+ return LE_HEAP_LOAD_F32((ptr >> 2) * 4);
2599
+ case "double":
2600
+ return LE_HEAP_LOAD_F64((ptr >> 3) * 8);
2601
+ case "*":
2602
+ return LE_HEAP_LOAD_U32((ptr >> 2) * 4);
2603
+ default:
2604
+ abort(`invalid type for getValue: ${type}`);
2605
+ }
2606
+ }
2607
+ __name(getValue, "getValue");
2608
+ var newDSO = /* @__PURE__ */ __name((name2, handle2, syms) => {
2609
+ var dso = {
2610
+ refcount: Infinity,
2611
+ name: name2,
2612
+ exports: syms,
2613
+ global: true
2614
+ };
2615
+ LDSO.loadedLibsByName[name2] = dso;
2616
+ if (handle2 != void 0) {
2617
+ LDSO.loadedLibsByHandle[handle2] = dso;
2618
+ }
2619
+ return dso;
2620
+ }, "newDSO");
2621
+ var LDSO = {
2622
+ loadedLibsByName: {},
2623
+ loadedLibsByHandle: {},
2624
+ init() {
2625
+ newDSO("__main__", 0, wasmImports);
2626
+ }
2627
+ };
2628
+ var ___heap_base = 78240;
2629
+ var alignMemory = /* @__PURE__ */ __name((size, alignment) => Math.ceil(size / alignment) * alignment, "alignMemory");
2630
+ var getMemory = /* @__PURE__ */ __name((size) => {
2631
+ if (runtimeInitialized) {
2632
+ return _calloc(size, 1);
2633
+ }
2634
+ var ret = ___heap_base;
2635
+ var end = ret + alignMemory(size, 16);
2636
+ ___heap_base = end;
2637
+ GOT["__heap_base"].value = end;
2638
+ return ret;
2639
+ }, "getMemory");
2640
+ 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");
2641
+ var uleb128EncodeWithLen = /* @__PURE__ */ __name((arr) => {
2642
+ const n = arr.length;
2643
+ return [n % 128 | 128, n >> 7, ...arr];
2644
+ }, "uleb128EncodeWithLen");
2645
+ var wasmTypeCodes = {
2646
+ "i": 127,
2647
+ // i32
2648
+ "p": 127,
2649
+ // i32
2650
+ "j": 126,
2651
+ // i64
2652
+ "f": 125,
2653
+ // f32
2654
+ "d": 124,
2655
+ // f64
2656
+ "e": 111
2657
+ };
2658
+ var generateTypePack = /* @__PURE__ */ __name((types) => uleb128EncodeWithLen(Array.from(types, (type) => {
2659
+ var code = wasmTypeCodes[type];
2660
+ return code;
2661
+ })), "generateTypePack");
2662
+ var convertJsFunctionToWasm = /* @__PURE__ */ __name((func2, sig) => {
2663
+ var bytes = Uint8Array.of(
2664
+ 0,
2665
+ 97,
2666
+ 115,
2667
+ 109,
2668
+ // magic ("\0asm")
2669
+ 1,
2670
+ 0,
2671
+ 0,
2672
+ 0,
2673
+ // version: 1
2674
+ 1,
2675
+ ...uleb128EncodeWithLen([
2676
+ 1,
2677
+ // count: 1
2678
+ 96,
2679
+ // param types
2680
+ ...generateTypePack(sig.slice(1)),
2681
+ // return types (for now only supporting [] if `void` and single [T] otherwise)
2682
+ ...generateTypePack(sig[0] === "v" ? "" : sig[0])
2683
+ ]),
2684
+ // The rest of the module is static
2685
+ 2,
2686
+ 7,
2687
+ // import section
2688
+ // (import "e" "f" (func 0 (type 0)))
2689
+ 1,
2690
+ 1,
2691
+ 101,
2692
+ 1,
2693
+ 102,
2694
+ 0,
2695
+ 0,
2696
+ 7,
2697
+ 5,
2698
+ // export section
2699
+ // (export "f" (func 0 (type 0)))
2700
+ 1,
2701
+ 1,
2702
+ 102,
2703
+ 0,
2704
+ 0
2705
+ );
2706
+ var module2 = new WebAssembly.Module(bytes);
2707
+ var instance2 = new WebAssembly.Instance(module2, {
2708
+ "e": {
2709
+ "f": func2
2710
+ }
2711
+ });
2712
+ var wrappedFunc = instance2.exports["f"];
2713
+ return wrappedFunc;
2714
+ }, "convertJsFunctionToWasm");
2715
+ var wasmTableMirror = [];
2716
+ var wasmTable = new WebAssembly.Table({
2717
+ "initial": 31,
2718
+ "element": "anyfunc"
2719
+ });
2720
+ var getWasmTableEntry = /* @__PURE__ */ __name((funcPtr) => {
2721
+ var func2 = wasmTableMirror[funcPtr];
2722
+ if (!func2) {
2723
+ wasmTableMirror[funcPtr] = func2 = wasmTable.get(funcPtr);
2724
+ }
2725
+ return func2;
2726
+ }, "getWasmTableEntry");
2727
+ var updateTableMap = /* @__PURE__ */ __name((offset, count) => {
2728
+ if (functionsInTableMap) {
2729
+ for (var i2 = offset; i2 < offset + count; i2++) {
2730
+ var item = getWasmTableEntry(i2);
2731
+ if (item) {
2732
+ functionsInTableMap.set(item, i2);
2733
+ }
2734
+ }
2735
+ }
2736
+ }, "updateTableMap");
2737
+ var functionsInTableMap;
2738
+ var getFunctionAddress = /* @__PURE__ */ __name((func2) => {
2739
+ if (!functionsInTableMap) {
2740
+ functionsInTableMap = /* @__PURE__ */ new WeakMap();
2741
+ updateTableMap(0, wasmTable.length);
2742
+ }
2743
+ return functionsInTableMap.get(func2) || 0;
2744
+ }, "getFunctionAddress");
2745
+ var freeTableIndexes = [];
2746
+ var getEmptyTableSlot = /* @__PURE__ */ __name(() => {
2747
+ if (freeTableIndexes.length) {
2748
+ return freeTableIndexes.pop();
2749
+ }
2750
+ return wasmTable["grow"](1);
2751
+ }, "getEmptyTableSlot");
2752
+ var setWasmTableEntry = /* @__PURE__ */ __name((idx, func2) => {
2753
+ wasmTable.set(idx, func2);
2754
+ wasmTableMirror[idx] = wasmTable.get(idx);
2755
+ }, "setWasmTableEntry");
2756
+ var addFunction = /* @__PURE__ */ __name((func2, sig) => {
2757
+ var rtn = getFunctionAddress(func2);
2758
+ if (rtn) {
2759
+ return rtn;
2760
+ }
2761
+ var ret = getEmptyTableSlot();
2762
+ try {
2763
+ setWasmTableEntry(ret, func2);
2764
+ } catch (err2) {
2765
+ if (!(err2 instanceof TypeError)) {
2766
+ throw err2;
2767
+ }
2768
+ var wrapped = convertJsFunctionToWasm(func2, sig);
2769
+ setWasmTableEntry(ret, wrapped);
2770
+ }
2771
+ functionsInTableMap.set(func2, ret);
2772
+ return ret;
2773
+ }, "addFunction");
2774
+ var updateGOT = /* @__PURE__ */ __name((exports, replace) => {
2775
+ for (var symName in exports) {
2776
+ if (isInternalSym(symName)) {
2777
+ continue;
2778
+ }
2779
+ var value = exports[symName];
2780
+ GOT[symName] ||= new WebAssembly.Global({
2781
+ "value": "i32",
2782
+ "mutable": true
2783
+ });
2784
+ if (replace || GOT[symName].value == 0) {
2785
+ if (typeof value == "function") {
2786
+ GOT[symName].value = addFunction(value);
2787
+ } else if (typeof value == "number") {
2788
+ GOT[symName].value = value;
2789
+ } else {
2790
+ err(`unhandled export type for '${symName}': ${typeof value}`);
2791
+ }
2792
+ }
2793
+ }
2794
+ }, "updateGOT");
2795
+ var relocateExports = /* @__PURE__ */ __name((exports, memoryBase2, replace) => {
2796
+ var relocated = {};
2797
+ for (var e in exports) {
2798
+ var value = exports[e];
2799
+ if (typeof value == "object") {
2800
+ value = value.value;
2801
+ }
2802
+ if (typeof value == "number") {
2803
+ value += memoryBase2;
2804
+ }
2805
+ relocated[e] = value;
2806
+ }
2807
+ updateGOT(relocated, replace);
2808
+ return relocated;
2809
+ }, "relocateExports");
2810
+ var isSymbolDefined = /* @__PURE__ */ __name((symName) => {
2811
+ var existing = wasmImports[symName];
2812
+ if (!existing || existing.stub) {
2813
+ return false;
2814
+ }
2815
+ return true;
2816
+ }, "isSymbolDefined");
2817
+ var dynCall = /* @__PURE__ */ __name((sig, ptr, args2 = [], promising = false) => {
2818
+ var func2 = getWasmTableEntry(ptr);
2819
+ var rtn = func2(...args2);
2820
+ function convert(rtn2) {
2821
+ return rtn2;
2822
+ }
2823
+ __name(convert, "convert");
2824
+ return convert(rtn);
2825
+ }, "dynCall");
2826
+ var stackSave = /* @__PURE__ */ __name(() => _emscripten_stack_get_current(), "stackSave");
2827
+ var stackRestore = /* @__PURE__ */ __name((val) => __emscripten_stack_restore(val), "stackRestore");
2828
+ var createInvokeFunction = /* @__PURE__ */ __name((sig) => (ptr, ...args2) => {
2829
+ var sp = stackSave();
2830
+ try {
2831
+ return dynCall(sig, ptr, args2);
2832
+ } catch (e) {
2833
+ stackRestore(sp);
2834
+ if (e !== e + 0) throw e;
2835
+ _setThrew(1, 0);
2836
+ if (sig[0] == "j") return 0n;
2837
+ }
2838
+ }, "createInvokeFunction");
2839
+ var resolveGlobalSymbol = /* @__PURE__ */ __name((symName, direct = false) => {
2840
+ var sym;
2841
+ if (isSymbolDefined(symName)) {
2842
+ sym = wasmImports[symName];
2843
+ } else if (symName.startsWith("invoke_")) {
2844
+ sym = wasmImports[symName] = createInvokeFunction(symName.split("_")[1]);
2845
+ }
2846
+ return {
2847
+ sym,
2848
+ name: symName
2849
+ };
2850
+ }, "resolveGlobalSymbol");
2851
+ var onPostCtors = [];
2852
+ var addOnPostCtor = /* @__PURE__ */ __name((cb) => onPostCtors.push(cb), "addOnPostCtor");
2853
+ var UTF8ToString = /* @__PURE__ */ __name((ptr, maxBytesToRead, ignoreNul) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : "", "UTF8ToString");
2854
+ var loadWebAssemblyModule = /* @__PURE__ */ __name((binary, flags, libName, localScope, handle) => {
2855
+ var metadata = getDylinkMetadata(binary);
2856
+ function loadModule() {
2857
+ var memAlign = Math.pow(2, metadata.memoryAlign);
2858
+ var memoryBase = metadata.memorySize ? alignMemory(getMemory(metadata.memorySize + memAlign), memAlign) : 0;
2859
+ var tableBase = metadata.tableSize ? wasmTable.length : 0;
2860
+ if (handle) {
2861
+ HEAP8[handle + 8] = 1;
2862
+ LE_HEAP_STORE_U32((handle + 12 >> 2) * 4, memoryBase);
2863
+ LE_HEAP_STORE_I32((handle + 16 >> 2) * 4, metadata.memorySize);
2864
+ LE_HEAP_STORE_U32((handle + 20 >> 2) * 4, tableBase);
2865
+ LE_HEAP_STORE_I32((handle + 24 >> 2) * 4, metadata.tableSize);
2866
+ }
2867
+ if (metadata.tableSize) {
2868
+ wasmTable.grow(metadata.tableSize);
2869
+ }
2870
+ var moduleExports;
2871
+ function resolveSymbol(sym) {
2872
+ var resolved = resolveGlobalSymbol(sym).sym;
2873
+ if (!resolved && localScope) {
2874
+ resolved = localScope[sym];
2875
+ }
2876
+ if (!resolved) {
2877
+ resolved = moduleExports[sym];
2878
+ }
2879
+ return resolved;
2880
+ }
2881
+ __name(resolveSymbol, "resolveSymbol");
2882
+ var proxyHandler = {
2883
+ get(stubs, prop) {
2884
+ switch (prop) {
2885
+ case "__memory_base":
2886
+ return memoryBase;
2887
+ case "__table_base":
2888
+ return tableBase;
2889
+ }
2890
+ if (prop in wasmImports && !wasmImports[prop].stub) {
2891
+ var res = wasmImports[prop];
2892
+ return res;
2893
+ }
2894
+ if (!(prop in stubs)) {
2895
+ var resolved;
2896
+ stubs[prop] = (...args2) => {
2897
+ resolved ||= resolveSymbol(prop);
2898
+ return resolved(...args2);
2899
+ };
2900
+ }
2901
+ return stubs[prop];
2902
+ }
2903
+ };
2904
+ var proxy = new Proxy({}, proxyHandler);
2905
+ currentModuleWeakSymbols = metadata.weakImports;
2906
+ var info = {
2907
+ "GOT.mem": new Proxy({}, GOTHandler),
2908
+ "GOT.func": new Proxy({}, GOTHandler),
2909
+ "env": proxy,
2910
+ "wasi_snapshot_preview1": proxy
2911
+ };
2912
+ function postInstantiation(module, instance) {
2913
+ updateTableMap(tableBase, metadata.tableSize);
2914
+ moduleExports = relocateExports(instance.exports, memoryBase);
2915
+ if (!flags.allowUndefined) {
2916
+ reportUndefinedSymbols();
2917
+ }
2918
+ function addEmAsm(addr, body) {
2919
+ var args = [];
2920
+ var arity = 0;
2921
+ for (; arity < 16; arity++) {
2922
+ if (body.indexOf("$" + arity) != -1) {
2923
+ args.push("$" + arity);
2924
+ } else {
2925
+ break;
2926
+ }
2927
+ }
2928
+ args = args.join(",");
2929
+ var func = `(${args}) => { ${body} };`;
2930
+ ASM_CONSTS[start] = eval(func);
2931
+ }
2932
+ __name(addEmAsm, "addEmAsm");
2933
+ if ("__start_em_asm" in moduleExports) {
2934
+ var start = moduleExports["__start_em_asm"];
2935
+ var stop = moduleExports["__stop_em_asm"];
2936
+ while (start < stop) {
2937
+ var jsString = UTF8ToString(start);
2938
+ addEmAsm(start, jsString);
2939
+ start = HEAPU8.indexOf(0, start) + 1;
2940
+ }
2941
+ }
2942
+ function addEmJs(name, cSig, body) {
2943
+ var jsArgs = [];
2944
+ cSig = cSig.slice(1, -1);
2945
+ if (cSig != "void") {
2946
+ cSig = cSig.split(",");
2947
+ for (var i in cSig) {
2948
+ var jsArg = cSig[i].split(" ").pop();
2949
+ jsArgs.push(jsArg.replace("*", ""));
2950
+ }
2951
+ }
2952
+ var func = `(${jsArgs}) => ${body};`;
2953
+ moduleExports[name] = eval(func);
2954
+ }
2955
+ __name(addEmJs, "addEmJs");
2956
+ for (var name in moduleExports) {
2957
+ if (name.startsWith("__em_js__")) {
2958
+ var start = moduleExports[name];
2959
+ var jsString = UTF8ToString(start);
2960
+ var parts = jsString.split("<::>");
2961
+ addEmJs(name.replace("__em_js__", ""), parts[0], parts[1]);
2962
+ delete moduleExports[name];
2963
+ }
2964
+ }
2965
+ var applyRelocs = moduleExports["__wasm_apply_data_relocs"];
2966
+ if (applyRelocs) {
2967
+ if (runtimeInitialized) {
2968
+ applyRelocs();
2969
+ } else {
2970
+ __RELOC_FUNCS__.push(applyRelocs);
2971
+ }
2972
+ }
2973
+ var init = moduleExports["__wasm_call_ctors"];
2974
+ if (init) {
2975
+ if (runtimeInitialized) {
2976
+ init();
2977
+ } else {
2978
+ addOnPostCtor(init);
2979
+ }
2980
+ }
2981
+ return moduleExports;
2982
+ }
2983
+ __name(postInstantiation, "postInstantiation");
2984
+ if (flags.loadAsync) {
2985
+ return (async () => {
2986
+ var instance2;
2987
+ if (binary instanceof WebAssembly.Module) {
2988
+ instance2 = new WebAssembly.Instance(binary, info);
2989
+ } else {
2990
+ ({ module: binary, instance: instance2 } = await WebAssembly.instantiate(binary, info));
2991
+ }
2992
+ return postInstantiation(binary, instance2);
2993
+ })();
2994
+ }
2995
+ var module = binary instanceof WebAssembly.Module ? binary : new WebAssembly.Module(binary);
2996
+ var instance = new WebAssembly.Instance(module, info);
2997
+ return postInstantiation(module, instance);
2998
+ }
2999
+ __name(loadModule, "loadModule");
3000
+ flags = {
3001
+ ...flags,
3002
+ rpath: {
3003
+ parentLibPath: libName,
3004
+ paths: metadata.runtimePaths
3005
+ }
3006
+ };
3007
+ if (flags.loadAsync) {
3008
+ return metadata.neededDynlibs.reduce((chain, dynNeeded) => chain.then(() => loadDynamicLibrary(dynNeeded, flags, localScope)), Promise.resolve()).then(loadModule);
3009
+ }
3010
+ metadata.neededDynlibs.forEach((needed) => loadDynamicLibrary(needed, flags, localScope));
3011
+ return loadModule();
3012
+ }, "loadWebAssemblyModule");
3013
+ var mergeLibSymbols = /* @__PURE__ */ __name((exports, libName2) => {
3014
+ for (var [sym, exp] of Object.entries(exports)) {
3015
+ const setImport = /* @__PURE__ */ __name((target) => {
3016
+ if (!isSymbolDefined(target)) {
3017
+ wasmImports[target] = exp;
3018
+ }
3019
+ }, "setImport");
3020
+ setImport(sym);
3021
+ const main_alias = "__main_argc_argv";
3022
+ if (sym == "main") {
3023
+ setImport(main_alias);
3024
+ }
3025
+ if (sym == main_alias) {
3026
+ setImport("main");
3027
+ }
3028
+ }
3029
+ }, "mergeLibSymbols");
3030
+ var asyncLoad = /* @__PURE__ */ __name(async (url) => {
3031
+ var arrayBuffer = await readAsync(url);
3032
+ return new Uint8Array(arrayBuffer);
3033
+ }, "asyncLoad");
3034
+ function loadDynamicLibrary(libName2, flags2 = {
3035
+ global: true,
3036
+ nodelete: true
3037
+ }, localScope2, handle2) {
3038
+ var dso = LDSO.loadedLibsByName[libName2];
3039
+ if (dso) {
3040
+ if (!flags2.global) {
3041
+ if (localScope2) {
3042
+ Object.assign(localScope2, dso.exports);
3043
+ }
3044
+ } else if (!dso.global) {
3045
+ dso.global = true;
3046
+ mergeLibSymbols(dso.exports, libName2);
3047
+ }
3048
+ if (flags2.nodelete && dso.refcount !== Infinity) {
3049
+ dso.refcount = Infinity;
3050
+ }
3051
+ dso.refcount++;
3052
+ if (handle2) {
3053
+ LDSO.loadedLibsByHandle[handle2] = dso;
3054
+ }
3055
+ return flags2.loadAsync ? Promise.resolve(true) : true;
3056
+ }
3057
+ dso = newDSO(libName2, handle2, "loading");
3058
+ dso.refcount = flags2.nodelete ? Infinity : 1;
3059
+ dso.global = flags2.global;
3060
+ function loadLibData() {
3061
+ if (handle2) {
3062
+ var data = LE_HEAP_LOAD_U32((handle2 + 28 >> 2) * 4);
3063
+ var dataSize = LE_HEAP_LOAD_U32((handle2 + 32 >> 2) * 4);
3064
+ if (data && dataSize) {
3065
+ var libData = HEAP8.slice(data, data + dataSize);
3066
+ return flags2.loadAsync ? Promise.resolve(libData) : libData;
3067
+ }
3068
+ }
3069
+ var libFile = locateFile(libName2);
3070
+ if (flags2.loadAsync) {
3071
+ return asyncLoad(libFile);
3072
+ }
3073
+ if (!readBinary) {
3074
+ throw new Error(`${libFile}: file not found, and synchronous loading of external files is not available`);
3075
+ }
3076
+ return readBinary(libFile);
3077
+ }
3078
+ __name(loadLibData, "loadLibData");
3079
+ function getExports() {
3080
+ if (flags2.loadAsync) {
3081
+ return loadLibData().then((libData) => loadWebAssemblyModule(libData, flags2, libName2, localScope2, handle2));
3082
+ }
3083
+ return loadWebAssemblyModule(loadLibData(), flags2, libName2, localScope2, handle2);
3084
+ }
3085
+ __name(getExports, "getExports");
3086
+ function moduleLoaded(exports) {
3087
+ if (dso.global) {
3088
+ mergeLibSymbols(exports, libName2);
3089
+ } else if (localScope2) {
3090
+ Object.assign(localScope2, exports);
3091
+ }
3092
+ dso.exports = exports;
3093
+ }
3094
+ __name(moduleLoaded, "moduleLoaded");
3095
+ if (flags2.loadAsync) {
3096
+ return getExports().then((exports) => {
3097
+ moduleLoaded(exports);
3098
+ return true;
3099
+ });
3100
+ }
3101
+ moduleLoaded(getExports());
3102
+ return true;
3103
+ }
3104
+ __name(loadDynamicLibrary, "loadDynamicLibrary");
3105
+ var reportUndefinedSymbols = /* @__PURE__ */ __name(() => {
3106
+ for (var [symName, entry] of Object.entries(GOT)) {
3107
+ if (entry.value == 0) {
3108
+ var value = resolveGlobalSymbol(symName, true).sym;
3109
+ if (!value && !entry.required) {
3110
+ continue;
3111
+ }
3112
+ if (typeof value == "function") {
3113
+ entry.value = addFunction(value, value.sig);
3114
+ } else if (typeof value == "number") {
3115
+ entry.value = value;
3116
+ } else {
3117
+ throw new Error(`bad export type for '${symName}': ${typeof value}`);
3118
+ }
3119
+ }
3120
+ }
3121
+ }, "reportUndefinedSymbols");
3122
+ var runDependencies = 0;
3123
+ var dependenciesFulfilled = null;
3124
+ var removeRunDependency = /* @__PURE__ */ __name((id) => {
3125
+ runDependencies--;
3126
+ Module["monitorRunDependencies"]?.(runDependencies);
3127
+ if (runDependencies == 0) {
3128
+ if (dependenciesFulfilled) {
3129
+ var callback = dependenciesFulfilled;
3130
+ dependenciesFulfilled = null;
3131
+ callback();
3132
+ }
3133
+ }
3134
+ }, "removeRunDependency");
3135
+ var addRunDependency = /* @__PURE__ */ __name((id) => {
3136
+ runDependencies++;
3137
+ Module["monitorRunDependencies"]?.(runDependencies);
3138
+ }, "addRunDependency");
3139
+ var loadDylibs = /* @__PURE__ */ __name(async () => {
3140
+ if (!dynamicLibraries.length) {
3141
+ reportUndefinedSymbols();
3142
+ return;
3143
+ }
3144
+ addRunDependency("loadDylibs");
3145
+ for (var lib of dynamicLibraries) {
3146
+ await loadDynamicLibrary(lib, {
3147
+ loadAsync: true,
3148
+ global: true,
3149
+ nodelete: true,
3150
+ allowUndefined: true
3151
+ });
3152
+ }
3153
+ reportUndefinedSymbols();
3154
+ removeRunDependency("loadDylibs");
3155
+ }, "loadDylibs");
3156
+ var noExitRuntime = true;
3157
+ function setValue(ptr, value, type = "i8") {
3158
+ if (type.endsWith("*")) type = "*";
3159
+ switch (type) {
3160
+ case "i1":
3161
+ HEAP8[ptr] = value;
3162
+ break;
3163
+ case "i8":
3164
+ HEAP8[ptr] = value;
3165
+ break;
3166
+ case "i16":
3167
+ LE_HEAP_STORE_I16((ptr >> 1) * 2, value);
3168
+ break;
3169
+ case "i32":
3170
+ LE_HEAP_STORE_I32((ptr >> 2) * 4, value);
3171
+ break;
3172
+ case "i64":
3173
+ LE_HEAP_STORE_I64((ptr >> 3) * 8, BigInt(value));
3174
+ break;
3175
+ case "float":
3176
+ LE_HEAP_STORE_F32((ptr >> 2) * 4, value);
3177
+ break;
3178
+ case "double":
3179
+ LE_HEAP_STORE_F64((ptr >> 3) * 8, value);
3180
+ break;
3181
+ case "*":
3182
+ LE_HEAP_STORE_U32((ptr >> 2) * 4, value);
3183
+ break;
3184
+ default:
3185
+ abort(`invalid type for setValue: ${type}`);
3186
+ }
3187
+ }
3188
+ __name(setValue, "setValue");
3189
+ var ___memory_base = new WebAssembly.Global({
3190
+ "value": "i32",
3191
+ "mutable": false
3192
+ }, 1024);
3193
+ var ___stack_high = 78240;
3194
+ var ___stack_low = 12704;
3195
+ var ___stack_pointer = new WebAssembly.Global({
3196
+ "value": "i32",
3197
+ "mutable": true
3198
+ }, 78240);
3199
+ var ___table_base = new WebAssembly.Global({
3200
+ "value": "i32",
3201
+ "mutable": false
3202
+ }, 1);
3203
+ var __abort_js = /* @__PURE__ */ __name(() => abort(""), "__abort_js");
3204
+ __abort_js.sig = "v";
3205
+ var getHeapMax = /* @__PURE__ */ __name(() => (
3206
+ // Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate
3207
+ // full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side
3208
+ // for any code that deals with heap sizes, which would require special
3209
+ // casing all heap size related code to treat 0 specially.
3210
+ 2147483648
3211
+ ), "getHeapMax");
3212
+ var growMemory = /* @__PURE__ */ __name((size) => {
3213
+ var oldHeapSize = wasmMemory.buffer.byteLength;
3214
+ var pages = (size - oldHeapSize + 65535) / 65536 | 0;
3215
+ try {
3216
+ wasmMemory.grow(pages);
3217
+ updateMemoryViews();
3218
+ return 1;
3219
+ } catch (e) {
3220
+ }
3221
+ }, "growMemory");
3222
+ var _emscripten_resize_heap = /* @__PURE__ */ __name((requestedSize) => {
3223
+ var oldSize = HEAPU8.length;
3224
+ requestedSize >>>= 0;
3225
+ var maxHeapSize = getHeapMax();
3226
+ if (requestedSize > maxHeapSize) {
3227
+ return false;
3228
+ }
3229
+ for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
3230
+ var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown);
3231
+ overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296);
3232
+ var newSize = Math.min(maxHeapSize, alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536));
3233
+ var replacement = growMemory(newSize);
3234
+ if (replacement) {
3235
+ return true;
3236
+ }
3237
+ }
3238
+ return false;
3239
+ }, "_emscripten_resize_heap");
3240
+ _emscripten_resize_heap.sig = "ip";
3241
+ var _fd_close = /* @__PURE__ */ __name((fd) => 52, "_fd_close");
3242
+ _fd_close.sig = "ii";
3243
+ var INT53_MAX = 9007199254740992;
3244
+ var INT53_MIN = -9007199254740992;
3245
+ var bigintToI53Checked = /* @__PURE__ */ __name((num) => num < INT53_MIN || num > INT53_MAX ? NaN : Number(num), "bigintToI53Checked");
3246
+ function _fd_seek(fd, offset, whence, newOffset) {
3247
+ offset = bigintToI53Checked(offset);
3248
+ return 70;
3249
+ }
3250
+ __name(_fd_seek, "_fd_seek");
3251
+ _fd_seek.sig = "iijip";
3252
+ var printCharBuffers = [null, [], []];
3253
+ var printChar = /* @__PURE__ */ __name((stream, curr) => {
3254
+ var buffer = printCharBuffers[stream];
3255
+ if (curr === 0 || curr === 10) {
3256
+ (stream === 1 ? out : err)(UTF8ArrayToString(buffer));
3257
+ buffer.length = 0;
3258
+ } else {
3259
+ buffer.push(curr);
3260
+ }
3261
+ }, "printChar");
3262
+ var _fd_write = /* @__PURE__ */ __name((fd, iov, iovcnt, pnum) => {
3263
+ var num = 0;
3264
+ for (var i2 = 0; i2 < iovcnt; i2++) {
3265
+ var ptr = LE_HEAP_LOAD_U32((iov >> 2) * 4);
3266
+ var len = LE_HEAP_LOAD_U32((iov + 4 >> 2) * 4);
3267
+ iov += 8;
3268
+ for (var j = 0; j < len; j++) {
3269
+ printChar(fd, HEAPU8[ptr + j]);
3270
+ }
3271
+ num += len;
3272
+ }
3273
+ LE_HEAP_STORE_U32((pnum >> 2) * 4, num);
3274
+ return 0;
3275
+ }, "_fd_write");
3276
+ _fd_write.sig = "iippp";
3277
+ function _tree_sitter_log_callback(isLexMessage, messageAddress) {
3278
+ if (Module.currentLogCallback) {
3279
+ const message = UTF8ToString(messageAddress);
3280
+ Module.currentLogCallback(message, isLexMessage !== 0);
3281
+ }
3282
+ }
3283
+ __name(_tree_sitter_log_callback, "_tree_sitter_log_callback");
3284
+ function _tree_sitter_parse_callback(inputBufferAddress, index, row, column, lengthAddress) {
3285
+ const INPUT_BUFFER_SIZE = 10 * 1024;
3286
+ const string = Module.currentParseCallback(index, {
3287
+ row,
3288
+ column
3289
+ });
3290
+ if (typeof string === "string") {
3291
+ setValue(lengthAddress, string.length, "i32");
3292
+ stringToUTF16(string, inputBufferAddress, INPUT_BUFFER_SIZE);
3293
+ } else {
3294
+ setValue(lengthAddress, 0, "i32");
3295
+ }
3296
+ }
3297
+ __name(_tree_sitter_parse_callback, "_tree_sitter_parse_callback");
3298
+ function _tree_sitter_progress_callback(currentOffset, hasError) {
3299
+ if (Module.currentProgressCallback) {
3300
+ return Module.currentProgressCallback({
3301
+ currentOffset,
3302
+ hasError
3303
+ });
3304
+ }
3305
+ return false;
3306
+ }
3307
+ __name(_tree_sitter_progress_callback, "_tree_sitter_progress_callback");
3308
+ function _tree_sitter_query_progress_callback(currentOffset) {
3309
+ if (Module.currentQueryProgressCallback) {
3310
+ return Module.currentQueryProgressCallback({
3311
+ currentOffset
3312
+ });
3313
+ }
3314
+ return false;
3315
+ }
3316
+ __name(_tree_sitter_query_progress_callback, "_tree_sitter_query_progress_callback");
3317
+ var runtimeKeepaliveCounter = 0;
3318
+ var keepRuntimeAlive = /* @__PURE__ */ __name(() => noExitRuntime || runtimeKeepaliveCounter > 0, "keepRuntimeAlive");
3319
+ var _proc_exit = /* @__PURE__ */ __name((code) => {
3320
+ EXITSTATUS = code;
3321
+ if (!keepRuntimeAlive()) {
3322
+ Module["onExit"]?.(code);
3323
+ ABORT = true;
3324
+ }
3325
+ quit_(code, new ExitStatus(code));
3326
+ }, "_proc_exit");
3327
+ _proc_exit.sig = "vi";
3328
+ var exitJS = /* @__PURE__ */ __name((status, implicit) => {
3329
+ EXITSTATUS = status;
3330
+ _proc_exit(status);
3331
+ }, "exitJS");
3332
+ var handleException = /* @__PURE__ */ __name((e) => {
3333
+ if (e instanceof ExitStatus || e == "unwind") {
3334
+ return EXITSTATUS;
3335
+ }
3336
+ quit_(1, e);
3337
+ }, "handleException");
3338
+ var lengthBytesUTF8 = /* @__PURE__ */ __name((str) => {
3339
+ var len = 0;
3340
+ for (var i2 = 0; i2 < str.length; ++i2) {
3341
+ var c = str.charCodeAt(i2);
3342
+ if (c <= 127) {
3343
+ len++;
3344
+ } else if (c <= 2047) {
3345
+ len += 2;
3346
+ } else if (c >= 55296 && c <= 57343) {
3347
+ len += 4;
3348
+ ++i2;
3349
+ } else {
3350
+ len += 3;
3351
+ }
3352
+ }
3353
+ return len;
3354
+ }, "lengthBytesUTF8");
3355
+ var stringToUTF8Array = /* @__PURE__ */ __name((str, heap, outIdx, maxBytesToWrite) => {
3356
+ if (!(maxBytesToWrite > 0)) return 0;
3357
+ var startIdx = outIdx;
3358
+ var endIdx = outIdx + maxBytesToWrite - 1;
3359
+ for (var i2 = 0; i2 < str.length; ++i2) {
3360
+ var u = str.codePointAt(i2);
3361
+ if (u <= 127) {
3362
+ if (outIdx >= endIdx) break;
3363
+ heap[outIdx++] = u;
3364
+ } else if (u <= 2047) {
3365
+ if (outIdx + 1 >= endIdx) break;
3366
+ heap[outIdx++] = 192 | u >> 6;
3367
+ heap[outIdx++] = 128 | u & 63;
3368
+ } else if (u <= 65535) {
3369
+ if (outIdx + 2 >= endIdx) break;
3370
+ heap[outIdx++] = 224 | u >> 12;
3371
+ heap[outIdx++] = 128 | u >> 6 & 63;
3372
+ heap[outIdx++] = 128 | u & 63;
3373
+ } else {
3374
+ if (outIdx + 3 >= endIdx) break;
3375
+ heap[outIdx++] = 240 | u >> 18;
3376
+ heap[outIdx++] = 128 | u >> 12 & 63;
3377
+ heap[outIdx++] = 128 | u >> 6 & 63;
3378
+ heap[outIdx++] = 128 | u & 63;
3379
+ i2++;
3380
+ }
3381
+ }
3382
+ heap[outIdx] = 0;
3383
+ return outIdx - startIdx;
3384
+ }, "stringToUTF8Array");
3385
+ var stringToUTF8 = /* @__PURE__ */ __name((str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite), "stringToUTF8");
3386
+ var stackAlloc = /* @__PURE__ */ __name((sz) => __emscripten_stack_alloc(sz), "stackAlloc");
3387
+ var stringToUTF8OnStack = /* @__PURE__ */ __name((str) => {
3388
+ var size = lengthBytesUTF8(str) + 1;
3389
+ var ret = stackAlloc(size);
3390
+ stringToUTF8(str, ret, size);
3391
+ return ret;
3392
+ }, "stringToUTF8OnStack");
3393
+ var AsciiToString = /* @__PURE__ */ __name((ptr) => {
3394
+ var str = "";
3395
+ while (1) {
3396
+ var ch = HEAPU8[ptr++];
3397
+ if (!ch) return str;
3398
+ str += String.fromCharCode(ch);
3399
+ }
3400
+ }, "AsciiToString");
3401
+ var stringToUTF16 = /* @__PURE__ */ __name((str, outPtr, maxBytesToWrite) => {
3402
+ maxBytesToWrite ??= 2147483647;
3403
+ if (maxBytesToWrite < 2) return 0;
3404
+ maxBytesToWrite -= 2;
3405
+ var startPtr = outPtr;
3406
+ var numCharsToWrite = maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length;
3407
+ for (var i2 = 0; i2 < numCharsToWrite; ++i2) {
3408
+ var codeUnit = str.charCodeAt(i2);
3409
+ LE_HEAP_STORE_I16((outPtr >> 1) * 2, codeUnit);
3410
+ outPtr += 2;
3411
+ }
3412
+ LE_HEAP_STORE_I16((outPtr >> 1) * 2, 0);
3413
+ return outPtr - startPtr;
3414
+ }, "stringToUTF16");
3415
+ LE_ATOMICS_NATIVE_BYTE_ORDER = new Int8Array(new Int16Array([1]).buffer)[0] === 1 ? [
3416
+ /* little endian */
3417
+ ((x) => x),
3418
+ ((x) => x),
3419
+ void 0,
3420
+ ((x) => x)
3421
+ ] : [
3422
+ /* big endian */
3423
+ ((x) => x),
3424
+ ((x) => ((x & 65280) << 8 | (x & 255) << 24) >> 16),
3425
+ void 0,
3426
+ ((x) => x >> 24 & 255 | x >> 8 & 65280 | (x & 65280) << 8 | (x & 255) << 24)
3427
+ ];
3428
+ function LE_HEAP_UPDATE() {
3429
+ HEAPU16.unsigned = ((x) => x & 65535);
3430
+ HEAPU32.unsigned = ((x) => x >>> 0);
3431
+ }
3432
+ __name(LE_HEAP_UPDATE, "LE_HEAP_UPDATE");
3433
+ {
3434
+ initMemory();
3435
+ if (Module["noExitRuntime"]) noExitRuntime = Module["noExitRuntime"];
3436
+ if (Module["print"]) out = Module["print"];
3437
+ if (Module["printErr"]) err = Module["printErr"];
3438
+ if (Module["dynamicLibraries"]) dynamicLibraries = Module["dynamicLibraries"];
3439
+ if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
3440
+ if (Module["arguments"]) arguments_ = Module["arguments"];
3441
+ if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
3442
+ if (Module["preInit"]) {
3443
+ if (typeof Module["preInit"] == "function") Module["preInit"] = [Module["preInit"]];
3444
+ while (Module["preInit"].length > 0) {
3445
+ Module["preInit"].shift()();
3446
+ }
3447
+ }
3448
+ }
3449
+ Module["setValue"] = setValue;
3450
+ Module["getValue"] = getValue;
3451
+ Module["UTF8ToString"] = UTF8ToString;
3452
+ Module["stringToUTF8"] = stringToUTF8;
3453
+ Module["lengthBytesUTF8"] = lengthBytesUTF8;
3454
+ Module["AsciiToString"] = AsciiToString;
3455
+ Module["stringToUTF16"] = stringToUTF16;
3456
+ Module["loadWebAssemblyModule"] = loadWebAssemblyModule;
3457
+ Module["LE_HEAP_STORE_I64"] = LE_HEAP_STORE_I64;
3458
+ var ASM_CONSTS = {};
3459
+ var _malloc, _calloc, _realloc, _free, _ts_range_edit, _memcmp, _ts_language_symbol_count, _ts_language_state_count, _ts_language_abi_version, _ts_language_name, _ts_language_field_count, _ts_language_next_state, _ts_language_symbol_name, _ts_language_symbol_for_name, _strncmp, _ts_language_symbol_type, _ts_language_field_name_for_id, _ts_lookahead_iterator_new, _ts_lookahead_iterator_delete, _ts_lookahead_iterator_reset_state, _ts_lookahead_iterator_reset, _ts_lookahead_iterator_next, _ts_lookahead_iterator_current_symbol, _ts_point_edit, _ts_parser_delete, _ts_parser_reset, _ts_parser_set_language, _ts_parser_set_included_ranges, _ts_query_new, _ts_query_delete, _iswspace, _iswalnum, _ts_query_pattern_count, _ts_query_capture_count, _ts_query_string_count, _ts_query_capture_name_for_id, _ts_query_capture_quantifier_for_id, _ts_query_string_value_for_id, _ts_query_predicates_for_pattern, _ts_query_start_byte_for_pattern, _ts_query_end_byte_for_pattern, _ts_query_is_pattern_rooted, _ts_query_is_pattern_non_local, _ts_query_is_pattern_guaranteed_at_step, _ts_query_disable_capture, _ts_query_disable_pattern, _ts_tree_copy, _ts_tree_delete, _ts_init, _ts_parser_new_wasm, _ts_parser_enable_logger_wasm, _ts_parser_parse_wasm, _ts_parser_included_ranges_wasm, _ts_language_type_is_named_wasm, _ts_language_type_is_visible_wasm, _ts_language_metadata_wasm, _ts_language_supertypes_wasm, _ts_language_subtypes_wasm, _ts_tree_root_node_wasm, _ts_tree_root_node_with_offset_wasm, _ts_tree_edit_wasm, _ts_tree_included_ranges_wasm, _ts_tree_get_changed_ranges_wasm, _ts_tree_cursor_new_wasm, _ts_tree_cursor_copy_wasm, _ts_tree_cursor_delete_wasm, _ts_tree_cursor_reset_wasm, _ts_tree_cursor_reset_to_wasm, _ts_tree_cursor_goto_first_child_wasm, _ts_tree_cursor_goto_last_child_wasm, _ts_tree_cursor_goto_first_child_for_index_wasm, _ts_tree_cursor_goto_first_child_for_position_wasm, _ts_tree_cursor_goto_next_sibling_wasm, _ts_tree_cursor_goto_previous_sibling_wasm, _ts_tree_cursor_goto_descendant_wasm, _ts_tree_cursor_goto_parent_wasm, _ts_tree_cursor_current_node_type_id_wasm, _ts_tree_cursor_current_node_state_id_wasm, _ts_tree_cursor_current_node_is_named_wasm, _ts_tree_cursor_current_node_is_missing_wasm, _ts_tree_cursor_current_node_id_wasm, _ts_tree_cursor_start_position_wasm, _ts_tree_cursor_end_position_wasm, _ts_tree_cursor_start_index_wasm, _ts_tree_cursor_end_index_wasm, _ts_tree_cursor_current_field_id_wasm, _ts_tree_cursor_current_depth_wasm, _ts_tree_cursor_current_descendant_index_wasm, _ts_tree_cursor_current_node_wasm, _ts_node_symbol_wasm, _ts_node_field_name_for_child_wasm, _ts_node_field_name_for_named_child_wasm, _ts_node_children_by_field_id_wasm, _ts_node_first_child_for_byte_wasm, _ts_node_first_named_child_for_byte_wasm, _ts_node_grammar_symbol_wasm, _ts_node_child_count_wasm, _ts_node_named_child_count_wasm, _ts_node_child_wasm, _ts_node_named_child_wasm, _ts_node_child_by_field_id_wasm, _ts_node_next_sibling_wasm, _ts_node_prev_sibling_wasm, _ts_node_next_named_sibling_wasm, _ts_node_prev_named_sibling_wasm, _ts_node_descendant_count_wasm, _ts_node_parent_wasm, _ts_node_child_with_descendant_wasm, _ts_node_descendant_for_index_wasm, _ts_node_named_descendant_for_index_wasm, _ts_node_descendant_for_position_wasm, _ts_node_named_descendant_for_position_wasm, _ts_node_start_point_wasm, _ts_node_end_point_wasm, _ts_node_start_index_wasm, _ts_node_end_index_wasm, _ts_node_to_string_wasm, _ts_node_children_wasm, _ts_node_named_children_wasm, _ts_node_descendants_of_type_wasm, _ts_node_is_named_wasm, _ts_node_has_changes_wasm, _ts_node_has_error_wasm, _ts_node_is_error_wasm, _ts_node_is_missing_wasm, _ts_node_is_extra_wasm, _ts_node_parse_state_wasm, _ts_node_next_parse_state_wasm, _ts_query_matches_wasm, _ts_query_captures_wasm, _memset, _memcpy, _memmove, _iswalpha, _iswblank, _iswdigit, _iswlower, _iswupper, _iswxdigit, _memchr, _strlen, _strcmp, _strncat, _strncpy, _towlower, _towupper, _setThrew, __emscripten_stack_restore, __emscripten_stack_alloc, _emscripten_stack_get_current, ___wasm_apply_data_relocs;
3460
+ function assignWasmExports(wasmExports2) {
3461
+ Module["_malloc"] = _malloc = wasmExports2["malloc"];
3462
+ Module["_calloc"] = _calloc = wasmExports2["calloc"];
3463
+ Module["_realloc"] = _realloc = wasmExports2["realloc"];
3464
+ Module["_free"] = _free = wasmExports2["free"];
3465
+ Module["_ts_range_edit"] = _ts_range_edit = wasmExports2["ts_range_edit"];
3466
+ Module["_memcmp"] = _memcmp = wasmExports2["memcmp"];
3467
+ Module["_ts_language_symbol_count"] = _ts_language_symbol_count = wasmExports2["ts_language_symbol_count"];
3468
+ Module["_ts_language_state_count"] = _ts_language_state_count = wasmExports2["ts_language_state_count"];
3469
+ Module["_ts_language_abi_version"] = _ts_language_abi_version = wasmExports2["ts_language_abi_version"];
3470
+ Module["_ts_language_name"] = _ts_language_name = wasmExports2["ts_language_name"];
3471
+ Module["_ts_language_field_count"] = _ts_language_field_count = wasmExports2["ts_language_field_count"];
3472
+ Module["_ts_language_next_state"] = _ts_language_next_state = wasmExports2["ts_language_next_state"];
3473
+ Module["_ts_language_symbol_name"] = _ts_language_symbol_name = wasmExports2["ts_language_symbol_name"];
3474
+ Module["_ts_language_symbol_for_name"] = _ts_language_symbol_for_name = wasmExports2["ts_language_symbol_for_name"];
3475
+ Module["_strncmp"] = _strncmp = wasmExports2["strncmp"];
3476
+ Module["_ts_language_symbol_type"] = _ts_language_symbol_type = wasmExports2["ts_language_symbol_type"];
3477
+ Module["_ts_language_field_name_for_id"] = _ts_language_field_name_for_id = wasmExports2["ts_language_field_name_for_id"];
3478
+ Module["_ts_lookahead_iterator_new"] = _ts_lookahead_iterator_new = wasmExports2["ts_lookahead_iterator_new"];
3479
+ Module["_ts_lookahead_iterator_delete"] = _ts_lookahead_iterator_delete = wasmExports2["ts_lookahead_iterator_delete"];
3480
+ Module["_ts_lookahead_iterator_reset_state"] = _ts_lookahead_iterator_reset_state = wasmExports2["ts_lookahead_iterator_reset_state"];
3481
+ Module["_ts_lookahead_iterator_reset"] = _ts_lookahead_iterator_reset = wasmExports2["ts_lookahead_iterator_reset"];
3482
+ Module["_ts_lookahead_iterator_next"] = _ts_lookahead_iterator_next = wasmExports2["ts_lookahead_iterator_next"];
3483
+ Module["_ts_lookahead_iterator_current_symbol"] = _ts_lookahead_iterator_current_symbol = wasmExports2["ts_lookahead_iterator_current_symbol"];
3484
+ Module["_ts_point_edit"] = _ts_point_edit = wasmExports2["ts_point_edit"];
3485
+ Module["_ts_parser_delete"] = _ts_parser_delete = wasmExports2["ts_parser_delete"];
3486
+ Module["_ts_parser_reset"] = _ts_parser_reset = wasmExports2["ts_parser_reset"];
3487
+ Module["_ts_parser_set_language"] = _ts_parser_set_language = wasmExports2["ts_parser_set_language"];
3488
+ Module["_ts_parser_set_included_ranges"] = _ts_parser_set_included_ranges = wasmExports2["ts_parser_set_included_ranges"];
3489
+ Module["_ts_query_new"] = _ts_query_new = wasmExports2["ts_query_new"];
3490
+ Module["_ts_query_delete"] = _ts_query_delete = wasmExports2["ts_query_delete"];
3491
+ Module["_iswspace"] = _iswspace = wasmExports2["iswspace"];
3492
+ Module["_iswalnum"] = _iswalnum = wasmExports2["iswalnum"];
3493
+ Module["_ts_query_pattern_count"] = _ts_query_pattern_count = wasmExports2["ts_query_pattern_count"];
3494
+ Module["_ts_query_capture_count"] = _ts_query_capture_count = wasmExports2["ts_query_capture_count"];
3495
+ Module["_ts_query_string_count"] = _ts_query_string_count = wasmExports2["ts_query_string_count"];
3496
+ Module["_ts_query_capture_name_for_id"] = _ts_query_capture_name_for_id = wasmExports2["ts_query_capture_name_for_id"];
3497
+ Module["_ts_query_capture_quantifier_for_id"] = _ts_query_capture_quantifier_for_id = wasmExports2["ts_query_capture_quantifier_for_id"];
3498
+ Module["_ts_query_string_value_for_id"] = _ts_query_string_value_for_id = wasmExports2["ts_query_string_value_for_id"];
3499
+ Module["_ts_query_predicates_for_pattern"] = _ts_query_predicates_for_pattern = wasmExports2["ts_query_predicates_for_pattern"];
3500
+ Module["_ts_query_start_byte_for_pattern"] = _ts_query_start_byte_for_pattern = wasmExports2["ts_query_start_byte_for_pattern"];
3501
+ Module["_ts_query_end_byte_for_pattern"] = _ts_query_end_byte_for_pattern = wasmExports2["ts_query_end_byte_for_pattern"];
3502
+ Module["_ts_query_is_pattern_rooted"] = _ts_query_is_pattern_rooted = wasmExports2["ts_query_is_pattern_rooted"];
3503
+ Module["_ts_query_is_pattern_non_local"] = _ts_query_is_pattern_non_local = wasmExports2["ts_query_is_pattern_non_local"];
3504
+ Module["_ts_query_is_pattern_guaranteed_at_step"] = _ts_query_is_pattern_guaranteed_at_step = wasmExports2["ts_query_is_pattern_guaranteed_at_step"];
3505
+ Module["_ts_query_disable_capture"] = _ts_query_disable_capture = wasmExports2["ts_query_disable_capture"];
3506
+ Module["_ts_query_disable_pattern"] = _ts_query_disable_pattern = wasmExports2["ts_query_disable_pattern"];
3507
+ Module["_ts_tree_copy"] = _ts_tree_copy = wasmExports2["ts_tree_copy"];
3508
+ Module["_ts_tree_delete"] = _ts_tree_delete = wasmExports2["ts_tree_delete"];
3509
+ Module["_ts_init"] = _ts_init = wasmExports2["ts_init"];
3510
+ Module["_ts_parser_new_wasm"] = _ts_parser_new_wasm = wasmExports2["ts_parser_new_wasm"];
3511
+ Module["_ts_parser_enable_logger_wasm"] = _ts_parser_enable_logger_wasm = wasmExports2["ts_parser_enable_logger_wasm"];
3512
+ Module["_ts_parser_parse_wasm"] = _ts_parser_parse_wasm = wasmExports2["ts_parser_parse_wasm"];
3513
+ Module["_ts_parser_included_ranges_wasm"] = _ts_parser_included_ranges_wasm = wasmExports2["ts_parser_included_ranges_wasm"];
3514
+ Module["_ts_language_type_is_named_wasm"] = _ts_language_type_is_named_wasm = wasmExports2["ts_language_type_is_named_wasm"];
3515
+ Module["_ts_language_type_is_visible_wasm"] = _ts_language_type_is_visible_wasm = wasmExports2["ts_language_type_is_visible_wasm"];
3516
+ Module["_ts_language_metadata_wasm"] = _ts_language_metadata_wasm = wasmExports2["ts_language_metadata_wasm"];
3517
+ Module["_ts_language_supertypes_wasm"] = _ts_language_supertypes_wasm = wasmExports2["ts_language_supertypes_wasm"];
3518
+ Module["_ts_language_subtypes_wasm"] = _ts_language_subtypes_wasm = wasmExports2["ts_language_subtypes_wasm"];
3519
+ Module["_ts_tree_root_node_wasm"] = _ts_tree_root_node_wasm = wasmExports2["ts_tree_root_node_wasm"];
3520
+ Module["_ts_tree_root_node_with_offset_wasm"] = _ts_tree_root_node_with_offset_wasm = wasmExports2["ts_tree_root_node_with_offset_wasm"];
3521
+ Module["_ts_tree_edit_wasm"] = _ts_tree_edit_wasm = wasmExports2["ts_tree_edit_wasm"];
3522
+ Module["_ts_tree_included_ranges_wasm"] = _ts_tree_included_ranges_wasm = wasmExports2["ts_tree_included_ranges_wasm"];
3523
+ Module["_ts_tree_get_changed_ranges_wasm"] = _ts_tree_get_changed_ranges_wasm = wasmExports2["ts_tree_get_changed_ranges_wasm"];
3524
+ Module["_ts_tree_cursor_new_wasm"] = _ts_tree_cursor_new_wasm = wasmExports2["ts_tree_cursor_new_wasm"];
3525
+ Module["_ts_tree_cursor_copy_wasm"] = _ts_tree_cursor_copy_wasm = wasmExports2["ts_tree_cursor_copy_wasm"];
3526
+ Module["_ts_tree_cursor_delete_wasm"] = _ts_tree_cursor_delete_wasm = wasmExports2["ts_tree_cursor_delete_wasm"];
3527
+ Module["_ts_tree_cursor_reset_wasm"] = _ts_tree_cursor_reset_wasm = wasmExports2["ts_tree_cursor_reset_wasm"];
3528
+ Module["_ts_tree_cursor_reset_to_wasm"] = _ts_tree_cursor_reset_to_wasm = wasmExports2["ts_tree_cursor_reset_to_wasm"];
3529
+ Module["_ts_tree_cursor_goto_first_child_wasm"] = _ts_tree_cursor_goto_first_child_wasm = wasmExports2["ts_tree_cursor_goto_first_child_wasm"];
3530
+ Module["_ts_tree_cursor_goto_last_child_wasm"] = _ts_tree_cursor_goto_last_child_wasm = wasmExports2["ts_tree_cursor_goto_last_child_wasm"];
3531
+ Module["_ts_tree_cursor_goto_first_child_for_index_wasm"] = _ts_tree_cursor_goto_first_child_for_index_wasm = wasmExports2["ts_tree_cursor_goto_first_child_for_index_wasm"];
3532
+ Module["_ts_tree_cursor_goto_first_child_for_position_wasm"] = _ts_tree_cursor_goto_first_child_for_position_wasm = wasmExports2["ts_tree_cursor_goto_first_child_for_position_wasm"];
3533
+ Module["_ts_tree_cursor_goto_next_sibling_wasm"] = _ts_tree_cursor_goto_next_sibling_wasm = wasmExports2["ts_tree_cursor_goto_next_sibling_wasm"];
3534
+ Module["_ts_tree_cursor_goto_previous_sibling_wasm"] = _ts_tree_cursor_goto_previous_sibling_wasm = wasmExports2["ts_tree_cursor_goto_previous_sibling_wasm"];
3535
+ Module["_ts_tree_cursor_goto_descendant_wasm"] = _ts_tree_cursor_goto_descendant_wasm = wasmExports2["ts_tree_cursor_goto_descendant_wasm"];
3536
+ Module["_ts_tree_cursor_goto_parent_wasm"] = _ts_tree_cursor_goto_parent_wasm = wasmExports2["ts_tree_cursor_goto_parent_wasm"];
3537
+ Module["_ts_tree_cursor_current_node_type_id_wasm"] = _ts_tree_cursor_current_node_type_id_wasm = wasmExports2["ts_tree_cursor_current_node_type_id_wasm"];
3538
+ Module["_ts_tree_cursor_current_node_state_id_wasm"] = _ts_tree_cursor_current_node_state_id_wasm = wasmExports2["ts_tree_cursor_current_node_state_id_wasm"];
3539
+ Module["_ts_tree_cursor_current_node_is_named_wasm"] = _ts_tree_cursor_current_node_is_named_wasm = wasmExports2["ts_tree_cursor_current_node_is_named_wasm"];
3540
+ Module["_ts_tree_cursor_current_node_is_missing_wasm"] = _ts_tree_cursor_current_node_is_missing_wasm = wasmExports2["ts_tree_cursor_current_node_is_missing_wasm"];
3541
+ Module["_ts_tree_cursor_current_node_id_wasm"] = _ts_tree_cursor_current_node_id_wasm = wasmExports2["ts_tree_cursor_current_node_id_wasm"];
3542
+ Module["_ts_tree_cursor_start_position_wasm"] = _ts_tree_cursor_start_position_wasm = wasmExports2["ts_tree_cursor_start_position_wasm"];
3543
+ Module["_ts_tree_cursor_end_position_wasm"] = _ts_tree_cursor_end_position_wasm = wasmExports2["ts_tree_cursor_end_position_wasm"];
3544
+ Module["_ts_tree_cursor_start_index_wasm"] = _ts_tree_cursor_start_index_wasm = wasmExports2["ts_tree_cursor_start_index_wasm"];
3545
+ Module["_ts_tree_cursor_end_index_wasm"] = _ts_tree_cursor_end_index_wasm = wasmExports2["ts_tree_cursor_end_index_wasm"];
3546
+ Module["_ts_tree_cursor_current_field_id_wasm"] = _ts_tree_cursor_current_field_id_wasm = wasmExports2["ts_tree_cursor_current_field_id_wasm"];
3547
+ Module["_ts_tree_cursor_current_depth_wasm"] = _ts_tree_cursor_current_depth_wasm = wasmExports2["ts_tree_cursor_current_depth_wasm"];
3548
+ Module["_ts_tree_cursor_current_descendant_index_wasm"] = _ts_tree_cursor_current_descendant_index_wasm = wasmExports2["ts_tree_cursor_current_descendant_index_wasm"];
3549
+ Module["_ts_tree_cursor_current_node_wasm"] = _ts_tree_cursor_current_node_wasm = wasmExports2["ts_tree_cursor_current_node_wasm"];
3550
+ Module["_ts_node_symbol_wasm"] = _ts_node_symbol_wasm = wasmExports2["ts_node_symbol_wasm"];
3551
+ Module["_ts_node_field_name_for_child_wasm"] = _ts_node_field_name_for_child_wasm = wasmExports2["ts_node_field_name_for_child_wasm"];
3552
+ Module["_ts_node_field_name_for_named_child_wasm"] = _ts_node_field_name_for_named_child_wasm = wasmExports2["ts_node_field_name_for_named_child_wasm"];
3553
+ Module["_ts_node_children_by_field_id_wasm"] = _ts_node_children_by_field_id_wasm = wasmExports2["ts_node_children_by_field_id_wasm"];
3554
+ Module["_ts_node_first_child_for_byte_wasm"] = _ts_node_first_child_for_byte_wasm = wasmExports2["ts_node_first_child_for_byte_wasm"];
3555
+ Module["_ts_node_first_named_child_for_byte_wasm"] = _ts_node_first_named_child_for_byte_wasm = wasmExports2["ts_node_first_named_child_for_byte_wasm"];
3556
+ Module["_ts_node_grammar_symbol_wasm"] = _ts_node_grammar_symbol_wasm = wasmExports2["ts_node_grammar_symbol_wasm"];
3557
+ Module["_ts_node_child_count_wasm"] = _ts_node_child_count_wasm = wasmExports2["ts_node_child_count_wasm"];
3558
+ Module["_ts_node_named_child_count_wasm"] = _ts_node_named_child_count_wasm = wasmExports2["ts_node_named_child_count_wasm"];
3559
+ Module["_ts_node_child_wasm"] = _ts_node_child_wasm = wasmExports2["ts_node_child_wasm"];
3560
+ Module["_ts_node_named_child_wasm"] = _ts_node_named_child_wasm = wasmExports2["ts_node_named_child_wasm"];
3561
+ Module["_ts_node_child_by_field_id_wasm"] = _ts_node_child_by_field_id_wasm = wasmExports2["ts_node_child_by_field_id_wasm"];
3562
+ Module["_ts_node_next_sibling_wasm"] = _ts_node_next_sibling_wasm = wasmExports2["ts_node_next_sibling_wasm"];
3563
+ Module["_ts_node_prev_sibling_wasm"] = _ts_node_prev_sibling_wasm = wasmExports2["ts_node_prev_sibling_wasm"];
3564
+ Module["_ts_node_next_named_sibling_wasm"] = _ts_node_next_named_sibling_wasm = wasmExports2["ts_node_next_named_sibling_wasm"];
3565
+ Module["_ts_node_prev_named_sibling_wasm"] = _ts_node_prev_named_sibling_wasm = wasmExports2["ts_node_prev_named_sibling_wasm"];
3566
+ Module["_ts_node_descendant_count_wasm"] = _ts_node_descendant_count_wasm = wasmExports2["ts_node_descendant_count_wasm"];
3567
+ Module["_ts_node_parent_wasm"] = _ts_node_parent_wasm = wasmExports2["ts_node_parent_wasm"];
3568
+ Module["_ts_node_child_with_descendant_wasm"] = _ts_node_child_with_descendant_wasm = wasmExports2["ts_node_child_with_descendant_wasm"];
3569
+ Module["_ts_node_descendant_for_index_wasm"] = _ts_node_descendant_for_index_wasm = wasmExports2["ts_node_descendant_for_index_wasm"];
3570
+ Module["_ts_node_named_descendant_for_index_wasm"] = _ts_node_named_descendant_for_index_wasm = wasmExports2["ts_node_named_descendant_for_index_wasm"];
3571
+ Module["_ts_node_descendant_for_position_wasm"] = _ts_node_descendant_for_position_wasm = wasmExports2["ts_node_descendant_for_position_wasm"];
3572
+ Module["_ts_node_named_descendant_for_position_wasm"] = _ts_node_named_descendant_for_position_wasm = wasmExports2["ts_node_named_descendant_for_position_wasm"];
3573
+ Module["_ts_node_start_point_wasm"] = _ts_node_start_point_wasm = wasmExports2["ts_node_start_point_wasm"];
3574
+ Module["_ts_node_end_point_wasm"] = _ts_node_end_point_wasm = wasmExports2["ts_node_end_point_wasm"];
3575
+ Module["_ts_node_start_index_wasm"] = _ts_node_start_index_wasm = wasmExports2["ts_node_start_index_wasm"];
3576
+ Module["_ts_node_end_index_wasm"] = _ts_node_end_index_wasm = wasmExports2["ts_node_end_index_wasm"];
3577
+ Module["_ts_node_to_string_wasm"] = _ts_node_to_string_wasm = wasmExports2["ts_node_to_string_wasm"];
3578
+ Module["_ts_node_children_wasm"] = _ts_node_children_wasm = wasmExports2["ts_node_children_wasm"];
3579
+ Module["_ts_node_named_children_wasm"] = _ts_node_named_children_wasm = wasmExports2["ts_node_named_children_wasm"];
3580
+ Module["_ts_node_descendants_of_type_wasm"] = _ts_node_descendants_of_type_wasm = wasmExports2["ts_node_descendants_of_type_wasm"];
3581
+ Module["_ts_node_is_named_wasm"] = _ts_node_is_named_wasm = wasmExports2["ts_node_is_named_wasm"];
3582
+ Module["_ts_node_has_changes_wasm"] = _ts_node_has_changes_wasm = wasmExports2["ts_node_has_changes_wasm"];
3583
+ Module["_ts_node_has_error_wasm"] = _ts_node_has_error_wasm = wasmExports2["ts_node_has_error_wasm"];
3584
+ Module["_ts_node_is_error_wasm"] = _ts_node_is_error_wasm = wasmExports2["ts_node_is_error_wasm"];
3585
+ Module["_ts_node_is_missing_wasm"] = _ts_node_is_missing_wasm = wasmExports2["ts_node_is_missing_wasm"];
3586
+ Module["_ts_node_is_extra_wasm"] = _ts_node_is_extra_wasm = wasmExports2["ts_node_is_extra_wasm"];
3587
+ Module["_ts_node_parse_state_wasm"] = _ts_node_parse_state_wasm = wasmExports2["ts_node_parse_state_wasm"];
3588
+ Module["_ts_node_next_parse_state_wasm"] = _ts_node_next_parse_state_wasm = wasmExports2["ts_node_next_parse_state_wasm"];
3589
+ Module["_ts_query_matches_wasm"] = _ts_query_matches_wasm = wasmExports2["ts_query_matches_wasm"];
3590
+ Module["_ts_query_captures_wasm"] = _ts_query_captures_wasm = wasmExports2["ts_query_captures_wasm"];
3591
+ Module["_memset"] = _memset = wasmExports2["memset"];
3592
+ Module["_memcpy"] = _memcpy = wasmExports2["memcpy"];
3593
+ Module["_memmove"] = _memmove = wasmExports2["memmove"];
3594
+ Module["_iswalpha"] = _iswalpha = wasmExports2["iswalpha"];
3595
+ Module["_iswblank"] = _iswblank = wasmExports2["iswblank"];
3596
+ Module["_iswdigit"] = _iswdigit = wasmExports2["iswdigit"];
3597
+ Module["_iswlower"] = _iswlower = wasmExports2["iswlower"];
3598
+ Module["_iswupper"] = _iswupper = wasmExports2["iswupper"];
3599
+ Module["_iswxdigit"] = _iswxdigit = wasmExports2["iswxdigit"];
3600
+ Module["_memchr"] = _memchr = wasmExports2["memchr"];
3601
+ Module["_strlen"] = _strlen = wasmExports2["strlen"];
3602
+ Module["_strcmp"] = _strcmp = wasmExports2["strcmp"];
3603
+ Module["_strncat"] = _strncat = wasmExports2["strncat"];
3604
+ Module["_strncpy"] = _strncpy = wasmExports2["strncpy"];
3605
+ Module["_towlower"] = _towlower = wasmExports2["towlower"];
3606
+ Module["_towupper"] = _towupper = wasmExports2["towupper"];
3607
+ _setThrew = wasmExports2["setThrew"];
3608
+ __emscripten_stack_restore = wasmExports2["_emscripten_stack_restore"];
3609
+ __emscripten_stack_alloc = wasmExports2["_emscripten_stack_alloc"];
3610
+ _emscripten_stack_get_current = wasmExports2["emscripten_stack_get_current"];
3611
+ ___wasm_apply_data_relocs = wasmExports2["__wasm_apply_data_relocs"];
3612
+ }
3613
+ __name(assignWasmExports, "assignWasmExports");
3614
+ var wasmImports = {
3615
+ /** @export */
3616
+ __heap_base: ___heap_base,
3617
+ /** @export */
3618
+ __indirect_function_table: wasmTable,
3619
+ /** @export */
3620
+ __memory_base: ___memory_base,
3621
+ /** @export */
3622
+ __stack_high: ___stack_high,
3623
+ /** @export */
3624
+ __stack_low: ___stack_low,
3625
+ /** @export */
3626
+ __stack_pointer: ___stack_pointer,
3627
+ /** @export */
3628
+ __table_base: ___table_base,
3629
+ /** @export */
3630
+ _abort_js: __abort_js,
3631
+ /** @export */
3632
+ emscripten_resize_heap: _emscripten_resize_heap,
3633
+ /** @export */
3634
+ fd_close: _fd_close,
3635
+ /** @export */
3636
+ fd_seek: _fd_seek,
3637
+ /** @export */
3638
+ fd_write: _fd_write,
3639
+ /** @export */
3640
+ memory: wasmMemory,
3641
+ /** @export */
3642
+ tree_sitter_log_callback: _tree_sitter_log_callback,
3643
+ /** @export */
3644
+ tree_sitter_parse_callback: _tree_sitter_parse_callback,
3645
+ /** @export */
3646
+ tree_sitter_progress_callback: _tree_sitter_progress_callback,
3647
+ /** @export */
3648
+ tree_sitter_query_progress_callback: _tree_sitter_query_progress_callback
3649
+ };
3650
+ function callMain(args2 = []) {
3651
+ var entryFunction = resolveGlobalSymbol("main").sym;
3652
+ if (!entryFunction) return;
3653
+ args2.unshift(thisProgram);
3654
+ var argc = args2.length;
3655
+ var argv = stackAlloc((argc + 1) * 4);
3656
+ var argv_ptr = argv;
3657
+ args2.forEach((arg) => {
3658
+ LE_HEAP_STORE_U32((argv_ptr >> 2) * 4, stringToUTF8OnStack(arg));
3659
+ argv_ptr += 4;
3660
+ });
3661
+ LE_HEAP_STORE_U32((argv_ptr >> 2) * 4, 0);
3662
+ try {
3663
+ var ret = entryFunction(argc, argv);
3664
+ exitJS(
3665
+ ret,
3666
+ /* implicit = */
3667
+ true
3668
+ );
3669
+ return ret;
3670
+ } catch (e) {
3671
+ return handleException(e);
3672
+ }
3673
+ }
3674
+ __name(callMain, "callMain");
3675
+ function run(args2 = arguments_) {
3676
+ if (runDependencies > 0) {
3677
+ dependenciesFulfilled = run;
3678
+ return;
3679
+ }
3680
+ preRun();
3681
+ if (runDependencies > 0) {
3682
+ dependenciesFulfilled = run;
3683
+ return;
3684
+ }
3685
+ function doRun() {
3686
+ Module["calledRun"] = true;
3687
+ if (ABORT) return;
3688
+ initRuntime();
3689
+ preMain();
3690
+ readyPromiseResolve?.(Module);
3691
+ Module["onRuntimeInitialized"]?.();
3692
+ var noInitialRun = Module["noInitialRun"] || false;
3693
+ if (!noInitialRun) callMain(args2);
3694
+ postRun();
3695
+ }
3696
+ __name(doRun, "doRun");
3697
+ if (Module["setStatus"]) {
3698
+ Module["setStatus"]("Running...");
3699
+ setTimeout(() => {
3700
+ setTimeout(() => Module["setStatus"](""), 1);
3701
+ doRun();
3702
+ }, 1);
3703
+ } else {
3704
+ doRun();
3705
+ }
3706
+ }
3707
+ __name(run, "run");
3708
+ var wasmExports;
3709
+ wasmExports = await createWasm();
3710
+ run();
3711
+ if (runtimeInitialized) {
3712
+ moduleRtn = Module;
3713
+ } else {
3714
+ moduleRtn = new Promise((resolve, reject) => {
3715
+ readyPromiseResolve = resolve;
3716
+ readyPromiseReject = reject;
3717
+ });
3718
+ }
3719
+ return moduleRtn;
3720
+ }
3721
+ __name(Module2, "Module");
3722
+ var web_tree_sitter_default = Module2;
3723
+ var Module3 = null;
3724
+ async function initializeBinding(moduleOptions) {
3725
+ return Module3 ??= await web_tree_sitter_default(moduleOptions);
3726
+ }
3727
+ __name(initializeBinding, "initializeBinding");
3728
+ function checkModule() {
3729
+ return !!Module3;
3730
+ }
3731
+ __name(checkModule, "checkModule");
3732
+ var TRANSFER_BUFFER;
3733
+ var LANGUAGE_VERSION;
3734
+ var MIN_COMPATIBLE_VERSION;
3735
+ var Parser = class {
3736
+ static {
3737
+ __name(this, "Parser");
3738
+ }
3739
+ /** @internal */
3740
+ [0] = 0;
3741
+ // Internal handle for Wasm
3742
+ /** @internal */
3743
+ [1] = 0;
3744
+ // Internal handle for Wasm
3745
+ /** @internal */
3746
+ logCallback = null;
3747
+ /** The parser's current language. */
3748
+ language = null;
3749
+ /**
3750
+ * This must always be called before creating a Parser.
3751
+ *
3752
+ * You can optionally pass in options to configure the Wasm module, the most common
3753
+ * one being `locateFile` to help the module find the `.wasm` file.
3754
+ */
3755
+ static async init(moduleOptions) {
3756
+ setModule(await initializeBinding(moduleOptions));
3757
+ TRANSFER_BUFFER = C._ts_init();
3758
+ LANGUAGE_VERSION = C.getValue(TRANSFER_BUFFER, "i32");
3759
+ MIN_COMPATIBLE_VERSION = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
3760
+ }
3761
+ /**
3762
+ * Create a new parser.
3763
+ */
3764
+ constructor() {
3765
+ this.initialize();
3766
+ }
3767
+ /** @internal */
3768
+ initialize() {
3769
+ if (!checkModule()) {
3770
+ throw new Error("cannot construct a Parser before calling `init()`");
3771
+ }
3772
+ C._ts_parser_new_wasm();
3773
+ this[0] = C.getValue(TRANSFER_BUFFER, "i32");
3774
+ this[1] = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
3775
+ }
3776
+ /** Delete the parser, freeing its resources. */
3777
+ delete() {
3778
+ C._ts_parser_delete(this[0]);
3779
+ C._free(this[1]);
3780
+ this[0] = 0;
3781
+ this[1] = 0;
3782
+ }
3783
+ /**
3784
+ * Set the language that the parser should use for parsing.
3785
+ *
3786
+ * If the language was not successfully assigned, an error will be thrown.
3787
+ * This happens if the language was generated with an incompatible
3788
+ * version of the Tree-sitter CLI. Check the language's version using
3789
+ * {@link Language#version} and compare it to this library's
3790
+ * {@link LANGUAGE_VERSION} and {@link MIN_COMPATIBLE_VERSION} constants.
3791
+ */
3792
+ setLanguage(language) {
3793
+ let address;
3794
+ if (!language) {
3795
+ address = 0;
3796
+ this.language = null;
3797
+ } else if (language.constructor === Language) {
3798
+ address = language[0];
3799
+ const version = C._ts_language_abi_version(address);
3800
+ if (version < MIN_COMPATIBLE_VERSION || LANGUAGE_VERSION < version) {
3801
+ throw new Error(
3802
+ `Incompatible language version ${version}. Compatibility range ${MIN_COMPATIBLE_VERSION} through ${LANGUAGE_VERSION}.`
3803
+ );
3804
+ }
3805
+ this.language = language;
3806
+ } else {
3807
+ throw new Error("Argument must be a Language");
3808
+ }
3809
+ C._ts_parser_set_language(this[0], address);
3810
+ return this;
3811
+ }
3812
+ /**
3813
+ * Parse a slice of UTF8 text.
3814
+ *
3815
+ * @param {string | ParseCallback} callback - The UTF8-encoded text to parse or a callback function.
3816
+ *
3817
+ * @param {Tree | null} [oldTree] - A previous syntax tree parsed from the same document. If the text of the
3818
+ * document has changed since `oldTree` was created, then you must edit `oldTree` to match
3819
+ * the new text using {@link Tree#edit}.
3820
+ *
3821
+ * @param {ParseOptions} [options] - Options for parsing the text.
3822
+ * This can be used to set the included ranges, or a progress callback.
3823
+ *
3824
+ * @returns {Tree | null} A {@link Tree} if parsing succeeded, or `null` if:
3825
+ * - The parser has not yet had a language assigned with {@link Parser#setLanguage}.
3826
+ * - The progress callback returned true.
3827
+ */
3828
+ parse(callback, oldTree, options) {
3829
+ if (typeof callback === "string") {
3830
+ C.currentParseCallback = (index) => callback.slice(index);
3831
+ } else if (typeof callback === "function") {
3832
+ C.currentParseCallback = callback;
3833
+ } else {
3834
+ throw new Error("Argument must be a string or a function");
3835
+ }
3836
+ if (options?.progressCallback) {
3837
+ C.currentProgressCallback = options.progressCallback;
3838
+ } else {
3839
+ C.currentProgressCallback = null;
3840
+ }
3841
+ if (this.logCallback) {
3842
+ C.currentLogCallback = this.logCallback;
3843
+ C._ts_parser_enable_logger_wasm(this[0], 1);
3844
+ } else {
3845
+ C.currentLogCallback = null;
3846
+ C._ts_parser_enable_logger_wasm(this[0], 0);
3847
+ }
3848
+ let rangeCount = 0;
3849
+ let rangeAddress = 0;
3850
+ if (options?.includedRanges) {
3851
+ rangeCount = options.includedRanges.length;
3852
+ rangeAddress = C._calloc(rangeCount, SIZE_OF_RANGE);
3853
+ let address = rangeAddress;
3854
+ for (let i2 = 0; i2 < rangeCount; i2++) {
3855
+ marshalRange(address, options.includedRanges[i2]);
3856
+ address += SIZE_OF_RANGE;
3857
+ }
3858
+ }
3859
+ const treeAddress = C._ts_parser_parse_wasm(
3860
+ this[0],
3861
+ this[1],
3862
+ oldTree ? oldTree[0] : 0,
3863
+ rangeAddress,
3864
+ rangeCount
3865
+ );
3866
+ if (!treeAddress) {
3867
+ C.currentParseCallback = null;
3868
+ C.currentLogCallback = null;
3869
+ C.currentProgressCallback = null;
3870
+ return null;
3871
+ }
3872
+ if (!this.language) {
3873
+ throw new Error("Parser must have a language to parse");
3874
+ }
3875
+ const result = new Tree(INTERNAL, treeAddress, this.language, C.currentParseCallback);
3876
+ C.currentParseCallback = null;
3877
+ C.currentLogCallback = null;
3878
+ C.currentProgressCallback = null;
3879
+ return result;
3880
+ }
3881
+ /**
3882
+ * Instruct the parser to start the next parse from the beginning.
3883
+ *
3884
+ * If the parser previously failed because of a callback,
3885
+ * then by default, it will resume where it left off on the
3886
+ * next call to {@link Parser#parse} or other parsing functions.
3887
+ * If you don't want to resume, and instead intend to use this parser to
3888
+ * parse some other document, you must call `reset` first.
3889
+ */
3890
+ reset() {
3891
+ C._ts_parser_reset(this[0]);
3892
+ }
3893
+ /** Get the ranges of text that the parser will include when parsing. */
3894
+ getIncludedRanges() {
3895
+ C._ts_parser_included_ranges_wasm(this[0]);
3896
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
3897
+ const buffer = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
3898
+ const result = new Array(count);
3899
+ if (count > 0) {
3900
+ let address = buffer;
3901
+ for (let i2 = 0; i2 < count; i2++) {
3902
+ result[i2] = unmarshalRange(address);
3903
+ address += SIZE_OF_RANGE;
3904
+ }
3905
+ C._free(buffer);
3906
+ }
3907
+ return result;
3908
+ }
3909
+ /** Set the logging callback that a parser should use during parsing. */
3910
+ setLogger(callback) {
3911
+ if (!callback) {
3912
+ this.logCallback = null;
3913
+ } else if (typeof callback !== "function") {
3914
+ throw new Error("Logger callback must be a function");
3915
+ } else {
3916
+ this.logCallback = callback;
3917
+ }
3918
+ return this;
3919
+ }
3920
+ /** Get the parser's current logger. */
3921
+ getLogger() {
3922
+ return this.logCallback;
3923
+ }
3924
+ };
3925
+ var PREDICATE_STEP_TYPE_CAPTURE = 1;
3926
+ var PREDICATE_STEP_TYPE_STRING = 2;
3927
+ var QUERY_WORD_REGEX = /[\w-]+/g;
3928
+ var CaptureQuantifier = {
3929
+ Zero: 0,
3930
+ ZeroOrOne: 1,
3931
+ ZeroOrMore: 2,
3932
+ One: 3,
3933
+ OneOrMore: 4
3934
+ };
3935
+ var isCaptureStep = /* @__PURE__ */ __name((step) => step.type === "capture", "isCaptureStep");
3936
+ var isStringStep = /* @__PURE__ */ __name((step) => step.type === "string", "isStringStep");
3937
+ var QueryErrorKind = {
3938
+ Syntax: 1,
3939
+ NodeName: 2,
3940
+ FieldName: 3,
3941
+ CaptureName: 4,
3942
+ PatternStructure: 5
3943
+ };
3944
+ var QueryError = class _QueryError extends Error {
3945
+ constructor(kind, info22, index, length) {
3946
+ super(_QueryError.formatMessage(kind, info22));
3947
+ this.kind = kind;
3948
+ this.info = info22;
3949
+ this.index = index;
3950
+ this.length = length;
3951
+ this.name = "QueryError";
3952
+ }
3953
+ static {
3954
+ __name(this, "QueryError");
3955
+ }
3956
+ /** Formats an error message based on the error kind and info */
3957
+ static formatMessage(kind, info22) {
3958
+ switch (kind) {
3959
+ case QueryErrorKind.NodeName:
3960
+ return `Bad node name '${info22.word}'`;
3961
+ case QueryErrorKind.FieldName:
3962
+ return `Bad field name '${info22.word}'`;
3963
+ case QueryErrorKind.CaptureName:
3964
+ return `Bad capture name @${info22.word}`;
3965
+ case QueryErrorKind.PatternStructure:
3966
+ return `Bad pattern structure at offset ${info22.suffix}`;
3967
+ case QueryErrorKind.Syntax:
3968
+ return `Bad syntax at offset ${info22.suffix}`;
3969
+ }
3970
+ }
3971
+ };
3972
+ function parseAnyPredicate(steps, index, operator, textPredicates) {
3973
+ if (steps.length !== 3) {
3974
+ throw new Error(
3975
+ `Wrong number of arguments to \`#${operator}\` predicate. Expected 2, got ${steps.length - 1}`
3976
+ );
3977
+ }
3978
+ if (!isCaptureStep(steps[1])) {
3979
+ throw new Error(
3980
+ `First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}"`
3981
+ );
3982
+ }
3983
+ const isPositive = operator === "eq?" || operator === "any-eq?";
3984
+ const matchAll = !operator.startsWith("any-");
3985
+ if (isCaptureStep(steps[2])) {
3986
+ const captureName1 = steps[1].name;
3987
+ const captureName2 = steps[2].name;
3988
+ textPredicates[index].push((captures) => {
3989
+ const nodes1 = [];
3990
+ const nodes2 = [];
3991
+ for (const c of captures) {
3992
+ if (c.name === captureName1) nodes1.push(c.node);
3993
+ if (c.name === captureName2) nodes2.push(c.node);
3994
+ }
3995
+ const compare = /* @__PURE__ */ __name((n1, n2, positive) => {
3996
+ return positive ? n1.text === n2.text : n1.text !== n2.text;
3997
+ }, "compare");
3998
+ return matchAll ? nodes1.every((n1) => nodes2.some((n2) => compare(n1, n2, isPositive))) : nodes1.some((n1) => nodes2.some((n2) => compare(n1, n2, isPositive)));
3999
+ });
4000
+ } else {
4001
+ const captureName = steps[1].name;
4002
+ const stringValue = steps[2].value;
4003
+ const matches = /* @__PURE__ */ __name((n) => n.text === stringValue, "matches");
4004
+ const doesNotMatch = /* @__PURE__ */ __name((n) => n.text !== stringValue, "doesNotMatch");
4005
+ textPredicates[index].push((captures) => {
4006
+ const nodes = [];
4007
+ for (const c of captures) {
4008
+ if (c.name === captureName) nodes.push(c.node);
4009
+ }
4010
+ const test = isPositive ? matches : doesNotMatch;
4011
+ return matchAll ? nodes.every(test) : nodes.some(test);
4012
+ });
4013
+ }
4014
+ }
4015
+ __name(parseAnyPredicate, "parseAnyPredicate");
4016
+ function parseMatchPredicate(steps, index, operator, textPredicates) {
4017
+ if (steps.length !== 3) {
4018
+ throw new Error(
4019
+ `Wrong number of arguments to \`#${operator}\` predicate. Expected 2, got ${steps.length - 1}.`
4020
+ );
4021
+ }
4022
+ if (steps[1].type !== "capture") {
4023
+ throw new Error(
4024
+ `First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}".`
4025
+ );
4026
+ }
4027
+ if (steps[2].type !== "string") {
4028
+ throw new Error(
4029
+ `Second argument of \`#${operator}\` predicate must be a string. Got @${steps[2].name}.`
4030
+ );
4031
+ }
4032
+ const isPositive = operator === "match?" || operator === "any-match?";
4033
+ const matchAll = !operator.startsWith("any-");
4034
+ const captureName = steps[1].name;
4035
+ const regex = new RegExp(steps[2].value);
4036
+ textPredicates[index].push((captures) => {
4037
+ const nodes = [];
4038
+ for (const c of captures) {
4039
+ if (c.name === captureName) nodes.push(c.node.text);
4040
+ }
4041
+ const test = /* @__PURE__ */ __name((text, positive) => {
4042
+ return positive ? regex.test(text) : !regex.test(text);
4043
+ }, "test");
4044
+ if (nodes.length === 0) return !isPositive;
4045
+ return matchAll ? nodes.every((text) => test(text, isPositive)) : nodes.some((text) => test(text, isPositive));
4046
+ });
4047
+ }
4048
+ __name(parseMatchPredicate, "parseMatchPredicate");
4049
+ function parseAnyOfPredicate(steps, index, operator, textPredicates) {
4050
+ if (steps.length < 2) {
4051
+ throw new Error(
4052
+ `Wrong number of arguments to \`#${operator}\` predicate. Expected at least 1. Got ${steps.length - 1}.`
4053
+ );
4054
+ }
4055
+ if (steps[1].type !== "capture") {
4056
+ throw new Error(
4057
+ `First argument of \`#${operator}\` predicate must be a capture. Got "${steps[1].value}".`
4058
+ );
4059
+ }
4060
+ const isPositive = operator === "any-of?";
4061
+ const captureName = steps[1].name;
4062
+ const stringSteps = steps.slice(2);
4063
+ if (!stringSteps.every(isStringStep)) {
4064
+ throw new Error(
4065
+ `Arguments to \`#${operator}\` predicate must be strings.".`
4066
+ );
4067
+ }
4068
+ const values = stringSteps.map((s) => s.value);
4069
+ textPredicates[index].push((captures) => {
4070
+ const nodes = [];
4071
+ for (const c of captures) {
4072
+ if (c.name === captureName) nodes.push(c.node.text);
4073
+ }
4074
+ if (nodes.length === 0) return !isPositive;
4075
+ return nodes.every((text) => values.includes(text)) === isPositive;
4076
+ });
4077
+ }
4078
+ __name(parseAnyOfPredicate, "parseAnyOfPredicate");
4079
+ function parseIsPredicate(steps, index, operator, assertedProperties, refutedProperties) {
4080
+ if (steps.length < 2 || steps.length > 3) {
4081
+ throw new Error(
4082
+ `Wrong number of arguments to \`#${operator}\` predicate. Expected 1 or 2. Got ${steps.length - 1}.`
4083
+ );
4084
+ }
4085
+ if (!steps.every(isStringStep)) {
4086
+ throw new Error(
4087
+ `Arguments to \`#${operator}\` predicate must be strings.".`
4088
+ );
4089
+ }
4090
+ const properties = operator === "is?" ? assertedProperties : refutedProperties;
4091
+ if (!properties[index]) properties[index] = {};
4092
+ properties[index][steps[1].value] = steps[2]?.value ?? null;
4093
+ }
4094
+ __name(parseIsPredicate, "parseIsPredicate");
4095
+ function parseSetDirective(steps, index, setProperties) {
4096
+ if (steps.length < 2 || steps.length > 3) {
4097
+ throw new Error(`Wrong number of arguments to \`#set!\` predicate. Expected 1 or 2. Got ${steps.length - 1}.`);
4098
+ }
4099
+ if (!steps.every(isStringStep)) {
4100
+ throw new Error(`Arguments to \`#set!\` predicate must be strings.".`);
4101
+ }
4102
+ if (!setProperties[index]) setProperties[index] = {};
4103
+ setProperties[index][steps[1].value] = steps[2]?.value ?? null;
4104
+ }
4105
+ __name(parseSetDirective, "parseSetDirective");
4106
+ function parsePattern(index, stepType, stepValueId, captureNames, stringValues, steps, textPredicates, predicates, setProperties, assertedProperties, refutedProperties) {
4107
+ if (stepType === PREDICATE_STEP_TYPE_CAPTURE) {
4108
+ const name2 = captureNames[stepValueId];
4109
+ steps.push({ type: "capture", name: name2 });
4110
+ } else if (stepType === PREDICATE_STEP_TYPE_STRING) {
4111
+ steps.push({ type: "string", value: stringValues[stepValueId] });
4112
+ } else if (steps.length > 0) {
4113
+ if (steps[0].type !== "string") {
4114
+ throw new Error("Predicates must begin with a literal value");
4115
+ }
4116
+ const operator = steps[0].value;
4117
+ switch (operator) {
4118
+ case "any-not-eq?":
4119
+ case "not-eq?":
4120
+ case "any-eq?":
4121
+ case "eq?":
4122
+ parseAnyPredicate(steps, index, operator, textPredicates);
4123
+ break;
4124
+ case "any-not-match?":
4125
+ case "not-match?":
4126
+ case "any-match?":
4127
+ case "match?":
4128
+ parseMatchPredicate(steps, index, operator, textPredicates);
4129
+ break;
4130
+ case "not-any-of?":
4131
+ case "any-of?":
4132
+ parseAnyOfPredicate(steps, index, operator, textPredicates);
4133
+ break;
4134
+ case "is?":
4135
+ case "is-not?":
4136
+ parseIsPredicate(steps, index, operator, assertedProperties, refutedProperties);
4137
+ break;
4138
+ case "set!":
4139
+ parseSetDirective(steps, index, setProperties);
4140
+ break;
4141
+ default:
4142
+ predicates[index].push({ operator, operands: steps.slice(1) });
4143
+ }
4144
+ steps.length = 0;
4145
+ }
4146
+ }
4147
+ __name(parsePattern, "parsePattern");
4148
+ var Query = class {
4149
+ static {
4150
+ __name(this, "Query");
4151
+ }
4152
+ /** @internal */
4153
+ [0] = 0;
4154
+ // Internal handle for Wasm
4155
+ /** @internal */
4156
+ exceededMatchLimit;
4157
+ /** @internal */
4158
+ textPredicates;
4159
+ /** The names of the captures used in the query. */
4160
+ captureNames;
4161
+ /** The quantifiers of the captures used in the query. */
4162
+ captureQuantifiers;
4163
+ /**
4164
+ * The other user-defined predicates associated with the given index.
4165
+ *
4166
+ * This includes predicates with operators other than:
4167
+ * - `match?`
4168
+ * - `eq?` and `not-eq?`
4169
+ * - `any-of?` and `not-any-of?`
4170
+ * - `is?` and `is-not?`
4171
+ * - `set!`
4172
+ */
4173
+ predicates;
4174
+ /** The properties for predicates with the operator `set!`. */
4175
+ setProperties;
4176
+ /** The properties for predicates with the operator `is?`. */
4177
+ assertedProperties;
4178
+ /** The properties for predicates with the operator `is-not?`. */
4179
+ refutedProperties;
4180
+ /** The maximum number of in-progress matches for this cursor. */
4181
+ matchLimit;
4182
+ /**
4183
+ * Create a new query from a string containing one or more S-expression
4184
+ * patterns.
4185
+ *
4186
+ * The query is associated with a particular language, and can only be run
4187
+ * on syntax nodes parsed with that language. References to Queries can be
4188
+ * shared between multiple threads.
4189
+ *
4190
+ * @link {@see https://tree-sitter.github.io/tree-sitter/using-parsers/queries}
4191
+ */
4192
+ constructor(language, source) {
4193
+ const sourceLength = C.lengthBytesUTF8(source);
4194
+ const sourceAddress = C._malloc(sourceLength + 1);
4195
+ C.stringToUTF8(source, sourceAddress, sourceLength + 1);
4196
+ const address = C._ts_query_new(
4197
+ language[0],
4198
+ sourceAddress,
4199
+ sourceLength,
4200
+ TRANSFER_BUFFER,
4201
+ TRANSFER_BUFFER + SIZE_OF_INT
4202
+ );
4203
+ if (!address) {
4204
+ const errorId = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
4205
+ const errorByte = C.getValue(TRANSFER_BUFFER, "i32");
4206
+ const errorIndex = C.UTF8ToString(sourceAddress, errorByte).length;
4207
+ const suffix = source.slice(errorIndex, errorIndex + 100).split("\n")[0];
4208
+ const word = suffix.match(QUERY_WORD_REGEX)?.[0] ?? "";
4209
+ C._free(sourceAddress);
4210
+ switch (errorId) {
4211
+ case QueryErrorKind.Syntax:
4212
+ throw new QueryError(QueryErrorKind.Syntax, { suffix: `${errorIndex}: '${suffix}'...` }, errorIndex, 0);
4213
+ case QueryErrorKind.NodeName:
4214
+ throw new QueryError(errorId, { word }, errorIndex, word.length);
4215
+ case QueryErrorKind.FieldName:
4216
+ throw new QueryError(errorId, { word }, errorIndex, word.length);
4217
+ case QueryErrorKind.CaptureName:
4218
+ throw new QueryError(errorId, { word }, errorIndex, word.length);
4219
+ case QueryErrorKind.PatternStructure:
4220
+ throw new QueryError(errorId, { suffix: `${errorIndex}: '${suffix}'...` }, errorIndex, 0);
4221
+ }
4222
+ }
4223
+ const stringCount = C._ts_query_string_count(address);
4224
+ const captureCount = C._ts_query_capture_count(address);
4225
+ const patternCount = C._ts_query_pattern_count(address);
4226
+ const captureNames = new Array(captureCount);
4227
+ const captureQuantifiers = new Array(patternCount);
4228
+ const stringValues = new Array(stringCount);
4229
+ for (let i2 = 0; i2 < captureCount; i2++) {
4230
+ const nameAddress = C._ts_query_capture_name_for_id(
4231
+ address,
4232
+ i2,
4233
+ TRANSFER_BUFFER
4234
+ );
4235
+ const nameLength = C.getValue(TRANSFER_BUFFER, "i32");
4236
+ captureNames[i2] = C.UTF8ToString(nameAddress, nameLength);
4237
+ }
4238
+ for (let i2 = 0; i2 < patternCount; i2++) {
4239
+ const captureQuantifiersArray = new Array(captureCount);
4240
+ for (let j = 0; j < captureCount; j++) {
4241
+ const quantifier = C._ts_query_capture_quantifier_for_id(address, i2, j);
4242
+ captureQuantifiersArray[j] = quantifier;
4243
+ }
4244
+ captureQuantifiers[i2] = captureQuantifiersArray;
4245
+ }
4246
+ for (let i2 = 0; i2 < stringCount; i2++) {
4247
+ const valueAddress = C._ts_query_string_value_for_id(
4248
+ address,
4249
+ i2,
4250
+ TRANSFER_BUFFER
4251
+ );
4252
+ const nameLength = C.getValue(TRANSFER_BUFFER, "i32");
4253
+ stringValues[i2] = C.UTF8ToString(valueAddress, nameLength);
4254
+ }
4255
+ const setProperties = new Array(patternCount);
4256
+ const assertedProperties = new Array(patternCount);
4257
+ const refutedProperties = new Array(patternCount);
4258
+ const predicates = new Array(patternCount);
4259
+ const textPredicates = new Array(patternCount);
4260
+ for (let i2 = 0; i2 < patternCount; i2++) {
4261
+ const predicatesAddress = C._ts_query_predicates_for_pattern(address, i2, TRANSFER_BUFFER);
4262
+ const stepCount = C.getValue(TRANSFER_BUFFER, "i32");
4263
+ predicates[i2] = [];
4264
+ textPredicates[i2] = [];
4265
+ const steps = new Array();
4266
+ let stepAddress = predicatesAddress;
4267
+ for (let j = 0; j < stepCount; j++) {
4268
+ const stepType = C.getValue(stepAddress, "i32");
4269
+ stepAddress += SIZE_OF_INT;
4270
+ const stepValueId = C.getValue(stepAddress, "i32");
4271
+ stepAddress += SIZE_OF_INT;
4272
+ parsePattern(
4273
+ i2,
4274
+ stepType,
4275
+ stepValueId,
4276
+ captureNames,
4277
+ stringValues,
4278
+ steps,
4279
+ textPredicates,
4280
+ predicates,
4281
+ setProperties,
4282
+ assertedProperties,
4283
+ refutedProperties
4284
+ );
4285
+ }
4286
+ Object.freeze(textPredicates[i2]);
4287
+ Object.freeze(predicates[i2]);
4288
+ Object.freeze(setProperties[i2]);
4289
+ Object.freeze(assertedProperties[i2]);
4290
+ Object.freeze(refutedProperties[i2]);
4291
+ }
4292
+ C._free(sourceAddress);
4293
+ this[0] = address;
4294
+ this.captureNames = captureNames;
4295
+ this.captureQuantifiers = captureQuantifiers;
4296
+ this.textPredicates = textPredicates;
4297
+ this.predicates = predicates;
4298
+ this.setProperties = setProperties;
4299
+ this.assertedProperties = assertedProperties;
4300
+ this.refutedProperties = refutedProperties;
4301
+ this.exceededMatchLimit = false;
4302
+ }
4303
+ /** Delete the query, freeing its resources. */
4304
+ delete() {
4305
+ C._ts_query_delete(this[0]);
4306
+ this[0] = 0;
4307
+ }
4308
+ /**
4309
+ * Iterate over all of the matches in the order that they were found.
4310
+ *
4311
+ * Each match contains the index of the pattern that matched, and a list of
4312
+ * captures. Because multiple patterns can match the same set of nodes,
4313
+ * one match may contain captures that appear *before* some of the
4314
+ * captures from a previous match.
4315
+ *
4316
+ * @param {Node} node - The node to execute the query on.
4317
+ *
4318
+ * @param {QueryOptions} options - Options for query execution.
4319
+ */
4320
+ matches(node, options = {}) {
4321
+ const startPosition = options.startPosition ?? ZERO_POINT;
4322
+ const endPosition = options.endPosition ?? ZERO_POINT;
4323
+ const startIndex = options.startIndex ?? 0;
4324
+ const endIndex = options.endIndex ?? 0;
4325
+ const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
4326
+ const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
4327
+ const startContainingIndex = options.startContainingIndex ?? 0;
4328
+ const endContainingIndex = options.endContainingIndex ?? 0;
4329
+ const matchLimit = options.matchLimit ?? 4294967295;
4330
+ const maxStartDepth = options.maxStartDepth ?? 4294967295;
4331
+ const progressCallback = options.progressCallback;
4332
+ if (typeof matchLimit !== "number") {
4333
+ throw new Error("Arguments must be numbers");
4334
+ }
4335
+ this.matchLimit = matchLimit;
4336
+ if (endIndex !== 0 && startIndex > endIndex) {
4337
+ throw new Error("`startIndex` cannot be greater than `endIndex`");
4338
+ }
4339
+ if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
4340
+ throw new Error("`startPosition` cannot be greater than `endPosition`");
4341
+ }
4342
+ if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
4343
+ throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
4344
+ }
4345
+ if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
4346
+ throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
4347
+ }
4348
+ if (progressCallback) {
4349
+ C.currentQueryProgressCallback = progressCallback;
4350
+ }
4351
+ marshalNode(node);
4352
+ C._ts_query_matches_wasm(
4353
+ this[0],
4354
+ node.tree[0],
4355
+ startPosition.row,
4356
+ startPosition.column,
4357
+ endPosition.row,
4358
+ endPosition.column,
4359
+ startIndex,
4360
+ endIndex,
4361
+ startContainingPosition.row,
4362
+ startContainingPosition.column,
4363
+ endContainingPosition.row,
4364
+ endContainingPosition.column,
4365
+ startContainingIndex,
4366
+ endContainingIndex,
4367
+ matchLimit,
4368
+ maxStartDepth
4369
+ );
4370
+ const rawCount = C.getValue(TRANSFER_BUFFER, "i32");
4371
+ const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
4372
+ const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
4373
+ const result = new Array(rawCount);
4374
+ this.exceededMatchLimit = Boolean(didExceedMatchLimit);
4375
+ let filteredCount = 0;
4376
+ let address = startAddress;
4377
+ for (let i2 = 0; i2 < rawCount; i2++) {
4378
+ const patternIndex = C.getValue(address, "i32");
4379
+ address += SIZE_OF_INT;
4380
+ const captureCount = C.getValue(address, "i32");
4381
+ address += SIZE_OF_INT;
4382
+ const captures = new Array(captureCount);
4383
+ address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
4384
+ if (this.textPredicates[patternIndex].every((p) => p(captures))) {
4385
+ result[filteredCount] = { patternIndex, captures };
4386
+ const setProperties = this.setProperties[patternIndex];
4387
+ result[filteredCount].setProperties = setProperties;
4388
+ const assertedProperties = this.assertedProperties[patternIndex];
4389
+ result[filteredCount].assertedProperties = assertedProperties;
4390
+ const refutedProperties = this.refutedProperties[patternIndex];
4391
+ result[filteredCount].refutedProperties = refutedProperties;
4392
+ filteredCount++;
4393
+ }
4394
+ }
4395
+ result.length = filteredCount;
4396
+ C._free(startAddress);
4397
+ C.currentQueryProgressCallback = null;
4398
+ return result;
4399
+ }
4400
+ /**
4401
+ * Iterate over all of the individual captures in the order that they
4402
+ * appear.
4403
+ *
4404
+ * This is useful if you don't care about which pattern matched, and just
4405
+ * want a single, ordered sequence of captures.
4406
+ *
4407
+ * @param {Node} node - The node to execute the query on.
4408
+ *
4409
+ * @param {QueryOptions} options - Options for query execution.
4410
+ */
4411
+ captures(node, options = {}) {
4412
+ const startPosition = options.startPosition ?? ZERO_POINT;
4413
+ const endPosition = options.endPosition ?? ZERO_POINT;
4414
+ const startIndex = options.startIndex ?? 0;
4415
+ const endIndex = options.endIndex ?? 0;
4416
+ const startContainingPosition = options.startContainingPosition ?? ZERO_POINT;
4417
+ const endContainingPosition = options.endContainingPosition ?? ZERO_POINT;
4418
+ const startContainingIndex = options.startContainingIndex ?? 0;
4419
+ const endContainingIndex = options.endContainingIndex ?? 0;
4420
+ const matchLimit = options.matchLimit ?? 4294967295;
4421
+ const maxStartDepth = options.maxStartDepth ?? 4294967295;
4422
+ const progressCallback = options.progressCallback;
4423
+ if (typeof matchLimit !== "number") {
4424
+ throw new Error("Arguments must be numbers");
4425
+ }
4426
+ this.matchLimit = matchLimit;
4427
+ if (endIndex !== 0 && startIndex > endIndex) {
4428
+ throw new Error("`startIndex` cannot be greater than `endIndex`");
4429
+ }
4430
+ if (endPosition !== ZERO_POINT && (startPosition.row > endPosition.row || startPosition.row === endPosition.row && startPosition.column > endPosition.column)) {
4431
+ throw new Error("`startPosition` cannot be greater than `endPosition`");
4432
+ }
4433
+ if (endContainingIndex !== 0 && startContainingIndex > endContainingIndex) {
4434
+ throw new Error("`startContainingIndex` cannot be greater than `endContainingIndex`");
4435
+ }
4436
+ if (endContainingPosition !== ZERO_POINT && (startContainingPosition.row > endContainingPosition.row || startContainingPosition.row === endContainingPosition.row && startContainingPosition.column > endContainingPosition.column)) {
4437
+ throw new Error("`startContainingPosition` cannot be greater than `endContainingPosition`");
4438
+ }
4439
+ if (progressCallback) {
4440
+ C.currentQueryProgressCallback = progressCallback;
4441
+ }
4442
+ marshalNode(node);
4443
+ C._ts_query_captures_wasm(
4444
+ this[0],
4445
+ node.tree[0],
4446
+ startPosition.row,
4447
+ startPosition.column,
4448
+ endPosition.row,
4449
+ endPosition.column,
4450
+ startIndex,
4451
+ endIndex,
4452
+ startContainingPosition.row,
4453
+ startContainingPosition.column,
4454
+ endContainingPosition.row,
4455
+ endContainingPosition.column,
4456
+ startContainingIndex,
4457
+ endContainingIndex,
4458
+ matchLimit,
4459
+ maxStartDepth
4460
+ );
4461
+ const count = C.getValue(TRANSFER_BUFFER, "i32");
4462
+ const startAddress = C.getValue(TRANSFER_BUFFER + SIZE_OF_INT, "i32");
4463
+ const didExceedMatchLimit = C.getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, "i32");
4464
+ const result = new Array();
4465
+ this.exceededMatchLimit = Boolean(didExceedMatchLimit);
4466
+ const captures = new Array();
4467
+ let address = startAddress;
4468
+ for (let i2 = 0; i2 < count; i2++) {
4469
+ const patternIndex = C.getValue(address, "i32");
4470
+ address += SIZE_OF_INT;
4471
+ const captureCount = C.getValue(address, "i32");
4472
+ address += SIZE_OF_INT;
4473
+ const captureIndex = C.getValue(address, "i32");
4474
+ address += SIZE_OF_INT;
4475
+ captures.length = captureCount;
4476
+ address = unmarshalCaptures(this, node.tree, address, patternIndex, captures);
4477
+ if (this.textPredicates[patternIndex].every((p) => p(captures))) {
4478
+ const capture = captures[captureIndex];
4479
+ const setProperties = this.setProperties[patternIndex];
4480
+ capture.setProperties = setProperties;
4481
+ const assertedProperties = this.assertedProperties[patternIndex];
4482
+ capture.assertedProperties = assertedProperties;
4483
+ const refutedProperties = this.refutedProperties[patternIndex];
4484
+ capture.refutedProperties = refutedProperties;
4485
+ result.push(capture);
4486
+ }
4487
+ }
4488
+ C._free(startAddress);
4489
+ C.currentQueryProgressCallback = null;
4490
+ return result;
4491
+ }
4492
+ /** Get the predicates for a given pattern. */
4493
+ predicatesForPattern(patternIndex) {
4494
+ return this.predicates[patternIndex];
4495
+ }
4496
+ /**
4497
+ * Disable a certain capture within a query.
4498
+ *
4499
+ * This prevents the capture from being returned in matches, and also
4500
+ * avoids any resource usage associated with recording the capture.
4501
+ */
4502
+ disableCapture(captureName) {
4503
+ const captureNameLength = C.lengthBytesUTF8(captureName);
4504
+ const captureNameAddress = C._malloc(captureNameLength + 1);
4505
+ C.stringToUTF8(captureName, captureNameAddress, captureNameLength + 1);
4506
+ C._ts_query_disable_capture(this[0], captureNameAddress, captureNameLength);
4507
+ C._free(captureNameAddress);
4508
+ }
4509
+ /**
4510
+ * Disable a certain pattern within a query.
4511
+ *
4512
+ * This prevents the pattern from matching, and also avoids any resource
4513
+ * usage associated with the pattern. This throws an error if the pattern
4514
+ * index is out of bounds.
4515
+ */
4516
+ disablePattern(patternIndex) {
4517
+ if (patternIndex >= this.predicates.length) {
4518
+ throw new Error(
4519
+ `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
4520
+ );
4521
+ }
4522
+ C._ts_query_disable_pattern(this[0], patternIndex);
4523
+ }
4524
+ /**
4525
+ * Check if, on its last execution, this cursor exceeded its maximum number
4526
+ * of in-progress matches.
4527
+ */
4528
+ didExceedMatchLimit() {
4529
+ return this.exceededMatchLimit;
4530
+ }
4531
+ /** Get the byte offset where the given pattern starts in the query's source. */
4532
+ startIndexForPattern(patternIndex) {
4533
+ if (patternIndex >= this.predicates.length) {
4534
+ throw new Error(
4535
+ `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
4536
+ );
4537
+ }
4538
+ return C._ts_query_start_byte_for_pattern(this[0], patternIndex);
4539
+ }
4540
+ /** Get the byte offset where the given pattern ends in the query's source. */
4541
+ endIndexForPattern(patternIndex) {
4542
+ if (patternIndex >= this.predicates.length) {
4543
+ throw new Error(
4544
+ `Pattern index is ${patternIndex} but the pattern count is ${this.predicates.length}`
4545
+ );
4546
+ }
4547
+ return C._ts_query_end_byte_for_pattern(this[0], patternIndex);
4548
+ }
4549
+ /** Get the number of patterns in the query. */
4550
+ patternCount() {
4551
+ return C._ts_query_pattern_count(this[0]);
4552
+ }
4553
+ /** Get the index for a given capture name. */
4554
+ captureIndexForName(captureName) {
4555
+ return this.captureNames.indexOf(captureName);
4556
+ }
4557
+ /** Check if a given pattern within a query has a single root node. */
4558
+ isPatternRooted(patternIndex) {
4559
+ return C._ts_query_is_pattern_rooted(this[0], patternIndex) === 1;
4560
+ }
4561
+ /** Check if a given pattern within a query has a single root node. */
4562
+ isPatternNonLocal(patternIndex) {
4563
+ return C._ts_query_is_pattern_non_local(this[0], patternIndex) === 1;
4564
+ }
4565
+ /**
4566
+ * Check if a given step in a query is 'definite'.
4567
+ *
4568
+ * A query step is 'definite' if its parent pattern will be guaranteed to
4569
+ * match successfully once it reaches the step.
4570
+ */
4571
+ isPatternGuaranteedAtStep(byteIndex) {
4572
+ return C._ts_query_is_pattern_guaranteed_at_step(this[0], byteIndex) === 1;
4573
+ }
4574
+ };
4575
+
4576
+ // packages/shared/dist/ast/grammars.js
4577
+ import { dirname, extname, join } from "node:path";
4578
+ import { fileURLToPath } from "node:url";
4579
+ var WASM_DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "wasm");
4580
+
4581
+ // packages/shared/dist/ast/astChunker.js
4582
+ var MAX_AST_PARSE_BYTES = 2 * 1024 * 1024;
4583
+
4584
+ // packages/shared/dist/codeScanner.js
4585
+ var MAX_SCANNED_FILE_BYTES = 10 * 1024 * 1024;
4586
+ var BUILT_IN_IGNORE_DIRS = [
4587
+ // JS / web
4588
+ "node_modules",
4589
+ ".next",
4590
+ ".nuxt",
4591
+ ".output",
4592
+ "dist",
4593
+ "build",
4594
+ "coverage",
4595
+ ".turbo",
4596
+ ".vercel",
4597
+ ".svelte-kit",
4598
+ ".angular",
4599
+ ".astro",
4600
+ ".parcel-cache",
4601
+ "bower_components",
4602
+ // Python
4603
+ "venv",
4604
+ ".venv",
4605
+ "env",
4606
+ "__pycache__",
4607
+ ".tox",
4608
+ ".mypy_cache",
4609
+ ".pytest_cache",
4610
+ ".ruff_cache",
4611
+ // Native mobile - iOS / Android / React Native / Flutter (2026-07-11 Pods incident)
4612
+ "Pods",
4613
+ "DerivedData",
4614
+ ".gradle",
4615
+ ".expo",
4616
+ ".dart_tool",
4617
+ // Infra / cloud
4618
+ ".terraform",
4619
+ "cdk.out",
4620
+ ".serverless",
4621
+ // Build systems, caches, VCS
4622
+ "target",
4623
+ "bin",
4624
+ "obj",
4625
+ ".cache",
4626
+ ".git",
4627
+ ".svn",
4628
+ ".hg",
4629
+ // The coding agent's captured shell environment, written as .sh files.
4630
+ // Harmless while only source extensions were collected; the moment shell
4631
+ // scripts became collectable these scanned as project code, which would put
4632
+ // an agent's own shell state into the user's searchable memory.
4633
+ //
4634
+ // Scoped to this one directory name deliberately. `.claude/` at large holds
4635
+ // real project content - `.claude/rules.md` is indexed on purpose
4636
+ // (tests/CodeScannerIgnorePatterns.test.ts), and only `.claude/worktrees/`
4637
+ // is suppressed, by the generic nested-git-boundary rule.
4638
+ "shell-snapshots"
4639
+ ];
4640
+ var BUILT_IN_IGNORE_FILE_PATTERNS = [
4641
+ // NOTE: the `.env` family and every other secret-bearing FILE KIND lives in
4642
+ // `isSecretFile` below, not here. This glob engine cannot express negation
4643
+ // (`.env.example` must stay collectable) and its unanchored substring
4644
+ // matching would make `.env.*` also swallow `.environment.ts`.
4645
+ ".DS_Store",
4646
+ "*.log",
4647
+ "*.lock",
4648
+ "package-lock.json",
4649
+ "yarn.lock",
4650
+ "*.min.js",
4651
+ "*.min.css",
4652
+ "*.bundle.js",
4653
+ "*.legacy.js",
4654
+ "*.map",
4655
+ "/tests/fixtures/*"
4656
+ ];
4657
+ var DEFAULT_INCLUDE_EXTENSIONS = [
4658
+ ".ts",
4659
+ ".tsx",
4660
+ ".js",
4661
+ ".jsx",
4662
+ ".py",
4663
+ ".rs",
4664
+ ".go",
4665
+ ".java",
4666
+ ".c",
4667
+ ".cpp",
4668
+ ".h",
4669
+ ".cs",
4670
+ ".rb",
4671
+ ".php",
4672
+ ".swift",
4673
+ ".kt",
4674
+ // Shell and Lua are the working languages of whole real projects -
4675
+ // deployment tooling, container entrypoints, imapfilter/nginx/redis
4676
+ // configuration. Omitting them meant such a project indexed ZERO code and
4677
+ // code_search could not answer anything about it, while reporting that as
4678
+ // "no indexed matches" rather than as missing coverage.
4679
+ ".sh",
4680
+ ".bash",
4681
+ ".zsh",
4682
+ ".lua",
4683
+ ".md",
4684
+ // -- Variants of languages already on the list. `.mjs`/`.cjs`/`.mts`/`.cts`/
4685
+ // `.pyi` inherit their language string from a listed extension, so their
4686
+ // absence was oversight rather than policy. The C++ spellings are a choice,
4687
+ // not an inheritance: `.h` stays 'c' (C headers dominate, and reading a C++
4688
+ // header as C is the safer default), while the unambiguously-C++ spellings
4689
+ // resolve to 'cpp'.
4690
+ ".mjs",
4691
+ ".cjs",
4692
+ ".mts",
4693
+ ".cts",
4694
+ ".pyi",
4695
+ ".hpp",
4696
+ ".hh",
4697
+ ".hxx",
4698
+ ".cc",
4699
+ ".cxx",
4700
+ ".kts",
4701
+ // -- Languages the scanner could not read at all.
4702
+ ".dart",
4703
+ ".m",
4704
+ ".mm",
4705
+ ".scala",
4706
+ ".sc",
4707
+ ".ex",
4708
+ ".exs",
4709
+ ".erl",
4710
+ ".hrl",
4711
+ ".hs",
4712
+ ".jl",
4713
+ ".ml",
4714
+ ".mli",
4715
+ ".clj",
4716
+ ".cljs",
4717
+ ".cljc",
4718
+ ".groovy",
4719
+ ".gradle",
4720
+ ".ps1",
4721
+ ".psm1",
4722
+ ".pl",
4723
+ ".pm",
4724
+ ".r",
4725
+ ".sol",
4726
+ ".zig",
4727
+ ".vue",
4728
+ ".svelte",
4729
+ // -- Infrastructure and schema DSLs, where real logic lives and where "how
4730
+ // is this deployed?" and "what does this table hold?" go unanswered today.
4731
+ ".tf",
4732
+ ".sql",
4733
+ ".proto",
4734
+ ".graphql",
4735
+ ".gql",
4736
+ ".cmake",
4737
+ ".nix",
4738
+ ".bzl"
4739
+ ];
4740
+ var DEFAULT_OPTIONS = {
4741
+ maxChunkSize: 8e3,
4742
+ // ~2000 tokens
4743
+ minChunkSize: 100,
4744
+ ignorePatterns: [...BUILT_IN_IGNORE_DIRS, ...BUILT_IN_IGNORE_FILE_PATTERNS],
4745
+ includeExtensions: [...DEFAULT_INCLUDE_EXTENSIONS],
4746
+ maxAstParseBytes: MAX_AST_PARSE_BYTES,
4747
+ protectedPaths: []
4748
+ };
4749
+ var BUILT_IN_IGNORE_DIR_SET = new Set(BUILT_IN_IGNORE_DIRS);
4750
+
4751
+ // packages/shared/dist/jitDeliveryAck.js
4752
+ init_runtimeSigners();
4753
+
4754
+ // packages/shared/dist/index.js
4755
+ init_repositoryFingerprint();
4756
+ init_projectIdentityFile();
4757
+ init_repositoryRoot();
4758
+
4759
+ // packages/local-setup/dist/storage.js
4760
+ init_hookRuntime();
4761
+ import { homedir } from "node:os";
4762
+ import { dirname as dirname2, join as join2, win32, posix } from "node:path";
4763
+ init_hookRuntime();
4764
+ function stateDirectory(platform = process.platform, env = process.env, home = homedir()) {
4765
+ if (env.MNEMONIK_STATE_DIR)
4766
+ return env.MNEMONIK_STATE_DIR;
4767
+ if (platform === "win32")
4768
+ return win32.join(env.LOCALAPPDATA || win32.join(home, "AppData", "Local"), "Mnemonik");
4769
+ if (platform === "darwin")
4770
+ return posix.join(home, "Library", "Application Support", "Mnemonik");
4771
+ return posix.join(env.XDG_STATE_HOME || posix.join(home, ".local", "state"), "mnemonik");
4772
+ }
4773
+
4774
+ // packages/local-setup/dist/index.js
4775
+ var MAX_ORIGINAL_BYTES = 64 * 1024;
4776
+
4777
+ // packages/cli/src/project/eligibility.ts
4778
+ var within = (path, parent, platform) => {
4779
+ const candidate = platform === "win32" ? path.toLowerCase() : path;
4780
+ const boundary = platform === "win32" ? parent.toLowerCase() : parent;
4781
+ return candidate === boundary || candidate.startsWith(`${boundary}${platform === "win32" ? "\\" : "/"}`);
4782
+ };
4783
+ async function canonical(path, platform) {
4784
+ const paths = platform === "win32" ? win322 : posix2;
4785
+ const absolute = paths.resolve(path);
4786
+ if (platform !== process.platform) return absolute;
4787
+ return realpath(path).catch(() => absolute);
4788
+ }
4789
+ async function broadWorkspace(root) {
4790
+ let repositories = 0;
4791
+ for (const entry of await readdir(root, { withFileTypes: true }).catch(() => [])) {
4792
+ if (!entry.isDirectory()) continue;
4793
+ const marker = await lstat(join3(root, entry.name, ".git")).catch(() => void 0);
4794
+ if (marker?.isDirectory() || marker?.isFile()) repositories += 1;
4795
+ if (repositories >= 2) return true;
4796
+ }
4797
+ return false;
4798
+ }
4799
+ async function evaluateRoot(resolution, options) {
4800
+ const platform = options.platform ?? process.platform;
4801
+ const env = options.env ?? process.env;
4802
+ const paths = platform === "win32" ? win322 : posix2;
4803
+ const root = await canonical("root" in resolution ? resolution.root : options.cwd, platform);
4804
+ const home = await canonical(options.home ?? homedir2(), platform);
4805
+ const temporary = await canonical(tmpdir(), platform);
4806
+ const state = await canonical(stateDirectory(platform, env, home), platform);
4807
+ if (root === paths.parse(root).root) return { allowed: false, root, reason: "filesystem_root" };
4808
+ if (root === home) return { allowed: false, root, reason: "home_directory" };
4809
+ if (root === temporary) return { allowed: false, root, reason: "temporary_directory" };
4810
+ if (within(root, state, platform))
4811
+ return { allowed: false, root, reason: "mnemonik_state_directory" };
4812
+ if (platform === "win32" && [
4813
+ env.LOCALAPPDATA ?? paths.join(home, "AppData", "Local"),
4814
+ env.APPDATA ?? paths.join(home, "AppData", "Roaming")
4815
+ ].some((directory) => within(root, paths.resolve(directory), platform)))
4816
+ return { allowed: false, root, reason: "user_data_directory" };
4817
+ if ([".claude", ".codex", ".cursor", ".grok", ".copilot", ".mnemonik"].some(
4818
+ (name2) => within(root, paths.join(home, name2), platform)
4819
+ ))
4820
+ return { allowed: false, root, reason: "host_config_directory" };
4821
+ const nonGit = "repository" in resolution && resolution.repository.kind === "plain";
4822
+ if (nonGit && await broadWorkspace(root))
4823
+ return { allowed: false, root, reason: "broad_workspace_parent" };
4824
+ if (nonGit && !options.nonGitSelected)
4825
+ return { allowed: false, root, reason: "non_git_selection_required" };
4826
+ return {
4827
+ allowed: true,
4828
+ root,
4829
+ reason: nonGit ? "explicit_non_git" : resolution.kind,
4830
+ nonGit
4831
+ };
4832
+ }
4833
+ export {
4834
+ evaluateRoot
4835
+ };