@bytecodealliance/jco 1.11.2-rc.2 → 1.11.3-rc.1

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/src/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["api.js"],"names":[],"mappings":"AAKA;;;GAGG;AACH,8BAHW,UAAU,CAAC,GAAoC,CAAC,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,GAAoC,CAAC,CAAC,CAKpE;AACD;;;GAGG;AACH,2BAHW,UAAU,CAAC,GAAoC,CAAC,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,GAAoC,CAAC,CAAC,CAKpE;AACD;;;GAGG;AACH,qCAHW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD;;;;GAIG;AACH,qCAJW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,YAC1D,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD;;;GAGG;AACH,0CAHW,UAAU,CAAC,GAA6C,CAAC,CAAC,CAAC,CAAC,GAC3D,OAAO,CAAC,UAAU,CAAC,GAA6C,CAAC,CAAC,CAK7E;AACD;;;;GAIG;AACH,oCAJW,UAAU,CAAC,GAA0C,CAAC,CAAC,CAAC,CAAC,YACzD,UAAU,CAAC,GAA0C,CAAC,CAAC,CAAC,CAAC,GACxD,OAAO,CAAC,UAAU,CAAC,GAA0C,CAAC,CAAC,CAK1E;AACD;;;GAGG;AACH,qCAHW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD,kDAEC;AACD,kDAEC"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["api.js"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,8BAHW,UAAU,CAAC,GAAoC,CAAC,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,GAAoC,CAAC,CAAC,CAKpE;AACD;;;GAGG;AACH,2BAHW,UAAU,CAAC,GAAoC,CAAC,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,GAAoC,CAAC,CAAC,CAKpE;AACD;;;GAGG;AACH,qCAHW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD;;;;GAIG;AACH,qCAJW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,YAC1D,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD;;;GAGG;AACH,0CAHW,UAAU,CAAC,GAA6C,CAAC,CAAC,CAAC,CAAC,GAC3D,OAAO,CAAC,UAAU,CAAC,GAA6C,CAAC,CAAC,CAK7E;AACD;;;;GAIG;AACH,oCAJW,UAAU,CAAC,GAA0C,CAAC,CAAC,CAAC,CAAC,YACzD,UAAU,CAAC,GAA0C,CAAC,CAAC,CAAC,CAAC,GACxD,OAAO,CAAC,UAAU,CAAC,GAA0C,CAAC,CAAC,CAK1E;AACD;;;GAGG;AACH,qCAHW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD,kDAKC;AACD,kDAKC"}
package/src/api.js CHANGED
@@ -1,69 +1,86 @@
1
1
  export { optimizeComponent as opt } from './cmd/opt.js';
2
- export { transpileComponent as transpile, typesComponent as types } from './cmd/transpile.js';
3
- import { $init, tools } from "../obj/wasm-tools.js";
4
- const { print: printFn, parse: parseFn, componentWit: componentWitFn, componentNew: componentNewFn, componentEmbed: componentEmbedFn, metadataAdd: metadataAddFn, metadataShow: metadataShowFn } = tools;
2
+ export {
3
+ transpileComponent as transpile,
4
+ typesComponent as types,
5
+ } from './cmd/transpile.js';
6
+ import { $init, tools } from '../obj/wasm-tools.js';
7
+ const {
8
+ print: printFn,
9
+ parse: parseFn,
10
+ componentWit: componentWitFn,
11
+ componentNew: componentNewFn,
12
+ componentEmbed: componentEmbedFn,
13
+ metadataAdd: metadataAddFn,
14
+ metadataShow: metadataShowFn,
15
+ } = tools;
5
16
 
6
17
  /**
7
18
  * @param {Parameters<import('../obj/wasm-tools.js').print>[0]} binary
8
19
  * @return {Promise<ReturnType<import('../obj/wasm-tools.js').print>>}
9
20
  */
10
- export async function print (binary) {
11
- await $init;
12
- return printFn(binary);
21
+ export async function print(binary) {
22
+ await $init;
23
+ return printFn(binary);
13
24
  }
14
25
  /**
15
26
  * @param {Parameters<import('../obj/wasm-tools.js').parse>[0]} wat
16
27
  * @return {Promise<ReturnType<import('../obj/wasm-tools.js').parse>>}
17
28
  */
18
- export async function parse (wat) {
19
- await $init;
20
- return parseFn(wat);
29
+ export async function parse(wat) {
30
+ await $init;
31
+ return parseFn(wat);
21
32
  }
22
33
  /**
23
34
  * @param {Parameters<import('../obj/wasm-tools.js').componentWit>[0]} binary
24
35
  * @return {Promise<ReturnType<import('../obj/wasm-tools.js').componentWit>>}
25
36
  */
26
- export async function componentWit (binary) {
27
- await $init;
28
- return componentWitFn(binary);
37
+ export async function componentWit(binary) {
38
+ await $init;
39
+ return componentWitFn(binary);
29
40
  }
30
41
  /**
31
42
  * @param {Parameters<import('../obj/wasm-tools.js').componentNew>[0]} binary
32
43
  * @param {Parameters<import('../obj/wasm-tools.js').componentNew>[1]} adapters
33
44
  * @return {Promise<ReturnType<import('../obj/wasm-tools.js').componentNew>>}
34
45
  */
35
- export async function componentNew (binary, adapters) {
36
- await $init;
37
- return componentNewFn(binary, adapters);
46
+ export async function componentNew(binary, adapters) {
47
+ await $init;
48
+ return componentNewFn(binary, adapters);
38
49
  }
39
50
  /**
40
51
  * @param {Parameters<import('../obj/wasm-tools.js').componentEmbed>[0]} embedOpts
41
52
  * @return {Promise<ReturnType<import('../obj/wasm-tools.js').componentEmbed>>}
42
53
  */
43
- export async function componentEmbed (embedOpts) {
44
- await $init;
45
- return componentEmbedFn(embedOpts);
54
+ export async function componentEmbed(embedOpts) {
55
+ await $init;
56
+ return componentEmbedFn(embedOpts);
46
57
  }
47
58
  /**
48
59
  * @param {Parameters<import('../obj/wasm-tools.js').metadataAdd>[0]} binary
49
60
  * @param {Parameters<import('../obj/wasm-tools.js').metadataAdd>[1]} metadata
50
61
  * @return {Promise<ReturnType<import('../obj/wasm-tools.js').metadataAdd>>}
51
62
  */
52
- export async function metadataAdd (binary, metadata) {
53
- await $init;
54
- return metadataAddFn(binary, metadata);
63
+ export async function metadataAdd(binary, metadata) {
64
+ await $init;
65
+ return metadataAddFn(binary, metadata);
55
66
  }
56
67
  /**
57
68
  * @param {Parameters<import('../obj/wasm-tools.js').metadataShow>[0]} binary
58
69
  * @return {Promise<ReturnType<import('../obj/wasm-tools.js').metadataShow>>}
59
70
  */
60
- export async function metadataShow (binary) {
61
- await $init;
62
- return metadataShowFn(binary);
71
+ export async function metadataShow(binary) {
72
+ await $init;
73
+ return metadataShowFn(binary);
63
74
  }
64
- export function preview1AdapterCommandPath () {
65
- return new URL('../lib/wasi_snapshot_preview1.command.wasm', import.meta.url);
75
+ export function preview1AdapterCommandPath() {
76
+ return new URL(
77
+ '../lib/wasi_snapshot_preview1.command.wasm',
78
+ import.meta.url
79
+ );
66
80
  }
67
- export function preview1AdapterReactorPath () {
68
- return new URL('../lib/wasi_snapshot_preview1.reactor.wasm', import.meta.url);
81
+ export function preview1AdapterReactorPath() {
82
+ return new URL(
83
+ '../lib/wasi_snapshot_preview1.reactor.wasm',
84
+ import.meta.url
85
+ );
69
86
  }
@@ -1 +1 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["browser.js"],"names":[],"mappings":"AAEA,uDAGC;AAED,4DAGC"}
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["browser.js"],"names":[],"mappings":"AAMA,uDAGC;AAED,4DAGC"}
package/src/browser.js CHANGED
@@ -1,14 +1,18 @@
1
- import { $init, generate as _generate, generateTypes as _generateTypes } from '../obj/js-component-bindgen-component.js';
1
+ import {
2
+ $init,
3
+ generate as _generate,
4
+ generateTypes as _generateTypes,
5
+ } from '../obj/js-component-bindgen-component.js';
2
6
 
3
- export async function generate () {
4
- await $init;
5
- return _generate.apply(this, arguments);
7
+ export async function generate() {
8
+ await $init;
9
+ return _generate.apply(this, arguments);
6
10
  }
7
11
 
8
- export async function generateTypes () {
9
- await $init;
10
- return _generateTypes.apply(this, arguments);
12
+ export async function generateTypes() {
13
+ await $init;
14
+ return _generateTypes.apply(this, arguments);
11
15
  }
12
16
 
13
17
  // for backwards compat
14
- export { generate as transpile }
18
+ export { generate as transpile };
@@ -1 +1 @@
1
- {"version":3,"file":"componentize.d.ts","sourceRoot":"","sources":["componentize.js"],"names":[],"mappings":"AAKA,sEA4CC"}
1
+ {"version":3,"file":"componentize.d.ts","sourceRoot":"","sources":["componentize.js"],"names":[],"mappings":"AAIA,sEAkBC"}
@@ -1 +1 @@
1
- {"version":3,"file":"opt.d.ts","sourceRoot":"","sources":["opt.js"],"names":[],"mappings":"AAgBA,gFA2CC;AAgBD;;;;;GAKG;AACH,kDAJW,UAAU,QACV;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5E,OAAO,CAAC;IAAE,SAAS,EAAE,UAAU,CAAC;IAAC,eAAe,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAA,CAAE,CA2L7G"}
1
+ {"version":3,"file":"opt.d.ts","sourceRoot":"","sources":["opt.js"],"names":[],"mappings":"AAgBA,gFA2CC;AAgBD;;;;;GAKG;AACH,kDAJW,UAAU,QACV;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5E,OAAO,CAAC;IAAE,SAAS,EAAE,UAAU,CAAC;IAAC,eAAe,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAA,CAAE,CAkK7G"}
package/src/cmd/opt.js CHANGED
@@ -17,10 +17,14 @@ import ora from '#ora';
17
17
  export async function opt(componentPath, opts, program) {
18
18
  await $init;
19
19
  const varIdx = program.parent.rawArgs.indexOf('--');
20
- if (varIdx !== -1) opts.optArgs = program.parent.rawArgs.slice(varIdx + 1);
20
+ if (varIdx !== -1) {
21
+ opts.optArgs = program.parent.rawArgs.slice(varIdx + 1);
22
+ }
21
23
  const componentBytes = await readFile(componentPath);
22
24
 
23
- if (!opts.quiet) setShowSpinner(true);
25
+ if (!opts.quiet) {
26
+ setShowSpinner(true);
27
+ }
24
28
  const optPromise = optimizeComponent(componentBytes, opts);
25
29
  const { component, compressionInfo } = await optPromise;
26
30
 
@@ -29,7 +33,7 @@ export async function opt(componentPath, opts, program) {
29
33
  let totalBeforeBytes = 0,
30
34
  totalAfterBytes = 0;
31
35
 
32
- if (!opts.quiet)
36
+ if (!opts.quiet) {
33
37
  console.log(c`
34
38
  {bold Optimized WebAssembly Component Internal Core Modules:}
35
39
 
@@ -57,6 +61,7 @@ ${table(
57
61
  ],
58
62
  [, , , , 'right']
59
63
  )}`);
64
+ }
60
65
  }
61
66
 
62
67
  /**
@@ -117,7 +122,9 @@ export async function optimizeComponent(componentBytes, opts) {
117
122
  '--enable-bulk-memory',
118
123
  '--strip-debug',
119
124
  ];
120
- if (opts?.asyncify) args.push('--asyncify');
125
+ if (opts?.asyncify) {
126
+ args.push('--asyncify');
127
+ }
121
128
 
122
129
  // process core Wasm modules with wasm-opt
123
130
  await Promise.all(
@@ -246,7 +253,7 @@ export async function optimizeComponent(componentBytes, opts) {
246
253
  // verify it still parses ok
247
254
  if (!opts?.noVerify) {
248
255
  try {
249
- await print(outComponentBytes);
256
+ print(outComponentBytes);
250
257
  } catch (e) {
251
258
  throw new Error(
252
259
  `Internal error performing optimization.\n${e.message}`
@@ -262,7 +269,9 @@ export async function optimizeComponent(componentBytes, opts) {
262
269
  })),
263
270
  };
264
271
  } finally {
265
- if (spinner) spinner.stop();
272
+ if (spinner) {
273
+ spinner.stop();
274
+ }
266
275
  }
267
276
  }
268
277
 
@@ -279,8 +288,9 @@ async function wasmOpt(source, args) {
279
288
  try {
280
289
  return await spawnIOTmp(wasmOptPath, source, [...args, '-o']);
281
290
  } catch (e) {
282
- if (e.toString().includes('BasicBlock requested'))
291
+ if (e.toString().includes('BasicBlock requested')) {
283
292
  return wasmOpt(source, args);
293
+ }
284
294
  throw e;
285
295
  }
286
296
  }
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["run.js"],"names":[],"mappings":"AAWA,6EAwBC;AAED,+EAqCC"}
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["run.js"],"names":[],"mappings":"AASA,6EAmBC;AAED,+EA2BC"}
package/src/cmd/run.js CHANGED
@@ -132,7 +132,9 @@ async function runComponent(componentPath, args, opts, executor) {
132
132
  'dir'
133
133
  );
134
134
  } catch (e) {
135
- if (e.code !== 'EEXIST') throw e;
135
+ if (e.code !== 'EEXIST') {
136
+ throw e;
137
+ }
136
138
  }
137
139
 
138
140
  const runPath = resolve(outDir, '_run.js');
@@ -169,7 +171,9 @@ async function runComponent(componentPath, args, opts, executor) {
169
171
  });
170
172
  } finally {
171
173
  try {
172
- if (!opts.jcoDir) await rm(outDir, { recursive: true });
174
+ if (!opts.jcoDir) {
175
+ await rm(outDir, { recursive: true });
176
+ }
173
177
  } catch {
174
178
  // empty
175
179
  }
@@ -20,13 +20,13 @@ export function typesComponent(witPath: string, opts: {
20
20
  name?: string;
21
21
  worldName?: string;
22
22
  instantiation?: "async" | "sync";
23
- tlaCompat?: bool;
23
+ tlaCompat?: boolean;
24
24
  asyncMode?: string;
25
25
  asyncImports?: string[];
26
26
  asyncExports?: string[];
27
27
  outDir?: string;
28
28
  features?: string[] | "all";
29
- guest?: bool;
29
+ guest?: boolean;
30
30
  }): Promise<{
31
31
  [filename: string]: Uint8Array;
32
32
  }>;
@@ -66,18 +66,18 @@ export function transpileComponent(component: Uint8Array, opts?: {
66
66
  asyncMode?: string;
67
67
  asyncImports?: string[];
68
68
  asyncExports?: string[];
69
- validLiftingOptimization?: bool;
70
- tracing?: bool;
71
- nodejsCompat?: bool;
72
- tlaCompat?: bool;
73
- base64Cutoff?: bool;
74
- js?: bool;
75
- minify?: bool;
76
- optimize?: bool;
77
- namespacedExports?: bool;
69
+ validLiftingOptimization?: boolean;
70
+ tracing?: boolean;
71
+ nodejsCompat?: boolean;
72
+ tlaCompat?: boolean;
73
+ base64Cutoff?: boolean;
74
+ js?: boolean;
75
+ minify?: boolean;
76
+ optimize?: boolean;
77
+ namespacedExports?: boolean;
78
78
  outDir?: string;
79
- multiMemory?: bool;
80
- experimentalIdlImports?: bool;
79
+ multiMemory?: boolean;
80
+ experimentalIdlImports?: boolean;
81
81
  optArgs?: string[];
82
82
  }): Promise<{
83
83
  files: {
@@ -86,4 +86,4 @@ export function transpileComponent(component: Uint8Array, opts?: {
86
86
  imports: string[];
87
87
  exports: [string, "function" | "instance"][];
88
88
  }>;
89
- //# sourceMappingURL=transpile.d.ts.map
89
+ //# sourceMappingURL=transpile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transpile.d.ts","sourceRoot":"","sources":["transpile.js"],"names":[],"mappings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b,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACjC,cAAc,CAAC,EAAE,IAAI,GAAG,WAAW,GAAG,QAAQ,GAAG,kBAAkB,CAAC;IACpE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,wBAAwB,CAAC,EAAE,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,YAAY,CAAC,EAAE,IAAI,CAAC;IACpB,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,YAAY,CAAC,EAAE,IAAI,CAAC;IACpB,EAAE,CAAC,EAAE,IAAI,CAAC;IACV,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,iBAAiB,CAAC,EAAE,IAAI,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB,sBAAsB,CAAC,EAAE,IAAI,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,GACS,OAAO,CAAC;IAAE,KAAK,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAA;KAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,EAAE,CAAA;CAAE,CAAC,CAyTnI"}
@@ -70,7 +70,11 @@ export async function guestTypes(witPath, opts) {
70
70
  * asyncImports?: string[],
71
71
  * asyncExports?: string[],
72
72
  * outDir?: string,
73
+ * allFeatures?: bool,
74
+ * feature?: string[] | 'all', // backwards compat
73
75
  * features?: string[] | 'all',
76
+ * asyncWasiImports?: string[],
77
+ * asyncWasiExports?: string[],
74
78
  * guest?: bool,
75
79
  * }} opts
76
80
  * @returns {Promise<{ [filename: string]: Uint8Array }>}
@@ -87,19 +91,25 @@ export async function typesComponent(witPath, opts) {
87
91
  instantiation = { tag: opts.instantiation };
88
92
  }
89
93
  let outDir = (opts.outDir ?? '').replace(/\\/g, '/');
90
- if (!outDir.endsWith('/') && outDir !== '') outDir += '/';
94
+ if (!outDir.endsWith('/') && outDir !== '') {
95
+ outDir += '/';
96
+ }
91
97
 
92
98
  let features = null;
93
99
  if (opts.allFeatures) {
94
100
  features = { tag: 'all' };
95
101
  } else if (Array.isArray(opts.feature)) {
96
102
  features = { tag: 'list', val: opts.feature };
103
+ } else if (Array.isArray(opts.features)) {
104
+ features = { tag: 'list', val: opts.features };
97
105
  }
98
106
 
99
- if (opts.asyncWasiImports)
107
+ if (opts.asyncWasiImports) {
100
108
  opts.asyncImports = ASYNC_WASI_IMPORTS.concat(opts.asyncImports || []);
101
- if (opts.asyncWasiExports)
109
+ }
110
+ if (opts.asyncWasiExports) {
102
111
  opts.asyncExports = ASYNC_WASI_EXPORTS.concat(opts.asyncExports || []);
112
+ }
103
113
 
104
114
  const asyncMode =
105
115
  !opts.asyncMode || opts.asyncMode === 'sync'
@@ -165,7 +175,9 @@ async function writeFiles(files, summaryTitle) {
165
175
  await writeFile(name, file);
166
176
  })
167
177
  );
168
- if (!summaryTitle) return;
178
+ if (!summaryTitle) {
179
+ return;
180
+ }
169
181
  console.log(c`
170
182
  {bold ${summaryTitle}:}
171
183
 
@@ -177,39 +189,46 @@ ${table(
177
189
  )}`);
178
190
  }
179
191
 
180
- export async function transpile(componentPath, opts, program) {
192
+ export async function transpile(witPath, opts, program) {
181
193
  const varIdx = program?.parent.rawArgs.indexOf('--');
182
- if (varIdx !== undefined && varIdx !== -1)
194
+ if (varIdx !== undefined && varIdx !== -1) {
183
195
  opts.optArgs = program.parent.rawArgs.slice(varIdx + 1);
196
+ }
184
197
 
185
198
  let component;
186
199
  if (!opts.stub) {
187
- component = await readFile(componentPath);
200
+ component = await readFile(witPath);
188
201
  } else {
189
202
  await wasmToolsInit;
190
203
  component = componentNew(
191
204
  componentEmbed({
192
205
  dummy: true,
193
- witPath: (isWindows ? '//?/' : '') + resolve(componentPath),
206
+ witPath: (isWindows ? '//?/' : '') + resolve(witPath),
194
207
  }),
195
208
  []
196
209
  );
197
210
  }
198
211
 
199
- if (!opts.quiet) setShowSpinner(true);
200
- if (!opts.name)
212
+ if (!opts.quiet) {
213
+ setShowSpinner(true);
214
+ }
215
+ if (!opts.name) {
201
216
  opts.name = basename(
202
- componentPath.slice(0, -extname(componentPath).length || Infinity)
217
+ witPath.slice(0, -extname(witPath).length || Infinity)
203
218
  );
204
- if (opts.map)
219
+ }
220
+ if (opts.map) {
205
221
  opts.map = Object.fromEntries(
206
222
  opts.map.map((mapping) => mapping.split('='))
207
223
  );
224
+ }
208
225
 
209
- if (opts.asyncWasiImports)
226
+ if (opts.asyncWasiImports) {
210
227
  opts.asyncImports = ASYNC_WASI_IMPORTS.concat(opts.asyncImports || []);
211
- if (opts.asyncWasiExports)
228
+ }
229
+ if (opts.asyncWasiExports) {
212
230
  opts.asyncExports = ASYNC_WASI_EXPORTS.concat(opts.asyncExports || []);
231
+ }
213
232
 
214
233
  const { files } = await transpileComponent(component, opts);
215
234
  await writeFiles(
@@ -230,13 +249,16 @@ async function wasm2Js(source) {
230
249
  try {
231
250
  return await spawnIOTmp(wasm2jsPath, source, ['-Oz', '-o']);
232
251
  } catch (e) {
233
- if (e.toString().includes('BasicBlock requested'))
252
+ if (e.toString().includes('BasicBlock requested')) {
234
253
  return wasm2Js(source);
254
+ }
235
255
  throw e;
236
256
  }
237
257
  }
238
258
 
239
259
  /**
260
+ * Execute the bundled pre-transpiled component that can perform component transpilation,
261
+ * for the given component.
240
262
  *
241
263
  * @param {Uint8Array} component
242
264
  * @param {{
@@ -265,13 +287,17 @@ async function wasm2Js(source) {
265
287
  */
266
288
  export async function transpileComponent(component, opts = {}) {
267
289
  await $init;
268
- if (opts.instantiation) opts.wasiShim = false;
290
+ if (opts.instantiation) {
291
+ opts.wasiShim = false;
292
+ }
269
293
 
270
294
  let spinner;
271
295
  const showSpinner = getShowSpinner();
272
296
 
273
297
  if (opts.optimize) {
274
- if (showSpinner) setShowSpinner(true);
298
+ if (showSpinner) {
299
+ setShowSpinner(true);
300
+ }
275
301
  ({ component } = await optimizeComponent(component, opts));
276
302
  }
277
303
 
@@ -333,7 +359,9 @@ export async function transpileComponent(component, opts = {}) {
333
359
  });
334
360
 
335
361
  let outDir = (opts.outDir ?? '').replace(/\\/g, '/');
336
- if (!outDir.endsWith('/') && outDir !== '') outDir += '/';
362
+ if (!outDir.endsWith('/') && outDir !== '') {
363
+ outDir += '/';
364
+ }
337
365
  files = files.map(([name, source]) => [`${outDir}${name}`, source]);
338
366
 
339
367
  const jsFile = files.find(([name]) => name.endsWith('.js'));
@@ -583,7 +611,9 @@ ${autoInstantiate}`;
583
611
  // for imports to match up we must do the same
584
612
  // See https://github.com/WebAssembly/binaryen/blob/main/src/asmjs/asmangle.cpp
585
613
  function asmMangle(name) {
586
- if (name === '') return '$';
614
+ if (name === '') {
615
+ return '$';
616
+ }
587
617
 
588
618
  let mightBeKeyword = true;
589
619
  let i = 1;
@@ -657,11 +687,15 @@ function asmMangle(name) {
657
687
  if (mightBeKeyword && len >= 2 && len <= 10) {
658
688
  switch (name[0]) {
659
689
  case 'a': {
660
- if (name == 'arguments') return name + '_';
690
+ if (name == 'arguments') {
691
+ return name + '_';
692
+ }
661
693
  break;
662
694
  }
663
695
  case 'b': {
664
- if (name == 'break') return name + '_';
696
+ if (name == 'break') {
697
+ return name + '_';
698
+ }
665
699
  break;
666
700
  }
667
701
  case 'c': {
@@ -671,13 +705,15 @@ function asmMangle(name) {
671
705
  name == 'catch' ||
672
706
  name == 'const' ||
673
707
  name == 'class'
674
- )
708
+ ) {
675
709
  return name + '_';
710
+ }
676
711
  break;
677
712
  }
678
713
  case 'd': {
679
- if (name == 'do' || name == 'default' || name == 'debugger')
714
+ if (name == 'do' || name == 'default' || name == 'debugger') {
680
715
  return name + '_';
716
+ }
681
717
  break;
682
718
  }
683
719
  case 'e': {
@@ -687,8 +723,9 @@ function asmMangle(name) {
687
723
  name == 'eval' || // to be sure
688
724
  name == 'export' ||
689
725
  name == 'extends'
690
- )
726
+ ) {
691
727
  return name + '_';
728
+ }
692
729
  break;
693
730
  }
694
731
  case 'f': {
@@ -697,8 +734,9 @@ function asmMangle(name) {
697
734
  name == 'false' ||
698
735
  name == 'finally' ||
699
736
  name == 'function'
700
- )
737
+ ) {
701
738
  return name + '_';
739
+ }
702
740
  break;
703
741
  }
704
742
  case 'i': {
@@ -709,16 +747,21 @@ function asmMangle(name) {
709
747
  name == 'interface' ||
710
748
  name == 'implements' ||
711
749
  name == 'instanceof'
712
- )
750
+ ) {
713
751
  return name + '_';
752
+ }
714
753
  break;
715
754
  }
716
755
  case 'l': {
717
- if (name == 'let') return name + '_';
756
+ if (name == 'let') {
757
+ return name + '_';
758
+ }
718
759
  break;
719
760
  }
720
761
  case 'n': {
721
- if (name == 'new' || name == 'null') return name + '_';
762
+ if (name == 'new' || name == 'null') {
763
+ return name + '_';
764
+ }
722
765
  break;
723
766
  }
724
767
  case 'p': {
@@ -727,17 +770,21 @@ function asmMangle(name) {
727
770
  name == 'package' ||
728
771
  name == 'private' ||
729
772
  name == 'protected'
730
- )
773
+ ) {
731
774
  return name + '_';
775
+ }
732
776
  break;
733
777
  }
734
778
  case 'r': {
735
- if (name == 'return') return name + '_';
779
+ if (name == 'return') {
780
+ return name + '_';
781
+ }
736
782
  break;
737
783
  }
738
784
  case 's': {
739
- if (name == 'super' || name == 'static' || name == 'switch')
785
+ if (name == 'super' || name == 'static' || name == 'switch') {
740
786
  return name + '_';
787
+ }
741
788
  break;
742
789
  }
743
790
  case 't': {
@@ -747,20 +794,27 @@ function asmMangle(name) {
747
794
  name == 'true' ||
748
795
  name == 'throw' ||
749
796
  name == 'typeof'
750
- )
797
+ ) {
751
798
  return name + '_';
799
+ }
752
800
  break;
753
801
  }
754
802
  case 'v': {
755
- if (name == 'var' || name == 'void') return name + '_';
803
+ if (name == 'var' || name == 'void') {
804
+ return name + '_';
805
+ }
756
806
  break;
757
807
  }
758
808
  case 'w': {
759
- if (name == 'with' || name == 'while') return name + '_';
809
+ if (name == 'with' || name == 'while') {
810
+ return name + '_';
811
+ }
760
812
  break;
761
813
  }
762
814
  case 'y': {
763
- if (name == 'yield') return name + '_';
815
+ if (name == 'yield') {
816
+ return name + '_';
817
+ }
764
818
  break;
765
819
  }
766
820
  }
@@ -1 +1 @@
1
- {"version":3,"file":"wasm-tools.d.ts","sourceRoot":"","sources":["wasm-tools.js"],"names":[],"mappings":"AAeA,2DAKC;AAED,2DASC;AAED,kEASC;AAED,kEAoDC;AAED,oEAaC;AAED,iEAUC;AAED,kEA8BC"}
1
+ {"version":3,"file":"wasm-tools.d.ts","sourceRoot":"","sources":["wasm-tools.js"],"names":[],"mappings":"AAOA,2DAKC;AAED,2DASC;AAED,kEASC;AAED,kEAsBC;AAED,oEAaC;AAED,iEAUC;AAED,kEAiCC"}