@volynets/reflex-store 0.0.0-stage → 0.0.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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +239 -2
  3. package/SPECIFICATION.md +137 -0
  4. package/dist/advanced.d.ts +13 -0
  5. package/dist/advanced.js +9 -0
  6. package/dist/chunks/compiler-CW_P8WsZ.js +2526 -0
  7. package/dist/chunks/createStore-DHj16Ehk.js +12 -0
  8. package/dist/chunks/hydrate-Bdtl9XyA.js +137 -0
  9. package/dist/chunks/keyed-C-QvvUv4.js +647 -0
  10. package/dist/chunks/names-BF36AyM3.js +11 -0
  11. package/dist/chunks/shared-BHHficW8.js +202 -0
  12. package/dist/compiled-store.d.ts +4 -0
  13. package/dist/compiled-store.js +4 -0
  14. package/dist/compiler/swc.wasm +0 -0
  15. package/dist/index.d.ts +23 -0
  16. package/dist/index.js +7 -0
  17. package/dist/licenses/NOTICE.txt +1 -0
  18. package/dist/licenses/SWC-APACHE-2.0.txt +202 -0
  19. package/dist/runtime/core.d.ts +2 -0
  20. package/dist/runtime/core.js +1 -0
  21. package/dist/runtime/internal.d.ts +3 -0
  22. package/dist/runtime/internal.js +41 -0
  23. package/dist/runtime/types.d.ts +45 -0
  24. package/dist/runtime/types.js +1 -0
  25. package/dist/runtime.d.ts +25 -0
  26. package/dist/runtime.js +78 -0
  27. package/dist/selectors/index.d.ts +13 -0
  28. package/dist/selectors/index.js +15 -0
  29. package/dist/selectors/shared.d.ts +3 -0
  30. package/dist/selectors/shared.js +2 -0
  31. package/dist/store.d.ts +9 -0
  32. package/dist/store.js +4 -0
  33. package/dist/types/contracts-BCsRPdQb.d.ts +78 -0
  34. package/dist/types/createStore-BJ66-pfq.d.ts +43 -0
  35. package/dist/types/internal-BIzJSPwN.d.ts +18 -0
  36. package/dist/types/keyed-CdSYzIOc.d.ts +18 -0
  37. package/dist/types/shared-CdTKzvLe.d.ts +114 -0
  38. package/dist/vite.d.ts +68 -0
  39. package/dist/vite.js +87 -0
  40. package/examples/task-board/README.md +15 -0
  41. package/examples/task-board/src/task-board.ts +159 -0
  42. package/examples/task-board/vite.config.ts +6 -0
  43. package/package.json +125 -4
  44. package/src/store/README.md +59 -0
  45. package/src/store/TRANSFORM_SPEC.md +85 -0
@@ -0,0 +1,2526 @@
1
+ import require$$0 from 'util';
2
+ import require$$1 from 'fs';
3
+
4
+ class CompiledStoreTransformError extends Error {
5
+ constructor(diagnostics){
6
+ super(diagnostics.map((diagnostic)=>diagnostic.message).join("\n"));
7
+ this.name = "CompiledStoreTransformError";
8
+ this.diagnostics = diagnostics;
9
+ }
10
+ }
11
+
12
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
13
+
14
+ var wasm = {exports: {}};
15
+
16
+ wasm.exports;
17
+
18
+ var hasRequiredWasm;
19
+
20
+ function requireWasm () {
21
+ if (hasRequiredWasm) return wasm.exports;
22
+ hasRequiredWasm = 1;
23
+ (function (module) {
24
+ let imports = {};
25
+ imports['__wbindgen_placeholder__'] = module.exports;
26
+ let wasm;
27
+ const { TextEncoder, TextDecoder } = require$$0;
28
+ const heap = new Array(128).fill(undefined);
29
+ heap.push(undefined, null, true, false);
30
+ function getObject(idx) {
31
+ return heap[idx];
32
+ }
33
+ let WASM_VECTOR_LEN = 0;
34
+ let cachedUint8ArrayMemory0 = null;
35
+ function getUint8ArrayMemory0() {
36
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
37
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
38
+ }
39
+ return cachedUint8ArrayMemory0;
40
+ }
41
+ let cachedTextEncoder = new TextEncoder('utf-8');
42
+ const encodeString = typeof cachedTextEncoder.encodeInto === 'function' ? function(arg, view) {
43
+ return cachedTextEncoder.encodeInto(arg, view);
44
+ } : function(arg, view) {
45
+ const buf = cachedTextEncoder.encode(arg);
46
+ view.set(buf);
47
+ return {
48
+ read: arg.length,
49
+ written: buf.length
50
+ };
51
+ };
52
+ function passStringToWasm0(arg, malloc, realloc) {
53
+ if (realloc === undefined) {
54
+ const buf = cachedTextEncoder.encode(arg);
55
+ const ptr = malloc(buf.length, 1) >>> 0;
56
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
57
+ WASM_VECTOR_LEN = buf.length;
58
+ return ptr;
59
+ }
60
+ let len = arg.length;
61
+ let ptr = malloc(len, 1) >>> 0;
62
+ const mem = getUint8ArrayMemory0();
63
+ let offset = 0;
64
+ for(; offset < len; offset++){
65
+ const code = arg.charCodeAt(offset);
66
+ if (code > 0x7F) break;
67
+ mem[ptr + offset] = code;
68
+ }
69
+ if (offset !== len) {
70
+ if (offset !== 0) {
71
+ arg = arg.slice(offset);
72
+ }
73
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
74
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
75
+ const ret = encodeString(arg, view);
76
+ offset += ret.written;
77
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
78
+ }
79
+ WASM_VECTOR_LEN = offset;
80
+ return ptr;
81
+ }
82
+ let cachedDataViewMemory0 = null;
83
+ function getDataViewMemory0() {
84
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
85
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
86
+ }
87
+ return cachedDataViewMemory0;
88
+ }
89
+ let heap_next = heap.length;
90
+ function addHeapObject(obj) {
91
+ if (heap_next === heap.length) heap.push(heap.length + 1);
92
+ const idx = heap_next;
93
+ heap_next = heap[idx];
94
+ heap[idx] = obj;
95
+ return idx;
96
+ }
97
+ function handleError(f, args) {
98
+ try {
99
+ return f.apply(this, args);
100
+ } catch (e) {
101
+ wasm.__wbindgen_export_2(addHeapObject(e));
102
+ }
103
+ }
104
+ let cachedTextDecoder = new TextDecoder('utf-8', {
105
+ ignoreBOM: true,
106
+ fatal: true
107
+ });
108
+ cachedTextDecoder.decode();
109
+ function getStringFromWasm0(ptr, len) {
110
+ ptr = ptr >>> 0;
111
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
112
+ }
113
+ function getCachedStringFromWasm0(ptr, len) {
114
+ if (ptr === 0) {
115
+ return getObject(len);
116
+ } else {
117
+ return getStringFromWasm0(ptr, len);
118
+ }
119
+ }
120
+ function getArrayU8FromWasm0(ptr, len) {
121
+ ptr = ptr >>> 0;
122
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
123
+ }
124
+ function dropObject(idx) {
125
+ if (idx < 132) return;
126
+ heap[idx] = heap_next;
127
+ heap_next = idx;
128
+ }
129
+ function takeObject(idx) {
130
+ const ret = getObject(idx);
131
+ dropObject(idx);
132
+ return ret;
133
+ }
134
+ function isLikeNone(x) {
135
+ return x === undefined || x === null;
136
+ }
137
+ const CLOSURE_DTORS = typeof FinalizationRegistry === 'undefined' ? {
138
+ register: ()=>{},
139
+ unregister: ()=>{}
140
+ } : new FinalizationRegistry((state)=>{
141
+ wasm.__wbindgen_export_4.get(state.dtor)(state.a, state.b);
142
+ });
143
+ function makeMutClosure(arg0, arg1, dtor, f) {
144
+ const state = {
145
+ a: arg0,
146
+ b: arg1,
147
+ cnt: 1,
148
+ dtor
149
+ };
150
+ const real = (...args)=>{
151
+ // First up with a closure we increment the internal reference
152
+ // count. This ensures that the Rust closure environment won't
153
+ // be deallocated while we're invoking it.
154
+ state.cnt++;
155
+ const a = state.a;
156
+ state.a = 0;
157
+ try {
158
+ return f(a, state.b, ...args);
159
+ } finally{
160
+ if (--state.cnt === 0) {
161
+ wasm.__wbindgen_export_4.get(state.dtor)(a, state.b);
162
+ CLOSURE_DTORS.unregister(state);
163
+ } else {
164
+ state.a = a;
165
+ }
166
+ }
167
+ };
168
+ real.original = state;
169
+ CLOSURE_DTORS.register(real, state, state);
170
+ return real;
171
+ }
172
+ function debugString(val) {
173
+ // primitive types
174
+ const type = typeof val;
175
+ if (type == 'number' || type == 'boolean' || val == null) {
176
+ return `${val}`;
177
+ }
178
+ if (type == 'string') {
179
+ return `"${val}"`;
180
+ }
181
+ if (type == 'symbol') {
182
+ const description = val.description;
183
+ if (description == null) {
184
+ return 'Symbol';
185
+ } else {
186
+ return `Symbol(${description})`;
187
+ }
188
+ }
189
+ if (type == 'function') {
190
+ const name = val.name;
191
+ if (typeof name == 'string' && name.length > 0) {
192
+ return `Function(${name})`;
193
+ } else {
194
+ return 'Function';
195
+ }
196
+ }
197
+ // objects
198
+ if (Array.isArray(val)) {
199
+ const length = val.length;
200
+ let debug = '[';
201
+ if (length > 0) {
202
+ debug += debugString(val[0]);
203
+ }
204
+ for(let i = 1; i < length; i++){
205
+ debug += ', ' + debugString(val[i]);
206
+ }
207
+ debug += ']';
208
+ return debug;
209
+ }
210
+ // Test for built-in
211
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
212
+ let className;
213
+ if (builtInMatches && builtInMatches.length > 1) {
214
+ className = builtInMatches[1];
215
+ } else {
216
+ // Failed to match the standard '[object ClassName]'
217
+ return toString.call(val);
218
+ }
219
+ if (className == 'Object') {
220
+ // we're a user defined class or Object
221
+ // JSON.stringify avoids problems with cycles, and is generally much
222
+ // easier than looping through ownProperties of `val`.
223
+ try {
224
+ return 'Object(' + JSON.stringify(val) + ')';
225
+ } catch (_) {
226
+ return 'Object';
227
+ }
228
+ }
229
+ // errors
230
+ if (val instanceof Error) {
231
+ return `${val.name}: ${val.message}\n${val.stack}`;
232
+ }
233
+ // TODO we could test for more things here, like `Set`s and `Map`s.
234
+ return className;
235
+ }
236
+ /**
237
+ * @param {string} s
238
+ * @param {any} opts
239
+ * @returns {any}
240
+ */ module.exports.minifySync = function(s, opts) {
241
+ try {
242
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
243
+ wasm.minifySync(retptr, addHeapObject(s), addHeapObject(opts));
244
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
245
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
246
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
247
+ if (r2) {
248
+ throw takeObject(r1);
249
+ }
250
+ return takeObject(r0);
251
+ } finally{
252
+ wasm.__wbindgen_add_to_stack_pointer(16);
253
+ }
254
+ };
255
+ /**
256
+ * @param {string} s
257
+ * @param {any} opts
258
+ * @returns {Promise<any>}
259
+ */ module.exports.minify = function(s, opts) {
260
+ const ret = wasm.minify(addHeapObject(s), addHeapObject(opts));
261
+ return takeObject(ret);
262
+ };
263
+ /**
264
+ * @param {string} s
265
+ * @param {any} opts
266
+ * @returns {any}
267
+ */ module.exports.parseSync = function(s, opts) {
268
+ try {
269
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
270
+ wasm.parseSync(retptr, addHeapObject(s), addHeapObject(opts));
271
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
272
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
273
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
274
+ if (r2) {
275
+ throw takeObject(r1);
276
+ }
277
+ return takeObject(r0);
278
+ } finally{
279
+ wasm.__wbindgen_add_to_stack_pointer(16);
280
+ }
281
+ };
282
+ /**
283
+ * @param {string} s
284
+ * @param {any} opts
285
+ * @returns {Promise<any>}
286
+ */ module.exports.parse = function(s, opts) {
287
+ const ret = wasm.parse(addHeapObject(s), addHeapObject(opts));
288
+ return takeObject(ret);
289
+ };
290
+ /**
291
+ * @param {any} s
292
+ * @param {any} opts
293
+ * @returns {any}
294
+ */ module.exports.printSync = function(s, opts) {
295
+ try {
296
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
297
+ wasm.printSync(retptr, addHeapObject(s), addHeapObject(opts));
298
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
299
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
300
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
301
+ if (r2) {
302
+ throw takeObject(r1);
303
+ }
304
+ return takeObject(r0);
305
+ } finally{
306
+ wasm.__wbindgen_add_to_stack_pointer(16);
307
+ }
308
+ };
309
+ /**
310
+ * @param {any} s
311
+ * @param {any} opts
312
+ * @returns {Promise<any>}
313
+ */ module.exports.print = function(s, opts) {
314
+ const ret = wasm.print(addHeapObject(s), addHeapObject(opts));
315
+ return takeObject(ret);
316
+ };
317
+ /**
318
+ * @param {any} s
319
+ * @param {any} opts
320
+ * @param {any} experimental_plugin_bytes_resolver
321
+ * @returns {any}
322
+ */ module.exports.transformSync = function(s, opts, experimental_plugin_bytes_resolver) {
323
+ try {
324
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
325
+ wasm.transformSync(retptr, addHeapObject(s), addHeapObject(opts), addHeapObject(experimental_plugin_bytes_resolver));
326
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
327
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
328
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
329
+ if (r2) {
330
+ throw takeObject(r1);
331
+ }
332
+ return takeObject(r0);
333
+ } finally{
334
+ wasm.__wbindgen_add_to_stack_pointer(16);
335
+ }
336
+ };
337
+ /**
338
+ * @param {any} s
339
+ * @param {any} opts
340
+ * @param {any} experimental_plugin_bytes_resolver
341
+ * @returns {Promise<any>}
342
+ */ module.exports.transform = function(s, opts, experimental_plugin_bytes_resolver) {
343
+ const ret = wasm.transform(addHeapObject(s), addHeapObject(opts), addHeapObject(experimental_plugin_bytes_resolver));
344
+ return takeObject(ret);
345
+ };
346
+ function __wbg_adapter_52(arg0, arg1, arg2) {
347
+ wasm.__wbindgen_export_5(arg0, arg1, addHeapObject(arg2));
348
+ }
349
+ function __wbg_adapter_97(arg0, arg1, arg2, arg3) {
350
+ wasm.__wbindgen_export_6(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
351
+ }
352
+ module.exports.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
353
+ const ret = String(getObject(arg1));
354
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
355
+ const len1 = WASM_VECTOR_LEN;
356
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
357
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
358
+ };
359
+ module.exports.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
360
+ const ret = getObject(arg0).buffer;
361
+ return addHeapObject(ret);
362
+ };
363
+ module.exports.__wbg_call_672a4d21634d4a24 = function() {
364
+ return handleError(function(arg0, arg1) {
365
+ const ret = getObject(arg0).call(getObject(arg1));
366
+ return addHeapObject(ret);
367
+ }, arguments);
368
+ };
369
+ module.exports.__wbg_call_7cccdd69e0791ae2 = function() {
370
+ return handleError(function(arg0, arg1, arg2) {
371
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
372
+ return addHeapObject(ret);
373
+ }, arguments);
374
+ };
375
+ module.exports.__wbg_done_769e5ede4b31c67b = function(arg0) {
376
+ const ret = getObject(arg0).done;
377
+ return ret;
378
+ };
379
+ module.exports.__wbg_entries_3265d4158b33e5dc = function(arg0) {
380
+ const ret = Object.entries(getObject(arg0));
381
+ return addHeapObject(ret);
382
+ };
383
+ module.exports.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
384
+ var v0 = getCachedStringFromWasm0(arg0, arg1);
385
+ if (arg0 !== 0) {
386
+ wasm.__wbindgen_export_3(arg0, arg1, 1);
387
+ }
388
+ console.error(v0);
389
+ };
390
+ module.exports.__wbg_getRandomValues_1c61fac11405ffdc = function() {
391
+ return handleError(function(arg0, arg1) {
392
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
393
+ }, arguments);
394
+ };
395
+ module.exports.__wbg_get_67b2ba62fc30de12 = function() {
396
+ return handleError(function(arg0, arg1) {
397
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
398
+ return addHeapObject(ret);
399
+ }, arguments);
400
+ };
401
+ module.exports.__wbg_get_b9b93047fe3cf45b = function(arg0, arg1) {
402
+ const ret = getObject(arg0)[arg1 >>> 0];
403
+ return addHeapObject(ret);
404
+ };
405
+ module.exports.__wbg_getwithrefkey_1dc361bd10053bfe = function(arg0, arg1) {
406
+ const ret = getObject(arg0)[getObject(arg1)];
407
+ return addHeapObject(ret);
408
+ };
409
+ module.exports.__wbg_instanceof_ArrayBuffer_e14585432e3737fc = function(arg0) {
410
+ let result;
411
+ try {
412
+ result = getObject(arg0) instanceof ArrayBuffer;
413
+ } catch (_) {
414
+ result = false;
415
+ }
416
+ const ret = result;
417
+ return ret;
418
+ };
419
+ module.exports.__wbg_instanceof_Map_f3469ce2244d2430 = function(arg0) {
420
+ let result;
421
+ try {
422
+ result = getObject(arg0) instanceof Map;
423
+ } catch (_) {
424
+ result = false;
425
+ }
426
+ const ret = result;
427
+ return ret;
428
+ };
429
+ module.exports.__wbg_instanceof_Uint8Array_17156bcf118086a9 = function(arg0) {
430
+ let result;
431
+ try {
432
+ result = getObject(arg0) instanceof Uint8Array;
433
+ } catch (_) {
434
+ result = false;
435
+ }
436
+ const ret = result;
437
+ return ret;
438
+ };
439
+ module.exports.__wbg_isArray_a1eab7e0d067391b = function(arg0) {
440
+ const ret = Array.isArray(getObject(arg0));
441
+ return ret;
442
+ };
443
+ module.exports.__wbg_isSafeInteger_343e2beeeece1bb0 = function(arg0) {
444
+ const ret = Number.isSafeInteger(getObject(arg0));
445
+ return ret;
446
+ };
447
+ module.exports.__wbg_iterator_9a24c88df860dc65 = function() {
448
+ const ret = Symbol.iterator;
449
+ return addHeapObject(ret);
450
+ };
451
+ module.exports.__wbg_length_a446193dc22c12f8 = function(arg0) {
452
+ const ret = getObject(arg0).length;
453
+ return ret;
454
+ };
455
+ module.exports.__wbg_length_e2d2a49132c1b256 = function(arg0) {
456
+ const ret = getObject(arg0).length;
457
+ return ret;
458
+ };
459
+ module.exports.__wbg_new_23a2665fac83c611 = function(arg0, arg1) {
460
+ try {
461
+ var state0 = {
462
+ a: arg0,
463
+ b: arg1
464
+ };
465
+ var cb0 = (arg0, arg1)=>{
466
+ const a = state0.a;
467
+ state0.a = 0;
468
+ try {
469
+ return __wbg_adapter_97(a, state0.b, arg0, arg1);
470
+ } finally{
471
+ state0.a = a;
472
+ }
473
+ };
474
+ const ret = new Promise(cb0);
475
+ return addHeapObject(ret);
476
+ } finally{
477
+ state0.a = state0.b = 0;
478
+ }
479
+ };
480
+ module.exports.__wbg_new_405e22f390576ce2 = function() {
481
+ const ret = new Object();
482
+ return addHeapObject(ret);
483
+ };
484
+ module.exports.__wbg_new_5e0be73521bc8c17 = function() {
485
+ const ret = new Map();
486
+ return addHeapObject(ret);
487
+ };
488
+ module.exports.__wbg_new_78feb108b6472713 = function() {
489
+ const ret = new Array();
490
+ return addHeapObject(ret);
491
+ };
492
+ module.exports.__wbg_new_8a6f238a6ece86ea = function() {
493
+ const ret = new Error();
494
+ return addHeapObject(ret);
495
+ };
496
+ module.exports.__wbg_new_a12002a7f91c75be = function(arg0) {
497
+ const ret = new Uint8Array(getObject(arg0));
498
+ return addHeapObject(ret);
499
+ };
500
+ module.exports.__wbg_newnoargs_105ed471475aaf50 = function(arg0, arg1) {
501
+ var v0 = getCachedStringFromWasm0(arg0, arg1);
502
+ const ret = new Function(v0);
503
+ return addHeapObject(ret);
504
+ };
505
+ module.exports.__wbg_next_25feadfc0913fea9 = function(arg0) {
506
+ const ret = getObject(arg0).next;
507
+ return addHeapObject(ret);
508
+ };
509
+ module.exports.__wbg_next_6574e1a8a62d1055 = function() {
510
+ return handleError(function(arg0) {
511
+ const ret = getObject(arg0).next();
512
+ return addHeapObject(ret);
513
+ }, arguments);
514
+ };
515
+ module.exports.__wbg_queueMicrotask_97d92b4fcc8a61c5 = function(arg0) {
516
+ queueMicrotask(getObject(arg0));
517
+ };
518
+ module.exports.__wbg_queueMicrotask_d3219def82552485 = function(arg0) {
519
+ const ret = getObject(arg0).queueMicrotask;
520
+ return addHeapObject(ret);
521
+ };
522
+ module.exports.__wbg_resolve_4851785c9c5f573d = function(arg0) {
523
+ const ret = Promise.resolve(getObject(arg0));
524
+ return addHeapObject(ret);
525
+ };
526
+ module.exports.__wbg_set_37837023f3d740e8 = function(arg0, arg1, arg2) {
527
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
528
+ };
529
+ module.exports.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
530
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
531
+ };
532
+ module.exports.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
533
+ getObject(arg0).set(getObject(arg1), arg2 >>> 0);
534
+ };
535
+ module.exports.__wbg_set_8fc6bf8a5b1071d1 = function(arg0, arg1, arg2) {
536
+ const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
537
+ return addHeapObject(ret);
538
+ };
539
+ module.exports.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
540
+ const ret = getObject(arg1).stack;
541
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
542
+ const len1 = WASM_VECTOR_LEN;
543
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
544
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
545
+ };
546
+ module.exports.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function() {
547
+ const ret = typeof commonjsGlobal === 'undefined' ? null : commonjsGlobal;
548
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
549
+ };
550
+ module.exports.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0 = function() {
551
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
552
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
553
+ };
554
+ module.exports.__wbg_static_accessor_SELF_37c5d418e4bf5819 = function() {
555
+ const ret = typeof self === 'undefined' ? null : self;
556
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
557
+ };
558
+ module.exports.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function() {
559
+ const ret = typeof window === 'undefined' ? null : window;
560
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
561
+ };
562
+ module.exports.__wbg_then_44b73946d2fb3e7d = function(arg0, arg1) {
563
+ const ret = getObject(arg0).then(getObject(arg1));
564
+ return addHeapObject(ret);
565
+ };
566
+ module.exports.__wbg_value_cd1ffa7b1ab794f1 = function(arg0) {
567
+ const ret = getObject(arg0).value;
568
+ return addHeapObject(ret);
569
+ };
570
+ module.exports.__wbindgen_as_number = function(arg0) {
571
+ const ret = +getObject(arg0);
572
+ return ret;
573
+ };
574
+ module.exports.__wbindgen_bigint_from_i64 = function(arg0) {
575
+ const ret = arg0;
576
+ return addHeapObject(ret);
577
+ };
578
+ module.exports.__wbindgen_bigint_from_u64 = function(arg0) {
579
+ const ret = BigInt.asUintN(64, arg0);
580
+ return addHeapObject(ret);
581
+ };
582
+ module.exports.__wbindgen_bigint_get_as_i64 = function(arg0, arg1) {
583
+ const v = getObject(arg1);
584
+ const ret = typeof v === 'bigint' ? v : undefined;
585
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
586
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
587
+ };
588
+ module.exports.__wbindgen_boolean_get = function(arg0) {
589
+ const v = getObject(arg0);
590
+ const ret = typeof v === 'boolean' ? v ? 1 : 0 : 2;
591
+ return ret;
592
+ };
593
+ module.exports.__wbindgen_cb_drop = function(arg0) {
594
+ const obj = takeObject(arg0).original;
595
+ if (obj.cnt-- == 1) {
596
+ obj.a = 0;
597
+ return true;
598
+ }
599
+ const ret = false;
600
+ return ret;
601
+ };
602
+ module.exports.__wbindgen_closure_wrapper16832 = function(arg0, arg1, arg2) {
603
+ const ret = makeMutClosure(arg0, arg1, 666, __wbg_adapter_52);
604
+ return addHeapObject(ret);
605
+ };
606
+ module.exports.__wbindgen_debug_string = function(arg0, arg1) {
607
+ const ret = debugString(getObject(arg1));
608
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
609
+ const len1 = WASM_VECTOR_LEN;
610
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
611
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
612
+ };
613
+ module.exports.__wbindgen_error_new = function(arg0, arg1) {
614
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
615
+ return addHeapObject(ret);
616
+ };
617
+ module.exports.__wbindgen_in = function(arg0, arg1) {
618
+ const ret = getObject(arg0) in getObject(arg1);
619
+ return ret;
620
+ };
621
+ module.exports.__wbindgen_is_bigint = function(arg0) {
622
+ const ret = typeof getObject(arg0) === 'bigint';
623
+ return ret;
624
+ };
625
+ module.exports.__wbindgen_is_function = function(arg0) {
626
+ const ret = typeof getObject(arg0) === 'function';
627
+ return ret;
628
+ };
629
+ module.exports.__wbindgen_is_null = function(arg0) {
630
+ const ret = getObject(arg0) === null;
631
+ return ret;
632
+ };
633
+ module.exports.__wbindgen_is_object = function(arg0) {
634
+ const val = getObject(arg0);
635
+ const ret = typeof val === 'object' && val !== null;
636
+ return ret;
637
+ };
638
+ module.exports.__wbindgen_is_string = function(arg0) {
639
+ const ret = typeof getObject(arg0) === 'string';
640
+ return ret;
641
+ };
642
+ module.exports.__wbindgen_is_undefined = function(arg0) {
643
+ const ret = getObject(arg0) === undefined;
644
+ return ret;
645
+ };
646
+ module.exports.__wbindgen_jsval_eq = function(arg0, arg1) {
647
+ const ret = getObject(arg0) === getObject(arg1);
648
+ return ret;
649
+ };
650
+ module.exports.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
651
+ const ret = getObject(arg0) == getObject(arg1);
652
+ return ret;
653
+ };
654
+ module.exports.__wbindgen_memory = function() {
655
+ const ret = wasm.memory;
656
+ return addHeapObject(ret);
657
+ };
658
+ module.exports.__wbindgen_number_get = function(arg0, arg1) {
659
+ const obj = getObject(arg1);
660
+ const ret = typeof obj === 'number' ? obj : undefined;
661
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
662
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
663
+ };
664
+ module.exports.__wbindgen_number_new = function(arg0) {
665
+ const ret = arg0;
666
+ return addHeapObject(ret);
667
+ };
668
+ module.exports.__wbindgen_object_clone_ref = function(arg0) {
669
+ const ret = getObject(arg0);
670
+ return addHeapObject(ret);
671
+ };
672
+ module.exports.__wbindgen_object_drop_ref = function(arg0) {
673
+ takeObject(arg0);
674
+ };
675
+ module.exports.__wbindgen_string_get = function(arg0, arg1) {
676
+ const obj = getObject(arg1);
677
+ const ret = typeof obj === 'string' ? obj : undefined;
678
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
679
+ var len1 = WASM_VECTOR_LEN;
680
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
681
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
682
+ };
683
+ module.exports.__wbindgen_string_new = function(arg0, arg1) {
684
+ const ret = getStringFromWasm0(arg0, arg1);
685
+ return addHeapObject(ret);
686
+ };
687
+ module.exports.__wbindgen_throw = function(arg0, arg1) {
688
+ throw new Error(getStringFromWasm0(arg0, arg1));
689
+ };
690
+ const path = new URL('../compiler/swc.wasm', import.meta.url);
691
+ const bytes = require$$1.readFileSync(path);
692
+ const wasmModule = new WebAssembly.Module(bytes);
693
+ const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
694
+ wasm = wasmInstance.exports;
695
+ module.exports.__wasm = wasm;
696
+ } (wasm));
697
+ return wasm.exports;
698
+ }
699
+
700
+ var wasmExports = requireWasm();
701
+
702
+ const DUMMY_SPAN = {
703
+ start: 0,
704
+ end: 0,
705
+ ctxt: 0
706
+ };
707
+ function parseModule(code, id) {
708
+ const isTypeScript = /\.([cm]?ts)x?$/i.test(id);
709
+ return normalizeParsed(wasmExports.parseSync(code, {
710
+ syntax: isTypeScript ? "typescript" : "ecmascript",
711
+ tsx: /\.([cm]?ts)x$/i.test(id),
712
+ jsx: /\.([cm]?jsx)$/i.test(id),
713
+ target: "es2022"
714
+ }));
715
+ }
716
+ function normalizeParsed(node) {
717
+ if (!node || typeof node !== "object") return node;
718
+ if (Array.isArray(node)) return node.map(normalizeParsed);
719
+ if (node.type === "FunctionBody") node.type = "BlockStatement";
720
+ for (const key of Object.keys(node)){
721
+ if (key !== "span") node[key] = normalizeParsed(node[key]);
722
+ }
723
+ return node;
724
+ }
725
+ /** SWC WASM uses FunctionBody where the compiler's normalized AST uses blocks. */ function printModule(program, options) {
726
+ const functionTypes = new Set([
727
+ "FunctionDeclaration",
728
+ "FunctionExpression",
729
+ "ArrowFunctionExpression",
730
+ "MethodProperty",
731
+ "GetterProperty",
732
+ "SetterProperty",
733
+ "ClassMethod",
734
+ "PrivateMethod",
735
+ "Constructor"
736
+ ]);
737
+ const convert = (node, parentType, key)=>{
738
+ if (!node || typeof node !== "object") return node;
739
+ if (Array.isArray(node)) return node.map((child)=>convert(child, parentType, key));
740
+ const result = {};
741
+ for (const field of Object.keys(node))result[field] = convert(node[field], node.type, field);
742
+ if (node.type === "BlockStatement" && key === "body" && functionTypes.has(parentType)) {
743
+ result.type = "FunctionBody";
744
+ delete result.ctxt;
745
+ }
746
+ if ((node.type === "GetterProperty" || node.type === "SetterProperty") && result.function?.body) result.function.body.type = "FunctionBody";
747
+ return result;
748
+ };
749
+ return wasmExports.printSync(convert(program), options);
750
+ }
751
+ function collectStaticMemberPath(node) {
752
+ const path = [];
753
+ let current = node;
754
+ while(current?.type === "MemberExpression"){
755
+ if (current.computed || current.property?.type === "Computed") {
756
+ return null;
757
+ }
758
+ const key = getStaticPropertyKey(current.property);
759
+ if (key === null) {
760
+ return null;
761
+ }
762
+ path.unshift(key);
763
+ current = current.object;
764
+ }
765
+ if (current?.type !== "Identifier") {
766
+ return null;
767
+ }
768
+ path.unshift(current.value);
769
+ return path;
770
+ }
771
+ function getStaticPropertyKey(node) {
772
+ switch(node?.type){
773
+ case "Identifier":
774
+ return node.value;
775
+ case "StringLiteral":
776
+ return node.value;
777
+ case "NumericLiteral":
778
+ return String(node.value);
779
+ default:
780
+ return null;
781
+ }
782
+ }
783
+ function visitNode(node, visit, parent) {
784
+ if (node === null || typeof node !== "object") {
785
+ return;
786
+ }
787
+ if (typeof node.type === "string") {
788
+ visit(node, parent);
789
+ }
790
+ for (const key of Object.keys(node)){
791
+ if (key === "span" || key === "ctxt" || key === "type" || key === "raw") {
792
+ continue;
793
+ }
794
+ const value = node[key];
795
+ if (Array.isArray(value)) {
796
+ for (const child of value){
797
+ visitNode(child, visit, node);
798
+ }
799
+ continue;
800
+ }
801
+ visitNode(value, visit, node);
802
+ }
803
+ }
804
+
805
+ const STORE_MODULES$1 = new Set([
806
+ "@volynets/reflex-store",
807
+ "@volynets/reflex-store/store",
808
+ "@volynets/reflex-store/compiled-store",
809
+ "@volynets/reflex-store/advanced",
810
+ "@reflex/store",
811
+ "@reflex/store/store",
812
+ "@reflex/store/compiled-store",
813
+ "@reflex/store/advanced"
814
+ ]);
815
+ const bindingKey = (identifier)=>identifier.value + "#" + identifier.ctxt;
816
+ function memberRoot(node) {
817
+ while(node?.type === "MemberExpression" || node?.type === "OptionalChainingExpression")node = node.object ?? node.base;
818
+ return node?.type === "Identifier" ? node : null;
819
+ }
820
+ function collectFactoryNames(program) {
821
+ const names = new Set();
822
+ let hasLocalCreateStore = false;
823
+ for (const item of program.body){
824
+ if (item.type === "ImportDeclaration") {
825
+ for (const specifier of item.specifiers){
826
+ if (specifier.local.value === "createStore") hasLocalCreateStore = true;
827
+ if (item.typeOnly || specifier.type !== "ImportSpecifier" || specifier.isTypeOnly || !STORE_MODULES$1.has(item.source.value)) continue;
828
+ if ((specifier.imported?.value ?? specifier.local.value) === "createStore") names.add(bindingKey(specifier.local));
829
+ }
830
+ } else if (item.type === "FunctionDeclaration" || item.type === "ClassDeclaration") {
831
+ if (item.identifier?.value === "createStore") hasLocalCreateStore = true;
832
+ } else if (item.type === "VariableDeclaration") {
833
+ for (const declaration of item.declarations){
834
+ if (declaration.id.type === "Identifier" && declaration.id.value === "createStore") hasLocalCreateStore = true;
835
+ }
836
+ }
837
+ }
838
+ // Bare declarations are supported by the compiler API (the Vite plugin gates them).
839
+ if (!hasLocalCreateStore && names.size === 0) {
840
+ const declared = new Set();
841
+ const collectDeclared = (pattern)=>visitNode(pattern, (node)=>{
842
+ if (node.type === "Identifier" && node.value === "createStore") declared.add(bindingKey(node));
843
+ });
844
+ visitNode(program, (node)=>{
845
+ if (node.type === "VariableDeclarator") collectDeclared(node.id);
846
+ if ([
847
+ "FunctionDeclaration",
848
+ "FunctionExpression",
849
+ "ArrowFunctionExpression",
850
+ "ClassDeclaration"
851
+ ].includes(node.type)) {
852
+ if (node.identifier) collectDeclared(node.identifier);
853
+ for (const parameter of node.params ?? [])collectDeclared(parameter.pat ?? parameter);
854
+ }
855
+ });
856
+ visitNode(program, (node)=>{
857
+ if (node.type === "CallExpression" && node.callee?.type === "Identifier" && node.callee.value === "createStore" && !declared.has(bindingKey(node.callee))) names.add(bindingKey(node.callee));
858
+ });
859
+ }
860
+ return names;
861
+ }
862
+ const pathKey = (path)=>JSON.stringify(path);
863
+ function collectStoreBindings(program, diagnostics = []) {
864
+ const stores = new Map();
865
+ const names = collectFactoryNames(program);
866
+ const recognized = new Set();
867
+ const factoryUses = new Set();
868
+ const parents = new WeakMap();
869
+ visitNode(program, (node, parent)=>{
870
+ if (parent !== undefined) parents.set(node, parent);
871
+ if (node.type === "ImportDeclaration") {
872
+ for (const specifier of node.specifiers)factoryUses.add(specifier.local);
873
+ }
874
+ });
875
+ visitNode(program, (node, parent)=>{
876
+ if (node.type !== "VariableDeclarator" || parent?.type !== "VariableDeclaration" || node.id?.type !== "Identifier" || !isCreateStoreCall(node.init, names)) return;
877
+ recognized.add(node.init);
878
+ factoryUses.add(node.init.callee);
879
+ if (!isSupportedStoreDeclarationContext(node, parents)) {
880
+ diagnostics.push({
881
+ code: "unsupported-binding",
882
+ message: "Compiled stores must be declared at module scope or inside a function body."
883
+ });
884
+ return;
885
+ }
886
+ const objectArg = node.init.arguments?.[0]?.expression;
887
+ if (objectArg?.type !== "ObjectExpression" || node.init.arguments.length < 1 || node.init.arguments.length > 2) {
888
+ diagnostics.push({
889
+ code: "unsupported-shape",
890
+ message: "Compiled stores require a static object literal and optional static options."
891
+ });
892
+ return;
893
+ }
894
+ let displayName;
895
+ const optionsArg = node.init.arguments[1]?.expression;
896
+ if (optionsArg) {
897
+ if (optionsArg.type !== "ObjectExpression" || optionsArg.properties.some((property)=>property.type !== "KeyValueProperty" || getStaticPropertyKey(property.key) !== "name" || property.value?.type !== "StringLiteral") || optionsArg.properties.length > 1) {
898
+ diagnostics.push({
899
+ code: "unsupported-shape",
900
+ message: "Compiled store options require a static optional name string."
901
+ });
902
+ return;
903
+ }
904
+ displayName = optionsArg.properties[0]?.value.value;
905
+ }
906
+ const branchPaths = new Set();
907
+ const leafPaths = new Map();
908
+ const leaves = [];
909
+ const methods = [];
910
+ const getters = [];
911
+ collectLeafPaths(objectArg, [], leafPaths, branchPaths, leaves, methods, getters, collectBoundaryNames(program), diagnostics);
912
+ stores.set(bindingKey(node.id), {
913
+ name: node.id.value,
914
+ identifier: node.id,
915
+ displayName,
916
+ needsFacade: methods.length > 0 || getters.length > 0,
917
+ branchPaths,
918
+ leafPaths,
919
+ leaves,
920
+ methods,
921
+ getters
922
+ });
923
+ });
924
+ visitNode(program, (node)=>{
925
+ if (node.type === "ForStatement" && node.init?.type === "VariableDeclaration" && node.init.declarations.some((declaration)=>isCreateStoreCall(declaration.init, names))) {
926
+ diagnostics.push({
927
+ code: "unsupported-binding",
928
+ message: "Compiled stores cannot be declared in a for-loop initializer."
929
+ });
930
+ }
931
+ if (node.type === "Identifier" && names.has(bindingKey(node)) && !factoryUses.has(node)) {
932
+ diagnostics.push({
933
+ code: "unsupported-binding",
934
+ message: "The createStore binding can only be used as a direct store factory."
935
+ });
936
+ }
937
+ if (isCreateStoreCall(node, names) && !recognized.has(node)) {
938
+ diagnostics.push({
939
+ code: "unsupported-binding",
940
+ message: "Compiled stores must be declared in a variable declaration."
941
+ });
942
+ }
943
+ });
944
+ visitNode(program, (node, parent)=>{
945
+ if (node.type !== "Identifier") return;
946
+ const store = stores.get(bindingKey(node));
947
+ if (!store || parent?.type === "VariableDeclarator" && parent.id === node) return;
948
+ if (parent?.type !== "MemberExpression" || parent.object !== node) {
949
+ store.needsFacade = true;
950
+ return;
951
+ }
952
+ let member = parent;
953
+ let owner = parents.get(member);
954
+ while(owner?.type === "MemberExpression" && owner.object === member){
955
+ member = owner;
956
+ owner = parents.get(member);
957
+ }
958
+ const parts = collectStaticMemberPath(member)?.slice(1);
959
+ if (!parts || ![
960
+ ...store.leafPaths.values()
961
+ ].some((leaf)=>leaf.parts.length <= parts.length && leaf.parts.every((key, index)=>parts[index] === key))) store.needsFacade = true;
962
+ });
963
+ return stores;
964
+ }
965
+ function isSupportedStoreDeclarationContext(declarator, parents) {
966
+ const declaration = parents.get(declarator);
967
+ if (declaration?.type !== "VariableDeclaration") return false;
968
+ const directParent = parents.get(declaration);
969
+ const statementContainers = new Set([
970
+ "BlockStatement",
971
+ "IfStatement",
972
+ "WhileStatement",
973
+ "DoWhileStatement",
974
+ "ForStatement",
975
+ "ForInStatement",
976
+ "ForOfStatement",
977
+ "SwitchStatement",
978
+ "SwitchCase",
979
+ "TryStatement",
980
+ "CatchClause",
981
+ "LabeledStatement",
982
+ "WithStatement"
983
+ ]);
984
+ let current = directParent;
985
+ let insideBlock = false;
986
+ while(current !== undefined){
987
+ if (current.type === "MethodProperty" || current.type === "FunctionDeclaration" || current.type === "FunctionExpression" || current.type === "ArrowFunctionExpression") return true;
988
+ if (current.type === "StaticBlock") return false;
989
+ if (current.type === "Module") {
990
+ return current === directParent || insideBlock;
991
+ }
992
+ if (current.type === "BlockStatement") insideBlock = true;
993
+ else if (!statementContainers.has(current.type)) return false;
994
+ current = parents.get(current);
995
+ }
996
+ return false;
997
+ }
998
+ function isCreateStoreCall(expression, names) {
999
+ return expression?.type === "CallExpression" && expression.callee?.type === "Identifier" && names.has(bindingKey(expression.callee));
1000
+ }
1001
+ function collectBoundaryNames(program) {
1002
+ const names = {
1003
+ leaf: new Set(),
1004
+ opaque: new Set()
1005
+ };
1006
+ for (const item of program.body){
1007
+ if (item.type !== "ImportDeclaration" || !STORE_MODULES$1.has(item.source.value)) continue;
1008
+ for (const specifier of item.specifiers){
1009
+ if (specifier.type !== "ImportSpecifier" || specifier.isTypeOnly) continue;
1010
+ const imported = specifier.imported?.value ?? specifier.local.value;
1011
+ if (imported === "leaf" || imported === "opaque") names[imported].add(bindingKey(specifier.local));
1012
+ }
1013
+ }
1014
+ return names;
1015
+ }
1016
+ function methodFunction(property) {
1017
+ return {
1018
+ type: "FunctionExpression",
1019
+ span: property.span,
1020
+ ctxt: property.ctxt ?? property.body?.ctxt ?? 0,
1021
+ identifier: null,
1022
+ params: property.params ?? [],
1023
+ decorators: property.decorators ?? [],
1024
+ body: property.body,
1025
+ generator: property.generator ?? false,
1026
+ async: property.async ?? false,
1027
+ typeParameters: property.typeParameters ?? null,
1028
+ returnType: property.returnType ?? property.typeAnnotation ?? null
1029
+ };
1030
+ }
1031
+ function getterFunction(property) {
1032
+ property = property.function ?? property;
1033
+ return {
1034
+ type: "FunctionExpression",
1035
+ span: property.span,
1036
+ ctxt: property.body?.ctxt ?? 0,
1037
+ identifier: null,
1038
+ params: [],
1039
+ decorators: [],
1040
+ body: property.body,
1041
+ generator: false,
1042
+ async: false,
1043
+ typeParameters: null,
1044
+ returnType: property.typeAnnotation ?? null
1045
+ };
1046
+ }
1047
+ function collectLeafPaths(object, prefix, target, branches, leaves, methods, getters, boundaries, diagnostics) {
1048
+ const keys = new Set();
1049
+ for (const property of object.properties ?? []){
1050
+ const key = getStaticPropertyKey(property.key);
1051
+ if (key === null || key === "__proto__" || prefix.length === 0 && (key === "dispose" || key === "constructor") || keys.has(key)) {
1052
+ diagnostics.push({
1053
+ code: "unsupported-shape",
1054
+ message: "Compiled store shapes require unique static keys and do not support spreads, shorthand, setters, __proto__ or reserved lifecycle names."
1055
+ });
1056
+ continue;
1057
+ }
1058
+ keys.add(key);
1059
+ if (property.type === "MethodProperty") {
1060
+ if (property.async || property.generator) {
1061
+ diagnostics.push({
1062
+ code: "unsupported-shape",
1063
+ message: "Compiled store methods must be synchronous non-generator actions."
1064
+ });
1065
+ continue;
1066
+ }
1067
+ if (prefix.length !== 0) {
1068
+ diagnostics.push({
1069
+ code: "unsupported-shape",
1070
+ message: "Compiled store methods are supported only at the root."
1071
+ });
1072
+ continue;
1073
+ }
1074
+ methods.push({
1075
+ key,
1076
+ fn: methodFunction(property)
1077
+ });
1078
+ continue;
1079
+ }
1080
+ if (property.type === "GetterProperty") {
1081
+ if (prefix.length !== 0) {
1082
+ diagnostics.push({
1083
+ code: "unsupported-shape",
1084
+ message: "Compiled store getters are supported only at the root."
1085
+ });
1086
+ continue;
1087
+ }
1088
+ getters.push({
1089
+ key,
1090
+ fn: getterFunction(property)
1091
+ });
1092
+ continue;
1093
+ }
1094
+ if (property.type !== "KeyValueProperty") {
1095
+ diagnostics.push({
1096
+ code: "unsupported-shape",
1097
+ message: "Compiled store shapes support data properties, root methods and root getters."
1098
+ });
1099
+ continue;
1100
+ }
1101
+ const path = [
1102
+ ...prefix,
1103
+ key
1104
+ ];
1105
+ let initial = property.value;
1106
+ let isBoundary = false;
1107
+ const value = property.value;
1108
+ if (value?.type === "CallExpression" && value.callee?.type === "Identifier") {
1109
+ const callee = bindingKey(value.callee);
1110
+ const isLeaf = boundaries.leaf.has(callee);
1111
+ const isOpaque = boundaries.opaque.has(callee);
1112
+ if (isLeaf || isOpaque) {
1113
+ if (value.arguments?.length !== 1 || !value.arguments[0]?.expression) {
1114
+ diagnostics.push({
1115
+ code: "unsupported-shape",
1116
+ message: "leaf() and opaque() compiled-store boundaries require one value argument."
1117
+ });
1118
+ continue;
1119
+ }
1120
+ initial = isOpaque ? value : value.arguments[0].expression;
1121
+ isBoundary = true;
1122
+ }
1123
+ }
1124
+ if (!isBoundary && initial?.type === "ObjectExpression") {
1125
+ branches.add(pathKey(path));
1126
+ collectLeafPaths(initial, path, target, branches, leaves, methods, getters, boundaries, diagnostics);
1127
+ continue;
1128
+ }
1129
+ const leaf = {
1130
+ initial,
1131
+ path: pathKey(path),
1132
+ parts: path,
1133
+ mangled: path.map((part)=>part.replace(/[^A-Za-z0-9_$]/g, "_")).join("_")
1134
+ };
1135
+ target.set(pathKey(path), leaf);
1136
+ leaves.push(leaf);
1137
+ }
1138
+ }
1139
+
1140
+ function scanUnsupportedStoreSyntax(program, state) {
1141
+ if (state.stores.size === 0) return;
1142
+ for (const store of state.stores.values()){
1143
+ for (const getter of store.getters){
1144
+ visitNode(getter.fn, (node)=>{
1145
+ if (node.type === "CallExpression" && node.callee?.type === "MemberExpression") {
1146
+ const path = collectStaticMemberPath(node.callee);
1147
+ const receiver = node.callee.object;
1148
+ const receiverStore = receiver?.type === "ThisExpression" ? store : path?.length === 2 ? state.stores.get(bindingKey(memberRoot(node.callee))) : undefined;
1149
+ const method = receiver?.type === "ThisExpression" ? node.callee.property?.value : path?.[1];
1150
+ if (receiverStore?.methods.some((candidate)=>candidate.key === method)) addDiagnostic(state, "unsupported-write", "Compiled getters cannot call store actions.");
1151
+ }
1152
+ if (node.type === "AwaitExpression" || node.type === "YieldExpression") addDiagnostic(state, "unsupported-write", "Compiled getters must be pure synchronous computations.");
1153
+ if (node.type === "AssignmentExpression" || node.type === "UpdateExpression") {
1154
+ let root = node.left ?? node.argument;
1155
+ while(root?.type === "MemberExpression")root = root.object;
1156
+ if (root?.type === "ThisExpression" || root?.type === "Identifier" && state.stores.has(bindingKey(root))) addDiagnostic(state, "unsupported-write", "Compiled getters cannot write store state.");
1157
+ }
1158
+ });
1159
+ }
1160
+ }
1161
+ const intrinsicNames = new Map();
1162
+ for (const item of program.body){
1163
+ if (item.type !== "ImportDeclaration" || !STORE_MODULES$1.has(item.source.value) && ![
1164
+ "@volynets/reflex",
1165
+ "@volynets/reflex-store/runtime"
1166
+ ].includes(item.source.value)) continue;
1167
+ for (const specifier of item.specifiers){
1168
+ if (specifier.type !== "ImportSpecifier" || specifier.isTypeOnly) continue;
1169
+ const imported = specifier.imported?.value ?? specifier.local.value;
1170
+ if ([
1171
+ "snapshot",
1172
+ "hydrate",
1173
+ "getStoreName"
1174
+ ].includes(imported) && STORE_MODULES$1.has(item.source.value)) intrinsicNames.set(bindingKey(specifier.local), {
1175
+ arity: imported === "hydrate" ? 2 : 1,
1176
+ rootIndex: 0
1177
+ });
1178
+ if (imported === "own" && [
1179
+ "@volynets/reflex",
1180
+ "@volynets/reflex-store/runtime"
1181
+ ].includes(item.source.value)) intrinsicNames.set(bindingKey(specifier.local), {
1182
+ arity: 2,
1183
+ rootIndex: 1
1184
+ });
1185
+ }
1186
+ }
1187
+ const returnRoots = new Set();
1188
+ const collectReturned = (node)=>{
1189
+ if (node?.type === "Identifier" && state.stores.has(bindingKey(node))) returnRoots.add(node);
1190
+ if (node?.type === "ObjectExpression") {
1191
+ for (const property of node.properties)collectReturned(property.type === "KeyValueProperty" ? property.value : property);
1192
+ }
1193
+ };
1194
+ visitNode(program, (node)=>{
1195
+ if (node.type === "ReturnStatement") collectReturned(node.argument);
1196
+ });
1197
+ const intrinsicRoots = new Set();
1198
+ visitNode(program, (node)=>{
1199
+ if (node.type !== "CallExpression" || node.callee?.type !== "Identifier") return;
1200
+ const intrinsic = intrinsicNames.get(bindingKey(node.callee));
1201
+ const root = node.arguments?.[intrinsic?.rootIndex ?? 0]?.expression;
1202
+ if (intrinsic && node.arguments.length === intrinsic.arity && node.arguments.every((arg)=>!arg.spread) && root?.type === "Identifier" && state.stores.has(bindingKey(root))) intrinsicRoots.add(root);
1203
+ });
1204
+ visitNode(program, (node, parent)=>{
1205
+ if (node.type === "Identifier" && state.stores.has(bindingKey(node)) && !intrinsicRoots.has(node) && !returnRoots.has(node) && !(parent?.type === "VariableDeclarator" && parent.id === node) && !(parent?.type === "MemberExpression" && parent.object === node) && !(parent?.type === "ReturnStatement" && parent.argument === node)) {
1206
+ addDiagnostic(state, "spread-reflection", REFLECTION_MESSAGE);
1207
+ }
1208
+ if (node.type === "AssignmentExpression" || node.type === "UpdateExpression") {
1209
+ const target = node.left ?? node.argument;
1210
+ if (isStoreMember(target, state) || isStoreRootOrBranch(target, state)) {
1211
+ const parts = collectStaticMemberPath(target);
1212
+ const root = memberRoot(target);
1213
+ const store = root && state.stores.get(bindingKey(root));
1214
+ if (!parts || !store?.leafPaths.has(pathKey(parts.slice(1))) || node.type === "AssignmentExpression" && ![
1215
+ "=",
1216
+ "+=",
1217
+ "-="
1218
+ ].includes(node.operator)) {
1219
+ addDiagnostic(state, "unsupported-write", "Only declared compiled-store leaves support =, +=, -=, ++ and --.");
1220
+ }
1221
+ if (node.type === "AssignmentExpression" && node.operator !== "=") {
1222
+ visitNode(node.right, (child)=>{
1223
+ if (child.type === "AwaitExpression" || child.type === "YieldExpression") addDiagnostic(state, "unsupported-write", "Suspending a compiled-store compound assignment is unsupported.");
1224
+ });
1225
+ }
1226
+ }
1227
+ } else if (node.type === "MemberExpression") {
1228
+ scanMemberExpression(node, state);
1229
+ } else if (node.type === "VariableDeclarator") {
1230
+ scanVariableDeclarator(node, state);
1231
+ } else if (node.type === "BinaryExpression" && node.operator === "in") {
1232
+ if (isStoreRootOrBranch(node.right, state)) {
1233
+ addDiagnostic(state, "spread-reflection", REFLECTION_MESSAGE);
1234
+ }
1235
+ } else if (node.type === "UnaryExpression" && node.operator === "delete") {
1236
+ if (isStoreMember(node.argument, state) || isStoreRootOrBranch(node.argument, state)) {
1237
+ addDiagnostic(state, "delete", "Deleting compiled-store paths is not supported in phase 1.");
1238
+ }
1239
+ } else if (node.type === "CallExpression") {
1240
+ scanCallExpression(node, state);
1241
+ } else if (node.type === "ObjectExpression") {
1242
+ scanObjectExpression(node, state);
1243
+ } else if (node.type === "OptionalChainingExpression" || node.type === "OptChainExpression") {
1244
+ if (!isStoreMember(node.base ?? node, state)) return;
1245
+ addDiagnostic(state, "optional-chain", "Optional chaining on compiled stores is not supported in phase 1.");
1246
+ }
1247
+ });
1248
+ }
1249
+ const REFLECTION_MESSAGE = "Spread and reflection are not guaranteed for compiled stores in phase 1.";
1250
+ function scanMemberExpression(node, state) {
1251
+ const root = memberRoot(node);
1252
+ if (root !== null && state.stores.has(bindingKey(root)) && hasDynamicMemberAccess(node)) {
1253
+ addDiagnostic(state, "dynamic-access", "Dynamic compiled-store access is not supported in phase 1.");
1254
+ }
1255
+ }
1256
+ function scanVariableDeclarator(node, state) {
1257
+ if (node.id?.type === "ObjectPattern" && isStoreRootOrBranch(node.init, state)) {
1258
+ addDiagnostic(state, "spread-reflection", REFLECTION_MESSAGE);
1259
+ } else if (node.id?.type === "Identifier" && isStoreBranchMember(node.init, state)) {
1260
+ addDiagnostic(state, "branch-alias", "Aliasing nested compiled-store branches is not supported in phase 1.");
1261
+ }
1262
+ }
1263
+ function scanCallExpression(node, state) {
1264
+ const calleePath = collectStaticMemberPath(node.callee);
1265
+ if (calleePath === null) return;
1266
+ const [root, method] = calleePath;
1267
+ const isReflection = root === "Object" && (method === "keys" || method === "values" || method === "entries" || method === "getOwnPropertyNames" || method === "getOwnPropertySymbols") || root === "Reflect" && method === "ownKeys";
1268
+ if (isReflection && isStoreRootOrBranch(node.arguments?.[0]?.expression, state)) {
1269
+ addDiagnostic(state, "spread-reflection", REFLECTION_MESSAGE);
1270
+ }
1271
+ }
1272
+ function scanObjectExpression(node, state) {
1273
+ for (const property of node.properties ?? []){
1274
+ if (property.type === "SpreadElement" && isStoreRootOrBranch(property.arguments ?? property.expression, state)) {
1275
+ addDiagnostic(state, "spread-reflection", REFLECTION_MESSAGE);
1276
+ }
1277
+ }
1278
+ }
1279
+ function isStoreRootOrBranch(node, state) {
1280
+ return node?.type === "Identifier" ? state.stores.has(bindingKey(node)) : isStoreBranchMember(node, state);
1281
+ }
1282
+ function isStoreBranchMember(node, state) {
1283
+ const parts = collectStaticMemberPath(node);
1284
+ if (parts === null || parts.length < 2) return false;
1285
+ const [root, ...path] = parts;
1286
+ if (root === undefined) return false;
1287
+ const rootNode = memberRoot(node);
1288
+ return rootNode !== null && (state.stores.get(bindingKey(rootNode))?.branchPaths.has(pathKey(path)) ?? false);
1289
+ }
1290
+ function isStoreMember(node, state) {
1291
+ const root = memberRoot(node);
1292
+ return root !== null && state.stores.has(bindingKey(root));
1293
+ }
1294
+ function hasDynamicMemberAccess(node) {
1295
+ let current = node;
1296
+ while(current?.type === "MemberExpression"){
1297
+ if (current.computed || current.property?.type === "Computed") return true;
1298
+ current = current.object;
1299
+ }
1300
+ return false;
1301
+ }
1302
+ function addDiagnostic(state, code, message) {
1303
+ if (!state.diagnostics.some((diagnostic)=>diagnostic.code === code && diagnostic.message === message)) {
1304
+ state.diagnostics.push({
1305
+ code,
1306
+ message
1307
+ });
1308
+ }
1309
+ }
1310
+
1311
+ const STORE_MODULES = new Set([
1312
+ "@volynets/reflex-store",
1313
+ "@volynets/reflex-store/store",
1314
+ "@volynets/reflex-store/compiled-store",
1315
+ "@volynets/reflex-store/advanced",
1316
+ "@reflex/store",
1317
+ "@reflex/store/store",
1318
+ "@reflex/store/compiled-store",
1319
+ "@reflex/store/advanced"
1320
+ ]);
1321
+ const DEFAULT_RUNTIME_MODULE = "@volynets/reflex-store/runtime";
1322
+ const DEFAULT_LOWERING_TARGET = {
1323
+ scope: {
1324
+ exportName: "createStoreScope",
1325
+ localName: "__reflex_createStoreScope",
1326
+ actionMethod: "action"
1327
+ },
1328
+ signal: {
1329
+ runtimeModule: "@volynets/reflex-store/runtime/internal",
1330
+ exportName: "createStoreCell",
1331
+ localName: "__reflex_signal"
1332
+ },
1333
+ identifiers: {
1334
+ context: "ctx",
1335
+ value: "value",
1336
+ read: ({ mangledPath })=>`__read_${mangledPath}`,
1337
+ set: ({ mangledPath })=>`__set_${mangledPath}`,
1338
+ write: ({ mangledPath })=>`__write_${mangledPath}`,
1339
+ temporary: ({ index, label })=>`__${label}_${index}`
1340
+ }
1341
+ };
1342
+ function compileStore(code, id = "compiled-store.ts", options = {}) {
1343
+ const ast = parseModule(code, id);
1344
+ const identifiers = new Set();
1345
+ visitNode(ast, (node)=>{
1346
+ if (node.type === "Identifier") identifiers.add(node.value);
1347
+ });
1348
+ const factoryNames = collectFactoryNames(ast);
1349
+ const diagnostics = [];
1350
+ const state = {
1351
+ diagnostics,
1352
+ options: {
1353
+ importRuntime: options.importRuntime ?? true,
1354
+ eraseFacade: options.eraseFacade ?? false,
1355
+ onDiagnostic: options.onDiagnostic ?? "throw"
1356
+ },
1357
+ target: resolveLoweringTarget(options),
1358
+ stores: collectStoreBindings(ast, diagnostics),
1359
+ tempCounter: 0,
1360
+ identifiers,
1361
+ factoryNames
1362
+ };
1363
+ state.target.scope.localName = allocateName(state.target.scope.localName, state);
1364
+ state.target.signal.localName = allocateName(state.target.signal.localName, state);
1365
+ state.target.identifiers.context = allocateName(state.target.identifiers.context, state);
1366
+ state.target.identifiers.value = allocateName(state.target.identifiers.value, state);
1367
+ const hasGetters = [
1368
+ ...state.stores.values()
1369
+ ].some((store)=>store.getters.length > 0);
1370
+ if (hasGetters) {
1371
+ state.computedName = allocateName("__reflex_createDisposableComputed", state);
1372
+ }
1373
+ const defaultScope = state.target.runtimeModule === DEFAULT_RUNTIME_MODULE && state.target.scope.exportName === "createStoreScope";
1374
+ if (!defaultScope) {
1375
+ for (const store of state.stores.values()){
1376
+ if (store.methods.length > 0 || store.getters.length > 0) {
1377
+ state.diagnostics.push({
1378
+ code: "unsupported-shape",
1379
+ message: "Compiled store methods and getters require the default Store scope lowering target."
1380
+ });
1381
+ }
1382
+ }
1383
+ }
1384
+ scanUnsupportedStoreSyntax(ast, state);
1385
+ for (const store of state.stores.values()){
1386
+ for (const member of [
1387
+ ...store.methods,
1388
+ ...store.getters
1389
+ ]){
1390
+ scanUnsupportedStoreSyntax({
1391
+ ...ast,
1392
+ body: [
1393
+ ...ast.body.filter((item)=>item.type === "ImportDeclaration"),
1394
+ {
1395
+ type: "ExpressionStatement",
1396
+ span: DUMMY_SPAN,
1397
+ expression: rewriteStoreThis(member.fn, store)
1398
+ }
1399
+ ]
1400
+ }, state);
1401
+ }
1402
+ }
1403
+ if (state.diagnostics.length > 0 && state.options.onDiagnostic === "throw") {
1404
+ throw new CompiledStoreTransformError(state.diagnostics);
1405
+ }
1406
+ if (state.diagnostics.length > 0) return {
1407
+ code,
1408
+ diagnostics: [
1409
+ ...state.diagnostics
1410
+ ],
1411
+ map: null
1412
+ };
1413
+ const transformed = transformProgram(ast, state);
1414
+ const output = printModule(transformed, {
1415
+ filename: id,
1416
+ sourceMaps: true
1417
+ });
1418
+ return {
1419
+ code: output.code,
1420
+ diagnostics: [
1421
+ ...state.diagnostics
1422
+ ],
1423
+ map: output.map ?? null
1424
+ };
1425
+ }
1426
+ function resolveLoweringTarget(options) {
1427
+ const target = options.loweringTarget;
1428
+ return {
1429
+ runtimeModule: target?.runtimeModule ?? options.runtimeModule ?? DEFAULT_RUNTIME_MODULE,
1430
+ scope: {
1431
+ ...DEFAULT_LOWERING_TARGET.scope,
1432
+ ...target?.model ? {
1433
+ curried: true
1434
+ } : {},
1435
+ ...target?.model,
1436
+ ...target?.scope
1437
+ },
1438
+ signal: {
1439
+ ...target?.runtimeModule || options.runtimeModule || target?.signal?.exportName ? {
1440
+ exportName: "signal",
1441
+ localName: "__reflex_signal"
1442
+ } : DEFAULT_LOWERING_TARGET.signal,
1443
+ ...target?.signal
1444
+ },
1445
+ identifiers: {
1446
+ ...DEFAULT_LOWERING_TARGET.identifiers,
1447
+ ...target?.identifiers
1448
+ }
1449
+ };
1450
+ }
1451
+ function transformCompiledStore(code, id = "compiled-store.ts", options = {}) {
1452
+ return compileStore(code, id, options);
1453
+ }
1454
+ function transformProgram(program, state) {
1455
+ if (program.type !== "Module") {
1456
+ return program;
1457
+ }
1458
+ let body = program.body.flatMap((item)=>transformModuleItem(item, state));
1459
+ if (state.stores.size > 0 && state.options.importRuntime) {
1460
+ body = insertRuntimeImport(body, state);
1461
+ }
1462
+ return {
1463
+ ...program,
1464
+ body
1465
+ };
1466
+ }
1467
+ function transformModuleItem(item, state) {
1468
+ switch(item.type){
1469
+ case "ImportDeclaration":
1470
+ return transformImportDeclaration(item, state);
1471
+ case "VariableDeclaration":
1472
+ return transformVariableDeclaration(item, state);
1473
+ case "ExpressionStatement":
1474
+ return [
1475
+ {
1476
+ ...item,
1477
+ expression: transformExpression(item.expression, state)
1478
+ }
1479
+ ];
1480
+ case "FunctionDeclaration":
1481
+ return [
1482
+ transformFunctionDeclaration(item, state)
1483
+ ];
1484
+ case "ExportDeclaration":
1485
+ return [
1486
+ {
1487
+ ...item,
1488
+ declaration: item.declaration?.type === "FunctionDeclaration" ? transformFunctionDeclaration(item.declaration, state) : transformNestedFunctions(item.declaration, state)
1489
+ }
1490
+ ];
1491
+ case "ExportDefaultDeclaration":
1492
+ return [
1493
+ {
1494
+ ...item,
1495
+ decl: transformNestedFunctions(item.decl, state)
1496
+ }
1497
+ ];
1498
+ case "ExportDefaultExpression":
1499
+ return [
1500
+ {
1501
+ ...item,
1502
+ expression: transformExpression(item.expression, state)
1503
+ }
1504
+ ];
1505
+ default:
1506
+ return [
1507
+ transformNestedFunctions(item, state)
1508
+ ];
1509
+ }
1510
+ }
1511
+ function transformBlockStatement(block, state) {
1512
+ return {
1513
+ ...block,
1514
+ stmts: (block.stmts ?? []).flatMap((statement)=>transformStatement(statement, state))
1515
+ };
1516
+ }
1517
+ function transformFunctionDeclaration(declaration, state) {
1518
+ return {
1519
+ ...declaration,
1520
+ body: transformBlockStatement(declaration.body, state)
1521
+ };
1522
+ }
1523
+ function transformNestedFunctions(node, state) {
1524
+ if (node === null || typeof node !== "object") return node;
1525
+ if (Array.isArray(node)) {
1526
+ return node.map((child)=>transformNestedFunctions(child, state));
1527
+ }
1528
+ if (node.type === "FunctionDeclaration") {
1529
+ return transformFunctionDeclaration(node, state);
1530
+ }
1531
+ if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
1532
+ return transformExpression(node, state);
1533
+ }
1534
+ if (node.type === "BlockStatement") {
1535
+ return transformBlockStatement(node, state);
1536
+ }
1537
+ const transformed = {
1538
+ ...node
1539
+ };
1540
+ for (const key of Object.keys(node)){
1541
+ if (key === "span" || key === "ctxt" || key === "type" || key === "raw") {
1542
+ continue;
1543
+ }
1544
+ const value = node[key];
1545
+ if (Array.isArray(value)) {
1546
+ transformed[key] = value.map((child)=>transformNestedFunctions(child, state));
1547
+ } else if (value !== null && typeof value === "object") {
1548
+ transformed[key] = transformNestedFunctions(value, state);
1549
+ }
1550
+ }
1551
+ return transformed;
1552
+ }
1553
+ function transformSingleStatement(statement, state) {
1554
+ const transformed = transformStatement(statement, state);
1555
+ if (transformed.length === 1) return transformed[0];
1556
+ return {
1557
+ type: "BlockStatement",
1558
+ span: statement.span,
1559
+ ctxt: statement.ctxt,
1560
+ stmts: transformed
1561
+ };
1562
+ }
1563
+ function transformStatement(statement, state) {
1564
+ switch(statement?.type){
1565
+ case "VariableDeclaration":
1566
+ return transformVariableDeclaration(statement, state);
1567
+ case "ExpressionStatement":
1568
+ return [
1569
+ {
1570
+ ...statement,
1571
+ expression: transformExpression(statement.expression, state)
1572
+ }
1573
+ ];
1574
+ case "ReturnStatement":
1575
+ case "ThrowStatement":
1576
+ return [
1577
+ {
1578
+ ...statement,
1579
+ argument: statement.argument ? transformExpression(statement.argument, state) : statement.argument
1580
+ }
1581
+ ];
1582
+ case "BlockStatement":
1583
+ return [
1584
+ transformBlockStatement(statement, state)
1585
+ ];
1586
+ case "FunctionDeclaration":
1587
+ return [
1588
+ transformFunctionDeclaration(statement, state)
1589
+ ];
1590
+ case "IfStatement":
1591
+ return [
1592
+ {
1593
+ ...statement,
1594
+ test: transformExpression(statement.test, state),
1595
+ consequent: transformSingleStatement(statement.consequent, state),
1596
+ alternate: statement.alternate ? transformSingleStatement(statement.alternate, state) : statement.alternate
1597
+ }
1598
+ ];
1599
+ case "WhileStatement":
1600
+ case "DoWhileStatement":
1601
+ return [
1602
+ {
1603
+ ...statement,
1604
+ test: transformExpression(statement.test, state),
1605
+ body: transformSingleStatement(statement.body, state)
1606
+ }
1607
+ ];
1608
+ case "ForStatement":
1609
+ return [
1610
+ {
1611
+ ...statement,
1612
+ init: statement.init?.type === "VariableDeclaration" ? transformVariableDeclaration(statement.init, state)[0] ?? statement.init : statement.init ? transformExpression(statement.init, state) : statement.init,
1613
+ test: statement.test ? transformExpression(statement.test, state) : statement.test,
1614
+ update: statement.update ? transformExpression(statement.update, state) : statement.update,
1615
+ body: transformSingleStatement(statement.body, state)
1616
+ }
1617
+ ];
1618
+ case "ForInStatement":
1619
+ case "ForOfStatement":
1620
+ return [
1621
+ {
1622
+ ...statement,
1623
+ right: transformExpression(statement.right, state),
1624
+ body: transformSingleStatement(statement.body, state)
1625
+ }
1626
+ ];
1627
+ case "LabeledStatement":
1628
+ return [
1629
+ {
1630
+ ...statement,
1631
+ body: transformSingleStatement(statement.body, state)
1632
+ }
1633
+ ];
1634
+ case "WithStatement":
1635
+ return [
1636
+ {
1637
+ ...statement,
1638
+ object: transformExpression(statement.object, state),
1639
+ body: transformSingleStatement(statement.body, state)
1640
+ }
1641
+ ];
1642
+ case "TryStatement":
1643
+ return [
1644
+ {
1645
+ ...statement,
1646
+ block: transformBlockStatement(statement.block, state),
1647
+ handler: statement.handler ? {
1648
+ ...statement.handler,
1649
+ body: transformBlockStatement(statement.handler.body, state)
1650
+ } : statement.handler,
1651
+ finalizer: statement.finalizer ? transformBlockStatement(statement.finalizer, state) : statement.finalizer
1652
+ }
1653
+ ];
1654
+ case "SwitchStatement":
1655
+ return [
1656
+ {
1657
+ ...statement,
1658
+ discriminant: transformExpression(statement.discriminant, state),
1659
+ cases: (statement.cases ?? []).map((item)=>({
1660
+ ...item,
1661
+ test: item.test ? transformExpression(item.test, state) : item.test,
1662
+ consequent: (item.consequent ?? []).flatMap((child)=>transformStatement(child, state))
1663
+ }))
1664
+ }
1665
+ ];
1666
+ default:
1667
+ return [
1668
+ statement
1669
+ ];
1670
+ }
1671
+ }
1672
+ function transformImportDeclaration(item, state) {
1673
+ if (!STORE_MODULES.has(item.source?.value)) {
1674
+ return [
1675
+ item
1676
+ ];
1677
+ }
1678
+ const specifiers = (item.specifiers ?? []).filter((specifier)=>!state.factoryNames.has(bindingKey(specifier.local)));
1679
+ if (specifiers.length === 0) {
1680
+ return [];
1681
+ }
1682
+ return [
1683
+ {
1684
+ ...item,
1685
+ specifiers
1686
+ }
1687
+ ];
1688
+ }
1689
+ function transformVariableDeclaration(item, state) {
1690
+ const output = [];
1691
+ let pending = [];
1692
+ const flushPending = ()=>{
1693
+ if (pending.length === 0) {
1694
+ return;
1695
+ }
1696
+ output.push({
1697
+ ...item,
1698
+ declarations: pending
1699
+ });
1700
+ pending = [];
1701
+ };
1702
+ for (const declaration of item.declarations ?? []){
1703
+ const name = declaration.id?.type === "Identifier" ? declaration.id.value : null;
1704
+ const binding = name === null ? undefined : state.stores.get(bindingKey(declaration.id));
1705
+ if (binding === undefined) {
1706
+ pending.push(transformVariableDeclarator(declaration, state));
1707
+ continue;
1708
+ }
1709
+ flushPending();
1710
+ output.push(...createCompiledStoreStatements(binding, item.kind, state));
1711
+ }
1712
+ flushPending();
1713
+ return output;
1714
+ }
1715
+ function transformVariableDeclarator(declaration, state) {
1716
+ if (declaration.init === undefined) {
1717
+ return declaration;
1718
+ }
1719
+ return {
1720
+ ...declaration,
1721
+ init: transformExpression(declaration.init, state)
1722
+ };
1723
+ }
1724
+ function insertRuntimeImport(body, state) {
1725
+ const { scope, runtimeModule, signal } = state.target;
1726
+ const signalModule = signal.runtimeModule ?? runtimeModule;
1727
+ const runtimeNames = [
1728
+ scope.exportName + " as " + scope.localName
1729
+ ];
1730
+ if (state.computedName) runtimeNames.push("createDisposableComputed as " + state.computedName);
1731
+ if (signalModule === runtimeModule) runtimeNames.push(signal.exportName + " as " + signal.localName);
1732
+ let source = "import { " + runtimeNames.join(", ") + " } from " + JSON.stringify(runtimeModule) + ";";
1733
+ if (signalModule !== runtimeModule) {
1734
+ source += "\nimport { " + signal.exportName + " as " + signal.localName + " } from " + JSON.stringify(signalModule) + ";";
1735
+ }
1736
+ const imports = parseModule(source, "compiled-store-runtime-import.ts").body;
1737
+ const insertIndex = body.findIndex((item)=>item.type !== "ImportDeclaration");
1738
+ const index = insertIndex === -1 ? body.length : insertIndex;
1739
+ return [
1740
+ ...body.slice(0, index),
1741
+ ...imports,
1742
+ ...body.slice(index)
1743
+ ];
1744
+ }
1745
+ function createCompiledStoreStatements(binding, kind, state) {
1746
+ const lines = [];
1747
+ const { identifiers, scope, signal } = state.target;
1748
+ const defaultScope = state.target.runtimeModule === DEFAULT_RUNTIME_MODULE && scope.exportName === "createStoreScope";
1749
+ const scopeName = defaultScope ? nextTemp(state, "scope") : binding.name;
1750
+ const emitFacade = defaultScope && (!state.options.eraseFacade || binding.needsFacade);
1751
+ if (emitFacade) binding.lifetimeName ??= allocateName("__store_alive", state);
1752
+ for (const method of binding.methods){
1753
+ method.internalName ??= allocateName("__store_method_" + method.key.replace(/[^A-Za-z0-9_$]/g, "_"), state);
1754
+ }
1755
+ for (const getter of binding.getters){
1756
+ getter.internalName ??= allocateName("__store_getter_" + getter.key.replace(/[^A-Za-z0-9_$]/g, "_"), state);
1757
+ }
1758
+ for (const leaf of binding.leaves){
1759
+ const names = getLeafNames(leaf, state);
1760
+ lines.push(defaultScope ? "let " + names.read + ";" : "const " + names.read + " = " + createCellSource(leaf, binding, state) + ";");
1761
+ lines.push("let " + names.write + ";");
1762
+ }
1763
+ lines.push(kind + " " + scopeName + " = " + scope.localName + "((" + identifiers.context + ") => {");
1764
+ for (const leaf of binding.leaves){
1765
+ const names = getLeafNames(leaf, state);
1766
+ const action = formatMemberAccess(identifiers.context, scope.actionMethod);
1767
+ if (defaultScope) {
1768
+ lines.push(" " + names.read + " = " + identifiers.context + ".own(" + createCellSource(leaf, binding, state) + ");");
1769
+ }
1770
+ if (!defaultScope && signal.exportName === "createStoreCell" && signal.runtimeModule === "@volynets/reflex-store/runtime/internal") {
1771
+ lines.push(" " + identifiers.context + ".onDispose(" + names.read + ".dispose);");
1772
+ }
1773
+ if (defaultScope && signal.exportName === "createStoreCell" && signal.runtimeModule === "@volynets/reflex-store/runtime/internal") {
1774
+ lines.push(" " + names.write + " = " + identifiers.context + ".writer(" + names.read + ");");
1775
+ continue;
1776
+ }
1777
+ lines.push(" " + names.write + " = " + action + "((" + identifiers.value + ") => {");
1778
+ lines.push(" " + names.read + ".set(" + identifiers.value + ");");
1779
+ lines.push(" return " + identifiers.value + ";");
1780
+ lines.push(" });");
1781
+ }
1782
+ const action = formatMemberAccess(identifiers.context, scope.actionMethod);
1783
+ for (const method of binding.methods){
1784
+ const fn = transformExpression(rewriteStoreThis(method.fn, binding), state);
1785
+ lines.push(" const " + method.internalName + " = " + action + "(" + printExpression(fn) + ");");
1786
+ }
1787
+ for (const getter of binding.getters){
1788
+ if (!state.computedName) {
1789
+ throw new Error("Missing generated computed import for store getter.");
1790
+ }
1791
+ const getterValue = nextTemp(state, "getter");
1792
+ const fn = transformExpression(rewriteStoreThis(getter.fn, binding), state);
1793
+ lines.push(" const " + getterValue + " = " + state.computedName + "(() => (" + printExpression(fn) + ").call(" + binding.name + "));");
1794
+ lines.push(" " + identifiers.context + ".own({ [Symbol.dispose]: () => " + getterValue + ".dispose() });");
1795
+ lines.push(" const " + getter.internalName + " = " + getterValue + ".read;");
1796
+ }
1797
+ lines.push(" return " + (defaultScope ? createStoreScopeSource(binding, identifiers.context, emitFacade) : createStoreObjectSource(binding, state)) + ";");
1798
+ lines.push(scope.curried ? "})();" : "});");
1799
+ if (emitFacade) {
1800
+ const facade = createStoreObjectSource(binding, state, scopeName);
1801
+ const contents = facade.slice(1, -1).trim();
1802
+ lines.push(kind + " " + binding.name + " = { " + contents + (contents ? "," : "") + " dispose: " + scopeName + ".dispose, [Symbol.dispose]: " + scopeName + "[Symbol.dispose] };");
1803
+ }
1804
+ if (emitFacade) {
1805
+ if (binding.displayName) lines.push("Object.defineProperty(" + binding.name + ", Symbol.for('@volynets/reflex-store/name'), { value: " + JSON.stringify(binding.displayName) + " });");
1806
+ const guard = "if (!" + formatMemberAccess(scopeName, binding.lifetimeName) + "()) throw new Error('Cannot use a disposed compiled store'); ";
1807
+ const writes = binding.leaves.map((leaf, index)=>getLeafNames(leaf, state).write + "(values[" + index + "]);").join(" ");
1808
+ const collects = binding.leaves.map((leaf)=>getLeafNames(leaf, state).read + ".collect();").join(" ");
1809
+ lines.push("Object.defineProperty(" + binding.name + ", Symbol.for('@volynets/reflex-store/data/1'), { value: {" + "raw: () => { " + guard + "return " + createStoreDataSource(binding, state) + "; }," + "snapshot: (data, copy) => { " + guard + "return " + createStoreDataSource(binding, state, true) + "; }," + "paths: " + JSON.stringify(binding.leaves.map((leaf)=>leaf.parts)) + "," + "branches: " + JSON.stringify([
1810
+ [],
1811
+ ...[
1812
+ ...binding.branchPaths
1813
+ ].map((path)=>JSON.parse(path))
1814
+ ]) + "," + "hydrate: (values) => { " + guard + writes + " }," + "collect: () => { " + collects + " }," + "dispose: " + binding.name + ".dispose } });");
1815
+ }
1816
+ return parseModule(lines.join("\n"), "compiled-store-lowering.ts").body;
1817
+ }
1818
+ function createCellSource(leaf, binding, state) {
1819
+ const signal = state.target.signal;
1820
+ const options = binding.displayName && signal.exportName === "createStoreCell" ? ", " + JSON.stringify({
1821
+ name: binding.displayName + "." + leaf.parts.join(".")
1822
+ }) : "";
1823
+ return signal.localName + "(" + printExpression(leaf.initial) + options + ")";
1824
+ }
1825
+ function rewriteStoreThis(node, binding, root = true) {
1826
+ if (!node || typeof node !== "object") return node;
1827
+ if (Array.isArray(node)) return node.map((child)=>rewriteStoreThis(child, binding, false));
1828
+ if (node.type === "ThisExpression") return {
1829
+ ...binding.identifier
1830
+ };
1831
+ if (!root && [
1832
+ "FunctionExpression",
1833
+ "FunctionDeclaration",
1834
+ "MethodProperty",
1835
+ "GetterProperty",
1836
+ "SetterProperty",
1837
+ "ClassExpression",
1838
+ "ClassDeclaration"
1839
+ ].includes(node.type)) return node;
1840
+ const result = {
1841
+ ...node
1842
+ };
1843
+ for (const key of Object.keys(node)){
1844
+ if (![
1845
+ "span",
1846
+ "ctxt"
1847
+ ].includes(key)) result[key] = rewriteStoreThis(node[key], binding, false);
1848
+ }
1849
+ return result;
1850
+ }
1851
+ function createStoreDataSource(binding, state, snapshot = false) {
1852
+ const root = createStoreTreeNode();
1853
+ for (const path of binding.branchPaths){
1854
+ let branch = root;
1855
+ for (const key of JSON.parse(path)){
1856
+ let next = branch.branches.get(key);
1857
+ if (!next) branch.branches.set(key, next = createStoreTreeNode());
1858
+ branch = next;
1859
+ }
1860
+ }
1861
+ for (const leaf of binding.leaves)insertStoreLeaf(root, leaf.parts, leaf);
1862
+ const render = (node)=>{
1863
+ const entries = [
1864
+ ...node.branches
1865
+ ].map(([key, branch])=>({
1866
+ key,
1867
+ value: render(branch)
1868
+ }));
1869
+ for (const [key, leaf] of node.leaves){
1870
+ let value = getLeafNames(leaf, state).read + "()";
1871
+ if (snapshot) {
1872
+ value = "data";
1873
+ for (const part of leaf.parts)value = formatMemberAccess(value, part);
1874
+ value = "copy(" + value + ")";
1875
+ }
1876
+ entries.push({
1877
+ key,
1878
+ value
1879
+ });
1880
+ }
1881
+ if (snapshot) {
1882
+ // Match Reflect.ownKeys ordering: array-index keys precede other strings.
1883
+ const indexOf = (key)=>{
1884
+ const index = Number(key);
1885
+ return Number.isInteger(index) && index >= 0 && index < 0xffffffff && String(index) === key ? index : Infinity;
1886
+ };
1887
+ entries.sort((a, b)=>indexOf(a.key) - indexOf(b.key));
1888
+ }
1889
+ const object = "{" + entries.map(({ key, value })=>formatObjectKey(key) + ": " + value).join(", ") + "}";
1890
+ return snapshot ? "Object.freeze(" + object + ")" : object;
1891
+ };
1892
+ return render(root);
1893
+ }
1894
+ function createStoreScopeSource(binding, context, emitFacade) {
1895
+ const members = [
1896
+ ...emitFacade ? [
1897
+ binding.lifetimeName + ": () => !" + context + ".disposed"
1898
+ ] : [],
1899
+ ...binding.methods.map((method)=>method.internalName + ": " + method.internalName),
1900
+ ...binding.getters.map((getter)=>getter.internalName + ": " + getter.internalName)
1901
+ ];
1902
+ return members.length === 0 ? "{}" : "{ " + members.join(", ") + " }";
1903
+ }
1904
+ function createStoreObjectSource(binding, state, scopeName) {
1905
+ const root = createStoreTreeNode();
1906
+ for (const path of binding.branchPaths){
1907
+ let branch = root;
1908
+ for (const key of JSON.parse(path)){
1909
+ let next = branch.branches.get(key);
1910
+ if (!next) {
1911
+ next = createStoreTreeNode();
1912
+ branch.branches.set(key, next);
1913
+ }
1914
+ branch = next;
1915
+ }
1916
+ }
1917
+ for (const leaf of binding.leaves){
1918
+ insertStoreLeaf(root, leaf.parts, leaf);
1919
+ }
1920
+ return createStoreTreeObjectSource(root, state, 2, binding, scopeName);
1921
+ }
1922
+ function createStoreTreeNode() {
1923
+ return {
1924
+ branches: new Map(),
1925
+ leaves: new Map()
1926
+ };
1927
+ }
1928
+ function insertStoreLeaf(node, parts, leaf) {
1929
+ const [head, ...tail] = parts;
1930
+ if (head === undefined) {
1931
+ return;
1932
+ }
1933
+ if (tail.length === 0) {
1934
+ node.leaves.set(head, leaf);
1935
+ return;
1936
+ }
1937
+ let branch = node.branches.get(head);
1938
+ if (branch === undefined) {
1939
+ branch = createStoreTreeNode();
1940
+ node.branches.set(head, branch);
1941
+ }
1942
+ insertStoreLeaf(branch, tail, leaf);
1943
+ }
1944
+ function createStoreTreeObjectSource(node, state, indent, rootBinding, scopeName) {
1945
+ const pad = " ".repeat(indent);
1946
+ const childPad = " ".repeat(indent + 2);
1947
+ const entries = [];
1948
+ for (const [key, branch] of node.branches){
1949
+ entries.push(childPad + formatObjectKey(key) + ": " + createStoreTreeObjectSource(branch, state, indent + 2));
1950
+ }
1951
+ for (const [key, leaf] of node.leaves){
1952
+ const names = getLeafNames(leaf, state);
1953
+ entries.push([
1954
+ childPad + "get " + formatObjectKey(key) + "() {",
1955
+ childPad + " return " + names.read + "();",
1956
+ childPad + "},",
1957
+ childPad + "set " + formatObjectKey(key) + "(" + state.target.identifiers.value + ") {",
1958
+ childPad + " " + names.write + "(" + state.target.identifiers.value + ");",
1959
+ childPad + "}"
1960
+ ].join("\n"));
1961
+ }
1962
+ if (rootBinding && scopeName) {
1963
+ for (const method of rootBinding.methods){
1964
+ entries.push(childPad + formatObjectKey(method.key) + ": " + "function (...args) { if (!" + formatMemberAccess(scopeName, rootBinding.lifetimeName) + "()) throw new Error('Cannot call a disposed compiled store'); return " + formatMemberAccess(scopeName, method.internalName) + ".apply(" + rootBinding.name + ", args); }");
1965
+ }
1966
+ for (const getter of rootBinding.getters){
1967
+ entries.push(childPad + "get " + formatObjectKey(getter.key) + "() { if (!" + formatMemberAccess(scopeName, rootBinding.lifetimeName) + "()) throw new Error('Cannot read a disposed compiled store'); return " + formatMemberAccess(scopeName, getter.internalName) + "(); }");
1968
+ }
1969
+ }
1970
+ if (entries.length === 0) {
1971
+ return "{}";
1972
+ }
1973
+ return "{\n" + entries.join(",\n") + "\n" + pad + "}";
1974
+ }
1975
+ function formatObjectKey(key) {
1976
+ return isIdentifierName(key) ? key : JSON.stringify(key);
1977
+ }
1978
+ function formatMemberAccess(object, property) {
1979
+ return isIdentifierName(property) ? `${object}.${property}` : `${object}[${JSON.stringify(property)}]`;
1980
+ }
1981
+ function allocateName(preferred, state) {
1982
+ if (!isIdentifierName(preferred)) throw new Error("Invalid generated identifier: " + preferred);
1983
+ let name = preferred;
1984
+ let suffix = 0;
1985
+ while(state.identifiers.has(name))name = preferred + "_" + ++suffix;
1986
+ state.identifiers.add(name);
1987
+ return name;
1988
+ }
1989
+ function getLeafNames(leaf, state) {
1990
+ if (leaf.names) return leaf.names;
1991
+ const context = {
1992
+ path: leaf.parts,
1993
+ mangledPath: leaf.mangled
1994
+ };
1995
+ return leaf.names = {
1996
+ read: allocateName(state.target.identifiers.read(context), state),
1997
+ set: allocateName(state.target.identifiers.set(context), state),
1998
+ write: allocateName(state.target.identifiers.write(context), state)
1999
+ };
2000
+ }
2001
+ function printExpression(expression) {
2002
+ const output = printModule({
2003
+ type: "Module",
2004
+ span: DUMMY_SPAN,
2005
+ body: [
2006
+ {
2007
+ type: "ExpressionStatement",
2008
+ span: DUMMY_SPAN,
2009
+ expression
2010
+ }
2011
+ ],
2012
+ interpreter: null
2013
+ }, {
2014
+ sourceMaps: false
2015
+ }).code.trim();
2016
+ return output.endsWith(";") ? output.slice(0, -1) : output;
2017
+ }
2018
+ function transformExpression(node, state) {
2019
+ if (node.type === "FunctionExpression") {
2020
+ return {
2021
+ ...node,
2022
+ body: transformBlockStatement(node.body, state)
2023
+ };
2024
+ }
2025
+ if (node.type === "ArrowFunctionExpression") {
2026
+ return {
2027
+ ...node,
2028
+ body: node.body.type === "BlockStatement" ? transformBlockStatement(node.body, state) : transformExpression(node.body, state)
2029
+ };
2030
+ }
2031
+ let result = node;
2032
+ const stack = [
2033
+ {
2034
+ phase: "enter",
2035
+ node,
2036
+ assign (expression) {
2037
+ result = expression;
2038
+ }
2039
+ }
2040
+ ];
2041
+ while(stack.length > 0){
2042
+ const frame = stack.pop();
2043
+ if (frame === undefined) continue;
2044
+ if (frame.phase === "exit") {
2045
+ frame.assign(finalizeExpression(frame.node, frame.slots, state));
2046
+ continue;
2047
+ }
2048
+ const expression = frame.node;
2049
+ if (expression.type === "FunctionExpression" || expression.type === "ArrowFunctionExpression") {
2050
+ frame.assign(transformExpression(expression, state));
2051
+ continue;
2052
+ }
2053
+ const childCount = countTransformChildren(expression, state);
2054
+ if (childCount === 0) {
2055
+ const withNestedFunctions = transformNestedFunctions(expression, state);
2056
+ frame.assign(finalizeExpression(withNestedFunctions, EMPTY_SLOTS, state));
2057
+ continue;
2058
+ }
2059
+ const slots = createSlots(childCount);
2060
+ stack.push({
2061
+ phase: "exit",
2062
+ node: expression,
2063
+ assign: frame.assign,
2064
+ slots
2065
+ });
2066
+ pushExpressionChildren(expression, state, slots, stack);
2067
+ }
2068
+ return result;
2069
+ }
2070
+ function nextTemp(state, label) {
2071
+ state.tempCounter += 1;
2072
+ return allocateName(state.target.identifiers.temporary({
2073
+ index: state.tempCounter,
2074
+ label
2075
+ }), state);
2076
+ }
2077
+ function isIdentifierName(value) {
2078
+ return /^[$A-Z_a-z][$\w]*$/.test(value);
2079
+ }
2080
+ function getLeafPathForMember(node, stores) {
2081
+ const parts = collectStaticMemberPath(node);
2082
+ if (parts === null || parts.length < 2) {
2083
+ return null;
2084
+ }
2085
+ const [root, ...path] = parts;
2086
+ if (root === undefined) {
2087
+ return null;
2088
+ }
2089
+ const rootNode = memberRoot(node);
2090
+ const store = rootNode ? stores.get(bindingKey(rootNode)) : undefined;
2091
+ if (!store) {
2092
+ return null;
2093
+ }
2094
+ return store.leafPaths.get(pathKey(path)) ?? null;
2095
+ }
2096
+ function getLeafPathForTarget(node, stores) {
2097
+ if (node?.type === "MemberExpression") {
2098
+ return getLeafPathForMember(node, stores);
2099
+ }
2100
+ if (node?.type === "SimpleAssignmentTarget" && node.value?.type === "MemberExpression") {
2101
+ return getLeafPathForMember(node.value, stores);
2102
+ }
2103
+ return null;
2104
+ }
2105
+ function createReadCall(leaf, state) {
2106
+ return createCallExpression(getLeafNames(leaf, state).read, []);
2107
+ }
2108
+ function createWriteCall(leaf, value, state) {
2109
+ return createCallExpression(getLeafNames(leaf, state).write, [
2110
+ value
2111
+ ]);
2112
+ }
2113
+ function createCompoundAssignment(leaf, operator, right, rhsTemp, nextTempName, state) {
2114
+ const previous = nextTemp(state, "previous");
2115
+ return createIIFE([
2116
+ createConstDeclaration(previous, createReadCall(leaf, state)),
2117
+ createConstDeclaration(rhsTemp, right),
2118
+ createConstDeclaration(nextTempName, createBinaryExpression(createIdentifierExpression(previous), operator, createIdentifierExpression(rhsTemp))),
2119
+ createExpressionStatement(createWriteCall(leaf, createIdentifierExpression(nextTempName), state)),
2120
+ createReturnStatement(createIdentifierExpression(nextTempName))
2121
+ ]);
2122
+ }
2123
+ function createUpdateExpressionLowering(leaf, operator, tempName, prefix, state) {
2124
+ const declaration = createConstDeclaration(tempName, createReadCall(leaf, state));
2125
+ declaration.kind = "let";
2126
+ const result = nextTemp(state, "result");
2127
+ return createIIFE([
2128
+ declaration,
2129
+ createConstDeclaration(result, {
2130
+ type: "UpdateExpression",
2131
+ span: DUMMY_SPAN,
2132
+ operator: operator === "+" ? "++" : "--",
2133
+ prefix,
2134
+ argument: createIdentifierExpression(tempName)
2135
+ }),
2136
+ createExpressionStatement(createWriteCall(leaf, createIdentifierExpression(tempName), state)),
2137
+ createReturnStatement(createIdentifierExpression(result))
2138
+ ]);
2139
+ }
2140
+ function createIdentifierExpression(name) {
2141
+ return {
2142
+ type: "Identifier",
2143
+ span: DUMMY_SPAN,
2144
+ ctxt: 0,
2145
+ value: name,
2146
+ optional: false
2147
+ };
2148
+ }
2149
+ function createCallExpression(calleeName, args) {
2150
+ return {
2151
+ type: "CallExpression",
2152
+ span: DUMMY_SPAN,
2153
+ ctxt: 0,
2154
+ callee: createIdentifierExpression(calleeName),
2155
+ arguments: args.map((expression)=>({
2156
+ expression
2157
+ })),
2158
+ typeArguments: undefined
2159
+ };
2160
+ }
2161
+ function createBinaryExpression(left, operator, right) {
2162
+ return {
2163
+ type: "BinaryExpression",
2164
+ span: DUMMY_SPAN,
2165
+ operator,
2166
+ left,
2167
+ right
2168
+ };
2169
+ }
2170
+ function createConstDeclaration(name, init) {
2171
+ return {
2172
+ type: "VariableDeclaration",
2173
+ span: DUMMY_SPAN,
2174
+ ctxt: 0,
2175
+ kind: "const",
2176
+ declare: false,
2177
+ declarations: [
2178
+ {
2179
+ type: "VariableDeclarator",
2180
+ span: DUMMY_SPAN,
2181
+ definite: false,
2182
+ id: {
2183
+ type: "Identifier",
2184
+ span: DUMMY_SPAN,
2185
+ ctxt: 0,
2186
+ value: name,
2187
+ optional: false,
2188
+ typeAnnotation: undefined
2189
+ },
2190
+ init
2191
+ }
2192
+ ]
2193
+ };
2194
+ }
2195
+ function createExpressionStatement(expression) {
2196
+ return {
2197
+ type: "ExpressionStatement",
2198
+ span: DUMMY_SPAN,
2199
+ expression
2200
+ };
2201
+ }
2202
+ function createReturnStatement(argument) {
2203
+ return {
2204
+ type: "ReturnStatement",
2205
+ span: DUMMY_SPAN,
2206
+ argument
2207
+ };
2208
+ }
2209
+ function createIIFE(statements) {
2210
+ return {
2211
+ type: "CallExpression",
2212
+ span: DUMMY_SPAN,
2213
+ ctxt: 0,
2214
+ callee: {
2215
+ type: "ParenthesisExpression",
2216
+ span: DUMMY_SPAN,
2217
+ expression: {
2218
+ type: "ArrowFunctionExpression",
2219
+ span: DUMMY_SPAN,
2220
+ ctxt: 0,
2221
+ params: [],
2222
+ body: {
2223
+ type: "BlockStatement",
2224
+ span: DUMMY_SPAN,
2225
+ ctxt: 0,
2226
+ stmts: statements
2227
+ },
2228
+ async: false,
2229
+ generator: false,
2230
+ typeParameters: undefined,
2231
+ returnType: undefined
2232
+ }
2233
+ },
2234
+ arguments: [],
2235
+ typeArguments: undefined
2236
+ };
2237
+ }
2238
+ const EMPTY_SLOTS = [];
2239
+ const SIMPLE_CHILDREN = new Set([
2240
+ "BinaryExpression",
2241
+ "ParenthesisExpression",
2242
+ "UnaryExpression",
2243
+ "ConditionalExpression",
2244
+ "SequenceExpression",
2245
+ "TemplateLiteral"
2246
+ ]);
2247
+ function createSlots(size) {
2248
+ return new Array(size);
2249
+ }
2250
+ function countTransformChildren(node, state) {
2251
+ switch(node.type){
2252
+ case "AssignmentExpression":
2253
+ return 1;
2254
+ case "UpdateExpression":
2255
+ return getLeafPathForTarget(node.argument, state.stores) === null ? 1 : 0;
2256
+ case "MemberExpression":
2257
+ return 1;
2258
+ case "CallExpression":
2259
+ return getCallExpressionChildCount(node);
2260
+ default:
2261
+ return SIMPLE_CHILDREN.has(node.type) ? getSimpleChildSpecs(node).length : 0;
2262
+ }
2263
+ }
2264
+ function pushExpressionChildren(node, state, slots, stack) {
2265
+ switch(node.type){
2266
+ case "AssignmentExpression":
2267
+ pushChild(stack, node.right, slots, 0);
2268
+ return;
2269
+ case "UpdateExpression":
2270
+ if (getLeafPathForTarget(node.argument, state.stores) === null) {
2271
+ pushChild(stack, node.argument, slots, 0);
2272
+ }
2273
+ return;
2274
+ case "MemberExpression":
2275
+ pushChild(stack, node.object, slots, 0);
2276
+ return;
2277
+ case "CallExpression":
2278
+ {
2279
+ for(let argIndex = node.arguments.length - 1; argIndex >= 0; argIndex--){
2280
+ const arg = node.arguments[argIndex];
2281
+ if (arg?.expression === undefined) {
2282
+ continue;
2283
+ }
2284
+ const slotIndex = getCallExpressionSlotIndex(node, argIndex);
2285
+ pushChild(stack, arg.expression, slots, slotIndex);
2286
+ }
2287
+ const index = getCallExpressionCalleeSlotIndex(node);
2288
+ if (index !== -1) {
2289
+ const calleeExpression = getCalleeExpression(node.callee);
2290
+ if (calleeExpression !== null) {
2291
+ pushChild(stack, calleeExpression, slots, index);
2292
+ }
2293
+ }
2294
+ return;
2295
+ }
2296
+ default:
2297
+ const specs = getSimpleChildSpecs(node);
2298
+ for(let i = specs.length - 1; i >= 0; i--){
2299
+ const [index, expression] = specs[i];
2300
+ pushChild(stack, expression, slots, index);
2301
+ }
2302
+ return;
2303
+ }
2304
+ }
2305
+ function finalizeExpression(node, slots, state) {
2306
+ switch(node.type){
2307
+ case "AssignmentExpression":
2308
+ return finalizeAssignmentExpression(node, slots, state);
2309
+ case "UpdateExpression":
2310
+ return finalizeUpdateExpression(node, slots, state);
2311
+ case "MemberExpression":
2312
+ return finalizeMemberExpression(node, slots, state);
2313
+ case "CallExpression":
2314
+ return finalizeCallExpression(node, slots);
2315
+ default:
2316
+ return SIMPLE_CHILDREN.has(node.type) ? finalizeSimpleExpression(node, slots) : node;
2317
+ }
2318
+ }
2319
+ function getSimpleChildSpecs(node) {
2320
+ switch(node.type){
2321
+ case "BinaryExpression":
2322
+ return [
2323
+ [
2324
+ 0,
2325
+ node.left
2326
+ ],
2327
+ [
2328
+ 1,
2329
+ node.right
2330
+ ]
2331
+ ];
2332
+ case "ParenthesisExpression":
2333
+ return [
2334
+ [
2335
+ 0,
2336
+ node.expression
2337
+ ]
2338
+ ];
2339
+ case "UnaryExpression":
2340
+ return [
2341
+ [
2342
+ 0,
2343
+ node.argument
2344
+ ]
2345
+ ];
2346
+ case "ConditionalExpression":
2347
+ return [
2348
+ [
2349
+ 0,
2350
+ node.test
2351
+ ],
2352
+ [
2353
+ 1,
2354
+ node.consequent
2355
+ ],
2356
+ [
2357
+ 2,
2358
+ node.alternate
2359
+ ]
2360
+ ];
2361
+ case "SequenceExpression":
2362
+ case "TemplateLiteral":
2363
+ return node.expressions.map((expression, index)=>[
2364
+ index,
2365
+ expression
2366
+ ]);
2367
+ default:
2368
+ return [];
2369
+ }
2370
+ }
2371
+ function finalizeSimpleExpression(node, slots) {
2372
+ switch(node.type){
2373
+ case "BinaryExpression":
2374
+ return {
2375
+ ...node,
2376
+ left: slots[0] ?? node.left,
2377
+ right: slots[1] ?? node.right
2378
+ };
2379
+ case "ParenthesisExpression":
2380
+ return {
2381
+ ...node,
2382
+ expression: slots[0] ?? node.expression
2383
+ };
2384
+ case "UnaryExpression":
2385
+ return {
2386
+ ...node,
2387
+ argument: slots[0] ?? node.argument
2388
+ };
2389
+ case "ConditionalExpression":
2390
+ return {
2391
+ ...node,
2392
+ test: slots[0] ?? node.test,
2393
+ consequent: slots[1] ?? node.consequent,
2394
+ alternate: slots[2] ?? node.alternate
2395
+ };
2396
+ case "SequenceExpression":
2397
+ case "TemplateLiteral":
2398
+ return {
2399
+ ...node,
2400
+ expressions: node.expressions.map((expression, index)=>slots[index] ?? expression)
2401
+ };
2402
+ default:
2403
+ return node;
2404
+ }
2405
+ }
2406
+ function finalizeAssignmentExpression(node, slots, state) {
2407
+ const leafPath = getLeafPathForTarget(node.left, state.stores);
2408
+ const right = slots[0] ?? node.right;
2409
+ if (leafPath === null) {
2410
+ return {
2411
+ ...node,
2412
+ right
2413
+ };
2414
+ }
2415
+ switch(node.operator){
2416
+ case "=":
2417
+ return createWriteCall(leafPath, right, state);
2418
+ case "+=":
2419
+ return createCompoundAssignment(leafPath, "+", right, nextTemp(state, "rhs"), nextTemp(state, "next"), state);
2420
+ case "-=":
2421
+ return createCompoundAssignment(leafPath, "-", right, nextTemp(state, "rhs"), nextTemp(state, "next"), state);
2422
+ default:
2423
+ return {
2424
+ ...node,
2425
+ right
2426
+ };
2427
+ }
2428
+ }
2429
+ function finalizeUpdateExpression(node, slots, state) {
2430
+ const leafPath = getLeafPathForTarget(node.argument, state.stores);
2431
+ if (leafPath === null) {
2432
+ return {
2433
+ ...node,
2434
+ argument: slots[0] ?? node.argument
2435
+ };
2436
+ }
2437
+ const operator = node.operator === "++" ? "+" : node.operator === "--" ? "-" : null;
2438
+ if (operator === null) {
2439
+ return node;
2440
+ }
2441
+ return createUpdateExpressionLowering(leafPath, operator, nextTemp(state, node.prefix ? "next" : "prev"), node.prefix, state);
2442
+ }
2443
+ function finalizeMemberExpression(node, slots, state) {
2444
+ const next = {
2445
+ ...node,
2446
+ object: slots[0] ?? node.object
2447
+ };
2448
+ const leafPath = getLeafPathForMember(next, state.stores);
2449
+ if (leafPath === null) {
2450
+ return next;
2451
+ }
2452
+ return createReadCall(leafPath, state);
2453
+ }
2454
+ function finalizeCallExpression(node, slots, state) {
2455
+ const nextArgs = node.arguments.map((arg, index)=>{
2456
+ if (arg?.expression === undefined) {
2457
+ return arg;
2458
+ }
2459
+ const slotIndex = getCallExpressionSlotIndex(node, index);
2460
+ return {
2461
+ ...arg,
2462
+ expression: slotIndex === -1 ? arg.expression : slots[slotIndex] ?? arg.expression
2463
+ };
2464
+ });
2465
+ const calleeSlotIndex = getCallExpressionCalleeSlotIndex(node);
2466
+ const calleeExpression = getCalleeExpression(node.callee);
2467
+ const nextCallee = calleeSlotIndex === -1 || calleeExpression === null ? node.callee : setCalleeExpression(node.callee, slots[calleeSlotIndex] ?? calleeExpression);
2468
+ return {
2469
+ ...node,
2470
+ callee: nextCallee,
2471
+ arguments: nextArgs
2472
+ };
2473
+ }
2474
+ function getCallExpressionChildCount(node) {
2475
+ let count = 0;
2476
+ if (getCalleeExpression(node.callee) !== null) {
2477
+ count += 1;
2478
+ }
2479
+ for (const arg of node.arguments ?? []){
2480
+ if (arg?.expression !== undefined) {
2481
+ count += 1;
2482
+ }
2483
+ }
2484
+ return count;
2485
+ }
2486
+ function getCallExpressionCalleeSlotIndex(node, _state) {
2487
+ return getCalleeExpression(node.callee) === null ? -1 : 0;
2488
+ }
2489
+ function getCallExpressionSlotIndex(node, argumentIndex, _state) {
2490
+ let index = getCallExpressionCalleeSlotIndex(node) === -1 ? 0 : 1;
2491
+ for(let i = 0; i < argumentIndex; i++){
2492
+ if (node.arguments[i]?.expression !== undefined) {
2493
+ index += 1;
2494
+ }
2495
+ }
2496
+ return node.arguments[argumentIndex]?.expression === undefined ? -1 : index;
2497
+ }
2498
+ function getCalleeExpression(callee) {
2499
+ if (callee?.type === "Super") {
2500
+ return null;
2501
+ }
2502
+ if (callee?.type === "Expression") {
2503
+ return callee.expression;
2504
+ }
2505
+ return callee;
2506
+ }
2507
+ function setCalleeExpression(callee, expression) {
2508
+ if (callee?.type === "Expression") {
2509
+ return {
2510
+ ...callee,
2511
+ expression
2512
+ };
2513
+ }
2514
+ return expression;
2515
+ }
2516
+ function pushChild(stack, node, slots, index) {
2517
+ stack.push({
2518
+ phase: "enter",
2519
+ node,
2520
+ assign (expression) {
2521
+ slots[index] = expression;
2522
+ }
2523
+ });
2524
+ }
2525
+
2526
+ export { CompiledStoreTransformError as C, compileStore as c, transformCompiledStore as t };