ts-pack-wasm 1.0.0-rc.1
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 +97 -0
- package/package.json +21 -0
- package/ts_pack_wasm.d.ts +124 -0
- package/ts_pack_wasm.js +532 -0
- package/ts_pack_wasm_bg.wasm +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<!-- Generated by scripts/generate_readme.py. DO NOT EDIT. -->
|
|
2
|
+
|
|
3
|
+
# 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.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
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<div align="center">
|
|
37
|
+
<a href="https://discord.gg/xt9WY3GnKR">
|
|
38
|
+
<img height="22" src="https://img.shields.io/badge/Discord-Join%20our%20community-7289da?logo=discord&logoColor=white" alt="Discord">
|
|
39
|
+
</a>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
WebAssembly bindings for tree-sitter-language-pack using wasm-bindgen.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
npm install @kreuzberg/tree-sitter-language-pack-wasm
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
pnpm add @kreuzberg/tree-sitter-language-pack-wasm
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
yarn add @kreuzberg/tree-sitter-language-pack-wasm
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Quick Start
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
import init, { availableLanguages, hasLanguage, parseString } from "@kreuzberg/tree-sitter-language-pack-wasm";
|
|
62
|
+
|
|
63
|
+
await init();
|
|
64
|
+
|
|
65
|
+
console.log(availableLanguages());
|
|
66
|
+
console.log(hasLanguage("python")); // true
|
|
67
|
+
|
|
68
|
+
import { process } from '@kreuzberg/tree-sitter-language-pack-wasm';
|
|
69
|
+
const result = process(source, { language: 'javascript' });
|
|
70
|
+
console.log('Structure:', result.structure);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## API Reference
|
|
74
|
+
|
|
75
|
+
### Language Discovery
|
|
76
|
+
|
|
77
|
+
- `available_languages()` -- list all supported language names
|
|
78
|
+
- `has_language(name)` -- check if a language is available
|
|
79
|
+
- `language_count()` -- total number of supported languages
|
|
80
|
+
|
|
81
|
+
### Parsing
|
|
82
|
+
|
|
83
|
+
- `get_parser(name)` / `parse_string(source, language)` -- parse source code into a syntax tree
|
|
84
|
+
|
|
85
|
+
### Intelligence
|
|
86
|
+
|
|
87
|
+
- `process(source, config)` -- extract structured analysis (functions, classes, imports, comments, chunks) from source code
|
|
88
|
+
|
|
89
|
+
For detailed API documentation, see the [WebAssembly package](https://github.com/kreuzberg-dev/tree-sitter-language-pack/tree/main/crates/ts-pack-wasm).
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT OR Apache-2.0 -- see [LICENSE](https://github.com/kreuzberg-dev/tree-sitter-language-pack/blob/main/LICENSE) for details.
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
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,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ts-pack-wasm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "WebAssembly bindings for tree-sitter language pack",
|
|
5
|
+
"version": "1.0.0-rc.1",
|
|
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
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
* Free the tree handle (called automatically by JS GC, but can be called manually).
|
|
17
|
+
*/
|
|
18
|
+
export function freeTree(_tree: WasmTree): void;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Returns the raw TSLanguage pointer as a u32 for wasm32 interop.
|
|
22
|
+
*
|
|
23
|
+
* Throws an error if the language is not found.
|
|
24
|
+
*/
|
|
25
|
+
export function getLanguagePtr(name: string): number;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Checks whether a language with the given name is available.
|
|
29
|
+
*/
|
|
30
|
+
export function hasLanguage(name: string): boolean;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns the number of available languages.
|
|
34
|
+
*/
|
|
35
|
+
export function languageCount(): number;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Parse a source string using the named language and return an opaque tree handle.
|
|
39
|
+
*
|
|
40
|
+
* Throws an error if the language is not found or parsing fails.
|
|
41
|
+
*/
|
|
42
|
+
export function parseString(language: string, source: string): WasmTree;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Process source code and extract metadata + chunks as a JavaScript object.
|
|
46
|
+
*
|
|
47
|
+
* `config` is a JS object with fields:
|
|
48
|
+
* - `language` (string, required): the language name
|
|
49
|
+
* - `chunk_max_size` (number, optional): maximum chunk size in bytes (default: 1500)
|
|
50
|
+
*/
|
|
51
|
+
export function process(source: string, config: any): any;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Check whether any node in the tree has the given type name.
|
|
55
|
+
*/
|
|
56
|
+
export function treeContainsNodeType(tree: WasmTree, node_type: string): boolean;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Check whether the tree contains any ERROR or MISSING nodes.
|
|
60
|
+
*/
|
|
61
|
+
export function treeHasErrorNodes(tree: WasmTree): boolean;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Get the number of named children of the root node.
|
|
65
|
+
*/
|
|
66
|
+
export function treeRootChildCount(tree: WasmTree): number;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get the type name of the root node.
|
|
70
|
+
*/
|
|
71
|
+
export function treeRootNodeType(tree: WasmTree): string;
|
|
72
|
+
|
|
73
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
74
|
+
|
|
75
|
+
export interface InitOutput {
|
|
76
|
+
readonly memory: WebAssembly.Memory;
|
|
77
|
+
readonly __wbg_wasmtree_free: (a: number, b: number) => void;
|
|
78
|
+
readonly availableLanguages: () => [number, number];
|
|
79
|
+
readonly freeTree: (a: number) => void;
|
|
80
|
+
readonly getLanguagePtr: (a: number, b: number) => [number, number, number];
|
|
81
|
+
readonly hasLanguage: (a: number, b: number) => number;
|
|
82
|
+
readonly iswalnum: (a: number) => number;
|
|
83
|
+
readonly iswalpha: (a: number) => number;
|
|
84
|
+
readonly iswspace: (a: number) => number;
|
|
85
|
+
readonly parseString: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
86
|
+
readonly process: (a: number, b: number, c: any) => [number, number, number];
|
|
87
|
+
readonly towupper: (a: number) => number;
|
|
88
|
+
readonly treeContainsNodeType: (a: number, b: number, c: number) => [number, number, number];
|
|
89
|
+
readonly treeHasErrorNodes: (a: number) => [number, number, number];
|
|
90
|
+
readonly treeRootChildCount: (a: number) => [number, number, number];
|
|
91
|
+
readonly treeRootNodeType: (a: number) => [number, number, number, number];
|
|
92
|
+
readonly languageCount: () => number;
|
|
93
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
94
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
95
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
96
|
+
readonly __externref_table_alloc: () => number;
|
|
97
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
98
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
99
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
100
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
101
|
+
readonly __wbindgen_start: () => void;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
108
|
+
* a precompiled `WebAssembly.Module`.
|
|
109
|
+
*
|
|
110
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
111
|
+
*
|
|
112
|
+
* @returns {InitOutput}
|
|
113
|
+
*/
|
|
114
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
118
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
119
|
+
*
|
|
120
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
121
|
+
*
|
|
122
|
+
* @returns {Promise<InitOutput>}
|
|
123
|
+
*/
|
|
124
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/ts_pack_wasm.js
ADDED
|
@@ -0,0 +1,532 @@
|
|
|
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
|
+
const ret = wasm.availableLanguages();
|
|
30
|
+
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
31
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
32
|
+
return v1;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Free the tree handle (called automatically by JS GC, but can be called manually).
|
|
37
|
+
* @param {WasmTree} _tree
|
|
38
|
+
*/
|
|
39
|
+
export function freeTree(_tree) {
|
|
40
|
+
_assertClass(_tree, WasmTree);
|
|
41
|
+
var ptr0 = _tree.__destroy_into_raw();
|
|
42
|
+
wasm.freeTree(ptr0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns the raw TSLanguage pointer as a u32 for wasm32 interop.
|
|
47
|
+
*
|
|
48
|
+
* Throws an error if the language is not found.
|
|
49
|
+
* @param {string} name
|
|
50
|
+
* @returns {number}
|
|
51
|
+
*/
|
|
52
|
+
export function getLanguagePtr(name) {
|
|
53
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
54
|
+
const len0 = WASM_VECTOR_LEN;
|
|
55
|
+
const ret = wasm.getLanguagePtr(ptr0, len0);
|
|
56
|
+
if (ret[2]) {
|
|
57
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
58
|
+
}
|
|
59
|
+
return ret[0] >>> 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Checks whether a language with the given name is available.
|
|
64
|
+
* @param {string} name
|
|
65
|
+
* @returns {boolean}
|
|
66
|
+
*/
|
|
67
|
+
export function hasLanguage(name) {
|
|
68
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
69
|
+
const len0 = WASM_VECTOR_LEN;
|
|
70
|
+
const ret = wasm.hasLanguage(ptr0, len0);
|
|
71
|
+
return ret !== 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Returns the number of available languages.
|
|
76
|
+
* @returns {number}
|
|
77
|
+
*/
|
|
78
|
+
export function languageCount() {
|
|
79
|
+
const ret = wasm.languageCount();
|
|
80
|
+
return ret >>> 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Parse a source string using the named language and return an opaque tree handle.
|
|
85
|
+
*
|
|
86
|
+
* Throws an error if the language is not found or parsing fails.
|
|
87
|
+
* @param {string} language
|
|
88
|
+
* @param {string} source
|
|
89
|
+
* @returns {WasmTree}
|
|
90
|
+
*/
|
|
91
|
+
export function parseString(language, source) {
|
|
92
|
+
const ptr0 = passStringToWasm0(language, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
93
|
+
const len0 = WASM_VECTOR_LEN;
|
|
94
|
+
const ptr1 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
95
|
+
const len1 = WASM_VECTOR_LEN;
|
|
96
|
+
const ret = wasm.parseString(ptr0, len0, ptr1, len1);
|
|
97
|
+
if (ret[2]) {
|
|
98
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
99
|
+
}
|
|
100
|
+
return WasmTree.__wrap(ret[0]);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Process source code and extract metadata + chunks as a JavaScript object.
|
|
105
|
+
*
|
|
106
|
+
* `config` is a JS object with fields:
|
|
107
|
+
* - `language` (string, required): the language name
|
|
108
|
+
* - `chunk_max_size` (number, optional): maximum chunk size in bytes (default: 1500)
|
|
109
|
+
* @param {string} source
|
|
110
|
+
* @param {any} config
|
|
111
|
+
* @returns {any}
|
|
112
|
+
*/
|
|
113
|
+
export function process(source, config) {
|
|
114
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
115
|
+
const len0 = WASM_VECTOR_LEN;
|
|
116
|
+
const ret = wasm.process(ptr0, len0, config);
|
|
117
|
+
if (ret[2]) {
|
|
118
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
119
|
+
}
|
|
120
|
+
return takeFromExternrefTable0(ret[0]);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Check whether any node in the tree has the given type name.
|
|
125
|
+
* @param {WasmTree} tree
|
|
126
|
+
* @param {string} node_type
|
|
127
|
+
* @returns {boolean}
|
|
128
|
+
*/
|
|
129
|
+
export function treeContainsNodeType(tree, node_type) {
|
|
130
|
+
_assertClass(tree, WasmTree);
|
|
131
|
+
const ptr0 = passStringToWasm0(node_type, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
132
|
+
const len0 = WASM_VECTOR_LEN;
|
|
133
|
+
const ret = wasm.treeContainsNodeType(tree.__wbg_ptr, ptr0, len0);
|
|
134
|
+
if (ret[2]) {
|
|
135
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
136
|
+
}
|
|
137
|
+
return ret[0] !== 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Check whether the tree contains any ERROR or MISSING nodes.
|
|
142
|
+
* @param {WasmTree} tree
|
|
143
|
+
* @returns {boolean}
|
|
144
|
+
*/
|
|
145
|
+
export function treeHasErrorNodes(tree) {
|
|
146
|
+
_assertClass(tree, WasmTree);
|
|
147
|
+
const ret = wasm.treeHasErrorNodes(tree.__wbg_ptr);
|
|
148
|
+
if (ret[2]) {
|
|
149
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
150
|
+
}
|
|
151
|
+
return ret[0] !== 0;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Get the number of named children of the root node.
|
|
156
|
+
* @param {WasmTree} tree
|
|
157
|
+
* @returns {number}
|
|
158
|
+
*/
|
|
159
|
+
export function treeRootChildCount(tree) {
|
|
160
|
+
_assertClass(tree, WasmTree);
|
|
161
|
+
const ret = wasm.treeRootChildCount(tree.__wbg_ptr);
|
|
162
|
+
if (ret[2]) {
|
|
163
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
164
|
+
}
|
|
165
|
+
return ret[0] >>> 0;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Get the type name of the root node.
|
|
170
|
+
* @param {WasmTree} tree
|
|
171
|
+
* @returns {string}
|
|
172
|
+
*/
|
|
173
|
+
export function treeRootNodeType(tree) {
|
|
174
|
+
let deferred2_0;
|
|
175
|
+
let deferred2_1;
|
|
176
|
+
try {
|
|
177
|
+
_assertClass(tree, WasmTree);
|
|
178
|
+
const ret = wasm.treeRootNodeType(tree.__wbg_ptr);
|
|
179
|
+
var ptr1 = ret[0];
|
|
180
|
+
var len1 = ret[1];
|
|
181
|
+
if (ret[3]) {
|
|
182
|
+
ptr1 = 0; len1 = 0;
|
|
183
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
184
|
+
}
|
|
185
|
+
deferred2_0 = ptr1;
|
|
186
|
+
deferred2_1 = len1;
|
|
187
|
+
return getStringFromWasm0(ptr1, len1);
|
|
188
|
+
} finally {
|
|
189
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function __wbg_get_imports() {
|
|
194
|
+
const import0 = {
|
|
195
|
+
__proto__: null,
|
|
196
|
+
__wbg___wbindgen_debug_string_5398f5bb970e0daa: function(arg0, arg1) {
|
|
197
|
+
const ret = debugString(arg1);
|
|
198
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
199
|
+
const len1 = WASM_VECTOR_LEN;
|
|
200
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
201
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
202
|
+
},
|
|
203
|
+
__wbg___wbindgen_string_get_395e606bd0ee4427: function(arg0, arg1) {
|
|
204
|
+
const obj = arg1;
|
|
205
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
206
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
207
|
+
var len1 = WASM_VECTOR_LEN;
|
|
208
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
209
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
210
|
+
},
|
|
211
|
+
__wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
|
|
212
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
213
|
+
},
|
|
214
|
+
__wbg_parse_e9eddd2a82c706eb: function() { return handleError(function (arg0, arg1) {
|
|
215
|
+
const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
|
|
216
|
+
return ret;
|
|
217
|
+
}, arguments); },
|
|
218
|
+
__wbg_stringify_5ae93966a84901ac: function() { return handleError(function (arg0) {
|
|
219
|
+
const ret = JSON.stringify(arg0);
|
|
220
|
+
return ret;
|
|
221
|
+
}, arguments); },
|
|
222
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
223
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
224
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
225
|
+
return ret;
|
|
226
|
+
},
|
|
227
|
+
__wbindgen_init_externref_table: function() {
|
|
228
|
+
const table = wasm.__wbindgen_externrefs;
|
|
229
|
+
const offset = table.grow(4);
|
|
230
|
+
table.set(0, undefined);
|
|
231
|
+
table.set(offset + 0, undefined);
|
|
232
|
+
table.set(offset + 1, null);
|
|
233
|
+
table.set(offset + 2, true);
|
|
234
|
+
table.set(offset + 3, false);
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
return {
|
|
238
|
+
__proto__: null,
|
|
239
|
+
"./ts_pack_wasm_bg.js": import0,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const WasmTreeFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
244
|
+
? { register: () => {}, unregister: () => {} }
|
|
245
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmtree_free(ptr >>> 0, 1));
|
|
246
|
+
|
|
247
|
+
function addToExternrefTable0(obj) {
|
|
248
|
+
const idx = wasm.__externref_table_alloc();
|
|
249
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
250
|
+
return idx;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function _assertClass(instance, klass) {
|
|
254
|
+
if (!(instance instanceof klass)) {
|
|
255
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function debugString(val) {
|
|
260
|
+
// primitive types
|
|
261
|
+
const type = typeof val;
|
|
262
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
263
|
+
return `${val}`;
|
|
264
|
+
}
|
|
265
|
+
if (type == 'string') {
|
|
266
|
+
return `"${val}"`;
|
|
267
|
+
}
|
|
268
|
+
if (type == 'symbol') {
|
|
269
|
+
const description = val.description;
|
|
270
|
+
if (description == null) {
|
|
271
|
+
return 'Symbol';
|
|
272
|
+
} else {
|
|
273
|
+
return `Symbol(${description})`;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (type == 'function') {
|
|
277
|
+
const name = val.name;
|
|
278
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
279
|
+
return `Function(${name})`;
|
|
280
|
+
} else {
|
|
281
|
+
return 'Function';
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
// objects
|
|
285
|
+
if (Array.isArray(val)) {
|
|
286
|
+
const length = val.length;
|
|
287
|
+
let debug = '[';
|
|
288
|
+
if (length > 0) {
|
|
289
|
+
debug += debugString(val[0]);
|
|
290
|
+
}
|
|
291
|
+
for(let i = 1; i < length; i++) {
|
|
292
|
+
debug += ', ' + debugString(val[i]);
|
|
293
|
+
}
|
|
294
|
+
debug += ']';
|
|
295
|
+
return debug;
|
|
296
|
+
}
|
|
297
|
+
// Test for built-in
|
|
298
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
299
|
+
let className;
|
|
300
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
301
|
+
className = builtInMatches[1];
|
|
302
|
+
} else {
|
|
303
|
+
// Failed to match the standard '[object ClassName]'
|
|
304
|
+
return toString.call(val);
|
|
305
|
+
}
|
|
306
|
+
if (className == 'Object') {
|
|
307
|
+
// we're a user defined class or Object
|
|
308
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
309
|
+
// easier than looping through ownProperties of `val`.
|
|
310
|
+
try {
|
|
311
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
312
|
+
} catch (_) {
|
|
313
|
+
return 'Object';
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// errors
|
|
317
|
+
if (val instanceof Error) {
|
|
318
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
319
|
+
}
|
|
320
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
321
|
+
return className;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
325
|
+
ptr = ptr >>> 0;
|
|
326
|
+
const mem = getDataViewMemory0();
|
|
327
|
+
const result = [];
|
|
328
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
329
|
+
result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
|
|
330
|
+
}
|
|
331
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
let cachedDataViewMemory0 = null;
|
|
336
|
+
function getDataViewMemory0() {
|
|
337
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
338
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
339
|
+
}
|
|
340
|
+
return cachedDataViewMemory0;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function getStringFromWasm0(ptr, len) {
|
|
344
|
+
ptr = ptr >>> 0;
|
|
345
|
+
return decodeText(ptr, len);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
let cachedUint8ArrayMemory0 = null;
|
|
349
|
+
function getUint8ArrayMemory0() {
|
|
350
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
351
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
352
|
+
}
|
|
353
|
+
return cachedUint8ArrayMemory0;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function handleError(f, args) {
|
|
357
|
+
try {
|
|
358
|
+
return f.apply(this, args);
|
|
359
|
+
} catch (e) {
|
|
360
|
+
const idx = addToExternrefTable0(e);
|
|
361
|
+
wasm.__wbindgen_exn_store(idx);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function isLikeNone(x) {
|
|
366
|
+
return x === undefined || x === null;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
370
|
+
if (realloc === undefined) {
|
|
371
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
372
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
373
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
374
|
+
WASM_VECTOR_LEN = buf.length;
|
|
375
|
+
return ptr;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
let len = arg.length;
|
|
379
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
380
|
+
|
|
381
|
+
const mem = getUint8ArrayMemory0();
|
|
382
|
+
|
|
383
|
+
let offset = 0;
|
|
384
|
+
|
|
385
|
+
for (; offset < len; offset++) {
|
|
386
|
+
const code = arg.charCodeAt(offset);
|
|
387
|
+
if (code > 0x7F) break;
|
|
388
|
+
mem[ptr + offset] = code;
|
|
389
|
+
}
|
|
390
|
+
if (offset !== len) {
|
|
391
|
+
if (offset !== 0) {
|
|
392
|
+
arg = arg.slice(offset);
|
|
393
|
+
}
|
|
394
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
395
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
396
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
397
|
+
|
|
398
|
+
offset += ret.written;
|
|
399
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
WASM_VECTOR_LEN = offset;
|
|
403
|
+
return ptr;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function takeFromExternrefTable0(idx) {
|
|
407
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
408
|
+
wasm.__externref_table_dealloc(idx);
|
|
409
|
+
return value;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
413
|
+
cachedTextDecoder.decode();
|
|
414
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
415
|
+
let numBytesDecoded = 0;
|
|
416
|
+
function decodeText(ptr, len) {
|
|
417
|
+
numBytesDecoded += len;
|
|
418
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
419
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
420
|
+
cachedTextDecoder.decode();
|
|
421
|
+
numBytesDecoded = len;
|
|
422
|
+
}
|
|
423
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const cachedTextEncoder = new TextEncoder();
|
|
427
|
+
|
|
428
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
429
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
430
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
431
|
+
view.set(buf);
|
|
432
|
+
return {
|
|
433
|
+
read: arg.length,
|
|
434
|
+
written: buf.length
|
|
435
|
+
};
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
let WASM_VECTOR_LEN = 0;
|
|
440
|
+
|
|
441
|
+
let wasmModule, wasm;
|
|
442
|
+
function __wbg_finalize_init(instance, module) {
|
|
443
|
+
wasm = instance.exports;
|
|
444
|
+
wasmModule = module;
|
|
445
|
+
cachedDataViewMemory0 = null;
|
|
446
|
+
cachedUint8ArrayMemory0 = null;
|
|
447
|
+
wasm.__wbindgen_start();
|
|
448
|
+
return wasm;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
async function __wbg_load(module, imports) {
|
|
452
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
453
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
454
|
+
try {
|
|
455
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
456
|
+
} catch (e) {
|
|
457
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
458
|
+
|
|
459
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
460
|
+
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);
|
|
461
|
+
|
|
462
|
+
} else { throw e; }
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const bytes = await module.arrayBuffer();
|
|
467
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
468
|
+
} else {
|
|
469
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
470
|
+
|
|
471
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
472
|
+
return { instance, module };
|
|
473
|
+
} else {
|
|
474
|
+
return instance;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function expectedResponseType(type) {
|
|
479
|
+
switch (type) {
|
|
480
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
481
|
+
}
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function initSync(module) {
|
|
487
|
+
if (wasm !== undefined) return wasm;
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
if (module !== undefined) {
|
|
491
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
492
|
+
({module} = module)
|
|
493
|
+
} else {
|
|
494
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const imports = __wbg_get_imports();
|
|
499
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
500
|
+
module = new WebAssembly.Module(module);
|
|
501
|
+
}
|
|
502
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
503
|
+
return __wbg_finalize_init(instance, module);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
async function __wbg_init(module_or_path) {
|
|
507
|
+
if (wasm !== undefined) return wasm;
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
if (module_or_path !== undefined) {
|
|
511
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
512
|
+
({module_or_path} = module_or_path)
|
|
513
|
+
} else {
|
|
514
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (module_or_path === undefined) {
|
|
519
|
+
module_or_path = new URL('ts_pack_wasm_bg.wasm', import.meta.url);
|
|
520
|
+
}
|
|
521
|
+
const imports = __wbg_get_imports();
|
|
522
|
+
|
|
523
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
524
|
+
module_or_path = fetch(module_or_path);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
528
|
+
|
|
529
|
+
return __wbg_finalize_init(instance, module);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|