@kreuzberg/tree-sitter-language-pack-wasm 1.0.0-rc.11

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.
package/README.md ADDED
@@ -0,0 +1,115 @@
1
+ <!-- Generated by scripts/generate_readme.py. DO NOT EDIT. -->
2
+
3
+ # tree-sitter-language-pack — WebAssembly
4
+
5
+ <div align="center" style="display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 20px 0;">
6
+ <!-- Language Bindings --> <a href="https://crates.io/crates/tree-sitter-language-pack">
7
+ <img src="https://img.shields.io/crates/v/tree-sitter-language-pack?label=Rust&color=007ec6" alt="Rust">
8
+ </a> <a href="https://pypi.org/project/tree-sitter-language-pack/">
9
+ <img src="https://img.shields.io/pypi/v/tree-sitter-language-pack?label=Python&color=007ec6" alt="Python">
10
+ </a> <a href="https://www.npmjs.com/package/@kreuzberg/tree-sitter-language-pack">
11
+ <img src="https://img.shields.io/npm/v/@kreuzberg/tree-sitter-language-pack?label=Node.js&color=007ec6" alt="Node">
12
+ </a> <a href="https://github.com/kreuzberg-dev/tree-sitter-language-pack/tree/main/packages/go/v1">
13
+ <img src="https://img.shields.io/github/v/tag/kreuzberg-dev/tree-sitter-language-pack?label=Go&color=007ec6" alt="Go">
14
+ </a> <a href="https://central.sonatype.com/artifact/dev.kreuzberg/tree-sitter-language-pack">
15
+ <img src="https://img.shields.io/maven-central/v/dev.kreuzberg/tree-sitter-language-pack?label=Java&color=007ec6" alt="Java">
16
+ </a> <a href="https://hex.pm/packages/tree_sitter_language_pack">
17
+ <img src="https://img.shields.io/hexpm/v/tree_sitter_language_pack?label=Elixir&color=007ec6" alt="Elixir">
18
+ </a> <a href="https://rubygems.org/gems/tree_sitter_language_pack">
19
+ <img src="https://img.shields.io/gem/v/tree_sitter_language_pack?label=Ruby&color=007ec6" alt="Ruby">
20
+ </a> <a href="https://www.npmjs.com/package/@kreuzberg/tree-sitter-language-pack-wasm">
21
+ <img src="https://img.shields.io/npm/v/@kreuzberg/tree-sitter-language-pack-wasm?label=WASM&color=007ec6" alt="Wasm">
22
+ </a> <a href="https://packagist.org/packages/kreuzberg/tree-sitter-language-pack">
23
+ <img src="https://img.shields.io/packagist/v/kreuzberg/tree-sitter-language-pack?label=PHP&color=007ec6" alt="Php">
24
+ </a> <a href="https://www.nuget.org/packages/TreeSitterLanguagePack">
25
+ <img src="https://img.shields.io/nuget/v/TreeSitterLanguagePack?label=C%23&color=007ec6" alt="Csharp">
26
+ </a>
27
+ <!-- Project Info -->
28
+ <a href="https://github.com/kreuzberg-dev/tree-sitter-language-pack/actions">
29
+ <img src="https://img.shields.io/github/actions/workflow/status/kreuzberg-dev/tree-sitter-language-pack/ci-rust.yaml?branch=main&label=CI" alt="CI">
30
+ </a>
31
+ <a href="https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/LICENSE">
32
+ <img src="https://img.shields.io/badge/License-MIT%20%7C%20Apache--2.0-blue" alt="License">
33
+ </a>
34
+ <a href="https://github.com/kreuzberg-dev/homebrew-tap">
35
+ <img src="https://img.shields.io/badge/homebrew-ts--pack-FBB040?logo=homebrew" alt="Homebrew">
36
+ </a>
37
+ <a href="https://docs.rs/tree-sitter-language-pack">
38
+ <img src="https://img.shields.io/badge/docs-crates.io-blue" alt="Docs">
39
+ </a>
40
+ </div>
41
+
42
+ <div align="center">
43
+ <a href="https://discord.gg/xt9WY3GnKR">
44
+ <img height="22" src="https://img.shields.io/badge/Discord-Join%20our%20community-7289da?logo=discord&logoColor=white" alt="Discord">
45
+ </a>
46
+ </div>
47
+
48
+ WebAssembly bindings for tree-sitter-language-pack with browser caching support.
49
+
50
+ ## Installation
51
+
52
+ ```sh
53
+ npm install @kreuzberg/tree-sitter-language-pack-wasm
54
+ ```
55
+
56
+ ```sh
57
+ pnpm add @kreuzberg/tree-sitter-language-pack-wasm
58
+ ```
59
+
60
+ ```sh
61
+ yarn add @kreuzberg/tree-sitter-language-pack-wasm
62
+ ```
63
+
64
+ ## Quick Start
65
+
66
+ ```javascript
67
+ import init, { availableLanguages, hasLanguage, init as initLanguages, download } from "@kreuzberg/tree-sitter-language-pack-wasm";
68
+
69
+ await init();
70
+
71
+ // Optional: Pre-download specific languages for offline use
72
+ initLanguages(["python", "javascript", "typescript"]);
73
+
74
+ console.log(availableLanguages());
75
+ console.log(hasLanguage("python")); // true
76
+
77
+ import { process } from '@kreuzberg/tree-sitter-language-pack-wasm';
78
+ // Auto-downloads language if not cached in IndexedDB
79
+ const result = process(source, { language: 'javascript' });
80
+ console.log('Structure:', result.structure);
81
+
82
+ // Pre-download languages for offline use
83
+ download(["python", "javascript"]);
84
+ ```
85
+
86
+ ## API Reference
87
+
88
+ ### Language Discovery
89
+
90
+ - `available_languages()` -- list all supported language names
91
+ - `has_language(name)` -- check if a language is available
92
+ - `language_count()` -- total number of supported languages
93
+
94
+ ### Parsing
95
+
96
+ - `get_parser(name)` / `parse_string(source, language)` -- parse source code into a syntax tree
97
+
98
+ ### Download API
99
+
100
+ - `init(languages)` -- pre-download specific languages for offline use
101
+ - `download(languages)` -- download parsers on demand
102
+
103
+ ### Intelligence
104
+
105
+ - `process(source, config)` -- extract structured analysis (functions, classes, imports, comments, chunks) from source code
106
+
107
+ For detailed API documentation, see the [WebAssembly package](https://github.com/kreuzberg-dev/tree-sitter-language-pack/tree/main/crates/ts-pack-wasm).
108
+
109
+ ## License
110
+
111
+ MIT OR Apache-2.0 -- see [LICENSE](https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/LICENSE) for details.
112
+
113
+ ---
114
+
115
+ Part of [tree-sitter-language-pack](https://github.com/kreuzberg-dev/tree-sitter-language-pack) -- A comprehensive collection of tree-sitter language parsers with polyglot bindings.
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@kreuzberg/tree-sitter-language-pack-wasm",
3
+ "type": "module",
4
+ "description": "WebAssembly bindings for tree-sitter language pack",
5
+ "version": "1.0.0-rc.11",
6
+ "license": "MIT OR Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/kreuzberg-dev/tree-sitter-language-pack"
10
+ },
11
+ "files": [
12
+ "ts_pack_wasm_bg.wasm",
13
+ "ts_pack_wasm.js",
14
+ "ts_pack_wasm.d.ts"
15
+ ],
16
+ "main": "ts_pack_wasm.js",
17
+ "types": "ts_pack_wasm.d.ts",
18
+ "sideEffects": [
19
+ "./snippets/*"
20
+ ],
21
+ "publishConfig": {
22
+ "registry": "https://registry.npmjs.org/",
23
+ "access": "public"
24
+ }
25
+ }
@@ -0,0 +1,172 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class WasmTree {
5
+ private constructor();
6
+ free(): void;
7
+ [Symbol.dispose](): void;
8
+ }
9
+
10
+ /**
11
+ * Returns an array of all available language names.
12
+ */
13
+ export function availableLanguages(): any[];
14
+
15
+ /**
16
+ * Get cache directory (not supported in WASM).
17
+ */
18
+ export function cacheDir(): string;
19
+
20
+ /**
21
+ * Clean cache (stub for WASM).
22
+ * WASM has no persistent cache, so this is a no-op.
23
+ */
24
+ export function cleanCache(): void;
25
+
26
+ /**
27
+ * Configure the language pack (stub for WASM).
28
+ * WASM cannot perform network I/O, so download functions are not supported.
29
+ */
30
+ export function configure(_config: string): void;
31
+
32
+ /**
33
+ * Download specific languages (not supported in WASM).
34
+ */
35
+ export function download(_languages: Array<any>): number;
36
+
37
+ /**
38
+ * Download all languages (not supported in WASM).
39
+ */
40
+ export function downloadAll(): number;
41
+
42
+ /**
43
+ * Get downloaded languages (stub for WASM).
44
+ * Returns empty array since WASM has no persistent cache.
45
+ */
46
+ export function downloadedLanguages(): Array<any>;
47
+
48
+ /**
49
+ * Free the tree handle (called automatically by JS GC, but can be called manually).
50
+ */
51
+ export function freeTree(_tree: WasmTree): void;
52
+
53
+ /**
54
+ * Returns the raw TSLanguage pointer as a u32 for wasm32 interop.
55
+ *
56
+ * Throws an error if the language is not found.
57
+ */
58
+ export function getLanguagePtr(name: string): number;
59
+
60
+ /**
61
+ * Checks whether a language with the given name is available.
62
+ */
63
+ export function hasLanguage(name: string): boolean;
64
+
65
+ /**
66
+ * Initialize the language pack (stub for WASM).
67
+ * WASM cannot perform network I/O, so download functions are not supported.
68
+ */
69
+ export function init(_config: string): void;
70
+
71
+ /**
72
+ * Returns the number of available languages.
73
+ */
74
+ export function languageCount(): number;
75
+
76
+ /**
77
+ * Get manifest languages (not supported in WASM).
78
+ */
79
+ export function manifestLanguages(): Array<any>;
80
+
81
+ /**
82
+ * Parse a source string using the named language and return an opaque tree handle.
83
+ *
84
+ * Throws an error if the language is not found or parsing fails.
85
+ */
86
+ export function parseString(language: string, source: string): WasmTree;
87
+
88
+ /**
89
+ * Process source code and extract metadata + chunks as a JavaScript object.
90
+ *
91
+ * `config` is a JS object with fields:
92
+ * - `language` (string, required): the language name
93
+ * - `chunk_max_size` (number, optional): maximum chunk size in bytes (default: 1500)
94
+ */
95
+ export function process(source: string, config: any): any;
96
+
97
+ /**
98
+ * Check whether any node in the tree has the given type name.
99
+ */
100
+ export function treeContainsNodeType(tree: WasmTree, node_type: string): boolean;
101
+
102
+ /**
103
+ * Check whether the tree contains any ERROR or MISSING nodes.
104
+ */
105
+ export function treeHasErrorNodes(tree: WasmTree): boolean;
106
+
107
+ /**
108
+ * Get the number of named children of the root node.
109
+ */
110
+ export function treeRootChildCount(tree: WasmTree): number;
111
+
112
+ /**
113
+ * Get the type name of the root node.
114
+ */
115
+ export function treeRootNodeType(tree: WasmTree): string;
116
+
117
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
118
+
119
+ export interface InitOutput {
120
+ readonly memory: WebAssembly.Memory;
121
+ readonly __wbg_wasmtree_free: (a: number, b: number) => void;
122
+ readonly availableLanguages: (a: number) => void;
123
+ readonly cacheDir: (a: number) => void;
124
+ readonly cleanCache: (a: number) => void;
125
+ readonly configure: (a: number, b: number, c: number) => void;
126
+ readonly download: (a: number, b: number) => void;
127
+ readonly downloadAll: (a: number) => void;
128
+ readonly downloadedLanguages: (a: number) => void;
129
+ readonly freeTree: (a: number) => void;
130
+ readonly getLanguagePtr: (a: number, b: number, c: number) => void;
131
+ readonly hasLanguage: (a: number, b: number) => number;
132
+ readonly init: (a: number, b: number, c: number) => void;
133
+ readonly iswalnum: (a: number) => number;
134
+ readonly iswalpha: (a: number) => number;
135
+ readonly iswspace: (a: number) => number;
136
+ readonly manifestLanguages: (a: number) => void;
137
+ readonly parseString: (a: number, b: number, c: number, d: number, e: number) => void;
138
+ readonly process: (a: number, b: number, c: number, d: number) => void;
139
+ readonly towupper: (a: number) => number;
140
+ readonly treeContainsNodeType: (a: number, b: number, c: number, d: number) => void;
141
+ readonly treeHasErrorNodes: (a: number, b: number) => void;
142
+ readonly treeRootChildCount: (a: number, b: number) => void;
143
+ readonly treeRootNodeType: (a: number, b: number) => void;
144
+ readonly languageCount: () => number;
145
+ readonly __wbindgen_export: (a: number, b: number) => number;
146
+ readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
147
+ readonly __wbindgen_export3: (a: number) => void;
148
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
149
+ readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
150
+ }
151
+
152
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
153
+
154
+ /**
155
+ * Instantiates the given `module`, which can either be bytes or
156
+ * a precompiled `WebAssembly.Module`.
157
+ *
158
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
159
+ *
160
+ * @returns {InitOutput}
161
+ */
162
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
163
+
164
+ /**
165
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
166
+ * for everything else, calls `WebAssembly.instantiate` directly.
167
+ *
168
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
169
+ *
170
+ * @returns {Promise<InitOutput>}
171
+ */
172
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,775 @@
1
+ /* @ts-self-types="./ts_pack_wasm.d.ts" */
2
+
3
+ export class WasmTree {
4
+ static __wrap(ptr) {
5
+ ptr = ptr >>> 0;
6
+ const obj = Object.create(WasmTree.prototype);
7
+ obj.__wbg_ptr = ptr;
8
+ WasmTreeFinalization.register(obj, obj.__wbg_ptr, obj);
9
+ return obj;
10
+ }
11
+ __destroy_into_raw() {
12
+ const ptr = this.__wbg_ptr;
13
+ this.__wbg_ptr = 0;
14
+ WasmTreeFinalization.unregister(this);
15
+ return ptr;
16
+ }
17
+ free() {
18
+ const ptr = this.__destroy_into_raw();
19
+ wasm.__wbg_wasmtree_free(ptr, 0);
20
+ }
21
+ }
22
+ if (Symbol.dispose) WasmTree.prototype[Symbol.dispose] = WasmTree.prototype.free;
23
+
24
+ /**
25
+ * Returns an array of all available language names.
26
+ * @returns {any[]}
27
+ */
28
+ export function availableLanguages() {
29
+ try {
30
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
31
+ wasm.availableLanguages(retptr);
32
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
33
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
34
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
35
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
36
+ return v1;
37
+ } finally {
38
+ wasm.__wbindgen_add_to_stack_pointer(16);
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Get cache directory (not supported in WASM).
44
+ * @returns {string}
45
+ */
46
+ export function cacheDir() {
47
+ let deferred2_0;
48
+ let deferred2_1;
49
+ try {
50
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
51
+ wasm.cacheDir(retptr);
52
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
53
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
54
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
55
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
56
+ var ptr1 = r0;
57
+ var len1 = r1;
58
+ if (r3) {
59
+ ptr1 = 0; len1 = 0;
60
+ throw takeObject(r2);
61
+ }
62
+ deferred2_0 = ptr1;
63
+ deferred2_1 = len1;
64
+ return getStringFromWasm0(ptr1, len1);
65
+ } finally {
66
+ wasm.__wbindgen_add_to_stack_pointer(16);
67
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Clean cache (stub for WASM).
73
+ * WASM has no persistent cache, so this is a no-op.
74
+ */
75
+ export function cleanCache() {
76
+ try {
77
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
78
+ wasm.cleanCache(retptr);
79
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
80
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
81
+ if (r1) {
82
+ throw takeObject(r0);
83
+ }
84
+ } finally {
85
+ wasm.__wbindgen_add_to_stack_pointer(16);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Configure the language pack (stub for WASM).
91
+ * WASM cannot perform network I/O, so download functions are not supported.
92
+ * @param {string} _config
93
+ */
94
+ export function configure(_config) {
95
+ try {
96
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
97
+ const ptr0 = passStringToWasm0(_config, wasm.__wbindgen_export, wasm.__wbindgen_export2);
98
+ const len0 = WASM_VECTOR_LEN;
99
+ wasm.configure(retptr, ptr0, len0);
100
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
101
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
102
+ if (r1) {
103
+ throw takeObject(r0);
104
+ }
105
+ } finally {
106
+ wasm.__wbindgen_add_to_stack_pointer(16);
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Download specific languages (not supported in WASM).
112
+ * @param {Array<any>} _languages
113
+ * @returns {number}
114
+ */
115
+ export function download(_languages) {
116
+ try {
117
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
118
+ wasm.download(retptr, addHeapObject(_languages));
119
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
120
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
121
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
122
+ if (r2) {
123
+ throw takeObject(r1);
124
+ }
125
+ return r0;
126
+ } finally {
127
+ wasm.__wbindgen_add_to_stack_pointer(16);
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Download all languages (not supported in WASM).
133
+ * @returns {number}
134
+ */
135
+ export function downloadAll() {
136
+ try {
137
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
138
+ wasm.downloadAll(retptr);
139
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
140
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
141
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
142
+ if (r2) {
143
+ throw takeObject(r1);
144
+ }
145
+ return r0;
146
+ } finally {
147
+ wasm.__wbindgen_add_to_stack_pointer(16);
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Get downloaded languages (stub for WASM).
153
+ * Returns empty array since WASM has no persistent cache.
154
+ * @returns {Array<any>}
155
+ */
156
+ export function downloadedLanguages() {
157
+ try {
158
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
159
+ wasm.downloadedLanguages(retptr);
160
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
161
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
162
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
163
+ if (r2) {
164
+ throw takeObject(r1);
165
+ }
166
+ return takeObject(r0);
167
+ } finally {
168
+ wasm.__wbindgen_add_to_stack_pointer(16);
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Free the tree handle (called automatically by JS GC, but can be called manually).
174
+ * @param {WasmTree} _tree
175
+ */
176
+ export function freeTree(_tree) {
177
+ _assertClass(_tree, WasmTree);
178
+ var ptr0 = _tree.__destroy_into_raw();
179
+ wasm.freeTree(ptr0);
180
+ }
181
+
182
+ /**
183
+ * Returns the raw TSLanguage pointer as a u32 for wasm32 interop.
184
+ *
185
+ * Throws an error if the language is not found.
186
+ * @param {string} name
187
+ * @returns {number}
188
+ */
189
+ export function getLanguagePtr(name) {
190
+ try {
191
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
192
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
193
+ const len0 = WASM_VECTOR_LEN;
194
+ wasm.getLanguagePtr(retptr, ptr0, len0);
195
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
196
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
197
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
198
+ if (r2) {
199
+ throw takeObject(r1);
200
+ }
201
+ return r0 >>> 0;
202
+ } finally {
203
+ wasm.__wbindgen_add_to_stack_pointer(16);
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Checks whether a language with the given name is available.
209
+ * @param {string} name
210
+ * @returns {boolean}
211
+ */
212
+ export function hasLanguage(name) {
213
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_export, wasm.__wbindgen_export2);
214
+ const len0 = WASM_VECTOR_LEN;
215
+ const ret = wasm.hasLanguage(ptr0, len0);
216
+ return ret !== 0;
217
+ }
218
+
219
+ /**
220
+ * Initialize the language pack (stub for WASM).
221
+ * WASM cannot perform network I/O, so download functions are not supported.
222
+ * @param {string} _config
223
+ */
224
+ export function init(_config) {
225
+ try {
226
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
227
+ const ptr0 = passStringToWasm0(_config, wasm.__wbindgen_export, wasm.__wbindgen_export2);
228
+ const len0 = WASM_VECTOR_LEN;
229
+ wasm.init(retptr, ptr0, len0);
230
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
231
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
232
+ if (r1) {
233
+ throw takeObject(r0);
234
+ }
235
+ } finally {
236
+ wasm.__wbindgen_add_to_stack_pointer(16);
237
+ }
238
+ }
239
+
240
+ /**
241
+ * Returns the number of available languages.
242
+ * @returns {number}
243
+ */
244
+ export function languageCount() {
245
+ const ret = wasm.languageCount();
246
+ return ret >>> 0;
247
+ }
248
+
249
+ /**
250
+ * Get manifest languages (not supported in WASM).
251
+ * @returns {Array<any>}
252
+ */
253
+ export function manifestLanguages() {
254
+ try {
255
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
256
+ wasm.manifestLanguages(retptr);
257
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
258
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
259
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
260
+ if (r2) {
261
+ throw takeObject(r1);
262
+ }
263
+ return takeObject(r0);
264
+ } finally {
265
+ wasm.__wbindgen_add_to_stack_pointer(16);
266
+ }
267
+ }
268
+
269
+ /**
270
+ * Parse a source string using the named language and return an opaque tree handle.
271
+ *
272
+ * Throws an error if the language is not found or parsing fails.
273
+ * @param {string} language
274
+ * @param {string} source
275
+ * @returns {WasmTree}
276
+ */
277
+ export function parseString(language, source) {
278
+ try {
279
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
280
+ const ptr0 = passStringToWasm0(language, wasm.__wbindgen_export, wasm.__wbindgen_export2);
281
+ const len0 = WASM_VECTOR_LEN;
282
+ const ptr1 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
283
+ const len1 = WASM_VECTOR_LEN;
284
+ wasm.parseString(retptr, ptr0, len0, ptr1, len1);
285
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
286
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
287
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
288
+ if (r2) {
289
+ throw takeObject(r1);
290
+ }
291
+ return WasmTree.__wrap(r0);
292
+ } finally {
293
+ wasm.__wbindgen_add_to_stack_pointer(16);
294
+ }
295
+ }
296
+
297
+ /**
298
+ * Process source code and extract metadata + chunks as a JavaScript object.
299
+ *
300
+ * `config` is a JS object with fields:
301
+ * - `language` (string, required): the language name
302
+ * - `chunk_max_size` (number, optional): maximum chunk size in bytes (default: 1500)
303
+ * @param {string} source
304
+ * @param {any} config
305
+ * @returns {any}
306
+ */
307
+ export function process(source, config) {
308
+ try {
309
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
310
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
311
+ const len0 = WASM_VECTOR_LEN;
312
+ wasm.process(retptr, ptr0, len0, addHeapObject(config));
313
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
314
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
315
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
316
+ if (r2) {
317
+ throw takeObject(r1);
318
+ }
319
+ return takeObject(r0);
320
+ } finally {
321
+ wasm.__wbindgen_add_to_stack_pointer(16);
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Check whether any node in the tree has the given type name.
327
+ * @param {WasmTree} tree
328
+ * @param {string} node_type
329
+ * @returns {boolean}
330
+ */
331
+ export function treeContainsNodeType(tree, node_type) {
332
+ try {
333
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
334
+ _assertClass(tree, WasmTree);
335
+ const ptr0 = passStringToWasm0(node_type, wasm.__wbindgen_export, wasm.__wbindgen_export2);
336
+ const len0 = WASM_VECTOR_LEN;
337
+ wasm.treeContainsNodeType(retptr, tree.__wbg_ptr, ptr0, len0);
338
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
339
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
340
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
341
+ if (r2) {
342
+ throw takeObject(r1);
343
+ }
344
+ return r0 !== 0;
345
+ } finally {
346
+ wasm.__wbindgen_add_to_stack_pointer(16);
347
+ }
348
+ }
349
+
350
+ /**
351
+ * Check whether the tree contains any ERROR or MISSING nodes.
352
+ * @param {WasmTree} tree
353
+ * @returns {boolean}
354
+ */
355
+ export function treeHasErrorNodes(tree) {
356
+ try {
357
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
358
+ _assertClass(tree, WasmTree);
359
+ wasm.treeHasErrorNodes(retptr, tree.__wbg_ptr);
360
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
361
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
362
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
363
+ if (r2) {
364
+ throw takeObject(r1);
365
+ }
366
+ return r0 !== 0;
367
+ } finally {
368
+ wasm.__wbindgen_add_to_stack_pointer(16);
369
+ }
370
+ }
371
+
372
+ /**
373
+ * Get the number of named children of the root node.
374
+ * @param {WasmTree} tree
375
+ * @returns {number}
376
+ */
377
+ export function treeRootChildCount(tree) {
378
+ try {
379
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
380
+ _assertClass(tree, WasmTree);
381
+ wasm.treeRootChildCount(retptr, tree.__wbg_ptr);
382
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
383
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
384
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
385
+ if (r2) {
386
+ throw takeObject(r1);
387
+ }
388
+ return r0 >>> 0;
389
+ } finally {
390
+ wasm.__wbindgen_add_to_stack_pointer(16);
391
+ }
392
+ }
393
+
394
+ /**
395
+ * Get the type name of the root node.
396
+ * @param {WasmTree} tree
397
+ * @returns {string}
398
+ */
399
+ export function treeRootNodeType(tree) {
400
+ let deferred2_0;
401
+ let deferred2_1;
402
+ try {
403
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
404
+ _assertClass(tree, WasmTree);
405
+ wasm.treeRootNodeType(retptr, tree.__wbg_ptr);
406
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
407
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
408
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
409
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
410
+ var ptr1 = r0;
411
+ var len1 = r1;
412
+ if (r3) {
413
+ ptr1 = 0; len1 = 0;
414
+ throw takeObject(r2);
415
+ }
416
+ deferred2_0 = ptr1;
417
+ deferred2_1 = len1;
418
+ return getStringFromWasm0(ptr1, len1);
419
+ } finally {
420
+ wasm.__wbindgen_add_to_stack_pointer(16);
421
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
422
+ }
423
+ }
424
+
425
+ function __wbg_get_imports() {
426
+ const import0 = {
427
+ __proto__: null,
428
+ __wbg___wbindgen_debug_string_5398f5bb970e0daa: function(arg0, arg1) {
429
+ const ret = debugString(getObject(arg1));
430
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
431
+ const len1 = WASM_VECTOR_LEN;
432
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
433
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
434
+ },
435
+ __wbg___wbindgen_string_get_395e606bd0ee4427: function(arg0, arg1) {
436
+ const obj = getObject(arg1);
437
+ const ret = typeof(obj) === 'string' ? obj : undefined;
438
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
439
+ var len1 = WASM_VECTOR_LEN;
440
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
441
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
442
+ },
443
+ __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
444
+ throw new Error(getStringFromWasm0(arg0, arg1));
445
+ },
446
+ __wbg_new_a70fbab9066b301f: function() {
447
+ const ret = new Array();
448
+ return addHeapObject(ret);
449
+ },
450
+ __wbg_parse_e9eddd2a82c706eb: function() { return handleError(function (arg0, arg1) {
451
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
452
+ return addHeapObject(ret);
453
+ }, arguments); },
454
+ __wbg_stringify_5ae93966a84901ac: function() { return handleError(function (arg0) {
455
+ const ret = JSON.stringify(getObject(arg0));
456
+ return addHeapObject(ret);
457
+ }, arguments); },
458
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
459
+ // Cast intrinsic for `Ref(String) -> Externref`.
460
+ const ret = getStringFromWasm0(arg0, arg1);
461
+ return addHeapObject(ret);
462
+ },
463
+ __wbindgen_object_drop_ref: function(arg0) {
464
+ takeObject(arg0);
465
+ },
466
+ };
467
+ return {
468
+ __proto__: null,
469
+ "./ts_pack_wasm_bg.js": import0,
470
+ };
471
+ }
472
+
473
+ const WasmTreeFinalization = (typeof FinalizationRegistry === 'undefined')
474
+ ? { register: () => {}, unregister: () => {} }
475
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmtree_free(ptr >>> 0, 1));
476
+
477
+ function addHeapObject(obj) {
478
+ if (heap_next === heap.length) heap.push(heap.length + 1);
479
+ const idx = heap_next;
480
+ heap_next = heap[idx];
481
+
482
+ heap[idx] = obj;
483
+ return idx;
484
+ }
485
+
486
+ function _assertClass(instance, klass) {
487
+ if (!(instance instanceof klass)) {
488
+ throw new Error(`expected instance of ${klass.name}`);
489
+ }
490
+ }
491
+
492
+ function debugString(val) {
493
+ // primitive types
494
+ const type = typeof val;
495
+ if (type == 'number' || type == 'boolean' || val == null) {
496
+ return `${val}`;
497
+ }
498
+ if (type == 'string') {
499
+ return `"${val}"`;
500
+ }
501
+ if (type == 'symbol') {
502
+ const description = val.description;
503
+ if (description == null) {
504
+ return 'Symbol';
505
+ } else {
506
+ return `Symbol(${description})`;
507
+ }
508
+ }
509
+ if (type == 'function') {
510
+ const name = val.name;
511
+ if (typeof name == 'string' && name.length > 0) {
512
+ return `Function(${name})`;
513
+ } else {
514
+ return 'Function';
515
+ }
516
+ }
517
+ // objects
518
+ if (Array.isArray(val)) {
519
+ const length = val.length;
520
+ let debug = '[';
521
+ if (length > 0) {
522
+ debug += debugString(val[0]);
523
+ }
524
+ for(let i = 1; i < length; i++) {
525
+ debug += ', ' + debugString(val[i]);
526
+ }
527
+ debug += ']';
528
+ return debug;
529
+ }
530
+ // Test for built-in
531
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
532
+ let className;
533
+ if (builtInMatches && builtInMatches.length > 1) {
534
+ className = builtInMatches[1];
535
+ } else {
536
+ // Failed to match the standard '[object ClassName]'
537
+ return toString.call(val);
538
+ }
539
+ if (className == 'Object') {
540
+ // we're a user defined class or Object
541
+ // JSON.stringify avoids problems with cycles, and is generally much
542
+ // easier than looping through ownProperties of `val`.
543
+ try {
544
+ return 'Object(' + JSON.stringify(val) + ')';
545
+ } catch (_) {
546
+ return 'Object';
547
+ }
548
+ }
549
+ // errors
550
+ if (val instanceof Error) {
551
+ return `${val.name}: ${val.message}\n${val.stack}`;
552
+ }
553
+ // TODO we could test for more things here, like `Set`s and `Map`s.
554
+ return className;
555
+ }
556
+
557
+ function dropObject(idx) {
558
+ if (idx < 1028) return;
559
+ heap[idx] = heap_next;
560
+ heap_next = idx;
561
+ }
562
+
563
+ function getArrayJsValueFromWasm0(ptr, len) {
564
+ ptr = ptr >>> 0;
565
+ const mem = getDataViewMemory0();
566
+ const result = [];
567
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
568
+ result.push(takeObject(mem.getUint32(i, true)));
569
+ }
570
+ return result;
571
+ }
572
+
573
+ let cachedDataViewMemory0 = null;
574
+ function getDataViewMemory0() {
575
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
576
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
577
+ }
578
+ return cachedDataViewMemory0;
579
+ }
580
+
581
+ function getStringFromWasm0(ptr, len) {
582
+ ptr = ptr >>> 0;
583
+ return decodeText(ptr, len);
584
+ }
585
+
586
+ let cachedUint8ArrayMemory0 = null;
587
+ function getUint8ArrayMemory0() {
588
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
589
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
590
+ }
591
+ return cachedUint8ArrayMemory0;
592
+ }
593
+
594
+ function getObject(idx) { return heap[idx]; }
595
+
596
+ function handleError(f, args) {
597
+ try {
598
+ return f.apply(this, args);
599
+ } catch (e) {
600
+ wasm.__wbindgen_export3(addHeapObject(e));
601
+ }
602
+ }
603
+
604
+ let heap = new Array(1024).fill(undefined);
605
+ heap.push(undefined, null, true, false);
606
+
607
+ let heap_next = heap.length;
608
+
609
+ function isLikeNone(x) {
610
+ return x === undefined || x === null;
611
+ }
612
+
613
+ function passStringToWasm0(arg, malloc, realloc) {
614
+ if (realloc === undefined) {
615
+ const buf = cachedTextEncoder.encode(arg);
616
+ const ptr = malloc(buf.length, 1) >>> 0;
617
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
618
+ WASM_VECTOR_LEN = buf.length;
619
+ return ptr;
620
+ }
621
+
622
+ let len = arg.length;
623
+ let ptr = malloc(len, 1) >>> 0;
624
+
625
+ const mem = getUint8ArrayMemory0();
626
+
627
+ let offset = 0;
628
+
629
+ for (; offset < len; offset++) {
630
+ const code = arg.charCodeAt(offset);
631
+ if (code > 0x7F) break;
632
+ mem[ptr + offset] = code;
633
+ }
634
+ if (offset !== len) {
635
+ if (offset !== 0) {
636
+ arg = arg.slice(offset);
637
+ }
638
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
639
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
640
+ const ret = cachedTextEncoder.encodeInto(arg, view);
641
+
642
+ offset += ret.written;
643
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
644
+ }
645
+
646
+ WASM_VECTOR_LEN = offset;
647
+ return ptr;
648
+ }
649
+
650
+ function takeObject(idx) {
651
+ const ret = getObject(idx);
652
+ dropObject(idx);
653
+ return ret;
654
+ }
655
+
656
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
657
+ cachedTextDecoder.decode();
658
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
659
+ let numBytesDecoded = 0;
660
+ function decodeText(ptr, len) {
661
+ numBytesDecoded += len;
662
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
663
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
664
+ cachedTextDecoder.decode();
665
+ numBytesDecoded = len;
666
+ }
667
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
668
+ }
669
+
670
+ const cachedTextEncoder = new TextEncoder();
671
+
672
+ if (!('encodeInto' in cachedTextEncoder)) {
673
+ cachedTextEncoder.encodeInto = function (arg, view) {
674
+ const buf = cachedTextEncoder.encode(arg);
675
+ view.set(buf);
676
+ return {
677
+ read: arg.length,
678
+ written: buf.length
679
+ };
680
+ };
681
+ }
682
+
683
+ let WASM_VECTOR_LEN = 0;
684
+
685
+ let wasmModule, wasm;
686
+ function __wbg_finalize_init(instance, module) {
687
+ wasm = instance.exports;
688
+ wasmModule = module;
689
+ cachedDataViewMemory0 = null;
690
+ cachedUint8ArrayMemory0 = null;
691
+ return wasm;
692
+ }
693
+
694
+ async function __wbg_load(module, imports) {
695
+ if (typeof Response === 'function' && module instanceof Response) {
696
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
697
+ try {
698
+ return await WebAssembly.instantiateStreaming(module, imports);
699
+ } catch (e) {
700
+ const validResponse = module.ok && expectedResponseType(module.type);
701
+
702
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
703
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
704
+
705
+ } else { throw e; }
706
+ }
707
+ }
708
+
709
+ const bytes = await module.arrayBuffer();
710
+ return await WebAssembly.instantiate(bytes, imports);
711
+ } else {
712
+ const instance = await WebAssembly.instantiate(module, imports);
713
+
714
+ if (instance instanceof WebAssembly.Instance) {
715
+ return { instance, module };
716
+ } else {
717
+ return instance;
718
+ }
719
+ }
720
+
721
+ function expectedResponseType(type) {
722
+ switch (type) {
723
+ case 'basic': case 'cors': case 'default': return true;
724
+ }
725
+ return false;
726
+ }
727
+ }
728
+
729
+ function initSync(module) {
730
+ if (wasm !== undefined) return wasm;
731
+
732
+
733
+ if (module !== undefined) {
734
+ if (Object.getPrototypeOf(module) === Object.prototype) {
735
+ ({module} = module)
736
+ } else {
737
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
738
+ }
739
+ }
740
+
741
+ const imports = __wbg_get_imports();
742
+ if (!(module instanceof WebAssembly.Module)) {
743
+ module = new WebAssembly.Module(module);
744
+ }
745
+ const instance = new WebAssembly.Instance(module, imports);
746
+ return __wbg_finalize_init(instance, module);
747
+ }
748
+
749
+ async function __wbg_init(module_or_path) {
750
+ if (wasm !== undefined) return wasm;
751
+
752
+
753
+ if (module_or_path !== undefined) {
754
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
755
+ ({module_or_path} = module_or_path)
756
+ } else {
757
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
758
+ }
759
+ }
760
+
761
+ if (module_or_path === undefined) {
762
+ module_or_path = new URL('ts_pack_wasm_bg.wasm', import.meta.url);
763
+ }
764
+ const imports = __wbg_get_imports();
765
+
766
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
767
+ module_or_path = fetch(module_or_path);
768
+ }
769
+
770
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
771
+
772
+ return __wbg_finalize_init(instance, module);
773
+ }
774
+
775
+ export { initSync, __wbg_init as default };
Binary file