rustfava 0.1.0__py3-none-any.whl

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