@mirascript/wasm 0.1.10 → 0.1.12
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 +9 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +23 -17
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Config as WasmConfig, CompileResult as WasmCompileResult } from '../lib/wasm.js';
|
|
2
2
|
import type { Config, ScriptInput } from './types.js';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export declare const ready: Promise<
|
|
3
|
+
export type { WasmCompileResult, WasmConfig };
|
|
4
|
+
export declare let wasm: typeof import('../lib/wasm.js');
|
|
5
|
+
export declare const ready: Promise<void>;
|
|
6
6
|
/** 创建可重用的配置 */
|
|
7
|
-
export declare function createConfig(config?: Config |
|
|
7
|
+
export declare function createConfig(config?: Config | WasmConfig): WasmConfig;
|
|
8
8
|
/** 编译结果 */
|
|
9
9
|
export interface CompileResult {
|
|
10
10
|
/** 编译诊断 */
|
|
@@ -13,7 +13,9 @@ export interface CompileResult {
|
|
|
13
13
|
readonly chunk?: Uint8Array;
|
|
14
14
|
}
|
|
15
15
|
/** 编译 MiraScript 代码 */
|
|
16
|
-
export declare function compileSync(script: ScriptInput, config: Config |
|
|
16
|
+
export declare function compileSync(script: ScriptInput, config: Config | WasmConfig): CompileResult;
|
|
17
17
|
/** 获取诊断消息 */
|
|
18
|
-
export declare function getDiagnosticMessage(code: number): string |
|
|
18
|
+
export declare function getDiagnosticMessage(code: number): string | null;
|
|
19
|
+
/** 获取关键字列表 */
|
|
20
|
+
export declare function keywords(): string[];
|
|
19
21
|
//# 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,IAAI,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC/F,OAAO,KAAK,EAAE,MAAM,EAAyC,WAAW,EAAE,MAAM,YAAY,CAAC;AAE7F,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAC;AAE9C,eAAO,IAAI,IAAI,EAAE,cAAc,gBAAgB,CAAC,CAAC;AACjD,eAAO,MAAM,KAAK,eAOjB,CAAC;AAEF,eAAe;AACf,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAmBrE;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,UAAU,GAAG,aAAa,CAI3F;AAED,aAAa;AACb,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEhE;AAED,cAAc;AACd,wBAAgB,QAAQ,IAAI,MAAM,EAAE,CAEnC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})
|
|
1
|
+
export let wasm;
|
|
2
|
+
export const ready = Promise.all([import('../lib/wasm.js'), import('@mirascript/wasm/loader')]).then(async ([_wasm, { module }]) => {
|
|
3
|
+
wasm = _wasm;
|
|
4
|
+
await wasm.default({
|
|
5
|
+
module_or_path: await module,
|
|
6
|
+
});
|
|
7
|
+
});
|
|
7
8
|
/** 创建可重用的配置 */
|
|
8
9
|
export function createConfig(config) {
|
|
9
10
|
if (!config)
|
|
@@ -56,6 +57,10 @@ export function compileSync(script, config) {
|
|
|
56
57
|
}
|
|
57
58
|
/** 获取诊断消息 */
|
|
58
59
|
export function getDiagnosticMessage(code) {
|
|
59
|
-
return wasm.get_diagnostic_message(code);
|
|
60
|
+
return wasm.get_diagnostic_message(code) || null;
|
|
61
|
+
}
|
|
62
|
+
/** 获取关键字列表 */
|
|
63
|
+
export function keywords() {
|
|
64
|
+
return wasm.keywords();
|
|
60
65
|
}
|
|
61
66
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,IAAI,IAAqC,CAAC;AACjD,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,IAAI,CAChG,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE;IAC1B,IAAI,GAAG,KAAK,CAAC;IACb,MAAM,IAAI,CAAC,OAAO,CAAC;QACf,cAAc,EAAE,MAAM,MAAM;KAC/B,CAAC,CAAC;AACP,CAAC,CACJ,CAAC;AAEF,eAAe;AACf,MAAM,UAAU,YAAY,CAAC,MAA4B;IACrD,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;IACtC,IAAI,MAAM,YAAY,IAAI,CAAC,MAAM;QAAE,OAAO,MAAM,CAAC;IACjD,MAAM,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AC;QACf,CAAC;IACL,CAAC;AACL,CAAC;AAED,uBAAuB;AACvB,MAAM,UAAU,WAAW,CAAC,MAAmB,EAAE,MAA2B;IACxE,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;AAED,aAAa;AACb,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC7C,OAAO,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AACrD,CAAC;AAED,cAAc;AACd,MAAM,UAAU,QAAQ;IACpB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { Config as WasmConfig, CompileResult as WasmCompileResult } from '../lib/wasm.js';
|
|
2
2
|
import type { Config, InputMode, DiagnosticPositionEncoding, ScriptInput } from './types.js';
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
export { wasm };
|
|
4
|
+
export type { WasmCompileResult, WasmConfig };
|
|
6
5
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
export let wasm: typeof import('../lib/wasm.js');
|
|
7
|
+
export const ready = Promise.all([import('../lib/wasm.js'), import('@mirascript/wasm/loader')]).then(
|
|
8
|
+
async ([_wasm, { module }]) => {
|
|
9
|
+
wasm = _wasm;
|
|
10
|
+
await wasm.default({
|
|
11
|
+
module_or_path: await module,
|
|
12
|
+
});
|
|
13
|
+
},
|
|
11
14
|
);
|
|
12
15
|
|
|
13
16
|
/** 创建可重用的配置 */
|
|
14
|
-
export function createConfig(config?: Config |
|
|
17
|
+
export function createConfig(config?: Config | WasmConfig): WasmConfig {
|
|
15
18
|
if (!config) return new wasm.Config();
|
|
16
19
|
if (config instanceof wasm.Config) return config;
|
|
17
20
|
const cfg = new wasm.Config();
|
|
@@ -20,12 +23,10 @@ export function createConfig(config?: Config | wasm.Config): wasm.Config {
|
|
|
20
23
|
if (!Object.hasOwn(config, key)) continue;
|
|
21
24
|
let value = config[key as keyof Config] as never;
|
|
22
25
|
if (key === 'input_mode') {
|
|
23
|
-
value = wasm.InputMode[value as InputMode]
|
|
26
|
+
value = wasm.InputMode[value as InputMode] as never;
|
|
24
27
|
}
|
|
25
28
|
if (key === 'diagnostic_position_encoding') {
|
|
26
|
-
value = wasm.DiagnosticPositionEncoding[
|
|
27
|
-
value as DiagnosticPositionEncoding
|
|
28
|
-
] satisfies wasm.DiagnosticPositionEncoding as never;
|
|
29
|
+
value = wasm.DiagnosticPositionEncoding[value as DiagnosticPositionEncoding] as never;
|
|
29
30
|
}
|
|
30
31
|
if (value === undefined) continue;
|
|
31
32
|
if (!(key in cfg)) continue;
|
|
@@ -44,9 +45,9 @@ export interface CompileResult {
|
|
|
44
45
|
|
|
45
46
|
/** 编译 */
|
|
46
47
|
function compileImpl<T>(
|
|
47
|
-
compiler: (script: T, config:
|
|
48
|
+
compiler: (script: T, config: WasmConfig) => WasmCompileResult,
|
|
48
49
|
script: T,
|
|
49
|
-
config: Config |
|
|
50
|
+
config: Config | WasmConfig,
|
|
50
51
|
): CompileResult {
|
|
51
52
|
const cfg = createConfig(config);
|
|
52
53
|
const result = compiler(script, cfg);
|
|
@@ -64,13 +65,18 @@ function compileImpl<T>(
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
/** 编译 MiraScript 代码 */
|
|
67
|
-
export function compileSync(script: ScriptInput, config: Config |
|
|
68
|
+
export function compileSync(script: ScriptInput, config: Config | WasmConfig): CompileResult {
|
|
68
69
|
return typeof script == 'string'
|
|
69
70
|
? compileImpl(wasm.compile, script, config)
|
|
70
71
|
: compileImpl(wasm.compile_buffer, script, config);
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
/** 获取诊断消息 */
|
|
74
|
-
export function getDiagnosticMessage(code: number): string |
|
|
75
|
-
return wasm.get_diagnostic_message(code);
|
|
75
|
+
export function getDiagnosticMessage(code: number): string | null {
|
|
76
|
+
return wasm.get_diagnostic_message(code) || null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 获取关键字列表 */
|
|
80
|
+
export function keywords(): string[] {
|
|
81
|
+
return wasm.keywords();
|
|
76
82
|
}
|