@mirascript/bindings 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ export { type InputMode, type ScriptInput, type Config, type DiagnosticPositionEncoding, DiagnosticCode, OpCode, } from '@mirascript/wasm/types';
2
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,0BAA0B,EAC/B,cAAc,EACd,MAAM,GACT,MAAM,wBAAwB,CAAC"}
package/dist/common.js ADDED
@@ -0,0 +1,2 @@
1
+ export { DiagnosticCode, OpCode, } from '@mirascript/wasm/types';
2
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,cAAc,EACd,MAAM,GACT,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import * as bundle from '#bundle';
2
+ import * as wasm from './wasm.js';
3
+ export * from './common.js';
4
+ /** 字节码模块 */
5
+ export type { BcModule } from '#bundle';
6
+ /** 字节码模块 */
7
+ export type BcModuleType = wasm.BcModuleType | bundle.BcModuleType;
8
+ /** 加载模块 */
9
+ export declare const loadModule: () => Promise<BcModuleType>;
10
+ /** 获取已加载的模块 */
11
+ export declare const getModule: () => BcModuleType;
12
+ //# 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,MAAM,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,cAAc,aAAa,CAAC;AAC5B,YAAY;AACZ,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,YAAY;AACZ,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;AAanE,WAAW;AACX,eAAO,MAAM,UAAU,EAAE,MAAM,OAAO,CAAC,YAAY,CAAe,CAAC;AACnE,eAAe;AACf,eAAO,MAAM,SAAS,EAAE,MAAM,YAAyB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import * as bundle from '#bundle';
2
+ import * as wasm from './wasm.js';
3
+ import { ModuleLoader } from './loader.js';
4
+ export * from './common.js';
5
+ const loader = new ModuleLoader(async () => {
6
+ try {
7
+ return await bundle.loadModule();
8
+ /* c8 ignore next 5 */
9
+ }
10
+ catch (ex) {
11
+ // eslint-disable-next-line no-console
12
+ console.warn('Failed to load compiler bundle, falling back to @mirascript/wasm');
13
+ return await wasm.loadModule();
14
+ }
15
+ });
16
+ /** 加载模块 */
17
+ export const loadModule = loader.load;
18
+ /** 获取已加载的模块 */
19
+ export const getModule = loader.get;
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,cAAc,aAAa,CAAC;AAM5B,MAAM,MAAM,GAAG,IAAI,YAAY,CAAe,KAAK,IAAI,EAAE;IACrD,IAAI,CAAC;QACD,OAAO,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;QACjC,sBAAsB;IAC1B,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACV,sCAAsC;QACtC,OAAO,CAAC,IAAI,CAAC,kEAAkE,CAAC,CAAC;QACjF,OAAO,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;IACnC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,WAAW;AACX,MAAM,CAAC,MAAM,UAAU,GAAgC,MAAM,CAAC,IAAI,CAAC;AACnE,eAAe;AACf,MAAM,CAAC,MAAM,SAAS,GAAuB,MAAM,CAAC,GAAG,CAAC"}
@@ -0,0 +1,15 @@
1
+ /** 模块加载器 */
2
+ export declare class ModuleLoader<T> {
3
+ private readonly loader;
4
+ constructor(loader: () => Promise<T>);
5
+ private module;
6
+ private loading;
7
+ /** 加载模块 */
8
+ readonly load: () => Promise<T>;
9
+ /**
10
+ * 获取已加载的模块
11
+ * @throws {Error} 模块尚未加载
12
+ */
13
+ readonly get: () => T;
14
+ }
15
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,qBAAa,YAAY,CAAC,CAAC;IACX,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IACrD,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,OAAO,CAAyB;IAExC,WAAW;IACX,QAAQ,CAAC,IAAI,QAAa,OAAO,CAAC,CAAC,CAAC,CAiBlC;IACF;;;OAGG;IACH,QAAQ,CAAC,GAAG,QAAO,CAAC,CAMlB;CACL"}
package/dist/loader.js ADDED
@@ -0,0 +1,38 @@
1
+ /** 模块加载器 */
2
+ export class ModuleLoader {
3
+ constructor(loader) {
4
+ this.loader = loader;
5
+ /** 加载模块 */
6
+ this.load = async () => {
7
+ const { module, loading, loader } = this;
8
+ if (module != null)
9
+ return module;
10
+ if (loading != null)
11
+ return loading;
12
+ const l = (async () => {
13
+ const mod = await loader();
14
+ this.module = mod;
15
+ return mod;
16
+ })();
17
+ void l.finally(() => {
18
+ if (this.loading === l) {
19
+ this.loading = undefined;
20
+ }
21
+ });
22
+ this.loading = l;
23
+ return l;
24
+ };
25
+ /**
26
+ * 获取已加载的模块
27
+ * @throws {Error} 模块尚未加载
28
+ */
29
+ this.get = () => {
30
+ const { module } = this;
31
+ if (module == null) {
32
+ throw new Error('MiraScript compiler module is not loaded.');
33
+ }
34
+ return module;
35
+ };
36
+ }
37
+ }
38
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,MAAM,OAAO,YAAY;IACrB,YAA6B,MAAwB;QAAxB,WAAM,GAAN,MAAM,CAAkB;QAIrD,WAAW;QACF,SAAI,GAAG,KAAK,IAAgB,EAAE;YACnC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;YACzC,IAAI,MAAM,IAAI,IAAI;gBAAE,OAAO,MAAM,CAAC;YAClC,IAAI,OAAO,IAAI,IAAI;gBAAE,OAAO,OAAO,CAAC;YAEpC,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;gBAClB,MAAM,GAAG,GAAG,MAAM,MAAM,EAAE,CAAC;gBAC3B,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC;gBAClB,OAAO,GAAG,CAAC;YACf,CAAC,CAAC,EAAE,CAAC;YACL,KAAK,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;gBAChB,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC,EAAE,CAAC;oBACrB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;gBAC7B,CAAC;YACL,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;YACjB,OAAO,CAAC,CAAC;QACb,CAAC,CAAC;QACF;;;WAGG;QACM,QAAG,GAAG,GAAM,EAAE;YACnB,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;YACxB,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC;IAjCsD,CAAC;CAkC5D"}
package/dist/napi.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type * as BcModule from '@mirascript/napi';
2
+ export * from './common.js';
3
+ /** 字节码模块 */
4
+ export type { BcModule };
5
+ /** 字节码模块 */
6
+ export type BcModuleType = typeof BcModule;
7
+ /** 加载模块 */
8
+ export declare const loadModule: () => Promise<BcModuleType>;
9
+ /** 获取已加载的模块 */
10
+ export declare const getModule: () => BcModuleType;
11
+ //# sourceMappingURL=napi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"napi.d.ts","sourceRoot":"","sources":["../src/napi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAElD,cAAc,aAAa,CAAC;AAC5B,YAAY;AACZ,YAAY,EAAE,QAAQ,EAAE,CAAC;AACzB,YAAY;AACZ,MAAM,MAAM,YAAY,GAAG,OAAO,QAAQ,CAAC;AAI3C,WAAW;AACX,eAAO,MAAM,UAAU,EAAE,MAAM,OAAO,CAAC,YAAY,CAAe,CAAC;AACnE,eAAe;AACf,eAAO,MAAM,SAAS,EAAE,MAAM,YAAyB,CAAC"}
package/dist/napi.js ADDED
@@ -0,0 +1,8 @@
1
+ import { ModuleLoader } from './loader.js';
2
+ export * from './common.js';
3
+ const loader = new ModuleLoader(async () => await import('@mirascript/napi'));
4
+ /** 加载模块 */
5
+ export const loadModule = loader.load;
6
+ /** 获取已加载的模块 */
7
+ export const getModule = loader.get;
8
+ //# sourceMappingURL=napi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"napi.js","sourceRoot":"","sources":["../src/napi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,cAAc,aAAa,CAAC;AAM5B,MAAM,MAAM,GAAG,IAAI,YAAY,CAAe,KAAK,IAAI,EAAE,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC;AAE5F,WAAW;AACX,MAAM,CAAC,MAAM,UAAU,GAAgC,MAAM,CAAC,IAAI,CAAC;AACnE,eAAe;AACf,MAAM,CAAC,MAAM,SAAS,GAAuB,MAAM,CAAC,GAAG,CAAC"}
package/dist/wasm.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type * as BcModule from '@mirascript/wasm';
2
+ export * from './common.js';
3
+ /** 字节码模块 */
4
+ export type { BcModule };
5
+ /** 字节码模块 */
6
+ export type BcModuleType = typeof BcModule;
7
+ /** 加载模块 */
8
+ export declare const loadModule: () => Promise<BcModuleType>;
9
+ /** 获取已加载的模块 */
10
+ export declare const getModule: () => BcModuleType;
11
+ //# sourceMappingURL=wasm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm.d.ts","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,QAAQ,MAAM,kBAAkB,CAAC;AAElD,cAAc,aAAa,CAAC;AAC5B,YAAY;AACZ,YAAY,EAAE,QAAQ,EAAE,CAAC;AACzB,YAAY;AACZ,MAAM,MAAM,YAAY,GAAG,OAAO,QAAQ,CAAC;AAQ3C,WAAW;AACX,eAAO,MAAM,UAAU,EAAE,MAAM,OAAO,CAAC,YAAY,CAAe,CAAC;AACnE,eAAe;AACf,eAAO,MAAM,SAAS,EAAE,MAAM,YAAyB,CAAC"}
package/dist/wasm.js ADDED
@@ -0,0 +1,12 @@
1
+ import { ModuleLoader } from './loader.js';
2
+ export * from './common.js';
3
+ const loader = new ModuleLoader(async () => {
4
+ const wasm = await import('@mirascript/wasm');
5
+ await wasm.ready;
6
+ return wasm;
7
+ });
8
+ /** 加载模块 */
9
+ export const loadModule = loader.load;
10
+ /** 获取已加载的模块 */
11
+ export const getModule = loader.get;
12
+ //# sourceMappingURL=wasm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm.js","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,cAAc,aAAa,CAAC;AAM5B,MAAM,MAAM,GAAG,IAAI,YAAY,CAAe,KAAK,IAAI,EAAE;IACrD,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAC9C,MAAM,IAAI,CAAC,KAAK,CAAC;IACjB,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC,CAAC;AAEH,WAAW;AACX,MAAM,CAAC,MAAM,UAAU,GAAgC,MAAM,CAAC,IAAI,CAAC;AACnE,eAAe;AACf,MAAM,CAAC,MAAM,SAAS,GAAuB,MAAM,CAAC,GAAG,CAAC"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@mirascript/bindings",
3
+ "version": "0.1.11",
4
+ "author": "CloudPSS",
5
+ "license": "MIT",
6
+ "description": "MiraScript compiler bindings",
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": "./dist/index.js",
12
+ "./wasm": "./dist/wasm.js",
13
+ "./napi": "./dist/napi.js"
14
+ },
15
+ "imports": {
16
+ "#bundle": {
17
+ "node": "./dist/napi.js",
18
+ "default": "./dist/wasm.js"
19
+ }
20
+ },
21
+ "dependencies": {
22
+ "@mirascript/napi": "~0.1.11",
23
+ "@mirascript/wasm": "~0.1.11"
24
+ },
25
+ "scripts": {
26
+ "watch": "pnpm build --watch",
27
+ "build": "pnpm clean && tsc",
28
+ "clean": "rimraf dist"
29
+ }
30
+ }
package/src/common.ts ADDED
@@ -0,0 +1,8 @@
1
+ export {
2
+ type InputMode,
3
+ type ScriptInput,
4
+ type Config,
5
+ type DiagnosticPositionEncoding,
6
+ DiagnosticCode,
7
+ OpCode,
8
+ } from '@mirascript/wasm/types';
package/src/index.ts ADDED
@@ -0,0 +1,25 @@
1
+ import * as bundle from '#bundle';
2
+ import * as wasm from './wasm.js';
3
+ import { ModuleLoader } from './loader.js';
4
+
5
+ export * from './common.js';
6
+ /** 字节码模块 */
7
+ export type { BcModule } from '#bundle';
8
+ /** 字节码模块 */
9
+ export type BcModuleType = wasm.BcModuleType | bundle.BcModuleType;
10
+
11
+ const loader = new ModuleLoader<BcModuleType>(async () => {
12
+ try {
13
+ return await bundle.loadModule();
14
+ /* c8 ignore next 5 */
15
+ } catch (ex) {
16
+ // eslint-disable-next-line no-console
17
+ console.warn('Failed to load compiler bundle, falling back to @mirascript/wasm');
18
+ return await wasm.loadModule();
19
+ }
20
+ });
21
+
22
+ /** 加载模块 */
23
+ export const loadModule: () => Promise<BcModuleType> = loader.load;
24
+ /** 获取已加载的模块 */
25
+ export const getModule: () => BcModuleType = loader.get;
package/src/loader.ts ADDED
@@ -0,0 +1,37 @@
1
+ /** 模块加载器 */
2
+ export class ModuleLoader<T> {
3
+ constructor(private readonly loader: () => Promise<T>) {}
4
+ private module: T | undefined;
5
+ private loading: Promise<T> | undefined;
6
+
7
+ /** 加载模块 */
8
+ readonly load = async (): Promise<T> => {
9
+ const { module, loading, loader } = this;
10
+ if (module != null) return module;
11
+ if (loading != null) return loading;
12
+
13
+ const l = (async () => {
14
+ const mod = await loader();
15
+ this.module = mod;
16
+ return mod;
17
+ })();
18
+ void l.finally(() => {
19
+ if (this.loading === l) {
20
+ this.loading = undefined;
21
+ }
22
+ });
23
+ this.loading = l;
24
+ return l;
25
+ };
26
+ /**
27
+ * 获取已加载的模块
28
+ * @throws {Error} 模块尚未加载
29
+ */
30
+ readonly get = (): T => {
31
+ const { module } = this;
32
+ if (module == null) {
33
+ throw new Error('MiraScript compiler module is not loaded.');
34
+ }
35
+ return module;
36
+ };
37
+ }
package/src/napi.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { ModuleLoader } from './loader.js';
2
+ import type * as BcModule from '@mirascript/napi';
3
+
4
+ export * from './common.js';
5
+ /** 字节码模块 */
6
+ export type { BcModule };
7
+ /** 字节码模块 */
8
+ export type BcModuleType = typeof BcModule;
9
+
10
+ const loader = new ModuleLoader<BcModuleType>(async () => await import('@mirascript/napi'));
11
+
12
+ /** 加载模块 */
13
+ export const loadModule: () => Promise<BcModuleType> = loader.load;
14
+ /** 获取已加载的模块 */
15
+ export const getModule: () => BcModuleType = loader.get;
package/src/wasm.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { ModuleLoader } from './loader.js';
2
+ import type * as BcModule from '@mirascript/wasm';
3
+
4
+ export * from './common.js';
5
+ /** 字节码模块 */
6
+ export type { BcModule };
7
+ /** 字节码模块 */
8
+ export type BcModuleType = typeof BcModule;
9
+
10
+ const loader = new ModuleLoader<BcModuleType>(async () => {
11
+ const wasm = await import('@mirascript/wasm');
12
+ await wasm.ready;
13
+ return wasm;
14
+ });
15
+
16
+ /** 加载模块 */
17
+ export const loadModule: () => Promise<BcModuleType> = loader.load;
18
+ /** 获取已加载的模块 */
19
+ export const getModule: () => BcModuleType = loader.get;
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ // 如果使用其他版本 TS,使用类似 "extends": "@cloudpss/tsconfig/4.2" 引入
3
+ "extends": "../../tsconfig.json",
4
+
5
+ "compilerOptions": {
6
+ "declaration": true,
7
+ "sourceMap": true,
8
+ "declarationMap": true,
9
+ "emitDeclarationOnly": false
10
+ }
11
+ }