@mirascript/wasm 0.1.62-alpha.7 → 0.1.62-alpha.9
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/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/loader/node.d.ts +3 -0
- package/dist/loader/node.d.ts.map +1 -0
- package/dist/loader/node.js +14 -0
- package/dist/loader/node.js.map +1 -0
- package/dist/loader/web.d.ts +3 -0
- package/dist/loader/web.d.ts.map +1 -0
- package/dist/loader/web.js +78 -0
- package/dist/loader/web.js.map +1 -0
- package/lib/wasm.d.ts +141 -0
- package/lib/wasm.js +646 -0
- package/lib/wasm_bg.wasm +0 -0
- package/lib/wasm_bg.wasm.d.ts +42 -0
- package/package.json +2 -2
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Config, ScriptInput } from '@mirascript/constants';
|
|
2
|
+
import * as wasm from '../lib/wasm.js';
|
|
3
|
+
export { wasm };
|
|
4
|
+
/** 初始化模块 */
|
|
5
|
+
export declare function init(): Promise<void>;
|
|
6
|
+
/** 创建可重用的配置 */
|
|
7
|
+
export declare function createConfig(config?: Config | wasm.Config): wasm.Config;
|
|
8
|
+
/** 编译结果 */
|
|
9
|
+
export interface CompileResult {
|
|
10
|
+
/** 编译诊断 */
|
|
11
|
+
readonly diagnostics: Uint32Array;
|
|
12
|
+
/** 编译生成的字节码 */
|
|
13
|
+
readonly chunk?: Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
/** 编译 MiraScript 代码 */
|
|
16
|
+
export declare function compileSync(script: ScriptInput, config: Config | wasm.Config): CompileResult;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAyC,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACxG,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAGvC,OAAO,EAAE,IAAI,EAAE,CAAC;AAEhB,YAAY;AACZ,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAG1C;AAED,eAAe;AACf,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAmBvE;AAED,WAAW;AACX,MAAM,WAAW,aAAa;IAC1B,WAAW;IACX,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,eAAe;IACf,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;CAC/B;AAuBD,uBAAuB;AACvB,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,aAAa,CAI5F"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as wasm from '../lib/wasm.js';
|
|
2
|
+
import { loadModule } from '#loader';
|
|
3
|
+
export { wasm };
|
|
4
|
+
/** 初始化模块 */
|
|
5
|
+
export async function init() {
|
|
6
|
+
const module = await loadModule();
|
|
7
|
+
await wasm.default({ module_or_path: module });
|
|
8
|
+
}
|
|
9
|
+
/** 创建可重用的配置 */
|
|
10
|
+
export function createConfig(config) {
|
|
11
|
+
if (!config)
|
|
12
|
+
return new wasm.Config();
|
|
13
|
+
if (config instanceof wasm.Config)
|
|
14
|
+
return config;
|
|
15
|
+
const cfg = new wasm.Config();
|
|
16
|
+
for (const key in config) {
|
|
17
|
+
if (key === 'free')
|
|
18
|
+
continue; // 忽略 free 方法
|
|
19
|
+
if (!Object.hasOwn(config, key))
|
|
20
|
+
continue;
|
|
21
|
+
let value = config[key];
|
|
22
|
+
if (key === 'input_mode') {
|
|
23
|
+
value = wasm.InputMode[value];
|
|
24
|
+
}
|
|
25
|
+
if (key === 'diagnostic_position_encoding') {
|
|
26
|
+
value = wasm.DiagnosticPositionEncoding[value];
|
|
27
|
+
}
|
|
28
|
+
if (value === undefined)
|
|
29
|
+
continue;
|
|
30
|
+
if (!(key in cfg))
|
|
31
|
+
continue;
|
|
32
|
+
cfg[key] = value;
|
|
33
|
+
}
|
|
34
|
+
return cfg;
|
|
35
|
+
}
|
|
36
|
+
/** 编译 */
|
|
37
|
+
function compileImpl(compiler, script, config) {
|
|
38
|
+
const cfg = createConfig(config);
|
|
39
|
+
const result = compiler(script, cfg);
|
|
40
|
+
try {
|
|
41
|
+
const diagnostics = result.diagnostics();
|
|
42
|
+
const chunk = result.chunk();
|
|
43
|
+
return { diagnostics, chunk };
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
result.free();
|
|
47
|
+
// 只在 cfg 是新创建的情况下释放
|
|
48
|
+
if (cfg !== config) {
|
|
49
|
+
cfg.free();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** 编译 MiraScript 代码 */
|
|
54
|
+
export function compileSync(script, config) {
|
|
55
|
+
return typeof script == 'string'
|
|
56
|
+
? compileImpl(wasm.compile, script, config)
|
|
57
|
+
: compileImpl(wasm.compile_buffer, script, config);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAAE,IAAI,EAAE,CAAC;AAEhB,YAAY;AACZ,MAAM,CAAC,KAAK,UAAU,IAAI;IACtB,MAAM,MAAM,GAAG,MAAM,UAAU,EAAE,CAAC;IAClC,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC;A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AAE,CAAC;QAC7B,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;IAClC,CAAC;YAAS,CAAC;QACP,MAAM,CAAC,IAAI,EAAE,CAAC;QACd,oBAAoB;QACpB,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;YACjB,GAAG,CAAC,IAAI,EAAE,CAAC;QACf,CAAC;IACL,CAAC;AACL,CAAC;AAED,uBAAuB;AACvB,MAAM,UAAU,WAAW,CAAC,MAAmB,EAAE,MAA4B;IACzE,OAAO,OAAO,MAAM,IAAI,QAAQ;QAC5B,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC;QAC3C,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/loader/node.ts"],"names":[],"mappings":"AAMA,iBAAiB;AACjB,wBAAsB,UAAU,IAAI,OAAO,CAAC,YAAY,GAAG,QAAQ,CAAC,CAOnE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { loadModule as loadWeb } from './web.js';
|
|
5
|
+
/** 加载 wasm 模块 */
|
|
6
|
+
export async function loadModule() {
|
|
7
|
+
const url = new URL('../../lib/wasm_bg.wasm', import.meta.url);
|
|
8
|
+
if (url.protocol !== 'file:') {
|
|
9
|
+
return await loadWeb();
|
|
10
|
+
}
|
|
11
|
+
const file = fileURLToPath(url);
|
|
12
|
+
return await fs.readFile(file);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/loader/node.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAE9B,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,MAAM,UAAU,CAAC;AAEjD,iBAAiB;AACjB,MAAM,CAAC,KAAK,UAAU,UAAU;IAC5B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,wBAAwB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/D,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAC3B,OAAO,MAAM,OAAO,EAAE,CAAC;IAC3B,CAAC;IACD,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAChC,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/loader/web.ts"],"names":[],"mappings":"AAmEA,iBAAiB;AACjB,wBAAsB,UAAU,IAAI,OAAO,CAAC,YAAY,GAAG,QAAQ,CAAC,CAYnE"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** 从 import.meta.url 推断 URL */
|
|
2
|
+
async function loadUrl() {
|
|
3
|
+
return await body(fetch(new URL('../../lib/wasm_bg.wasm', import.meta.url)));
|
|
4
|
+
}
|
|
5
|
+
/** 由 esm 加载模块 */
|
|
6
|
+
async function loadEsm() {
|
|
7
|
+
// use ?url to force vite to load as bytes
|
|
8
|
+
// https://github.com/vitejs/vite/issues/12366
|
|
9
|
+
const m = await import('../../lib/wasm_bg.wasm?url', { with: { type: 'bytes' } });
|
|
10
|
+
return await mod(m);
|
|
11
|
+
}
|
|
12
|
+
/** 由 esm.sh 加载模块 */
|
|
13
|
+
async function loadEsmSh() {
|
|
14
|
+
const url = new URL(import.meta.url);
|
|
15
|
+
const { pathname, protocol } = url;
|
|
16
|
+
if (!pathname.includes('/@mirascript/wasm') || !(protocol === 'https:' || protocol === 'http:')) {
|
|
17
|
+
throw new Error('Not loaded from esm.sh');
|
|
18
|
+
}
|
|
19
|
+
const segments = pathname.split('/');
|
|
20
|
+
let newUrl = url.origin;
|
|
21
|
+
for (let i = 0; i < segments.length; i++) {
|
|
22
|
+
const segment = segments[i];
|
|
23
|
+
newUrl += segment + '/';
|
|
24
|
+
if (i >= 1 && segments[i - 1] === '@mirascript' && (segment === 'wasm' || segment?.startsWith('wasm@'))) {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
newUrl += 'lib/wasm_bg.wasm';
|
|
29
|
+
return await body(fetch(newUrl));
|
|
30
|
+
}
|
|
31
|
+
/** 加载模块 */
|
|
32
|
+
async function mod(m) {
|
|
33
|
+
if (m && typeof m == 'object' && 'default' in m) {
|
|
34
|
+
return mod(m.default);
|
|
35
|
+
}
|
|
36
|
+
if (m instanceof URL ||
|
|
37
|
+
(typeof m == 'string' &&
|
|
38
|
+
(m.startsWith('data:') || m.startsWith('http:') || m.startsWith('https:') || m.startsWith('//')))) {
|
|
39
|
+
return await body(fetch(m));
|
|
40
|
+
}
|
|
41
|
+
if (m instanceof Response) {
|
|
42
|
+
return await body(m);
|
|
43
|
+
}
|
|
44
|
+
if (ArrayBuffer.isView(m) || m instanceof ArrayBuffer) {
|
|
45
|
+
return m;
|
|
46
|
+
}
|
|
47
|
+
if (m instanceof WebAssembly.Module) {
|
|
48
|
+
return m;
|
|
49
|
+
}
|
|
50
|
+
throw new Error('Failed to load wasm module');
|
|
51
|
+
}
|
|
52
|
+
/** 获取模块的响应体 */
|
|
53
|
+
async function body(response) {
|
|
54
|
+
const resp = await response;
|
|
55
|
+
if (resp.ok) {
|
|
56
|
+
return resp;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw new Error(`Failed to fetch wasm module: ${resp.status} ${resp.statusText}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** 加载 wasm 模块 */
|
|
63
|
+
export async function loadModule() {
|
|
64
|
+
const candidates = [loadEsmSh, loadEsm, loadUrl];
|
|
65
|
+
for (const candidate of candidates) {
|
|
66
|
+
try {
|
|
67
|
+
const mod = await candidate();
|
|
68
|
+
if (mod == null)
|
|
69
|
+
continue;
|
|
70
|
+
return mod;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// ignore
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
throw new Error('Failed to load wasm module');
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/loader/web.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,KAAK,UAAU,OAAO;IAClB,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,wBAAwB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACjF,CAAC;AAED,iBAAiB;AACjB,KAAK,UAAU,OAAO;IAClB,0CAA0C;IAC1C,8CAA8C;IAC9C,MAAM,CAAC,GAAY,MAAM,MAAM,CAAC,4BAA4B,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;IAC3F,OAAO,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,oBAAoB;AACpB,KAAK,UAAU,SAAS;IACpB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC;IACnC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,OAAO,CAA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|
|
3
|
+
|
|
4
|
+
export class CompileResult {
|
|
5
|
+
private constructor();
|
|
6
|
+
free(): void;
|
|
7
|
+
[Symbol.dispose](): void;
|
|
8
|
+
chunk(): Uint8Array | undefined;
|
|
9
|
+
diagnostics(): Uint32Array;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class Config {
|
|
13
|
+
free(): void;
|
|
14
|
+
[Symbol.dispose](): void;
|
|
15
|
+
constructor();
|
|
16
|
+
diagnostic_error: boolean;
|
|
17
|
+
diagnostic_hint: boolean;
|
|
18
|
+
diagnostic_info: boolean;
|
|
19
|
+
diagnostic_position_encoding: DiagnosticPositionEncoding;
|
|
20
|
+
diagnostic_reference: boolean;
|
|
21
|
+
diagnostic_sourcemap: boolean;
|
|
22
|
+
diagnostic_tag: boolean;
|
|
23
|
+
diagnostic_warning: boolean;
|
|
24
|
+
input_mode: InputMode;
|
|
25
|
+
trivia: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Encoding for counting positions in diagnostics.
|
|
30
|
+
*/
|
|
31
|
+
export enum DiagnosticPositionEncoding {
|
|
32
|
+
/**
|
|
33
|
+
* Use the default encoding (UTF-8) and
|
|
34
|
+
* 0-based indexing from the start of the file.
|
|
35
|
+
* Do not convert positions to line-column format.
|
|
36
|
+
*/
|
|
37
|
+
None = 0,
|
|
38
|
+
/**
|
|
39
|
+
* Convert positions to 1-based UTF-8 line-column format.
|
|
40
|
+
*/
|
|
41
|
+
Utf8 = 1,
|
|
42
|
+
/**
|
|
43
|
+
* Convert positions to 1-based UTF-16 line-column format.
|
|
44
|
+
*/
|
|
45
|
+
Utf16 = 2,
|
|
46
|
+
/**
|
|
47
|
+
* Convert positions to 1-based UTF-32 line-column format.
|
|
48
|
+
*/
|
|
49
|
+
Utf32 = 3,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Mode for reading input.
|
|
54
|
+
*/
|
|
55
|
+
export enum InputMode {
|
|
56
|
+
Script = 0,
|
|
57
|
+
Template = 1,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class MonacoCompiler {
|
|
61
|
+
free(): void;
|
|
62
|
+
[Symbol.dispose](): void;
|
|
63
|
+
diagnostics(): Uint32Array;
|
|
64
|
+
emit(): Uint8Array | undefined;
|
|
65
|
+
format(): string | undefined;
|
|
66
|
+
constructor(input: string, config: Config);
|
|
67
|
+
parse(): boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function compile(script: string, config: Config): CompileResult;
|
|
71
|
+
|
|
72
|
+
export function compile_buffer(script: Uint8Array, config: Config): CompileResult;
|
|
73
|
+
|
|
74
|
+
export function main(): void;
|
|
75
|
+
|
|
76
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
77
|
+
|
|
78
|
+
export interface InitOutput {
|
|
79
|
+
readonly memory: WebAssembly.Memory;
|
|
80
|
+
readonly __wbg_compileresult_free: (a: number, b: number) => void;
|
|
81
|
+
readonly __wbg_monacocompiler_free: (a: number, b: number) => void;
|
|
82
|
+
readonly compile: (a: number, b: number, c: number) => number;
|
|
83
|
+
readonly compileresult_chunk: (a: number, b: number) => void;
|
|
84
|
+
readonly compileresult_diagnostics: (a: number, b: number) => void;
|
|
85
|
+
readonly main: () => void;
|
|
86
|
+
readonly monacocompiler_diagnostics: (a: number, b: number) => void;
|
|
87
|
+
readonly monacocompiler_emit: (a: number, b: number) => void;
|
|
88
|
+
readonly monacocompiler_format: (a: number, b: number) => void;
|
|
89
|
+
readonly monacocompiler_new: (a: number, b: number, c: number) => number;
|
|
90
|
+
readonly monacocompiler_parse: (a: number) => number;
|
|
91
|
+
readonly compile_buffer: (a: number, b: number, c: number) => number;
|
|
92
|
+
readonly __wbg_config_free: (a: number, b: number) => void;
|
|
93
|
+
readonly __wbg_get_config_diagnostic_error: (a: number) => number;
|
|
94
|
+
readonly __wbg_get_config_diagnostic_hint: (a: number) => number;
|
|
95
|
+
readonly __wbg_get_config_diagnostic_info: (a: number) => number;
|
|
96
|
+
readonly __wbg_get_config_diagnostic_position_encoding: (a: number) => number;
|
|
97
|
+
readonly __wbg_get_config_diagnostic_reference: (a: number) => number;
|
|
98
|
+
readonly __wbg_get_config_diagnostic_sourcemap: (a: number) => number;
|
|
99
|
+
readonly __wbg_get_config_diagnostic_tag: (a: number) => number;
|
|
100
|
+
readonly __wbg_get_config_diagnostic_warning: (a: number) => number;
|
|
101
|
+
readonly __wbg_get_config_input_mode: (a: number) => number;
|
|
102
|
+
readonly __wbg_get_config_trivia: (a: number) => number;
|
|
103
|
+
readonly __wbg_set_config_diagnostic_error: (a: number, b: number) => void;
|
|
104
|
+
readonly __wbg_set_config_diagnostic_hint: (a: number, b: number) => void;
|
|
105
|
+
readonly __wbg_set_config_diagnostic_info: (a: number, b: number) => void;
|
|
106
|
+
readonly __wbg_set_config_diagnostic_position_encoding: (a: number, b: number) => void;
|
|
107
|
+
readonly __wbg_set_config_diagnostic_reference: (a: number, b: number) => void;
|
|
108
|
+
readonly __wbg_set_config_diagnostic_sourcemap: (a: number, b: number) => void;
|
|
109
|
+
readonly __wbg_set_config_diagnostic_tag: (a: number, b: number) => void;
|
|
110
|
+
readonly __wbg_set_config_diagnostic_warning: (a: number, b: number) => void;
|
|
111
|
+
readonly __wbg_set_config_input_mode: (a: number, b: number) => void;
|
|
112
|
+
readonly __wbg_set_config_trivia: (a: number, b: number) => void;
|
|
113
|
+
readonly config_new: () => number;
|
|
114
|
+
readonly __wbindgen_export: (a: number, b: number, c: number) => void;
|
|
115
|
+
readonly __wbindgen_export2: (a: number, b: number) => number;
|
|
116
|
+
readonly __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
|
|
117
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
118
|
+
readonly __wbindgen_start: () => void;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
125
|
+
* a precompiled `WebAssembly.Module`.
|
|
126
|
+
*
|
|
127
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
128
|
+
*
|
|
129
|
+
* @returns {InitOutput}
|
|
130
|
+
*/
|
|
131
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
135
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
136
|
+
*
|
|
137
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
138
|
+
*
|
|
139
|
+
* @returns {Promise<InitOutput>}
|
|
140
|
+
*/
|
|
141
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/lib/wasm.js
ADDED
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
/* @ts-self-types="./wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
export class CompileResult {
|
|
4
|
+
static __wrap(ptr) {
|
|
5
|
+
ptr = ptr >>> 0;
|
|
6
|
+
const obj = Object.create(CompileResult.prototype);
|
|
7
|
+
obj.__wbg_ptr = ptr;
|
|
8
|
+
CompileResultFinalization.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
|
+
CompileResultFinalization.unregister(this);
|
|
15
|
+
return ptr;
|
|
16
|
+
}
|
|
17
|
+
free() {
|
|
18
|
+
const ptr = this.__destroy_into_raw();
|
|
19
|
+
wasm.__wbg_compileresult_free(ptr, 0);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @returns {Uint8Array | undefined}
|
|
23
|
+
*/
|
|
24
|
+
chunk() {
|
|
25
|
+
try {
|
|
26
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
27
|
+
wasm.compileresult_chunk(retptr, this.__wbg_ptr);
|
|
28
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
29
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
30
|
+
let v1;
|
|
31
|
+
if (r0 !== 0) {
|
|
32
|
+
v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
33
|
+
wasm.__wbindgen_export(r0, r1 * 1, 1);
|
|
34
|
+
}
|
|
35
|
+
return v1;
|
|
36
|
+
} finally {
|
|
37
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @returns {Uint32Array}
|
|
42
|
+
*/
|
|
43
|
+
diagnostics() {
|
|
44
|
+
try {
|
|
45
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
46
|
+
wasm.compileresult_diagnostics(retptr, this.__wbg_ptr);
|
|
47
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
48
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
49
|
+
var v1 = getArrayU32FromWasm0(r0, r1).slice();
|
|
50
|
+
wasm.__wbindgen_export(r0, r1 * 4, 4);
|
|
51
|
+
return v1;
|
|
52
|
+
} finally {
|
|
53
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (Symbol.dispose) CompileResult.prototype[Symbol.dispose] = CompileResult.prototype.free;
|
|
58
|
+
|
|
59
|
+
export class Config {
|
|
60
|
+
__destroy_into_raw() {
|
|
61
|
+
const ptr = this.__wbg_ptr;
|
|
62
|
+
this.__wbg_ptr = 0;
|
|
63
|
+
ConfigFinalization.unregister(this);
|
|
64
|
+
return ptr;
|
|
65
|
+
}
|
|
66
|
+
free() {
|
|
67
|
+
const ptr = this.__destroy_into_raw();
|
|
68
|
+
wasm.__wbg_config_free(ptr, 0);
|
|
69
|
+
}
|
|
70
|
+
constructor() {
|
|
71
|
+
const ret = wasm.config_new();
|
|
72
|
+
this.__wbg_ptr = ret >>> 0;
|
|
73
|
+
ConfigFinalization.register(this, this.__wbg_ptr, this);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @returns {boolean}
|
|
78
|
+
*/
|
|
79
|
+
get diagnostic_error() {
|
|
80
|
+
const ret = wasm.__wbg_get_config_diagnostic_error(this.__wbg_ptr);
|
|
81
|
+
return ret !== 0;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* @returns {boolean}
|
|
85
|
+
*/
|
|
86
|
+
get diagnostic_hint() {
|
|
87
|
+
const ret = wasm.__wbg_get_config_diagnostic_hint(this.__wbg_ptr);
|
|
88
|
+
return ret !== 0;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @returns {boolean}
|
|
92
|
+
*/
|
|
93
|
+
get diagnostic_info() {
|
|
94
|
+
const ret = wasm.__wbg_get_config_diagnostic_info(this.__wbg_ptr);
|
|
95
|
+
return ret !== 0;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @returns {DiagnosticPositionEncoding}
|
|
99
|
+
*/
|
|
100
|
+
get diagnostic_position_encoding() {
|
|
101
|
+
const ret = wasm.__wbg_get_config_diagnostic_position_encoding(this.__wbg_ptr);
|
|
102
|
+
return ret;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* @returns {boolean}
|
|
106
|
+
*/
|
|
107
|
+
get diagnostic_reference() {
|
|
108
|
+
const ret = wasm.__wbg_get_config_diagnostic_reference(this.__wbg_ptr);
|
|
109
|
+
return ret !== 0;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @returns {boolean}
|
|
113
|
+
*/
|
|
114
|
+
get diagnostic_sourcemap() {
|
|
115
|
+
const ret = wasm.__wbg_get_config_diagnostic_sourcemap(this.__wbg_ptr);
|
|
116
|
+
return ret !== 0;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @returns {boolean}
|
|
120
|
+
*/
|
|
121
|
+
get diagnostic_tag() {
|
|
122
|
+
const ret = wasm.__wbg_get_config_diagnostic_tag(this.__wbg_ptr);
|
|
123
|
+
return ret !== 0;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* @returns {boolean}
|
|
127
|
+
*/
|
|
128
|
+
get diagnostic_warning() {
|
|
129
|
+
const ret = wasm.__wbg_get_config_diagnostic_warning(this.__wbg_ptr);
|
|
130
|
+
return ret !== 0;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* @returns {InputMode}
|
|
134
|
+
*/
|
|
135
|
+
get input_mode() {
|
|
136
|
+
const ret = wasm.__wbg_get_config_input_mode(this.__wbg_ptr);
|
|
137
|
+
return ret;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @returns {boolean}
|
|
141
|
+
*/
|
|
142
|
+
get trivia() {
|
|
143
|
+
const ret = wasm.__wbg_get_config_trivia(this.__wbg_ptr);
|
|
144
|
+
return ret !== 0;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @param {boolean} arg0
|
|
148
|
+
*/
|
|
149
|
+
set diagnostic_error(arg0) {
|
|
150
|
+
wasm.__wbg_set_config_diagnostic_error(this.__wbg_ptr, arg0);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @param {boolean} arg0
|
|
154
|
+
*/
|
|
155
|
+
set diagnostic_hint(arg0) {
|
|
156
|
+
wasm.__wbg_set_config_diagnostic_hint(this.__wbg_ptr, arg0);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* @param {boolean} arg0
|
|
160
|
+
*/
|
|
161
|
+
set diagnostic_info(arg0) {
|
|
162
|
+
wasm.__wbg_set_config_diagnostic_info(this.__wbg_ptr, arg0);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @param {DiagnosticPositionEncoding} arg0
|
|
166
|
+
*/
|
|
167
|
+
set diagnostic_position_encoding(arg0) {
|
|
168
|
+
wasm.__wbg_set_config_diagnostic_position_encoding(this.__wbg_ptr, arg0);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* @param {boolean} arg0
|
|
172
|
+
*/
|
|
173
|
+
set diagnostic_reference(arg0) {
|
|
174
|
+
wasm.__wbg_set_config_diagnostic_reference(this.__wbg_ptr, arg0);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* @param {boolean} arg0
|
|
178
|
+
*/
|
|
179
|
+
set diagnostic_sourcemap(arg0) {
|
|
180
|
+
wasm.__wbg_set_config_diagnostic_sourcemap(this.__wbg_ptr, arg0);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* @param {boolean} arg0
|
|
184
|
+
*/
|
|
185
|
+
set diagnostic_tag(arg0) {
|
|
186
|
+
wasm.__wbg_set_config_diagnostic_tag(this.__wbg_ptr, arg0);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* @param {boolean} arg0
|
|
190
|
+
*/
|
|
191
|
+
set diagnostic_warning(arg0) {
|
|
192
|
+
wasm.__wbg_set_config_diagnostic_warning(this.__wbg_ptr, arg0);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* @param {InputMode} arg0
|
|
196
|
+
*/
|
|
197
|
+
set input_mode(arg0) {
|
|
198
|
+
wasm.__wbg_set_config_input_mode(this.__wbg_ptr, arg0);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* @param {boolean} arg0
|
|
202
|
+
*/
|
|
203
|
+
set trivia(arg0) {
|
|
204
|
+
wasm.__wbg_set_config_trivia(this.__wbg_ptr, arg0);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (Symbol.dispose) Config.prototype[Symbol.dispose] = Config.prototype.free;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Encoding for counting positions in diagnostics.
|
|
211
|
+
* @enum {0 | 1 | 2 | 3}
|
|
212
|
+
*/
|
|
213
|
+
export const DiagnosticPositionEncoding = Object.freeze({
|
|
214
|
+
/**
|
|
215
|
+
* Use the default encoding (UTF-8) and
|
|
216
|
+
* 0-based indexing from the start of the file.
|
|
217
|
+
* Do not convert positions to line-column format.
|
|
218
|
+
*/
|
|
219
|
+
None: 0, "0": "None",
|
|
220
|
+
/**
|
|
221
|
+
* Convert positions to 1-based UTF-8 line-column format.
|
|
222
|
+
*/
|
|
223
|
+
Utf8: 1, "1": "Utf8",
|
|
224
|
+
/**
|
|
225
|
+
* Convert positions to 1-based UTF-16 line-column format.
|
|
226
|
+
*/
|
|
227
|
+
Utf16: 2, "2": "Utf16",
|
|
228
|
+
/**
|
|
229
|
+
* Convert positions to 1-based UTF-32 line-column format.
|
|
230
|
+
*/
|
|
231
|
+
Utf32: 3, "3": "Utf32",
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Mode for reading input.
|
|
236
|
+
* @enum {0 | 1}
|
|
237
|
+
*/
|
|
238
|
+
export const InputMode = Object.freeze({
|
|
239
|
+
Script: 0, "0": "Script",
|
|
240
|
+
Template: 1, "1": "Template",
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
export class MonacoCompiler {
|
|
244
|
+
__destroy_into_raw() {
|
|
245
|
+
const ptr = this.__wbg_ptr;
|
|
246
|
+
this.__wbg_ptr = 0;
|
|
247
|
+
MonacoCompilerFinalization.unregister(this);
|
|
248
|
+
return ptr;
|
|
249
|
+
}
|
|
250
|
+
free() {
|
|
251
|
+
const ptr = this.__destroy_into_raw();
|
|
252
|
+
wasm.__wbg_monacocompiler_free(ptr, 0);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* @returns {Uint32Array}
|
|
256
|
+
*/
|
|
257
|
+
diagnostics() {
|
|
258
|
+
try {
|
|
259
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
260
|
+
wasm.monacocompiler_diagnostics(retptr, this.__wbg_ptr);
|
|
261
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
262
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
263
|
+
var v1 = getArrayU32FromWasm0(r0, r1).slice();
|
|
264
|
+
wasm.__wbindgen_export(r0, r1 * 4, 4);
|
|
265
|
+
return v1;
|
|
266
|
+
} finally {
|
|
267
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* @returns {Uint8Array | undefined}
|
|
272
|
+
*/
|
|
273
|
+
emit() {
|
|
274
|
+
try {
|
|
275
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
276
|
+
wasm.monacocompiler_emit(retptr, this.__wbg_ptr);
|
|
277
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
278
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
279
|
+
let v1;
|
|
280
|
+
if (r0 !== 0) {
|
|
281
|
+
v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
282
|
+
wasm.__wbindgen_export(r0, r1 * 1, 1);
|
|
283
|
+
}
|
|
284
|
+
return v1;
|
|
285
|
+
} finally {
|
|
286
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* @returns {string | undefined}
|
|
291
|
+
*/
|
|
292
|
+
format() {
|
|
293
|
+
try {
|
|
294
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
295
|
+
wasm.monacocompiler_format(retptr, this.__wbg_ptr);
|
|
296
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
297
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
298
|
+
let v1;
|
|
299
|
+
if (r0 !== 0) {
|
|
300
|
+
v1 = getStringFromWasm0(r0, r1).slice();
|
|
301
|
+
wasm.__wbindgen_export(r0, r1 * 1, 1);
|
|
302
|
+
}
|
|
303
|
+
return v1;
|
|
304
|
+
} finally {
|
|
305
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* @param {string} input
|
|
310
|
+
* @param {Config} config
|
|
311
|
+
*/
|
|
312
|
+
constructor(input, config) {
|
|
313
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
314
|
+
const len0 = WASM_VECTOR_LEN;
|
|
315
|
+
_assertClass(config, Config);
|
|
316
|
+
const ret = wasm.monacocompiler_new(ptr0, len0, config.__wbg_ptr);
|
|
317
|
+
this.__wbg_ptr = ret >>> 0;
|
|
318
|
+
MonacoCompilerFinalization.register(this, this.__wbg_ptr, this);
|
|
319
|
+
return this;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* @returns {boolean}
|
|
323
|
+
*/
|
|
324
|
+
parse() {
|
|
325
|
+
const ret = wasm.monacocompiler_parse(this.__wbg_ptr);
|
|
326
|
+
return ret !== 0;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (Symbol.dispose) MonacoCompiler.prototype[Symbol.dispose] = MonacoCompiler.prototype.free;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* @param {string} script
|
|
333
|
+
* @param {Config} config
|
|
334
|
+
* @returns {CompileResult}
|
|
335
|
+
*/
|
|
336
|
+
export function compile(script, config) {
|
|
337
|
+
const ptr0 = passStringToWasm0(script, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
338
|
+
const len0 = WASM_VECTOR_LEN;
|
|
339
|
+
_assertClass(config, Config);
|
|
340
|
+
const ret = wasm.compile(ptr0, len0, config.__wbg_ptr);
|
|
341
|
+
return CompileResult.__wrap(ret);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* @param {Uint8Array} script
|
|
346
|
+
* @param {Config} config
|
|
347
|
+
* @returns {CompileResult}
|
|
348
|
+
*/
|
|
349
|
+
export function compile_buffer(script, config) {
|
|
350
|
+
const ptr0 = passArray8ToWasm0(script, wasm.__wbindgen_export2);
|
|
351
|
+
const len0 = WASM_VECTOR_LEN;
|
|
352
|
+
_assertClass(config, Config);
|
|
353
|
+
const ret = wasm.compile_buffer(ptr0, len0, config.__wbg_ptr);
|
|
354
|
+
return CompileResult.__wrap(ret);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export function main() {
|
|
358
|
+
wasm.main();
|
|
359
|
+
}
|
|
360
|
+
function __wbg_get_imports() {
|
|
361
|
+
const import0 = {
|
|
362
|
+
__proto__: null,
|
|
363
|
+
__wbg___wbindgen_throw_6b64449b9b9ed33c: function(arg0, arg1) {
|
|
364
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
365
|
+
},
|
|
366
|
+
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
|
367
|
+
let deferred0_0;
|
|
368
|
+
let deferred0_1;
|
|
369
|
+
try {
|
|
370
|
+
deferred0_0 = arg0;
|
|
371
|
+
deferred0_1 = arg1;
|
|
372
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
373
|
+
} finally {
|
|
374
|
+
wasm.__wbindgen_export(deferred0_0, deferred0_1, 1);
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
__wbg_new_227d7c05414eb861: function() {
|
|
378
|
+
const ret = new Error();
|
|
379
|
+
return addHeapObject(ret);
|
|
380
|
+
},
|
|
381
|
+
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
|
|
382
|
+
const ret = getObject(arg1).stack;
|
|
383
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
|
|
384
|
+
const len1 = WASM_VECTOR_LEN;
|
|
385
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
386
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
387
|
+
},
|
|
388
|
+
__wbindgen_object_drop_ref: function(arg0) {
|
|
389
|
+
takeObject(arg0);
|
|
390
|
+
},
|
|
391
|
+
};
|
|
392
|
+
return {
|
|
393
|
+
__proto__: null,
|
|
394
|
+
"./wasm_bg.js": import0,
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const CompileResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
399
|
+
? { register: () => {}, unregister: () => {} }
|
|
400
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_compileresult_free(ptr >>> 0, 1));
|
|
401
|
+
const ConfigFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
402
|
+
? { register: () => {}, unregister: () => {} }
|
|
403
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_config_free(ptr >>> 0, 1));
|
|
404
|
+
const MonacoCompilerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
405
|
+
? { register: () => {}, unregister: () => {} }
|
|
406
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_monacocompiler_free(ptr >>> 0, 1));
|
|
407
|
+
|
|
408
|
+
function addHeapObject(obj) {
|
|
409
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
410
|
+
const idx = heap_next;
|
|
411
|
+
heap_next = heap[idx];
|
|
412
|
+
|
|
413
|
+
heap[idx] = obj;
|
|
414
|
+
return idx;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function _assertClass(instance, klass) {
|
|
418
|
+
if (!(instance instanceof klass)) {
|
|
419
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function dropObject(idx) {
|
|
424
|
+
if (idx < 1028) return;
|
|
425
|
+
heap[idx] = heap_next;
|
|
426
|
+
heap_next = idx;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function getArrayU32FromWasm0(ptr, len) {
|
|
430
|
+
ptr = ptr >>> 0;
|
|
431
|
+
return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
435
|
+
ptr = ptr >>> 0;
|
|
436
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
let cachedDataViewMemory0 = null;
|
|
440
|
+
function getDataViewMemory0() {
|
|
441
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
442
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
443
|
+
}
|
|
444
|
+
return cachedDataViewMemory0;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function getStringFromWasm0(ptr, len) {
|
|
448
|
+
ptr = ptr >>> 0;
|
|
449
|
+
return decodeText(ptr, len);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
let cachedUint32ArrayMemory0 = null;
|
|
453
|
+
function getUint32ArrayMemory0() {
|
|
454
|
+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
455
|
+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
456
|
+
}
|
|
457
|
+
return cachedUint32ArrayMemory0;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
let cachedUint8ArrayMemory0 = null;
|
|
461
|
+
function getUint8ArrayMemory0() {
|
|
462
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
463
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
464
|
+
}
|
|
465
|
+
return cachedUint8ArrayMemory0;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function getObject(idx) { return heap[idx]; }
|
|
469
|
+
|
|
470
|
+
let heap = new Array(1024).fill(undefined);
|
|
471
|
+
heap.push(undefined, null, true, false);
|
|
472
|
+
|
|
473
|
+
let heap_next = heap.length;
|
|
474
|
+
|
|
475
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
476
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
477
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
478
|
+
WASM_VECTOR_LEN = arg.length;
|
|
479
|
+
return ptr;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
483
|
+
if (realloc === undefined) {
|
|
484
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
485
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
486
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
487
|
+
WASM_VECTOR_LEN = buf.length;
|
|
488
|
+
return ptr;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
let len = arg.length;
|
|
492
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
493
|
+
|
|
494
|
+
const mem = getUint8ArrayMemory0();
|
|
495
|
+
|
|
496
|
+
let offset = 0;
|
|
497
|
+
|
|
498
|
+
for (; offset < len; offset++) {
|
|
499
|
+
const code = arg.charCodeAt(offset);
|
|
500
|
+
if (code > 0x7F) break;
|
|
501
|
+
mem[ptr + offset] = code;
|
|
502
|
+
}
|
|
503
|
+
if (offset !== len) {
|
|
504
|
+
if (offset !== 0) {
|
|
505
|
+
arg = arg.slice(offset);
|
|
506
|
+
}
|
|
507
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
508
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
509
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
510
|
+
|
|
511
|
+
offset += ret.written;
|
|
512
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
WASM_VECTOR_LEN = offset;
|
|
516
|
+
return ptr;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function takeObject(idx) {
|
|
520
|
+
const ret = getObject(idx);
|
|
521
|
+
dropObject(idx);
|
|
522
|
+
return ret;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
526
|
+
cachedTextDecoder.decode();
|
|
527
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
528
|
+
let numBytesDecoded = 0;
|
|
529
|
+
function decodeText(ptr, len) {
|
|
530
|
+
numBytesDecoded += len;
|
|
531
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
532
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
533
|
+
cachedTextDecoder.decode();
|
|
534
|
+
numBytesDecoded = len;
|
|
535
|
+
}
|
|
536
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
const cachedTextEncoder = new TextEncoder();
|
|
540
|
+
|
|
541
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
542
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
543
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
544
|
+
view.set(buf);
|
|
545
|
+
return {
|
|
546
|
+
read: arg.length,
|
|
547
|
+
written: buf.length
|
|
548
|
+
};
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
let WASM_VECTOR_LEN = 0;
|
|
553
|
+
|
|
554
|
+
let wasmModule, wasm;
|
|
555
|
+
function __wbg_finalize_init(instance, module) {
|
|
556
|
+
wasm = instance.exports;
|
|
557
|
+
wasmModule = module;
|
|
558
|
+
cachedDataViewMemory0 = null;
|
|
559
|
+
cachedUint32ArrayMemory0 = null;
|
|
560
|
+
cachedUint8ArrayMemory0 = null;
|
|
561
|
+
wasm.__wbindgen_start();
|
|
562
|
+
return wasm;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
async function __wbg_load(module, imports) {
|
|
566
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
567
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
568
|
+
try {
|
|
569
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
570
|
+
} catch (e) {
|
|
571
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
572
|
+
|
|
573
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
574
|
+
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);
|
|
575
|
+
|
|
576
|
+
} else { throw e; }
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const bytes = await module.arrayBuffer();
|
|
581
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
582
|
+
} else {
|
|
583
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
584
|
+
|
|
585
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
586
|
+
return { instance, module };
|
|
587
|
+
} else {
|
|
588
|
+
return instance;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function expectedResponseType(type) {
|
|
593
|
+
switch (type) {
|
|
594
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
595
|
+
}
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function initSync(module) {
|
|
601
|
+
if (wasm !== undefined) return wasm;
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
if (module !== undefined) {
|
|
605
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
606
|
+
({module} = module)
|
|
607
|
+
} else {
|
|
608
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
const imports = __wbg_get_imports();
|
|
613
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
614
|
+
module = new WebAssembly.Module(module);
|
|
615
|
+
}
|
|
616
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
617
|
+
return __wbg_finalize_init(instance, module);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
async function __wbg_init(module_or_path) {
|
|
621
|
+
if (wasm !== undefined) return wasm;
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
if (module_or_path !== undefined) {
|
|
625
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
626
|
+
({module_or_path} = module_or_path)
|
|
627
|
+
} else {
|
|
628
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (module_or_path === undefined) {
|
|
633
|
+
module_or_path = new URL('wasm_bg.wasm', import.meta.url);
|
|
634
|
+
}
|
|
635
|
+
const imports = __wbg_get_imports();
|
|
636
|
+
|
|
637
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
638
|
+
module_or_path = fetch(module_or_path);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
642
|
+
|
|
643
|
+
return __wbg_finalize_init(instance, module);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
export { initSync, __wbg_init as default };
|
package/lib/wasm_bg.wasm
ADDED
|
Binary file
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_compileresult_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_monacocompiler_free: (a: number, b: number) => void;
|
|
6
|
+
export const compile: (a: number, b: number, c: number) => number;
|
|
7
|
+
export const compileresult_chunk: (a: number, b: number) => void;
|
|
8
|
+
export const compileresult_diagnostics: (a: number, b: number) => void;
|
|
9
|
+
export const main: () => void;
|
|
10
|
+
export const monacocompiler_diagnostics: (a: number, b: number) => void;
|
|
11
|
+
export const monacocompiler_emit: (a: number, b: number) => void;
|
|
12
|
+
export const monacocompiler_format: (a: number, b: number) => void;
|
|
13
|
+
export const monacocompiler_new: (a: number, b: number, c: number) => number;
|
|
14
|
+
export const monacocompiler_parse: (a: number) => number;
|
|
15
|
+
export const compile_buffer: (a: number, b: number, c: number) => number;
|
|
16
|
+
export const __wbg_config_free: (a: number, b: number) => void;
|
|
17
|
+
export const __wbg_get_config_diagnostic_error: (a: number) => number;
|
|
18
|
+
export const __wbg_get_config_diagnostic_hint: (a: number) => number;
|
|
19
|
+
export const __wbg_get_config_diagnostic_info: (a: number) => number;
|
|
20
|
+
export const __wbg_get_config_diagnostic_position_encoding: (a: number) => number;
|
|
21
|
+
export const __wbg_get_config_diagnostic_reference: (a: number) => number;
|
|
22
|
+
export const __wbg_get_config_diagnostic_sourcemap: (a: number) => number;
|
|
23
|
+
export const __wbg_get_config_diagnostic_tag: (a: number) => number;
|
|
24
|
+
export const __wbg_get_config_diagnostic_warning: (a: number) => number;
|
|
25
|
+
export const __wbg_get_config_input_mode: (a: number) => number;
|
|
26
|
+
export const __wbg_get_config_trivia: (a: number) => number;
|
|
27
|
+
export const __wbg_set_config_diagnostic_error: (a: number, b: number) => void;
|
|
28
|
+
export const __wbg_set_config_diagnostic_hint: (a: number, b: number) => void;
|
|
29
|
+
export const __wbg_set_config_diagnostic_info: (a: number, b: number) => void;
|
|
30
|
+
export const __wbg_set_config_diagnostic_position_encoding: (a: number, b: number) => void;
|
|
31
|
+
export const __wbg_set_config_diagnostic_reference: (a: number, b: number) => void;
|
|
32
|
+
export const __wbg_set_config_diagnostic_sourcemap: (a: number, b: number) => void;
|
|
33
|
+
export const __wbg_set_config_diagnostic_tag: (a: number, b: number) => void;
|
|
34
|
+
export const __wbg_set_config_diagnostic_warning: (a: number, b: number) => void;
|
|
35
|
+
export const __wbg_set_config_input_mode: (a: number, b: number) => void;
|
|
36
|
+
export const __wbg_set_config_trivia: (a: number, b: number) => void;
|
|
37
|
+
export const config_new: () => number;
|
|
38
|
+
export const __wbindgen_export: (a: number, b: number, c: number) => void;
|
|
39
|
+
export const __wbindgen_export2: (a: number, b: number) => number;
|
|
40
|
+
export const __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
|
|
41
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
42
|
+
export const __wbindgen_start: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirascript/wasm",
|
|
3
|
-
"version": "0.1.62-alpha.
|
|
3
|
+
"version": "0.1.62-alpha.9",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "MiraScript compiler for WebAssembly",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/node": "^25.6.0",
|
|
21
21
|
"nodemon": "^3.1.14",
|
|
22
|
-
"@mirascript/constants": "~0.1.62-alpha.
|
|
22
|
+
"@mirascript/constants": "~0.1.62-alpha.9"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"wasm": "wasm-pack build --target web --out-dir ../../packages/wasm/lib --no-pack ../../crates/wasm",
|