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