@mirascript/wasm 0.1.90 → 0.1.91
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 +30 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -1
- package/lib/wasm.d.ts +36 -2
- package/lib/wasm.js +161 -12
- package/lib/wasm_bg.wasm +0 -0
- package/lib/wasm_bg.wasm.d.ts +15 -1
- package/package.json +2 -2
- package/src/index.ts +68 -0
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,36 @@ export interface CompileResult {
|
|
|
12
12
|
/** 编译生成的字节码 */
|
|
13
13
|
readonly chunk?: Uint8Array;
|
|
14
14
|
}
|
|
15
|
+
/** 源码格式化选项 */
|
|
16
|
+
export interface FormatOptions {
|
|
17
|
+
/** 制表符宽度。 */
|
|
18
|
+
readonly tabSize?: number;
|
|
19
|
+
/** 是否使用空格缩进。 */
|
|
20
|
+
readonly insertSpaces?: boolean;
|
|
21
|
+
/** 最大打印宽度。 */
|
|
22
|
+
readonly printWidth?: number;
|
|
23
|
+
}
|
|
24
|
+
/** UTF-16 绝对偏移范围 */
|
|
25
|
+
export interface FormatRange {
|
|
26
|
+
/** 起始 UTF-16 偏移。 */
|
|
27
|
+
readonly start: number;
|
|
28
|
+
/** 结束 UTF-16 偏移。 */
|
|
29
|
+
readonly end: number;
|
|
30
|
+
}
|
|
31
|
+
/** 源码格式化编辑 */
|
|
32
|
+
export interface FormatEdit extends FormatRange {
|
|
33
|
+
/** 替换文本。 */
|
|
34
|
+
readonly text: string;
|
|
35
|
+
}
|
|
36
|
+
/** 源码格式化结果 */
|
|
37
|
+
export interface FormatResult {
|
|
38
|
+
/** 编译诊断。 */
|
|
39
|
+
readonly diagnostics: Uint32Array;
|
|
40
|
+
/** 互不重叠的格式化编辑。 */
|
|
41
|
+
readonly edits: readonly FormatEdit[];
|
|
42
|
+
}
|
|
15
43
|
/** 编译 MiraScript 代码 */
|
|
16
44
|
export declare function compileSync(script: ScriptInput, config: Config | wasm.CompileConfig): CompileResult;
|
|
45
|
+
/** 格式化 MiraScript 源码;ranges 使用 UTF-16 绝对偏移,省略时格式化整篇文档。 */
|
|
46
|
+
export declare function formatSync(source: string, config: Config | wasm.CompileConfig, options?: FormatOptions, ranges?: readonly FormatRange[]): FormatResult;
|
|
17
47
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,aAAa,GAAG,IAAI,CAAC,aAAa,CAkBrF;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,aAAa,GAAG,aAAa,CAInG"}
|
|
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;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Aa,EACnC,OAAO,GAAE,aAAkB,EAC3B,MAAM,CAAC,EAAE,SAAS,WAAW,EAAE,GAChC,YAAY,CA4Bd"}
|
package/dist/index.js
CHANGED
|
@@ -56,4 +56,36 @@ export function compileSync(script, config) {
|
|
|
56
56
|
? compileImpl(wasm.compile, script, config)
|
|
57
57
|
: compileImpl(wasm.compile_buffer, script, config);
|
|
58
58
|
}
|
|
59
|
+
/** 格式化 MiraScript 源码;ranges 使用 UTF-16 绝对偏移,省略时格式化整篇文档。 */
|
|
60
|
+
export function formatSync(source, config, options = {}, ranges) {
|
|
61
|
+
const cfg = createConfig(config);
|
|
62
|
+
const rawOptions = new wasm.FormatOptions();
|
|
63
|
+
rawOptions.tab_size = options.tabSize ?? 2;
|
|
64
|
+
rawOptions.insert_spaces = options.insertSpaces ?? true;
|
|
65
|
+
rawOptions.print_width = options.printWidth ?? 80;
|
|
66
|
+
const rawRanges = new Uint32Array((ranges?.length ?? 0) * 2);
|
|
67
|
+
for (const [index, range] of (ranges ?? []).entries()) {
|
|
68
|
+
rawRanges[index * 2] = range.start;
|
|
69
|
+
rawRanges[index * 2 + 1] = range.end;
|
|
70
|
+
}
|
|
71
|
+
const result = wasm.format_sync(source, cfg, rawOptions, rawRanges);
|
|
72
|
+
try {
|
|
73
|
+
const encodedRanges = result.ranges();
|
|
74
|
+
const edits = [];
|
|
75
|
+
for (let index = 0; index < result.edit_count(); index++) {
|
|
76
|
+
edits.push({
|
|
77
|
+
start: encodedRanges[index * 2],
|
|
78
|
+
end: encodedRanges[index * 2 + 1],
|
|
79
|
+
text: result.edit_text(index) ?? '',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return { diagnostics: result.diagnostics(), edits };
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
result.free();
|
|
86
|
+
rawOptions.free();
|
|
87
|
+
if (cfg !== config)
|
|
88
|
+
cfg.free();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
59
91
|
//# sourceMappingURL=index.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AAC;IACxD,CAAC;YAAS,CAAC;QACP,MAAM,CAAC,IAAI,EAAE,CAAC;QACd,UAAU,CAAC,IAAI,EAAE,CAAC;QAClB,IAAI,GAAG,KAAK,MAAM;YAAE,GAAG,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;AACL,CAAC"}
|
package/lib/wasm.d.ts
CHANGED
|
@@ -43,6 +43,25 @@ export enum DiagnosticPositionEncoding {
|
|
|
43
43
|
Utf32 = 2,
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
export class FormatOptions {
|
|
47
|
+
free(): void;
|
|
48
|
+
[Symbol.dispose](): void;
|
|
49
|
+
constructor();
|
|
50
|
+
insert_spaces: boolean;
|
|
51
|
+
print_width: number;
|
|
52
|
+
tab_size: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class FormatResult {
|
|
56
|
+
private constructor();
|
|
57
|
+
free(): void;
|
|
58
|
+
[Symbol.dispose](): void;
|
|
59
|
+
diagnostics(): Uint32Array;
|
|
60
|
+
edit_count(): number;
|
|
61
|
+
edit_text(index: number): string | undefined;
|
|
62
|
+
ranges(): Uint32Array;
|
|
63
|
+
}
|
|
64
|
+
|
|
46
65
|
/**
|
|
47
66
|
* Mode for reading input.
|
|
48
67
|
*/
|
|
@@ -62,7 +81,6 @@ export class MonacoCompiler {
|
|
|
62
81
|
[Symbol.dispose](): void;
|
|
63
82
|
diagnostics(): Uint32Array;
|
|
64
83
|
emit(): Uint8Array | undefined;
|
|
65
|
-
format(): string | undefined;
|
|
66
84
|
constructor(input: string, config: CompileConfig);
|
|
67
85
|
parse(): boolean;
|
|
68
86
|
}
|
|
@@ -71,6 +89,8 @@ export function compile(script: string, config: CompileConfig): CompileResult;
|
|
|
71
89
|
|
|
72
90
|
export function compile_buffer(script: Uint8Array, config: CompileConfig): CompileResult;
|
|
73
91
|
|
|
92
|
+
export function format_sync(source: string, config: CompileConfig, options: FormatOptions, ranges: Uint32Array): FormatResult;
|
|
93
|
+
|
|
74
94
|
export function main(): void;
|
|
75
95
|
|
|
76
96
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
@@ -78,16 +98,29 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
78
98
|
export interface InitOutput {
|
|
79
99
|
readonly memory: WebAssembly.Memory;
|
|
80
100
|
readonly __wbg_compileresult_free: (a: number, b: number) => void;
|
|
101
|
+
readonly __wbg_formatoptions_free: (a: number, b: number) => void;
|
|
102
|
+
readonly __wbg_formatresult_free: (a: number, b: number) => void;
|
|
81
103
|
readonly __wbg_monacocompiler_free: (a: number, b: number) => void;
|
|
82
104
|
readonly compile: (a: number, b: number, c: number) => number;
|
|
83
105
|
readonly compileresult_chunk: (a: number) => [number, number];
|
|
84
106
|
readonly compileresult_diagnostics: (a: number) => [number, number];
|
|
107
|
+
readonly format_sync: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
108
|
+
readonly formatoptions_insert_spaces: (a: number) => number;
|
|
109
|
+
readonly formatoptions_new: () => number;
|
|
110
|
+
readonly formatoptions_print_width: (a: number) => number;
|
|
111
|
+
readonly formatoptions_set_insert_spaces: (a: number, b: number) => void;
|
|
112
|
+
readonly formatoptions_set_print_width: (a: number, b: number) => void;
|
|
113
|
+
readonly formatoptions_set_tab_size: (a: number, b: number) => void;
|
|
114
|
+
readonly formatoptions_tab_size: (a: number) => number;
|
|
115
|
+
readonly formatresult_edit_count: (a: number) => number;
|
|
116
|
+
readonly formatresult_edit_text: (a: number, b: number) => [number, number];
|
|
117
|
+
readonly formatresult_ranges: (a: number) => [number, number];
|
|
85
118
|
readonly main: () => void;
|
|
86
119
|
readonly monacocompiler_diagnostics: (a: number) => [number, number];
|
|
87
120
|
readonly monacocompiler_emit: (a: number) => [number, number];
|
|
88
|
-
readonly monacocompiler_format: (a: number) => [number, number];
|
|
89
121
|
readonly monacocompiler_new: (a: number, b: number, c: number) => number;
|
|
90
122
|
readonly monacocompiler_parse: (a: number) => number;
|
|
123
|
+
readonly formatresult_diagnostics: (a: number) => [number, number];
|
|
91
124
|
readonly compile_buffer: (a: number, b: number, c: number) => number;
|
|
92
125
|
readonly __wbg_compileconfig_free: (a: number, b: number) => void;
|
|
93
126
|
readonly __wbg_get_compileconfig_diagnostic_error: (a: number) => number;
|
|
@@ -115,6 +148,7 @@ export interface InitOutput {
|
|
|
115
148
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
116
149
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
117
150
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
151
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
118
152
|
readonly __wbindgen_start: () => void;
|
|
119
153
|
}
|
|
120
154
|
|
package/lib/wasm.js
CHANGED
|
@@ -210,6 +210,123 @@ export const DiagnosticPositionEncoding = Object.freeze({
|
|
|
210
210
|
Utf32: 2, "2": "Utf32",
|
|
211
211
|
});
|
|
212
212
|
|
|
213
|
+
export class FormatOptions {
|
|
214
|
+
__destroy_into_raw() {
|
|
215
|
+
const ptr = this.__wbg_ptr;
|
|
216
|
+
this.__wbg_ptr = 0;
|
|
217
|
+
FormatOptionsFinalization.unregister(this);
|
|
218
|
+
return ptr;
|
|
219
|
+
}
|
|
220
|
+
free() {
|
|
221
|
+
const ptr = this.__destroy_into_raw();
|
|
222
|
+
wasm.__wbg_formatoptions_free(ptr, 0);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* @returns {boolean}
|
|
226
|
+
*/
|
|
227
|
+
get insert_spaces() {
|
|
228
|
+
const ret = wasm.formatoptions_insert_spaces(this.__wbg_ptr);
|
|
229
|
+
return ret !== 0;
|
|
230
|
+
}
|
|
231
|
+
constructor() {
|
|
232
|
+
const ret = wasm.formatoptions_new();
|
|
233
|
+
this.__wbg_ptr = ret;
|
|
234
|
+
FormatOptionsFinalization.register(this, this.__wbg_ptr, this);
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* @returns {number}
|
|
239
|
+
*/
|
|
240
|
+
get print_width() {
|
|
241
|
+
const ret = wasm.formatoptions_print_width(this.__wbg_ptr);
|
|
242
|
+
return ret >>> 0;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* @param {boolean} value
|
|
246
|
+
*/
|
|
247
|
+
set insert_spaces(value) {
|
|
248
|
+
wasm.formatoptions_set_insert_spaces(this.__wbg_ptr, value);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* @param {number} value
|
|
252
|
+
*/
|
|
253
|
+
set print_width(value) {
|
|
254
|
+
wasm.formatoptions_set_print_width(this.__wbg_ptr, value);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* @param {number} value
|
|
258
|
+
*/
|
|
259
|
+
set tab_size(value) {
|
|
260
|
+
wasm.formatoptions_set_tab_size(this.__wbg_ptr, value);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* @returns {number}
|
|
264
|
+
*/
|
|
265
|
+
get tab_size() {
|
|
266
|
+
const ret = wasm.formatoptions_tab_size(this.__wbg_ptr);
|
|
267
|
+
return ret >>> 0;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (Symbol.dispose) FormatOptions.prototype[Symbol.dispose] = FormatOptions.prototype.free;
|
|
271
|
+
|
|
272
|
+
export class FormatResult {
|
|
273
|
+
static __wrap(ptr) {
|
|
274
|
+
const obj = Object.create(FormatResult.prototype);
|
|
275
|
+
obj.__wbg_ptr = ptr;
|
|
276
|
+
FormatResultFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
277
|
+
return obj;
|
|
278
|
+
}
|
|
279
|
+
__destroy_into_raw() {
|
|
280
|
+
const ptr = this.__wbg_ptr;
|
|
281
|
+
this.__wbg_ptr = 0;
|
|
282
|
+
FormatResultFinalization.unregister(this);
|
|
283
|
+
return ptr;
|
|
284
|
+
}
|
|
285
|
+
free() {
|
|
286
|
+
const ptr = this.__destroy_into_raw();
|
|
287
|
+
wasm.__wbg_formatresult_free(ptr, 0);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* @returns {Uint32Array}
|
|
291
|
+
*/
|
|
292
|
+
diagnostics() {
|
|
293
|
+
const ret = wasm.formatresult_diagnostics(this.__wbg_ptr);
|
|
294
|
+
var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
295
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
296
|
+
return v1;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* @returns {number}
|
|
300
|
+
*/
|
|
301
|
+
edit_count() {
|
|
302
|
+
const ret = wasm.formatresult_edit_count(this.__wbg_ptr);
|
|
303
|
+
return ret >>> 0;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* @param {number} index
|
|
307
|
+
* @returns {string | undefined}
|
|
308
|
+
*/
|
|
309
|
+
edit_text(index) {
|
|
310
|
+
const ret = wasm.formatresult_edit_text(this.__wbg_ptr, index);
|
|
311
|
+
let v1;
|
|
312
|
+
if (ret[0] !== 0) {
|
|
313
|
+
v1 = getStringFromWasm0(ret[0], ret[1]);
|
|
314
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
315
|
+
}
|
|
316
|
+
return v1;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* @returns {Uint32Array}
|
|
320
|
+
*/
|
|
321
|
+
ranges() {
|
|
322
|
+
const ret = wasm.formatresult_ranges(this.__wbg_ptr);
|
|
323
|
+
var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
324
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
325
|
+
return v1;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (Symbol.dispose) FormatResult.prototype[Symbol.dispose] = FormatResult.prototype.free;
|
|
329
|
+
|
|
213
330
|
/**
|
|
214
331
|
* Mode for reading input.
|
|
215
332
|
* @enum {0 | 1}
|
|
@@ -257,18 +374,6 @@ export class MonacoCompiler {
|
|
|
257
374
|
}
|
|
258
375
|
return v1;
|
|
259
376
|
}
|
|
260
|
-
/**
|
|
261
|
-
* @returns {string | undefined}
|
|
262
|
-
*/
|
|
263
|
-
format() {
|
|
264
|
-
const ret = wasm.monacocompiler_format(this.__wbg_ptr);
|
|
265
|
-
let v1;
|
|
266
|
-
if (ret[0] !== 0) {
|
|
267
|
-
v1 = getStringFromWasm0(ret[0], ret[1]);
|
|
268
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
269
|
-
}
|
|
270
|
-
return v1;
|
|
271
|
-
}
|
|
272
377
|
/**
|
|
273
378
|
* @param {string} input
|
|
274
379
|
* @param {CompileConfig} config
|
|
@@ -318,12 +423,37 @@ export function compile_buffer(script, config) {
|
|
|
318
423
|
return CompileResult.__wrap(ret);
|
|
319
424
|
}
|
|
320
425
|
|
|
426
|
+
/**
|
|
427
|
+
* @param {string} source
|
|
428
|
+
* @param {CompileConfig} config
|
|
429
|
+
* @param {FormatOptions} options
|
|
430
|
+
* @param {Uint32Array} ranges
|
|
431
|
+
* @returns {FormatResult}
|
|
432
|
+
*/
|
|
433
|
+
export function format_sync(source, config, options, ranges) {
|
|
434
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
435
|
+
const len0 = WASM_VECTOR_LEN;
|
|
436
|
+
_assertClass(config, CompileConfig);
|
|
437
|
+
_assertClass(options, FormatOptions);
|
|
438
|
+
const ptr1 = passArray32ToWasm0(ranges, wasm.__wbindgen_malloc);
|
|
439
|
+
const len1 = WASM_VECTOR_LEN;
|
|
440
|
+
const ret = wasm.format_sync(ptr0, len0, config.__wbg_ptr, options.__wbg_ptr, ptr1, len1);
|
|
441
|
+
if (ret[2]) {
|
|
442
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
443
|
+
}
|
|
444
|
+
return FormatResult.__wrap(ret[0]);
|
|
445
|
+
}
|
|
446
|
+
|
|
321
447
|
export function main() {
|
|
322
448
|
wasm.main();
|
|
323
449
|
}
|
|
324
450
|
function __wbg_get_imports() {
|
|
325
451
|
const import0 = {
|
|
326
452
|
__proto__: null,
|
|
453
|
+
__wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
|
|
454
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
455
|
+
return ret;
|
|
456
|
+
},
|
|
327
457
|
__wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
|
|
328
458
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
329
459
|
},
|
|
@@ -371,6 +501,12 @@ const CompileConfigFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
|
371
501
|
const CompileResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
372
502
|
? { register: () => {}, unregister: () => {} }
|
|
373
503
|
: new FinalizationRegistry(ptr => wasm.__wbg_compileresult_free(ptr, 1));
|
|
504
|
+
const FormatOptionsFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
505
|
+
? { register: () => {}, unregister: () => {} }
|
|
506
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_formatoptions_free(ptr, 1));
|
|
507
|
+
const FormatResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
508
|
+
? { register: () => {}, unregister: () => {} }
|
|
509
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_formatresult_free(ptr, 1));
|
|
374
510
|
const MonacoCompilerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
375
511
|
? { register: () => {}, unregister: () => {} }
|
|
376
512
|
: new FinalizationRegistry(ptr => wasm.__wbg_monacocompiler_free(ptr, 1));
|
|
@@ -419,6 +555,13 @@ function getUint8ArrayMemory0() {
|
|
|
419
555
|
return cachedUint8ArrayMemory0;
|
|
420
556
|
}
|
|
421
557
|
|
|
558
|
+
function passArray32ToWasm0(arg, malloc) {
|
|
559
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
560
|
+
getUint32ArrayMemory0().set(arg, ptr / 4);
|
|
561
|
+
WASM_VECTOR_LEN = arg.length;
|
|
562
|
+
return ptr;
|
|
563
|
+
}
|
|
564
|
+
|
|
422
565
|
function passArray8ToWasm0(arg, malloc) {
|
|
423
566
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
424
567
|
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
@@ -463,6 +606,12 @@ function passStringToWasm0(arg, malloc, realloc) {
|
|
|
463
606
|
return ptr;
|
|
464
607
|
}
|
|
465
608
|
|
|
609
|
+
function takeFromExternrefTable0(idx) {
|
|
610
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
611
|
+
wasm.__externref_table_dealloc(idx);
|
|
612
|
+
return value;
|
|
613
|
+
}
|
|
614
|
+
|
|
466
615
|
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
467
616
|
cachedTextDecoder.decode();
|
|
468
617
|
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
package/lib/wasm_bg.wasm
CHANGED
|
Binary file
|
package/lib/wasm_bg.wasm.d.ts
CHANGED
|
@@ -2,16 +2,29 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const __wbg_compileresult_free: (a: number, b: number) => void;
|
|
5
|
+
export const __wbg_formatoptions_free: (a: number, b: number) => void;
|
|
6
|
+
export const __wbg_formatresult_free: (a: number, b: number) => void;
|
|
5
7
|
export const __wbg_monacocompiler_free: (a: number, b: number) => void;
|
|
6
8
|
export const compile: (a: number, b: number, c: number) => number;
|
|
7
9
|
export const compileresult_chunk: (a: number) => [number, number];
|
|
8
10
|
export const compileresult_diagnostics: (a: number) => [number, number];
|
|
11
|
+
export const format_sync: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
12
|
+
export const formatoptions_insert_spaces: (a: number) => number;
|
|
13
|
+
export const formatoptions_new: () => number;
|
|
14
|
+
export const formatoptions_print_width: (a: number) => number;
|
|
15
|
+
export const formatoptions_set_insert_spaces: (a: number, b: number) => void;
|
|
16
|
+
export const formatoptions_set_print_width: (a: number, b: number) => void;
|
|
17
|
+
export const formatoptions_set_tab_size: (a: number, b: number) => void;
|
|
18
|
+
export const formatoptions_tab_size: (a: number) => number;
|
|
19
|
+
export const formatresult_edit_count: (a: number) => number;
|
|
20
|
+
export const formatresult_edit_text: (a: number, b: number) => [number, number];
|
|
21
|
+
export const formatresult_ranges: (a: number) => [number, number];
|
|
9
22
|
export const main: () => void;
|
|
10
23
|
export const monacocompiler_diagnostics: (a: number) => [number, number];
|
|
11
24
|
export const monacocompiler_emit: (a: number) => [number, number];
|
|
12
|
-
export const monacocompiler_format: (a: number) => [number, number];
|
|
13
25
|
export const monacocompiler_new: (a: number, b: number, c: number) => number;
|
|
14
26
|
export const monacocompiler_parse: (a: number) => number;
|
|
27
|
+
export const formatresult_diagnostics: (a: number) => [number, number];
|
|
15
28
|
export const compile_buffer: (a: number, b: number, c: number) => number;
|
|
16
29
|
export const __wbg_compileconfig_free: (a: number, b: number) => void;
|
|
17
30
|
export const __wbg_get_compileconfig_diagnostic_error: (a: number) => number;
|
|
@@ -39,4 +52,5 @@ export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
|
39
52
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
40
53
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
41
54
|
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
55
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
42
56
|
export const __wbindgen_start: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirascript/wasm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.91",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "MiraScript compiler for WebAssembly",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@mirascript/constants": "~0.1.
|
|
33
|
+
"@mirascript/constants": "~0.1.91",
|
|
34
34
|
"nodemon": "^3.1.14"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
package/src/index.ts
CHANGED
|
@@ -39,6 +39,38 @@ export interface CompileResult {
|
|
|
39
39
|
readonly chunk?: Uint8Array;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** 源码格式化选项 */
|
|
43
|
+
export interface FormatOptions {
|
|
44
|
+
/** 制表符宽度。 */
|
|
45
|
+
readonly tabSize?: number;
|
|
46
|
+
/** 是否使用空格缩进。 */
|
|
47
|
+
readonly insertSpaces?: boolean;
|
|
48
|
+
/** 最大打印宽度。 */
|
|
49
|
+
readonly printWidth?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** UTF-16 绝对偏移范围 */
|
|
53
|
+
export interface FormatRange {
|
|
54
|
+
/** 起始 UTF-16 偏移。 */
|
|
55
|
+
readonly start: number;
|
|
56
|
+
/** 结束 UTF-16 偏移。 */
|
|
57
|
+
readonly end: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 源码格式化编辑 */
|
|
61
|
+
export interface FormatEdit extends FormatRange {
|
|
62
|
+
/** 替换文本。 */
|
|
63
|
+
readonly text: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 源码格式化结果 */
|
|
67
|
+
export interface FormatResult {
|
|
68
|
+
/** 编译诊断。 */
|
|
69
|
+
readonly diagnostics: Uint32Array;
|
|
70
|
+
/** 互不重叠的格式化编辑。 */
|
|
71
|
+
readonly edits: readonly FormatEdit[];
|
|
72
|
+
}
|
|
73
|
+
|
|
42
74
|
/** 编译 */
|
|
43
75
|
function compileImpl<T>(
|
|
44
76
|
compiler: (script: T, config: wasm.CompileConfig) => wasm.CompileResult,
|
|
@@ -66,3 +98,39 @@ export function compileSync(script: ScriptInput, config: Config | wasm.CompileCo
|
|
|
66
98
|
? compileImpl(wasm.compile, script, config)
|
|
67
99
|
: compileImpl(wasm.compile_buffer, script, config);
|
|
68
100
|
}
|
|
101
|
+
|
|
102
|
+
/** 格式化 MiraScript 源码;ranges 使用 UTF-16 绝对偏移,省略时格式化整篇文档。 */
|
|
103
|
+
export function formatSync(
|
|
104
|
+
source: string,
|
|
105
|
+
config: Config | wasm.CompileConfig,
|
|
106
|
+
options: FormatOptions = {},
|
|
107
|
+
ranges?: readonly FormatRange[],
|
|
108
|
+
): FormatResult {
|
|
109
|
+
const cfg = createConfig(config);
|
|
110
|
+
const rawOptions = new wasm.FormatOptions();
|
|
111
|
+
rawOptions.tab_size = options.tabSize ?? 2;
|
|
112
|
+
rawOptions.insert_spaces = options.insertSpaces ?? true;
|
|
113
|
+
rawOptions.print_width = options.printWidth ?? 80;
|
|
114
|
+
const rawRanges = new Uint32Array((ranges?.length ?? 0) * 2);
|
|
115
|
+
for (const [index, range] of (ranges ?? []).entries()) {
|
|
116
|
+
rawRanges[index * 2] = range.start;
|
|
117
|
+
rawRanges[index * 2 + 1] = range.end;
|
|
118
|
+
}
|
|
119
|
+
const result = wasm.format_sync(source, cfg, rawOptions, rawRanges);
|
|
120
|
+
try {
|
|
121
|
+
const encodedRanges = result.ranges();
|
|
122
|
+
const edits: FormatEdit[] = [];
|
|
123
|
+
for (let index = 0; index < result.edit_count(); index++) {
|
|
124
|
+
edits.push({
|
|
125
|
+
start: encodedRanges[index * 2]!,
|
|
126
|
+
end: encodedRanges[index * 2 + 1]!,
|
|
127
|
+
text: result.edit_text(index) ?? '',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return { diagnostics: result.diagnostics(), edits };
|
|
131
|
+
} finally {
|
|
132
|
+
result.free();
|
|
133
|
+
rawOptions.free();
|
|
134
|
+
if (cfg !== config) cfg.free();
|
|
135
|
+
}
|
|
136
|
+
}
|