@mirascript/wasm 0.1.39 → 0.1.41

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.
@@ -1 +1 @@
1
- {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/loader/web.ts"],"names":[],"mappings":"AAuCA,eAAO,MAAM,MAAM,EAAE,OAAO,CAAC,YAAY,CAYrC,CAAC"}
1
+ {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/loader/web.ts"],"names":[],"mappings":"AA2DA,eAAO,MAAM,MAAM,EAAE,OAAO,CAAC,YAAY,CAIrC,CAAC"}
@@ -1,10 +1,45 @@
1
- /** 回退加载 */
2
- async function loadFallback() {
1
+ /** Document 推断 URL */
2
+ async function load3() {
3
3
  const fallbackUrl = (document?.currentScript instanceof HTMLScriptElement
4
4
  ? document.currentScript.src
5
5
  : (document.currentScript?.href?.baseVal ?? '')) || document.location.href;
6
6
  return await body(fetch(new URL('../../lib/wasm_bg.wasm', fallbackUrl)));
7
7
  }
8
+ /** 从 import.meta 推断 URL */
9
+ async function load2() {
10
+ return await body(fetch(new URL('../../lib/wasm_bg.wasm', import.meta.url)));
11
+ }
12
+ /** 由 esm 加载模块 */
13
+ async function load1() {
14
+ /** 加载模块 */
15
+ async function loadMod(mod) {
16
+ if (mod && typeof mod == 'object' && 'default' in mod) {
17
+ return loadMod(mod.default);
18
+ }
19
+ if (mod instanceof URL ||
20
+ (typeof mod == 'string' &&
21
+ (mod.startsWith('data:') ||
22
+ mod.startsWith('http:') ||
23
+ mod.startsWith('https:') ||
24
+ mod.startsWith('//')))) {
25
+ return await body(fetch(mod));
26
+ }
27
+ if (mod instanceof Response) {
28
+ return await body(mod);
29
+ }
30
+ if (ArrayBuffer.isView(mod) || mod instanceof ArrayBuffer) {
31
+ return mod;
32
+ }
33
+ if (mod instanceof WebAssembly.Module) {
34
+ return mod;
35
+ }
36
+ throw new Error('Failed to load wasm module');
37
+ }
38
+ // use ?url to force vite to load as bytes
39
+ // https://github.com/vitejs/vite/issues/12366
40
+ const mod = await import('../../lib/wasm_bg.wasm?url', { with: { type: 'bytes' } });
41
+ return await loadMod(mod);
42
+ }
8
43
  /** 获取模块的响应体 */
9
44
  async function body(response) {
10
45
  const resp = await response;
@@ -15,38 +50,9 @@ async function body(response) {
15
50
  throw new Error(`Failed to fetch wasm module: ${resp.status} ${resp.statusText}`);
16
51
  }
17
52
  }
18
- /** 加载模块 */
19
- async function loadMod(mod) {
20
- if (mod && typeof mod == 'object' && 'default' in mod) {
21
- return loadMod(mod.default);
22
- }
23
- if (typeof mod == 'string' && mod.startsWith('data:')) {
24
- return await body(fetch(mod));
25
- }
26
- if (mod instanceof Response) {
27
- return await body(mod);
28
- }
29
- if (ArrayBuffer.isView(mod) || mod instanceof ArrayBuffer) {
30
- return mod;
31
- }
32
- if (mod instanceof WebAssembly.Module) {
33
- return mod;
34
- }
35
- throw new Error('Failed to load wasm module');
36
- }
37
53
  export const module = /* @__PURE__ */ (async () => {
38
- try {
39
- // use ?url to force vite to load as bytes
40
- // https://github.com/vitejs/vite/issues/12366
41
- return await loadMod(await import('../../lib/wasm_bg.wasm?url', { with: { type: 'bytes' } }));
42
- }
43
- catch {
44
- if (!import.meta.url) {
45
- return await loadFallback();
46
- }
47
- else {
48
- return await body(fetch(new URL('../../lib/wasm_bg.wasm?url', import.meta.url)));
49
- }
50
- }
54
+ return load1()
55
+ .catch(async () => load2())
56
+ .catch(async () => load3());
51
57
  })();
52
58
  //# sourceMappingURL=web.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/loader/web.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,KAAK,UAAU,YAAY;IACvB,MAAM,WAAW,GACb,CAAC,QAAQ,EAAE,aAAa,YAAY,iBAAiB;QACjD,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG;QAC5B,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,EAAE,IAAI,EA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ACf,KAAK,UAAU,IAAI,CAAC,QAAsC;IACtD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC;IAC5B,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;QACV,OAAO,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;IACpC,CAAC;SAAM,CAAC;QACJ,MAAM,IAAI,KAAK,CAAC,gCAAgC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IACtF,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAA0B,eAAe,CAAC,CAAC,KAAK,IAAI,EAAE;IACrE,OAAO,KAAK,EAAE;SACT,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC;SAC1B,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;AACpC,CAAC,CAAC,EAAE,CAAC"}
package/lib/wasm.d.ts CHANGED
@@ -80,7 +80,6 @@ export interface InitOutput {
80
80
  readonly __wbg_compileresult_free: (a: number, b: number) => void;
81
81
  readonly __wbg_monacocompiler_free: (a: number, b: number) => void;
82
82
  readonly compile: (a: number, b: number, c: number) => number;
83
- readonly compile_buffer: (a: number, b: number, c: number) => number;
84
83
  readonly compileresult_chunk: (a: number, b: number) => void;
85
84
  readonly compileresult_diagnostics: (a: number, b: number) => void;
86
85
  readonly main: () => void;
@@ -89,6 +88,7 @@ export interface InitOutput {
89
88
  readonly monacocompiler_format: (a: number, b: number) => void;
90
89
  readonly monacocompiler_new: (a: number, b: number, c: number) => number;
91
90
  readonly monacocompiler_parse: (a: number) => number;
91
+ readonly compile_buffer: (a: number, b: number, c: number) => number;
92
92
  readonly __wbg_config_free: (a: number, b: number) => void;
93
93
  readonly __wbg_get_config_diagnostic_error: (a: number) => number;
94
94
  readonly __wbg_get_config_diagnostic_hint: (a: number) => number;
package/lib/wasm.js CHANGED
@@ -350,7 +350,7 @@ export function compile_buffer(script, config) {
350
350
  const ptr0 = passArray8ToWasm0(script, wasm.__wbindgen_export2);
351
351
  const len0 = WASM_VECTOR_LEN;
352
352
  _assertClass(config, Config);
353
- const ret = wasm.compile_buffer(ptr0, len0, config.__wbg_ptr);
353
+ const ret = wasm.compile(ptr0, len0, config.__wbg_ptr);
354
354
  return CompileResult.__wrap(ret);
355
355
  }
356
356
 
package/lib/wasm_bg.wasm CHANGED
Binary file
@@ -4,7 +4,6 @@ export const memory: WebAssembly.Memory;
4
4
  export const __wbg_compileresult_free: (a: number, b: number) => void;
5
5
  export const __wbg_monacocompiler_free: (a: number, b: number) => void;
6
6
  export const compile: (a: number, b: number, c: number) => number;
7
- export const compile_buffer: (a: number, b: number, c: number) => number;
8
7
  export const compileresult_chunk: (a: number, b: number) => void;
9
8
  export const compileresult_diagnostics: (a: number, b: number) => void;
10
9
  export const main: () => void;
@@ -13,6 +12,7 @@ export const monacocompiler_emit: (a: number, b: number) => void;
13
12
  export const monacocompiler_format: (a: number, b: number) => void;
14
13
  export const monacocompiler_new: (a: number, b: number, c: number) => number;
15
14
  export const monacocompiler_parse: (a: number) => number;
15
+ export const compile_buffer: (a: number, b: number, c: number) => number;
16
16
  export const __wbg_config_free: (a: number, b: number) => void;
17
17
  export const __wbg_get_config_diagnostic_error: (a: number) => number;
18
18
  export const __wbg_get_config_diagnostic_hint: (a: number) => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mirascript/wasm",
3
- "version": "0.1.39",
3
+ "version": "0.1.41",
4
4
  "author": "CloudPSS",
5
5
  "license": "MIT",
6
6
  "description": "MiraScript compiler for WebAssembly",
@@ -16,9 +16,9 @@
16
16
  }
17
17
  },
18
18
  "devDependencies": {
19
- "@types/node": "^25.0.9",
19
+ "@types/node": "^25.0.10",
20
20
  "nodemon": "^3.1.11",
21
- "@mirascript/constants": "~0.1.39"
21
+ "@mirascript/constants": "~0.1.41"
22
22
  },
23
23
  "scripts": {
24
24
  "wasm": "wasm-pack build --target web --out-dir ../../packages/wasm/lib --no-pack ../../crates/wasm",
package/src/loader/web.ts CHANGED
@@ -1,5 +1,5 @@
1
- /** 回退加载 */
2
- async function loadFallback() {
1
+ /** Document 推断 URL */
2
+ async function load3() {
3
3
  const fallbackUrl =
4
4
  (document?.currentScript instanceof HTMLScriptElement
5
5
  ? document.currentScript.src
@@ -7,6 +7,46 @@ async function loadFallback() {
7
7
  return await body(fetch(new URL('../../lib/wasm_bg.wasm', fallbackUrl)));
8
8
  }
9
9
 
10
+ /** 从 import.meta 推断 URL */
11
+ async function load2() {
12
+ return await body(fetch(new URL('../../lib/wasm_bg.wasm', import.meta.url)));
13
+ }
14
+
15
+ /** 由 esm 加载模块 */
16
+ async function load1() {
17
+ /** 加载模块 */
18
+ async function loadMod(mod: unknown): Promise<BufferSource> {
19
+ if (mod && typeof mod == 'object' && 'default' in mod) {
20
+ return loadMod(mod.default);
21
+ }
22
+ if (
23
+ mod instanceof URL ||
24
+ (typeof mod == 'string' &&
25
+ (mod.startsWith('data:') ||
26
+ mod.startsWith('http:') ||
27
+ mod.startsWith('https:') ||
28
+ mod.startsWith('//')))
29
+ ) {
30
+ return await body(fetch(mod));
31
+ }
32
+ if (mod instanceof Response) {
33
+ return await body(mod);
34
+ }
35
+ if (ArrayBuffer.isView(mod) || mod instanceof ArrayBuffer) {
36
+ return mod as ArrayBuffer;
37
+ }
38
+ if (mod instanceof WebAssembly.Module) {
39
+ return mod as unknown as BufferSource;
40
+ }
41
+ throw new Error('Failed to load wasm module');
42
+ }
43
+
44
+ // use ?url to force vite to load as bytes
45
+ // https://github.com/vitejs/vite/issues/12366
46
+ const mod: unknown = await import('../../lib/wasm_bg.wasm?url', { with: { type: 'bytes' } });
47
+ return await loadMod(mod);
48
+ }
49
+
10
50
  /** 获取模块的响应体 */
11
51
  async function body(response: Response | Promise<Response>): Promise<BufferSource> {
12
52
  const resp = await response;
@@ -17,36 +57,8 @@ async function body(response: Response | Promise<Response>): Promise<BufferSourc
17
57
  }
18
58
  }
19
59
 
20
- /** 加载模块 */
21
- async function loadMod(mod: unknown): Promise<BufferSource> {
22
- if (mod && typeof mod == 'object' && 'default' in mod) {
23
- return loadMod(mod.default);
24
- }
25
- if (typeof mod == 'string' && mod.startsWith('data:')) {
26
- return await body(fetch(mod));
27
- }
28
- if (mod instanceof Response) {
29
- return await body(mod);
30
- }
31
- if (ArrayBuffer.isView(mod) || mod instanceof ArrayBuffer) {
32
- return mod as ArrayBuffer;
33
- }
34
- if (mod instanceof WebAssembly.Module) {
35
- return mod as unknown as BufferSource;
36
- }
37
- throw new Error('Failed to load wasm module');
38
- }
39
-
40
60
  export const module: Promise<BufferSource> = /* @__PURE__ */ (async () => {
41
- try {
42
- // use ?url to force vite to load as bytes
43
- // https://github.com/vitejs/vite/issues/12366
44
- return await loadMod(await import('../../lib/wasm_bg.wasm?url', { with: { type: 'bytes' } }));
45
- } catch {
46
- if (!import.meta.url) {
47
- return await loadFallback();
48
- } else {
49
- return await body(fetch(new URL('../../lib/wasm_bg.wasm?url', import.meta.url)));
50
- }
51
- }
61
+ return load1()
62
+ .catch(async () => load2())
63
+ .catch(async () => load3());
52
64
  })();