@wasm-fmt/gofmt 0.4.5 → 0.4.7
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/gofmt.d.ts +2 -1
- package/gofmt.js +50 -51
- package/gofmt.wasm +0 -0
- package/gofmt_node.js +10 -0
- package/{vite.js → gofmt_vite.js} +2 -2
- package/package.json +3 -2
- package/go.mod +0 -3
package/gofmt.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export type InitInput =
|
|
|
5
5
|
| BufferSource
|
|
6
6
|
| WebAssembly.Module;
|
|
7
7
|
|
|
8
|
-
export default function
|
|
8
|
+
export default function initAsync(wasm_url?: InitInput): Promise<void>;
|
|
9
|
+
export declare function initSync(module: BufferSource | WebAssembly.Module): void;
|
|
9
10
|
export declare function format(input: string): string;
|
package/gofmt.js
CHANGED
|
@@ -287,65 +287,64 @@
|
|
|
287
287
|
* ================== End of wasm_exec.js ==================
|
|
288
288
|
*/
|
|
289
289
|
/**/let wasm;
|
|
290
|
-
/**/
|
|
291
|
-
/**/ if (wasm) {
|
|
292
|
-
/**/ await wasm;
|
|
293
|
-
/**/ return;
|
|
294
|
-
/**/ }
|
|
295
|
-
/**/ const go = new Go();
|
|
296
|
-
/**/ wasm = load(input, go.importObject);
|
|
297
|
-
/**/ wasm = await wasm;
|
|
298
|
-
/**/ go.run(wasm.instance);
|
|
299
|
-
/**/}
|
|
300
|
-
/**/
|
|
301
|
-
/**/async function load(module, importObject) {
|
|
302
|
-
/**/ switch (typeof module) {
|
|
303
|
-
/**/ case "undefined":
|
|
304
|
-
/**/ module = "gofmt.wasm";
|
|
305
|
-
/**/ case "string":
|
|
306
|
-
/**/ module = new URL(module, import.meta.url);
|
|
307
|
-
/**/ }
|
|
308
|
-
/**/ if (module instanceof URL || module instanceof Request) {
|
|
309
|
-
/**/ if (
|
|
310
|
-
/**/ typeof __webpack_require__ !== "function" &&
|
|
311
|
-
/**/ module.protocol === "file:"
|
|
312
|
-
/**/ ) {
|
|
313
|
-
/**/ const fs = await import("node:fs/promises");
|
|
314
|
-
/**/ module = await fs.readFile(module);
|
|
315
|
-
/**/ } else {
|
|
316
|
-
/**/ module = await fetch(module);
|
|
317
|
-
/**/ }
|
|
318
|
-
/**/ }
|
|
290
|
+
/**/async function __load(module, imports) {
|
|
319
291
|
/**/ if (typeof Response === 'function' && module instanceof Response) {
|
|
320
|
-
/**/ if (
|
|
321
|
-
/**/ try {
|
|
322
|
-
/**/
|
|
323
|
-
/**/
|
|
324
|
-
/**/
|
|
325
|
-
/**/
|
|
326
|
-
/**/ } catch (e) {
|
|
327
|
-
/**/ if (module.headers.get("Content-Type") != "application/wasm") {
|
|
328
|
-
/**/ console.warn(
|
|
329
|
-
/**/ "`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",
|
|
330
|
-
/**/ e
|
|
331
|
-
/**/ );
|
|
332
|
-
/**/ } else {
|
|
333
|
-
/**/ throw e;
|
|
334
|
-
/**/ }
|
|
292
|
+
/**/ if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
293
|
+
/**/ try { return await WebAssembly.instantiateStreaming(module, imports); }
|
|
294
|
+
/**/ catch (e) {
|
|
295
|
+
/**/ if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
296
|
+
/**/ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
297
|
+
/**/ } else { throw e; }
|
|
335
298
|
/**/ }
|
|
336
299
|
/**/ }
|
|
337
300
|
/**/ const bytes = await module.arrayBuffer();
|
|
338
|
-
/**/ return await WebAssembly.instantiate(bytes,
|
|
301
|
+
/**/ return await WebAssembly.instantiate(bytes, imports);
|
|
302
|
+
/**/ } else {
|
|
303
|
+
/**/ const instance = await WebAssembly.instantiate(module, imports);
|
|
304
|
+
/**/ if (instance instanceof WebAssembly.Instance) return { instance, module };
|
|
305
|
+
/**/ else return instance;
|
|
339
306
|
/**/ }
|
|
340
|
-
/**/ const instance = await WebAssembly.instantiate(module, importObject);
|
|
341
|
-
/**/ if (instance instanceof WebAssembly.Instance) {
|
|
342
|
-
/**/ return { instance, module };
|
|
343
|
-
/**/ }
|
|
344
|
-
/**/ return instance;
|
|
345
307
|
/**/}
|
|
308
|
+
/**/function __finalize_init(instance) {
|
|
309
|
+
/**/ return wasm = instance;
|
|
310
|
+
/**/}
|
|
311
|
+
/**/function __init_memory(imports, maybe_memory) { }
|
|
312
|
+
/**/export function initSync(module) {
|
|
313
|
+
/**/ if (wasm !== undefined) return wasm;
|
|
314
|
+
/**/
|
|
315
|
+
/**/ const go = new Go;
|
|
316
|
+
/**/ const imports = go.importObject;
|
|
317
|
+
/**/
|
|
318
|
+
/**/ __init_memory(imports);
|
|
319
|
+
/**/
|
|
320
|
+
/**/ if (!(module instanceof WebAssembly.Module)) module = new WebAssembly.Module(module);
|
|
346
321
|
/**/
|
|
322
|
+
/**/ const instance = new WebAssembly.Instance(module, imports);
|
|
323
|
+
/**/
|
|
324
|
+
/**/ go.run(instance);
|
|
325
|
+
/**/ return __finalize_init(instance, module);
|
|
326
|
+
/**/}
|
|
327
|
+
/**/export default async function initAsync(input) {
|
|
328
|
+
/**/ if (wasm !== undefined) return wasm;
|
|
329
|
+
/**/
|
|
330
|
+
/**/ if (typeof input === 'undefined') input = new URL('gofmt.wasm', import.meta.url);
|
|
331
|
+
/**/
|
|
332
|
+
/**/ const go = new Go;
|
|
333
|
+
/**/ const imports = go.importObject;
|
|
334
|
+
/**/
|
|
335
|
+
/**/ if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
|
|
336
|
+
/**/ input = fetch(input);
|
|
337
|
+
/**/ }
|
|
338
|
+
/**/
|
|
339
|
+
/**/ __init_memory(imports);
|
|
340
|
+
/**/
|
|
341
|
+
/**/ const { instance, module } = await __load(await input, imports);
|
|
342
|
+
/**/
|
|
343
|
+
/**/ go.run(instance);
|
|
344
|
+
/**/ return __finalize_init(instance, module);
|
|
345
|
+
/**/}
|
|
347
346
|
/**/export function format(input) {
|
|
348
|
-
/**/ const [err, result] = wasm.
|
|
347
|
+
/**/ const [err, result] = wasm.format(input);
|
|
349
348
|
/**/ if (err) {
|
|
350
349
|
/**/ throw new Error(result);
|
|
351
350
|
/**/ }
|
package/gofmt.wasm
CHANGED
|
Binary file
|
package/gofmt_node.js
ADDED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@wasm-fmt/gofmt",
|
|
3
3
|
"description": "A wasm based golang formatter",
|
|
4
4
|
"author": "magic-akari <akari.ccino@gamil.com>",
|
|
5
|
-
"version": "0.4.
|
|
5
|
+
"version": "0.4.7",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"wasm",
|
|
@@ -24,11 +24,12 @@
|
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
26
|
"types": "./gofmt.d.ts",
|
|
27
|
+
"node": "./gofmt_node.js",
|
|
27
28
|
"default": "./gofmt.js"
|
|
28
29
|
},
|
|
29
30
|
"./vite": {
|
|
30
31
|
"types": "./gofmt.d.ts",
|
|
31
|
-
"default": "./
|
|
32
|
+
"default": "./gofmt_vite.js"
|
|
32
33
|
},
|
|
33
34
|
"./package.json": "./package.json",
|
|
34
35
|
"./*": "./*"
|
package/go.mod
DELETED