@wasm-fmt/mago_fmt 0.3.1 → 0.4.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/mago_fmt_bg.js ADDED
@@ -0,0 +1,437 @@
1
+ let wasm;
2
+ export function __wbg_set_wasm(val) {
3
+ wasm = val;
4
+ }
5
+
6
+ function addHeapObject(obj) {
7
+ if (heap_next === heap.length) heap.push(heap.length + 1);
8
+ const idx = heap_next;
9
+ heap_next = heap[idx];
10
+
11
+ heap[idx] = obj;
12
+ return idx;
13
+ }
14
+
15
+ function debugString(val) {
16
+ // primitive types
17
+ const type = typeof val;
18
+ if (type == 'number' || type == 'boolean' || val == null) {
19
+ return `${val}`;
20
+ }
21
+ if (type == 'string') {
22
+ return `"${val}"`;
23
+ }
24
+ if (type == 'symbol') {
25
+ const description = val.description;
26
+ if (description == null) {
27
+ return 'Symbol';
28
+ } else {
29
+ return `Symbol(${description})`;
30
+ }
31
+ }
32
+ if (type == 'function') {
33
+ const name = val.name;
34
+ if (typeof name == 'string' && name.length > 0) {
35
+ return `Function(${name})`;
36
+ } else {
37
+ return 'Function';
38
+ }
39
+ }
40
+ // objects
41
+ if (Array.isArray(val)) {
42
+ const length = val.length;
43
+ let debug = '[';
44
+ if (length > 0) {
45
+ debug += debugString(val[0]);
46
+ }
47
+ for(let i = 1; i < length; i++) {
48
+ debug += ', ' + debugString(val[i]);
49
+ }
50
+ debug += ']';
51
+ return debug;
52
+ }
53
+ // Test for built-in
54
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
55
+ let className;
56
+ if (builtInMatches && builtInMatches.length > 1) {
57
+ className = builtInMatches[1];
58
+ } else {
59
+ // Failed to match the standard '[object ClassName]'
60
+ return toString.call(val);
61
+ }
62
+ if (className == 'Object') {
63
+ // we're a user defined class or Object
64
+ // JSON.stringify avoids problems with cycles, and is generally much
65
+ // easier than looping through ownProperties of `val`.
66
+ try {
67
+ return 'Object(' + JSON.stringify(val) + ')';
68
+ } catch (_) {
69
+ return 'Object';
70
+ }
71
+ }
72
+ // errors
73
+ if (val instanceof Error) {
74
+ return `${val.name}: ${val.message}\n${val.stack}`;
75
+ }
76
+ // TODO we could test for more things here, like `Set`s and `Map`s.
77
+ return className;
78
+ }
79
+
80
+ function dropObject(idx) {
81
+ if (idx < 132) return;
82
+ heap[idx] = heap_next;
83
+ heap_next = idx;
84
+ }
85
+
86
+ function getArrayU8FromWasm0(ptr, len) {
87
+ ptr = ptr >>> 0;
88
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
89
+ }
90
+
91
+ let cachedDataViewMemory0 = null;
92
+ function getDataViewMemory0() {
93
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
94
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
95
+ }
96
+ return cachedDataViewMemory0;
97
+ }
98
+
99
+ function getStringFromWasm0(ptr, len) {
100
+ ptr = ptr >>> 0;
101
+ return decodeText(ptr, len);
102
+ }
103
+
104
+ let cachedUint8ArrayMemory0 = null;
105
+ function getUint8ArrayMemory0() {
106
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
107
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
108
+ }
109
+ return cachedUint8ArrayMemory0;
110
+ }
111
+
112
+ function getObject(idx) { return heap[idx]; }
113
+
114
+ let heap = new Array(128).fill(undefined);
115
+ heap.push(undefined, null, true, false);
116
+
117
+ let heap_next = heap.length;
118
+
119
+ function isLikeNone(x) {
120
+ return x === undefined || x === null;
121
+ }
122
+
123
+ function passStringToWasm0(arg, malloc, realloc) {
124
+ if (realloc === undefined) {
125
+ const buf = cachedTextEncoder.encode(arg);
126
+ const ptr = malloc(buf.length, 1) >>> 0;
127
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
128
+ WASM_VECTOR_LEN = buf.length;
129
+ return ptr;
130
+ }
131
+
132
+ let len = arg.length;
133
+ let ptr = malloc(len, 1) >>> 0;
134
+
135
+ const mem = getUint8ArrayMemory0();
136
+
137
+ let offset = 0;
138
+
139
+ for (; offset < len; offset++) {
140
+ const code = arg.charCodeAt(offset);
141
+ if (code > 0x7F) break;
142
+ mem[ptr + offset] = code;
143
+ }
144
+ if (offset !== len) {
145
+ if (offset !== 0) {
146
+ arg = arg.slice(offset);
147
+ }
148
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
149
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
150
+ const ret = cachedTextEncoder.encodeInto(arg, view);
151
+
152
+ offset += ret.written;
153
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
154
+ }
155
+
156
+ WASM_VECTOR_LEN = offset;
157
+ return ptr;
158
+ }
159
+
160
+ function takeObject(idx) {
161
+ const ret = getObject(idx);
162
+ dropObject(idx);
163
+ return ret;
164
+ }
165
+
166
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
167
+ cachedTextDecoder.decode();
168
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
169
+ let numBytesDecoded = 0;
170
+ function decodeText(ptr, len) {
171
+ numBytesDecoded += len;
172
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
173
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
174
+ cachedTextDecoder.decode();
175
+ numBytesDecoded = len;
176
+ }
177
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
178
+ }
179
+
180
+ const cachedTextEncoder = new TextEncoder();
181
+
182
+ if (!('encodeInto' in cachedTextEncoder)) {
183
+ cachedTextEncoder.encodeInto = function (arg, view) {
184
+ const buf = cachedTextEncoder.encode(arg);
185
+ view.set(buf);
186
+ return {
187
+ read: arg.length,
188
+ written: buf.length
189
+ };
190
+ }
191
+ }
192
+
193
+ let WASM_VECTOR_LEN = 0;
194
+
195
+ /**
196
+ * Format PHP code with optional filename and settings.
197
+ * @param {string} code - PHP code to format
198
+ * @param {string | null} [filename] - Optional filename for context
199
+ * @param {Settings | null} [settings] - Optional formatter settings
200
+ * @returns {string}
201
+ */
202
+ export function format(code, filename, settings) {
203
+ let deferred4_0;
204
+ let deferred4_1;
205
+ try {
206
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
207
+ const ptr0 = passStringToWasm0(code, wasm.__wbindgen_export, wasm.__wbindgen_export2);
208
+ const len0 = WASM_VECTOR_LEN;
209
+ var ptr1 = isLikeNone(filename) ? 0 : passStringToWasm0(filename, wasm.__wbindgen_export, wasm.__wbindgen_export2);
210
+ var len1 = WASM_VECTOR_LEN;
211
+ wasm.format(retptr, ptr0, len0, ptr1, len1, isLikeNone(settings) ? 0 : addHeapObject(settings));
212
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
213
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
214
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
215
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
216
+ var ptr3 = r0;
217
+ var len3 = r1;
218
+ if (r3) {
219
+ ptr3 = 0; len3 = 0;
220
+ throw takeObject(r2);
221
+ }
222
+ deferred4_0 = ptr3;
223
+ deferred4_1 = len3;
224
+ return getStringFromWasm0(ptr3, len3);
225
+ } finally {
226
+ wasm.__wbindgen_add_to_stack_pointer(16);
227
+ wasm.__wbindgen_export3(deferred4_0, deferred4_1, 1);
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Format PHP code with specified PHP version, optional filename and settings.
233
+ * @param {string} code - PHP code to format
234
+ * @param {string} php_version - PHP version (e.g., '7.4', '8.0', '8.1')
235
+ * @param {string | null} [filename] - Optional filename for context
236
+ * @param {Settings | null} [settings] - Optional formatter settings
237
+ * @returns {string}
238
+ */
239
+ export function format_with_version(code, php_version, filename, settings) {
240
+ let deferred5_0;
241
+ let deferred5_1;
242
+ try {
243
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
244
+ const ptr0 = passStringToWasm0(code, wasm.__wbindgen_export, wasm.__wbindgen_export2);
245
+ const len0 = WASM_VECTOR_LEN;
246
+ const ptr1 = passStringToWasm0(php_version, wasm.__wbindgen_export, wasm.__wbindgen_export2);
247
+ const len1 = WASM_VECTOR_LEN;
248
+ var ptr2 = isLikeNone(filename) ? 0 : passStringToWasm0(filename, wasm.__wbindgen_export, wasm.__wbindgen_export2);
249
+ var len2 = WASM_VECTOR_LEN;
250
+ wasm.format_with_version(retptr, ptr0, len0, ptr1, len1, ptr2, len2, isLikeNone(settings) ? 0 : addHeapObject(settings));
251
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
252
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
253
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
254
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
255
+ var ptr4 = r0;
256
+ var len4 = r1;
257
+ if (r3) {
258
+ ptr4 = 0; len4 = 0;
259
+ throw takeObject(r2);
260
+ }
261
+ deferred5_0 = ptr4;
262
+ deferred5_1 = len4;
263
+ return getStringFromWasm0(ptr4, len4);
264
+ } finally {
265
+ wasm.__wbindgen_add_to_stack_pointer(16);
266
+ wasm.__wbindgen_export3(deferred5_0, deferred5_1, 1);
267
+ }
268
+ }
269
+
270
+ export function __wbg_Error_52673b7de5a0ca89(arg0, arg1) {
271
+ const ret = Error(getStringFromWasm0(arg0, arg1));
272
+ return addHeapObject(ret);
273
+ };
274
+
275
+ export function __wbg_Number_2d1dcfcf4ec51736(arg0) {
276
+ const ret = Number(getObject(arg0));
277
+ return ret;
278
+ };
279
+
280
+ export function __wbg___wbindgen_bigint_get_as_i64_6e32f5e6aff02e1d(arg0, arg1) {
281
+ const v = getObject(arg1);
282
+ const ret = typeof(v) === 'bigint' ? v : undefined;
283
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
284
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
285
+ };
286
+
287
+ export function __wbg___wbindgen_boolean_get_dea25b33882b895b(arg0) {
288
+ const v = getObject(arg0);
289
+ const ret = typeof(v) === 'boolean' ? v : undefined;
290
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
291
+ };
292
+
293
+ export function __wbg___wbindgen_debug_string_adfb662ae34724b6(arg0, arg1) {
294
+ const ret = debugString(getObject(arg1));
295
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
296
+ const len1 = WASM_VECTOR_LEN;
297
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
298
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
299
+ };
300
+
301
+ export function __wbg___wbindgen_in_0d3e1e8f0c669317(arg0, arg1) {
302
+ const ret = getObject(arg0) in getObject(arg1);
303
+ return ret;
304
+ };
305
+
306
+ export function __wbg___wbindgen_is_bigint_0e1a2e3f55cfae27(arg0) {
307
+ const ret = typeof(getObject(arg0)) === 'bigint';
308
+ return ret;
309
+ };
310
+
311
+ export function __wbg___wbindgen_is_object_ce774f3490692386(arg0) {
312
+ const val = getObject(arg0);
313
+ const ret = typeof(val) === 'object' && val !== null;
314
+ return ret;
315
+ };
316
+
317
+ export function __wbg___wbindgen_is_string_704ef9c8fc131030(arg0) {
318
+ const ret = typeof(getObject(arg0)) === 'string';
319
+ return ret;
320
+ };
321
+
322
+ export function __wbg___wbindgen_is_undefined_f6b95eab589e0269(arg0) {
323
+ const ret = getObject(arg0) === undefined;
324
+ return ret;
325
+ };
326
+
327
+ export function __wbg___wbindgen_jsval_eq_b6101cc9cef1fe36(arg0, arg1) {
328
+ const ret = getObject(arg0) === getObject(arg1);
329
+ return ret;
330
+ };
331
+
332
+ export function __wbg___wbindgen_jsval_loose_eq_766057600fdd1b0d(arg0, arg1) {
333
+ const ret = getObject(arg0) == getObject(arg1);
334
+ return ret;
335
+ };
336
+
337
+ export function __wbg___wbindgen_number_get_9619185a74197f95(arg0, arg1) {
338
+ const obj = getObject(arg1);
339
+ const ret = typeof(obj) === 'number' ? obj : undefined;
340
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
341
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
342
+ };
343
+
344
+ export function __wbg___wbindgen_string_get_a2a31e16edf96e42(arg0, arg1) {
345
+ const obj = getObject(arg1);
346
+ const ret = typeof(obj) === 'string' ? obj : undefined;
347
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
348
+ var len1 = WASM_VECTOR_LEN;
349
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
350
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
351
+ };
352
+
353
+ export function __wbg___wbindgen_throw_dd24417ed36fc46e(arg0, arg1) {
354
+ throw new Error(getStringFromWasm0(arg0, arg1));
355
+ };
356
+
357
+ export function __wbg_entries_83c79938054e065f(arg0) {
358
+ const ret = Object.entries(getObject(arg0));
359
+ return addHeapObject(ret);
360
+ };
361
+
362
+ export function __wbg_get_6b7bd52aca3f9671(arg0, arg1) {
363
+ const ret = getObject(arg0)[arg1 >>> 0];
364
+ return addHeapObject(ret);
365
+ };
366
+
367
+ export function __wbg_get_with_ref_key_1dc361bd10053bfe(arg0, arg1) {
368
+ const ret = getObject(arg0)[getObject(arg1)];
369
+ return addHeapObject(ret);
370
+ };
371
+
372
+ export function __wbg_instanceof_ArrayBuffer_f3320d2419cd0355(arg0) {
373
+ let result;
374
+ try {
375
+ result = getObject(arg0) instanceof ArrayBuffer;
376
+ } catch (_) {
377
+ result = false;
378
+ }
379
+ const ret = result;
380
+ return ret;
381
+ };
382
+
383
+ export function __wbg_instanceof_Uint8Array_da54ccc9d3e09434(arg0) {
384
+ let result;
385
+ try {
386
+ result = getObject(arg0) instanceof Uint8Array;
387
+ } catch (_) {
388
+ result = false;
389
+ }
390
+ const ret = result;
391
+ return ret;
392
+ };
393
+
394
+ export function __wbg_isSafeInteger_ae7d3f054d55fa16(arg0) {
395
+ const ret = Number.isSafeInteger(getObject(arg0));
396
+ return ret;
397
+ };
398
+
399
+ export function __wbg_length_22ac23eaec9d8053(arg0) {
400
+ const ret = getObject(arg0).length;
401
+ return ret;
402
+ };
403
+
404
+ export function __wbg_length_d45040a40c570362(arg0) {
405
+ const ret = getObject(arg0).length;
406
+ return ret;
407
+ };
408
+
409
+ export function __wbg_new_6421f6084cc5bc5a(arg0) {
410
+ const ret = new Uint8Array(getObject(arg0));
411
+ return addHeapObject(ret);
412
+ };
413
+
414
+ export function __wbg_prototypesetcall_dfe9b766cdc1f1fd(arg0, arg1, arg2) {
415
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
416
+ };
417
+
418
+ export function __wbindgen_cast_2241b6af4c4b2941(arg0, arg1) {
419
+ // Cast intrinsic for `Ref(String) -> Externref`.
420
+ const ret = getStringFromWasm0(arg0, arg1);
421
+ return addHeapObject(ret);
422
+ };
423
+
424
+ export function __wbindgen_cast_4625c577ab2ec9ee(arg0) {
425
+ // Cast intrinsic for `U64 -> Externref`.
426
+ const ret = BigInt.asUintN(64, arg0);
427
+ return addHeapObject(ret);
428
+ };
429
+
430
+ export function __wbindgen_object_clone_ref(arg0) {
431
+ const ret = getObject(arg0);
432
+ return addHeapObject(ret);
433
+ };
434
+
435
+ export function __wbindgen_object_drop_ref(arg0) {
436
+ takeObject(arg0);
437
+ };
package/mago_fmt_bg.wasm CHANGED
Binary file
@@ -0,0 +1,27 @@
1
+ /* @ts-self-types="./mago_fmt.d.ts" */
2
+ // prettier-ignore
3
+ import source wasmModule from "./mago_fmt_bg.wasm";
4
+
5
+ import * as import_bg from "./mago_fmt_bg.js";
6
+ const { __wbg_set_wasm, format, format_with_version, ...wasmImport } = import_bg;
7
+
8
+ function getImports() {
9
+ return {
10
+ __proto__: null,
11
+ "./mago_fmt_bg.js": wasmImport,
12
+ };
13
+ }
14
+
15
+ const instance = new WebAssembly.Instance(wasmModule, getImports());
16
+
17
+ /**
18
+ * @import * as WASM from "./mago_fmt_bg.wasm"
19
+ */
20
+
21
+ /**
22
+ * @type {WASM}
23
+ */
24
+ const wasm = instance.exports;
25
+ __wbg_set_wasm(wasm);
26
+
27
+ export { format, format_with_version };
package/mago_fmt_node.js CHANGED
@@ -1,12 +1,29 @@
1
- import fs from "node:fs/promises";
2
- import initAsync from "./mago_fmt.js";
1
+ /* @ts-self-types="./mago_fmt.d.ts" */
2
+ import { readFileSync } from "node:fs";
3
+ import * as import_bg from "./mago_fmt_bg.js";
4
+ const { format, format_with_version, __wbg_set_wasm, ...wasmImport } = import_bg;
3
5
 
4
- const wasm = new URL("./mago_fmt_bg.wasm", import.meta.url);
6
+ const wasmUrl = new URL("mago_fmt_bg.wasm", import.meta.url);
7
+ const wasmBytes = readFileSync(wasmUrl);
8
+ const wasmModule = new WebAssembly.Module(wasmBytes);
5
9
 
6
- export default function __wbg_init(
7
- init = { module_or_path: fs.readFile(wasm) },
8
- ) {
9
- return initAsync(init);
10
+ function getImports() {
11
+ return {
12
+ __proto__: null,
13
+ "./mago_fmt_bg.js": wasmImport,
14
+ };
10
15
  }
11
16
 
12
- export * from "./mago_fmt.js";
17
+ /**
18
+ * @import * as WASM from "./mago_fmt.wasm"
19
+ */
20
+
21
+ const instance = new WebAssembly.Instance(wasmModule, getImports());
22
+
23
+ /**
24
+ * @type {WASM}
25
+ */
26
+ const wasm = instance.exports;
27
+ __wbg_set_wasm(wasm);
28
+
29
+ export { format, format_with_version };