@volynets/reflex-store 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +237 -2
- package/SPECIFICATION.md +137 -0
- package/dist/advanced.d.ts +12 -0
- package/dist/advanced.js +10 -0
- package/dist/chunks/collections-yHy0wH0f.js +268 -0
- package/dist/chunks/compiler-Dsb3E2ck.js +2516 -0
- package/dist/chunks/createStore-DHj16Ehk.js +12 -0
- package/dist/chunks/hydrate-DMnHCI5q.js +138 -0
- package/dist/chunks/keyed-CQKtL8a7.js +383 -0
- package/dist/chunks/names-Cx4YcvsH.js +11 -0
- package/dist/chunks/values-DCB6zyMz.js +142 -0
- package/dist/compiled-store.d.ts +4 -0
- package/dist/compiled-store.js +4 -0
- package/dist/compiler/swc.wasm +0 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +8 -0
- package/dist/licenses/NOTICE.txt +1 -0
- package/dist/licenses/SWC-APACHE-2.0.txt +202 -0
- package/dist/runtime/core.d.ts +2 -0
- package/dist/runtime/core.js +1 -0
- package/dist/runtime/internal.d.ts +3 -0
- package/dist/runtime/internal.js +41 -0
- package/dist/runtime.d.ts +29 -0
- package/dist/runtime.js +88 -0
- package/dist/selectors/index.d.ts +13 -0
- package/dist/selectors/index.js +16 -0
- package/dist/selectors/shared.d.ts +3 -0
- package/dist/selectors/shared.js +64 -0
- package/dist/store.d.ts +9 -0
- package/dist/store.js +4 -0
- package/dist/types/contracts-BCsRPdQb.d.ts +78 -0
- package/dist/types/createStore-BJ66-pfq.d.ts +43 -0
- package/dist/types/internal-BIzJSPwN.d.ts +18 -0
- package/dist/types/keyed-CdSYzIOc.d.ts +18 -0
- package/dist/types/shared-CdTKzvLe.d.ts +114 -0
- package/dist/vite.d.ts +68 -0
- package/dist/vite.js +87 -0
- package/examples/task-board/README.md +15 -0
- package/examples/task-board/src/reactivity.ts +33 -0
- package/examples/task-board/src/task-board.ts +159 -0
- package/examples/task-board/vite.config.ts +6 -0
- package/package.json +119 -4
- package/src/store/README.md +59 -0
- package/src/store/TRANSFORM_SPEC.md +85 -0
|
@@ -0,0 +1,2516 @@
|
|
|
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)) continue;
|
|
1164
|
+
for (const specifier of item.specifiers){
|
|
1165
|
+
if (specifier.type !== "ImportSpecifier" || specifier.isTypeOnly) continue;
|
|
1166
|
+
const imported = specifier.imported?.value ?? specifier.local.value;
|
|
1167
|
+
if ([
|
|
1168
|
+
"snapshot",
|
|
1169
|
+
"hydrate",
|
|
1170
|
+
"getStoreName"
|
|
1171
|
+
].includes(imported) && STORE_MODULES$1.has(item.source.value)) intrinsicNames.set(bindingKey(specifier.local), {
|
|
1172
|
+
arity: imported === "hydrate" ? 2 : 1,
|
|
1173
|
+
rootIndex: 0
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
const returnRoots = new Set();
|
|
1178
|
+
const collectReturned = (node)=>{
|
|
1179
|
+
if (node?.type === "Identifier" && state.stores.has(bindingKey(node))) returnRoots.add(node);
|
|
1180
|
+
if (node?.type === "ObjectExpression") {
|
|
1181
|
+
for (const property of node.properties)collectReturned(property.type === "KeyValueProperty" ? property.value : property);
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
visitNode(program, (node)=>{
|
|
1185
|
+
if (node.type === "ReturnStatement") collectReturned(node.argument);
|
|
1186
|
+
});
|
|
1187
|
+
const intrinsicRoots = new Set();
|
|
1188
|
+
visitNode(program, (node)=>{
|
|
1189
|
+
if (node.type !== "CallExpression" || node.callee?.type !== "Identifier") return;
|
|
1190
|
+
const intrinsic = intrinsicNames.get(bindingKey(node.callee));
|
|
1191
|
+
const root = node.arguments?.[intrinsic?.rootIndex ?? 0]?.expression;
|
|
1192
|
+
if (intrinsic && node.arguments.length === intrinsic.arity && node.arguments.every((arg)=>!arg.spread) && root?.type === "Identifier" && state.stores.has(bindingKey(root))) intrinsicRoots.add(root);
|
|
1193
|
+
});
|
|
1194
|
+
visitNode(program, (node, parent)=>{
|
|
1195
|
+
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)) {
|
|
1196
|
+
addDiagnostic(state, "spread-reflection", REFLECTION_MESSAGE);
|
|
1197
|
+
}
|
|
1198
|
+
if (node.type === "AssignmentExpression" || node.type === "UpdateExpression") {
|
|
1199
|
+
const target = node.left ?? node.argument;
|
|
1200
|
+
if (isStoreMember(target, state) || isStoreRootOrBranch(target, state)) {
|
|
1201
|
+
const parts = collectStaticMemberPath(target);
|
|
1202
|
+
const root = memberRoot(target);
|
|
1203
|
+
const store = root && state.stores.get(bindingKey(root));
|
|
1204
|
+
if (!parts || !store?.leafPaths.has(pathKey(parts.slice(1))) || node.type === "AssignmentExpression" && ![
|
|
1205
|
+
"=",
|
|
1206
|
+
"+=",
|
|
1207
|
+
"-="
|
|
1208
|
+
].includes(node.operator)) {
|
|
1209
|
+
addDiagnostic(state, "unsupported-write", "Only declared compiled-store leaves support =, +=, -=, ++ and --.");
|
|
1210
|
+
}
|
|
1211
|
+
if (node.type === "AssignmentExpression" && node.operator !== "=") {
|
|
1212
|
+
visitNode(node.right, (child)=>{
|
|
1213
|
+
if (child.type === "AwaitExpression" || child.type === "YieldExpression") addDiagnostic(state, "unsupported-write", "Suspending a compiled-store compound assignment is unsupported.");
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
} else if (node.type === "MemberExpression") {
|
|
1218
|
+
scanMemberExpression(node, state);
|
|
1219
|
+
} else if (node.type === "VariableDeclarator") {
|
|
1220
|
+
scanVariableDeclarator(node, state);
|
|
1221
|
+
} else if (node.type === "BinaryExpression" && node.operator === "in") {
|
|
1222
|
+
if (isStoreRootOrBranch(node.right, state)) {
|
|
1223
|
+
addDiagnostic(state, "spread-reflection", REFLECTION_MESSAGE);
|
|
1224
|
+
}
|
|
1225
|
+
} else if (node.type === "UnaryExpression" && node.operator === "delete") {
|
|
1226
|
+
if (isStoreMember(node.argument, state) || isStoreRootOrBranch(node.argument, state)) {
|
|
1227
|
+
addDiagnostic(state, "delete", "Deleting compiled-store paths is not supported in phase 1.");
|
|
1228
|
+
}
|
|
1229
|
+
} else if (node.type === "CallExpression") {
|
|
1230
|
+
scanCallExpression(node, state);
|
|
1231
|
+
} else if (node.type === "ObjectExpression") {
|
|
1232
|
+
scanObjectExpression(node, state);
|
|
1233
|
+
} else if (node.type === "OptionalChainingExpression" || node.type === "OptChainExpression") {
|
|
1234
|
+
if (!isStoreMember(node.base ?? node, state)) return;
|
|
1235
|
+
addDiagnostic(state, "optional-chain", "Optional chaining on compiled stores is not supported in phase 1.");
|
|
1236
|
+
}
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
const REFLECTION_MESSAGE = "Spread and reflection are not guaranteed for compiled stores in phase 1.";
|
|
1240
|
+
function scanMemberExpression(node, state) {
|
|
1241
|
+
const root = memberRoot(node);
|
|
1242
|
+
if (root !== null && state.stores.has(bindingKey(root)) && hasDynamicMemberAccess(node)) {
|
|
1243
|
+
addDiagnostic(state, "dynamic-access", "Dynamic compiled-store access is not supported in phase 1.");
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
function scanVariableDeclarator(node, state) {
|
|
1247
|
+
if (node.id?.type === "ObjectPattern" && isStoreRootOrBranch(node.init, state)) {
|
|
1248
|
+
addDiagnostic(state, "spread-reflection", REFLECTION_MESSAGE);
|
|
1249
|
+
} else if (node.id?.type === "Identifier" && isStoreBranchMember(node.init, state)) {
|
|
1250
|
+
addDiagnostic(state, "branch-alias", "Aliasing nested compiled-store branches is not supported in phase 1.");
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
function scanCallExpression(node, state) {
|
|
1254
|
+
const calleePath = collectStaticMemberPath(node.callee);
|
|
1255
|
+
if (calleePath === null) return;
|
|
1256
|
+
const [root, method] = calleePath;
|
|
1257
|
+
const isReflection = root === "Object" && (method === "keys" || method === "values" || method === "entries" || method === "getOwnPropertyNames" || method === "getOwnPropertySymbols") || root === "Reflect" && method === "ownKeys";
|
|
1258
|
+
if (isReflection && isStoreRootOrBranch(node.arguments?.[0]?.expression, state)) {
|
|
1259
|
+
addDiagnostic(state, "spread-reflection", REFLECTION_MESSAGE);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
function scanObjectExpression(node, state) {
|
|
1263
|
+
for (const property of node.properties ?? []){
|
|
1264
|
+
if (property.type === "SpreadElement" && isStoreRootOrBranch(property.arguments ?? property.expression, state)) {
|
|
1265
|
+
addDiagnostic(state, "spread-reflection", REFLECTION_MESSAGE);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
function isStoreRootOrBranch(node, state) {
|
|
1270
|
+
return node?.type === "Identifier" ? state.stores.has(bindingKey(node)) : isStoreBranchMember(node, state);
|
|
1271
|
+
}
|
|
1272
|
+
function isStoreBranchMember(node, state) {
|
|
1273
|
+
const parts = collectStaticMemberPath(node);
|
|
1274
|
+
if (parts === null || parts.length < 2) return false;
|
|
1275
|
+
const [root, ...path] = parts;
|
|
1276
|
+
if (root === undefined) return false;
|
|
1277
|
+
const rootNode = memberRoot(node);
|
|
1278
|
+
return rootNode !== null && (state.stores.get(bindingKey(rootNode))?.branchPaths.has(pathKey(path)) ?? false);
|
|
1279
|
+
}
|
|
1280
|
+
function isStoreMember(node, state) {
|
|
1281
|
+
const root = memberRoot(node);
|
|
1282
|
+
return root !== null && state.stores.has(bindingKey(root));
|
|
1283
|
+
}
|
|
1284
|
+
function hasDynamicMemberAccess(node) {
|
|
1285
|
+
let current = node;
|
|
1286
|
+
while(current?.type === "MemberExpression"){
|
|
1287
|
+
if (current.computed || current.property?.type === "Computed") return true;
|
|
1288
|
+
current = current.object;
|
|
1289
|
+
}
|
|
1290
|
+
return false;
|
|
1291
|
+
}
|
|
1292
|
+
function addDiagnostic(state, code, message) {
|
|
1293
|
+
if (!state.diagnostics.some((diagnostic)=>diagnostic.code === code && diagnostic.message === message)) {
|
|
1294
|
+
state.diagnostics.push({
|
|
1295
|
+
code,
|
|
1296
|
+
message
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
const STORE_MODULES = new Set([
|
|
1302
|
+
"@volynets/reflex-store",
|
|
1303
|
+
"@volynets/reflex-store/store",
|
|
1304
|
+
"@volynets/reflex-store/compiled-store",
|
|
1305
|
+
"@volynets/reflex-store/advanced",
|
|
1306
|
+
"@reflex/store",
|
|
1307
|
+
"@reflex/store/store",
|
|
1308
|
+
"@reflex/store/compiled-store",
|
|
1309
|
+
"@reflex/store/advanced"
|
|
1310
|
+
]);
|
|
1311
|
+
const DEFAULT_RUNTIME_MODULE = "@volynets/reflex-store/runtime";
|
|
1312
|
+
const DEFAULT_LOWERING_TARGET = {
|
|
1313
|
+
scope: {
|
|
1314
|
+
exportName: "createStoreScope",
|
|
1315
|
+
localName: "__reflex_createStoreScope",
|
|
1316
|
+
actionMethod: "action"
|
|
1317
|
+
},
|
|
1318
|
+
signal: {
|
|
1319
|
+
runtimeModule: "@volynets/reflex-store/runtime/internal",
|
|
1320
|
+
exportName: "createStoreCell",
|
|
1321
|
+
localName: "__reflex_signal"
|
|
1322
|
+
},
|
|
1323
|
+
identifiers: {
|
|
1324
|
+
context: "ctx",
|
|
1325
|
+
value: "value",
|
|
1326
|
+
read: ({ mangledPath })=>`__read_${mangledPath}`,
|
|
1327
|
+
set: ({ mangledPath })=>`__set_${mangledPath}`,
|
|
1328
|
+
write: ({ mangledPath })=>`__write_${mangledPath}`,
|
|
1329
|
+
temporary: ({ index, label })=>`__${label}_${index}`
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
function compileStore(code, id = "compiled-store.ts", options = {}) {
|
|
1333
|
+
const ast = parseModule(code, id);
|
|
1334
|
+
const identifiers = new Set();
|
|
1335
|
+
visitNode(ast, (node)=>{
|
|
1336
|
+
if (node.type === "Identifier") identifiers.add(node.value);
|
|
1337
|
+
});
|
|
1338
|
+
const factoryNames = collectFactoryNames(ast);
|
|
1339
|
+
const diagnostics = [];
|
|
1340
|
+
const state = {
|
|
1341
|
+
diagnostics,
|
|
1342
|
+
options: {
|
|
1343
|
+
importRuntime: options.importRuntime ?? true,
|
|
1344
|
+
eraseFacade: options.eraseFacade ?? false,
|
|
1345
|
+
onDiagnostic: options.onDiagnostic ?? "throw"
|
|
1346
|
+
},
|
|
1347
|
+
target: resolveLoweringTarget(options),
|
|
1348
|
+
stores: collectStoreBindings(ast, diagnostics),
|
|
1349
|
+
tempCounter: 0,
|
|
1350
|
+
identifiers,
|
|
1351
|
+
factoryNames
|
|
1352
|
+
};
|
|
1353
|
+
state.target.scope.localName = allocateName(state.target.scope.localName, state);
|
|
1354
|
+
state.target.signal.localName = allocateName(state.target.signal.localName, state);
|
|
1355
|
+
state.target.identifiers.context = allocateName(state.target.identifiers.context, state);
|
|
1356
|
+
state.target.identifiers.value = allocateName(state.target.identifiers.value, state);
|
|
1357
|
+
const hasGetters = [
|
|
1358
|
+
...state.stores.values()
|
|
1359
|
+
].some((store)=>store.getters.length > 0);
|
|
1360
|
+
if (hasGetters) {
|
|
1361
|
+
state.computedName = allocateName("__reflex_createDisposableComputed", state);
|
|
1362
|
+
}
|
|
1363
|
+
const defaultScope = state.target.runtimeModule === DEFAULT_RUNTIME_MODULE && state.target.scope.exportName === "createStoreScope";
|
|
1364
|
+
if (!defaultScope) {
|
|
1365
|
+
for (const store of state.stores.values()){
|
|
1366
|
+
if (store.methods.length > 0 || store.getters.length > 0) {
|
|
1367
|
+
state.diagnostics.push({
|
|
1368
|
+
code: "unsupported-shape",
|
|
1369
|
+
message: "Compiled store methods and getters require the default Store scope lowering target."
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
scanUnsupportedStoreSyntax(ast, state);
|
|
1375
|
+
for (const store of state.stores.values()){
|
|
1376
|
+
for (const member of [
|
|
1377
|
+
...store.methods,
|
|
1378
|
+
...store.getters
|
|
1379
|
+
]){
|
|
1380
|
+
scanUnsupportedStoreSyntax({
|
|
1381
|
+
...ast,
|
|
1382
|
+
body: [
|
|
1383
|
+
...ast.body.filter((item)=>item.type === "ImportDeclaration"),
|
|
1384
|
+
{
|
|
1385
|
+
type: "ExpressionStatement",
|
|
1386
|
+
span: DUMMY_SPAN,
|
|
1387
|
+
expression: rewriteStoreThis(member.fn, store)
|
|
1388
|
+
}
|
|
1389
|
+
]
|
|
1390
|
+
}, state);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
if (state.diagnostics.length > 0 && state.options.onDiagnostic === "throw") {
|
|
1394
|
+
throw new CompiledStoreTransformError(state.diagnostics);
|
|
1395
|
+
}
|
|
1396
|
+
if (state.diagnostics.length > 0) return {
|
|
1397
|
+
code,
|
|
1398
|
+
diagnostics: [
|
|
1399
|
+
...state.diagnostics
|
|
1400
|
+
],
|
|
1401
|
+
map: null
|
|
1402
|
+
};
|
|
1403
|
+
const transformed = transformProgram(ast, state);
|
|
1404
|
+
const output = printModule(transformed, {
|
|
1405
|
+
filename: id,
|
|
1406
|
+
sourceMaps: true
|
|
1407
|
+
});
|
|
1408
|
+
return {
|
|
1409
|
+
code: output.code,
|
|
1410
|
+
diagnostics: [
|
|
1411
|
+
...state.diagnostics
|
|
1412
|
+
],
|
|
1413
|
+
map: output.map ?? null
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
function resolveLoweringTarget(options) {
|
|
1417
|
+
const target = options.loweringTarget;
|
|
1418
|
+
return {
|
|
1419
|
+
runtimeModule: target?.runtimeModule ?? options.runtimeModule ?? DEFAULT_RUNTIME_MODULE,
|
|
1420
|
+
scope: {
|
|
1421
|
+
...DEFAULT_LOWERING_TARGET.scope,
|
|
1422
|
+
...target?.model ? {
|
|
1423
|
+
curried: true
|
|
1424
|
+
} : {},
|
|
1425
|
+
...target?.model,
|
|
1426
|
+
...target?.scope
|
|
1427
|
+
},
|
|
1428
|
+
signal: {
|
|
1429
|
+
...target?.runtimeModule || options.runtimeModule || target?.signal?.exportName ? {
|
|
1430
|
+
exportName: "signal",
|
|
1431
|
+
localName: "__reflex_signal"
|
|
1432
|
+
} : DEFAULT_LOWERING_TARGET.signal,
|
|
1433
|
+
...target?.signal
|
|
1434
|
+
},
|
|
1435
|
+
identifiers: {
|
|
1436
|
+
...DEFAULT_LOWERING_TARGET.identifiers,
|
|
1437
|
+
...target?.identifiers
|
|
1438
|
+
}
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1441
|
+
function transformCompiledStore(code, id = "compiled-store.ts", options = {}) {
|
|
1442
|
+
return compileStore(code, id, options);
|
|
1443
|
+
}
|
|
1444
|
+
function transformProgram(program, state) {
|
|
1445
|
+
if (program.type !== "Module") {
|
|
1446
|
+
return program;
|
|
1447
|
+
}
|
|
1448
|
+
let body = program.body.flatMap((item)=>transformModuleItem(item, state));
|
|
1449
|
+
if (state.stores.size > 0 && state.options.importRuntime) {
|
|
1450
|
+
body = insertRuntimeImport(body, state);
|
|
1451
|
+
}
|
|
1452
|
+
return {
|
|
1453
|
+
...program,
|
|
1454
|
+
body
|
|
1455
|
+
};
|
|
1456
|
+
}
|
|
1457
|
+
function transformModuleItem(item, state) {
|
|
1458
|
+
switch(item.type){
|
|
1459
|
+
case "ImportDeclaration":
|
|
1460
|
+
return transformImportDeclaration(item, state);
|
|
1461
|
+
case "VariableDeclaration":
|
|
1462
|
+
return transformVariableDeclaration(item, state);
|
|
1463
|
+
case "ExpressionStatement":
|
|
1464
|
+
return [
|
|
1465
|
+
{
|
|
1466
|
+
...item,
|
|
1467
|
+
expression: transformExpression(item.expression, state)
|
|
1468
|
+
}
|
|
1469
|
+
];
|
|
1470
|
+
case "FunctionDeclaration":
|
|
1471
|
+
return [
|
|
1472
|
+
transformFunctionDeclaration(item, state)
|
|
1473
|
+
];
|
|
1474
|
+
case "ExportDeclaration":
|
|
1475
|
+
return [
|
|
1476
|
+
{
|
|
1477
|
+
...item,
|
|
1478
|
+
declaration: item.declaration?.type === "FunctionDeclaration" ? transformFunctionDeclaration(item.declaration, state) : transformNestedFunctions(item.declaration, state)
|
|
1479
|
+
}
|
|
1480
|
+
];
|
|
1481
|
+
case "ExportDefaultDeclaration":
|
|
1482
|
+
return [
|
|
1483
|
+
{
|
|
1484
|
+
...item,
|
|
1485
|
+
decl: transformNestedFunctions(item.decl, state)
|
|
1486
|
+
}
|
|
1487
|
+
];
|
|
1488
|
+
case "ExportDefaultExpression":
|
|
1489
|
+
return [
|
|
1490
|
+
{
|
|
1491
|
+
...item,
|
|
1492
|
+
expression: transformExpression(item.expression, state)
|
|
1493
|
+
}
|
|
1494
|
+
];
|
|
1495
|
+
default:
|
|
1496
|
+
return [
|
|
1497
|
+
transformNestedFunctions(item, state)
|
|
1498
|
+
];
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
function transformBlockStatement(block, state) {
|
|
1502
|
+
return {
|
|
1503
|
+
...block,
|
|
1504
|
+
stmts: (block.stmts ?? []).flatMap((statement)=>transformStatement(statement, state))
|
|
1505
|
+
};
|
|
1506
|
+
}
|
|
1507
|
+
function transformFunctionDeclaration(declaration, state) {
|
|
1508
|
+
return {
|
|
1509
|
+
...declaration,
|
|
1510
|
+
body: transformBlockStatement(declaration.body, state)
|
|
1511
|
+
};
|
|
1512
|
+
}
|
|
1513
|
+
function transformNestedFunctions(node, state) {
|
|
1514
|
+
if (node === null || typeof node !== "object") return node;
|
|
1515
|
+
if (Array.isArray(node)) {
|
|
1516
|
+
return node.map((child)=>transformNestedFunctions(child, state));
|
|
1517
|
+
}
|
|
1518
|
+
if (node.type === "FunctionDeclaration") {
|
|
1519
|
+
return transformFunctionDeclaration(node, state);
|
|
1520
|
+
}
|
|
1521
|
+
if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
|
|
1522
|
+
return transformExpression(node, state);
|
|
1523
|
+
}
|
|
1524
|
+
if (node.type === "BlockStatement") {
|
|
1525
|
+
return transformBlockStatement(node, state);
|
|
1526
|
+
}
|
|
1527
|
+
const transformed = {
|
|
1528
|
+
...node
|
|
1529
|
+
};
|
|
1530
|
+
for (const key of Object.keys(node)){
|
|
1531
|
+
if (key === "span" || key === "ctxt" || key === "type" || key === "raw") {
|
|
1532
|
+
continue;
|
|
1533
|
+
}
|
|
1534
|
+
const value = node[key];
|
|
1535
|
+
if (Array.isArray(value)) {
|
|
1536
|
+
transformed[key] = value.map((child)=>transformNestedFunctions(child, state));
|
|
1537
|
+
} else if (value !== null && typeof value === "object") {
|
|
1538
|
+
transformed[key] = transformNestedFunctions(value, state);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
return transformed;
|
|
1542
|
+
}
|
|
1543
|
+
function transformSingleStatement(statement, state) {
|
|
1544
|
+
const transformed = transformStatement(statement, state);
|
|
1545
|
+
if (transformed.length === 1) return transformed[0];
|
|
1546
|
+
return {
|
|
1547
|
+
type: "BlockStatement",
|
|
1548
|
+
span: statement.span,
|
|
1549
|
+
ctxt: statement.ctxt,
|
|
1550
|
+
stmts: transformed
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
function transformStatement(statement, state) {
|
|
1554
|
+
switch(statement?.type){
|
|
1555
|
+
case "VariableDeclaration":
|
|
1556
|
+
return transformVariableDeclaration(statement, state);
|
|
1557
|
+
case "ExpressionStatement":
|
|
1558
|
+
return [
|
|
1559
|
+
{
|
|
1560
|
+
...statement,
|
|
1561
|
+
expression: transformExpression(statement.expression, state)
|
|
1562
|
+
}
|
|
1563
|
+
];
|
|
1564
|
+
case "ReturnStatement":
|
|
1565
|
+
case "ThrowStatement":
|
|
1566
|
+
return [
|
|
1567
|
+
{
|
|
1568
|
+
...statement,
|
|
1569
|
+
argument: statement.argument ? transformExpression(statement.argument, state) : statement.argument
|
|
1570
|
+
}
|
|
1571
|
+
];
|
|
1572
|
+
case "BlockStatement":
|
|
1573
|
+
return [
|
|
1574
|
+
transformBlockStatement(statement, state)
|
|
1575
|
+
];
|
|
1576
|
+
case "FunctionDeclaration":
|
|
1577
|
+
return [
|
|
1578
|
+
transformFunctionDeclaration(statement, state)
|
|
1579
|
+
];
|
|
1580
|
+
case "IfStatement":
|
|
1581
|
+
return [
|
|
1582
|
+
{
|
|
1583
|
+
...statement,
|
|
1584
|
+
test: transformExpression(statement.test, state),
|
|
1585
|
+
consequent: transformSingleStatement(statement.consequent, state),
|
|
1586
|
+
alternate: statement.alternate ? transformSingleStatement(statement.alternate, state) : statement.alternate
|
|
1587
|
+
}
|
|
1588
|
+
];
|
|
1589
|
+
case "WhileStatement":
|
|
1590
|
+
case "DoWhileStatement":
|
|
1591
|
+
return [
|
|
1592
|
+
{
|
|
1593
|
+
...statement,
|
|
1594
|
+
test: transformExpression(statement.test, state),
|
|
1595
|
+
body: transformSingleStatement(statement.body, state)
|
|
1596
|
+
}
|
|
1597
|
+
];
|
|
1598
|
+
case "ForStatement":
|
|
1599
|
+
return [
|
|
1600
|
+
{
|
|
1601
|
+
...statement,
|
|
1602
|
+
init: statement.init?.type === "VariableDeclaration" ? transformVariableDeclaration(statement.init, state)[0] ?? statement.init : statement.init ? transformExpression(statement.init, state) : statement.init,
|
|
1603
|
+
test: statement.test ? transformExpression(statement.test, state) : statement.test,
|
|
1604
|
+
update: statement.update ? transformExpression(statement.update, state) : statement.update,
|
|
1605
|
+
body: transformSingleStatement(statement.body, state)
|
|
1606
|
+
}
|
|
1607
|
+
];
|
|
1608
|
+
case "ForInStatement":
|
|
1609
|
+
case "ForOfStatement":
|
|
1610
|
+
return [
|
|
1611
|
+
{
|
|
1612
|
+
...statement,
|
|
1613
|
+
right: transformExpression(statement.right, state),
|
|
1614
|
+
body: transformSingleStatement(statement.body, state)
|
|
1615
|
+
}
|
|
1616
|
+
];
|
|
1617
|
+
case "LabeledStatement":
|
|
1618
|
+
return [
|
|
1619
|
+
{
|
|
1620
|
+
...statement,
|
|
1621
|
+
body: transformSingleStatement(statement.body, state)
|
|
1622
|
+
}
|
|
1623
|
+
];
|
|
1624
|
+
case "WithStatement":
|
|
1625
|
+
return [
|
|
1626
|
+
{
|
|
1627
|
+
...statement,
|
|
1628
|
+
object: transformExpression(statement.object, state),
|
|
1629
|
+
body: transformSingleStatement(statement.body, state)
|
|
1630
|
+
}
|
|
1631
|
+
];
|
|
1632
|
+
case "TryStatement":
|
|
1633
|
+
return [
|
|
1634
|
+
{
|
|
1635
|
+
...statement,
|
|
1636
|
+
block: transformBlockStatement(statement.block, state),
|
|
1637
|
+
handler: statement.handler ? {
|
|
1638
|
+
...statement.handler,
|
|
1639
|
+
body: transformBlockStatement(statement.handler.body, state)
|
|
1640
|
+
} : statement.handler,
|
|
1641
|
+
finalizer: statement.finalizer ? transformBlockStatement(statement.finalizer, state) : statement.finalizer
|
|
1642
|
+
}
|
|
1643
|
+
];
|
|
1644
|
+
case "SwitchStatement":
|
|
1645
|
+
return [
|
|
1646
|
+
{
|
|
1647
|
+
...statement,
|
|
1648
|
+
discriminant: transformExpression(statement.discriminant, state),
|
|
1649
|
+
cases: (statement.cases ?? []).map((item)=>({
|
|
1650
|
+
...item,
|
|
1651
|
+
test: item.test ? transformExpression(item.test, state) : item.test,
|
|
1652
|
+
consequent: (item.consequent ?? []).flatMap((child)=>transformStatement(child, state))
|
|
1653
|
+
}))
|
|
1654
|
+
}
|
|
1655
|
+
];
|
|
1656
|
+
default:
|
|
1657
|
+
return [
|
|
1658
|
+
statement
|
|
1659
|
+
];
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
function transformImportDeclaration(item, state) {
|
|
1663
|
+
if (!STORE_MODULES.has(item.source?.value)) {
|
|
1664
|
+
return [
|
|
1665
|
+
item
|
|
1666
|
+
];
|
|
1667
|
+
}
|
|
1668
|
+
const specifiers = (item.specifiers ?? []).filter((specifier)=>!state.factoryNames.has(bindingKey(specifier.local)));
|
|
1669
|
+
if (specifiers.length === 0) {
|
|
1670
|
+
return [];
|
|
1671
|
+
}
|
|
1672
|
+
return [
|
|
1673
|
+
{
|
|
1674
|
+
...item,
|
|
1675
|
+
specifiers
|
|
1676
|
+
}
|
|
1677
|
+
];
|
|
1678
|
+
}
|
|
1679
|
+
function transformVariableDeclaration(item, state) {
|
|
1680
|
+
const output = [];
|
|
1681
|
+
let pending = [];
|
|
1682
|
+
const flushPending = ()=>{
|
|
1683
|
+
if (pending.length === 0) {
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
output.push({
|
|
1687
|
+
...item,
|
|
1688
|
+
declarations: pending
|
|
1689
|
+
});
|
|
1690
|
+
pending = [];
|
|
1691
|
+
};
|
|
1692
|
+
for (const declaration of item.declarations ?? []){
|
|
1693
|
+
const name = declaration.id?.type === "Identifier" ? declaration.id.value : null;
|
|
1694
|
+
const binding = name === null ? undefined : state.stores.get(bindingKey(declaration.id));
|
|
1695
|
+
if (binding === undefined) {
|
|
1696
|
+
pending.push(transformVariableDeclarator(declaration, state));
|
|
1697
|
+
continue;
|
|
1698
|
+
}
|
|
1699
|
+
flushPending();
|
|
1700
|
+
output.push(...createCompiledStoreStatements(binding, item.kind, state));
|
|
1701
|
+
}
|
|
1702
|
+
flushPending();
|
|
1703
|
+
return output;
|
|
1704
|
+
}
|
|
1705
|
+
function transformVariableDeclarator(declaration, state) {
|
|
1706
|
+
if (declaration.init === undefined) {
|
|
1707
|
+
return declaration;
|
|
1708
|
+
}
|
|
1709
|
+
return {
|
|
1710
|
+
...declaration,
|
|
1711
|
+
init: transformExpression(declaration.init, state)
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
function insertRuntimeImport(body, state) {
|
|
1715
|
+
const { scope, runtimeModule, signal } = state.target;
|
|
1716
|
+
const signalModule = signal.runtimeModule ?? runtimeModule;
|
|
1717
|
+
const runtimeNames = [
|
|
1718
|
+
scope.exportName + " as " + scope.localName
|
|
1719
|
+
];
|
|
1720
|
+
if (state.computedName) runtimeNames.push("createDisposableComputed as " + state.computedName);
|
|
1721
|
+
if (signalModule === runtimeModule) runtimeNames.push(signal.exportName + " as " + signal.localName);
|
|
1722
|
+
let source = "import { " + runtimeNames.join(", ") + " } from " + JSON.stringify(runtimeModule) + ";";
|
|
1723
|
+
if (signalModule !== runtimeModule) {
|
|
1724
|
+
source += "\nimport { " + signal.exportName + " as " + signal.localName + " } from " + JSON.stringify(signalModule) + ";";
|
|
1725
|
+
}
|
|
1726
|
+
const imports = parseModule(source, "compiled-store-runtime-import.ts").body;
|
|
1727
|
+
const insertIndex = body.findIndex((item)=>item.type !== "ImportDeclaration");
|
|
1728
|
+
const index = insertIndex === -1 ? body.length : insertIndex;
|
|
1729
|
+
return [
|
|
1730
|
+
...body.slice(0, index),
|
|
1731
|
+
...imports,
|
|
1732
|
+
...body.slice(index)
|
|
1733
|
+
];
|
|
1734
|
+
}
|
|
1735
|
+
function createCompiledStoreStatements(binding, kind, state) {
|
|
1736
|
+
const lines = [];
|
|
1737
|
+
const { identifiers, scope, signal } = state.target;
|
|
1738
|
+
const defaultScope = state.target.runtimeModule === DEFAULT_RUNTIME_MODULE && scope.exportName === "createStoreScope";
|
|
1739
|
+
const scopeName = defaultScope ? nextTemp(state, "scope") : binding.name;
|
|
1740
|
+
const emitFacade = defaultScope && (!state.options.eraseFacade || binding.needsFacade);
|
|
1741
|
+
if (emitFacade) binding.lifetimeName ??= allocateName("__store_alive", state);
|
|
1742
|
+
for (const method of binding.methods){
|
|
1743
|
+
method.internalName ??= allocateName("__store_method_" + method.key.replace(/[^A-Za-z0-9_$]/g, "_"), state);
|
|
1744
|
+
}
|
|
1745
|
+
for (const getter of binding.getters){
|
|
1746
|
+
getter.internalName ??= allocateName("__store_getter_" + getter.key.replace(/[^A-Za-z0-9_$]/g, "_"), state);
|
|
1747
|
+
}
|
|
1748
|
+
for (const leaf of binding.leaves){
|
|
1749
|
+
const names = getLeafNames(leaf, state);
|
|
1750
|
+
lines.push(defaultScope ? "let " + names.read + ";" : "const " + names.read + " = " + createCellSource(leaf, binding, state) + ";");
|
|
1751
|
+
lines.push("let " + names.write + ";");
|
|
1752
|
+
}
|
|
1753
|
+
lines.push(kind + " " + scopeName + " = " + scope.localName + "((" + identifiers.context + ") => {");
|
|
1754
|
+
for (const leaf of binding.leaves){
|
|
1755
|
+
const names = getLeafNames(leaf, state);
|
|
1756
|
+
const action = formatMemberAccess(identifiers.context, scope.actionMethod);
|
|
1757
|
+
if (defaultScope) {
|
|
1758
|
+
lines.push(" " + names.read + " = " + identifiers.context + ".own(" + createCellSource(leaf, binding, state) + ");");
|
|
1759
|
+
}
|
|
1760
|
+
if (!defaultScope && signal.exportName === "createStoreCell" && signal.runtimeModule === "@volynets/reflex-store/runtime/internal") {
|
|
1761
|
+
lines.push(" " + identifiers.context + ".onDispose(" + names.read + ".dispose);");
|
|
1762
|
+
}
|
|
1763
|
+
if (defaultScope && signal.exportName === "createStoreCell" && signal.runtimeModule === "@volynets/reflex-store/runtime/internal") {
|
|
1764
|
+
lines.push(" " + names.write + " = " + identifiers.context + ".writer(" + names.read + ");");
|
|
1765
|
+
continue;
|
|
1766
|
+
}
|
|
1767
|
+
lines.push(" " + names.write + " = " + action + "((" + identifiers.value + ") => {");
|
|
1768
|
+
lines.push(" " + names.read + ".set(" + identifiers.value + ");");
|
|
1769
|
+
lines.push(" return " + identifiers.value + ";");
|
|
1770
|
+
lines.push(" });");
|
|
1771
|
+
}
|
|
1772
|
+
const action = formatMemberAccess(identifiers.context, scope.actionMethod);
|
|
1773
|
+
for (const method of binding.methods){
|
|
1774
|
+
const fn = transformExpression(rewriteStoreThis(method.fn, binding), state);
|
|
1775
|
+
lines.push(" const " + method.internalName + " = " + action + "(" + printExpression(fn) + ");");
|
|
1776
|
+
}
|
|
1777
|
+
for (const getter of binding.getters){
|
|
1778
|
+
if (!state.computedName) {
|
|
1779
|
+
throw new Error("Missing generated computed import for store getter.");
|
|
1780
|
+
}
|
|
1781
|
+
const getterValue = nextTemp(state, "getter");
|
|
1782
|
+
const fn = transformExpression(rewriteStoreThis(getter.fn, binding), state);
|
|
1783
|
+
lines.push(" const " + getterValue + " = " + state.computedName + "(() => (" + printExpression(fn) + ").call(" + binding.name + "));");
|
|
1784
|
+
lines.push(" " + identifiers.context + ".own({ [Symbol.dispose]: () => " + getterValue + ".dispose() });");
|
|
1785
|
+
lines.push(" const " + getter.internalName + " = " + getterValue + ".read;");
|
|
1786
|
+
}
|
|
1787
|
+
lines.push(" return " + (defaultScope ? createStoreScopeSource(binding, identifiers.context, emitFacade) : createStoreObjectSource(binding, state)) + ";");
|
|
1788
|
+
lines.push(scope.curried ? "})();" : "});");
|
|
1789
|
+
if (emitFacade) {
|
|
1790
|
+
const facade = createStoreObjectSource(binding, state, scopeName);
|
|
1791
|
+
const contents = facade.slice(1, -1).trim();
|
|
1792
|
+
lines.push(kind + " " + binding.name + " = { " + contents + (contents ? "," : "") + " dispose: " + scopeName + ".dispose, [Symbol.dispose]: " + scopeName + "[Symbol.dispose] };");
|
|
1793
|
+
}
|
|
1794
|
+
if (emitFacade) {
|
|
1795
|
+
if (binding.displayName) lines.push("Object.defineProperty(" + binding.name + ", Symbol.for('@volynets/reflex-store/name'), { value: " + JSON.stringify(binding.displayName) + " });");
|
|
1796
|
+
const guard = "if (!" + formatMemberAccess(scopeName, binding.lifetimeName) + "()) throw new Error('Cannot use a disposed compiled store'); ";
|
|
1797
|
+
const writes = binding.leaves.map((leaf, index)=>getLeafNames(leaf, state).write + "(values[" + index + "]);").join(" ");
|
|
1798
|
+
const collects = binding.leaves.map((leaf)=>getLeafNames(leaf, state).read + ".collect();").join(" ");
|
|
1799
|
+
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([
|
|
1800
|
+
[],
|
|
1801
|
+
...[
|
|
1802
|
+
...binding.branchPaths
|
|
1803
|
+
].map((path)=>JSON.parse(path))
|
|
1804
|
+
]) + "," + "hydrate: (values) => { " + guard + writes + " }," + "collect: () => { " + collects + " }," + "dispose: " + binding.name + ".dispose } });");
|
|
1805
|
+
}
|
|
1806
|
+
return parseModule(lines.join("\n"), "compiled-store-lowering.ts").body;
|
|
1807
|
+
}
|
|
1808
|
+
function createCellSource(leaf, binding, state) {
|
|
1809
|
+
const signal = state.target.signal;
|
|
1810
|
+
const options = binding.displayName && signal.exportName === "createStoreCell" ? ", " + JSON.stringify({
|
|
1811
|
+
name: binding.displayName + "." + leaf.parts.join(".")
|
|
1812
|
+
}) : "";
|
|
1813
|
+
return signal.localName + "(" + printExpression(leaf.initial) + options + ")";
|
|
1814
|
+
}
|
|
1815
|
+
function rewriteStoreThis(node, binding, root = true) {
|
|
1816
|
+
if (!node || typeof node !== "object") return node;
|
|
1817
|
+
if (Array.isArray(node)) return node.map((child)=>rewriteStoreThis(child, binding, false));
|
|
1818
|
+
if (node.type === "ThisExpression") return {
|
|
1819
|
+
...binding.identifier
|
|
1820
|
+
};
|
|
1821
|
+
if (!root && [
|
|
1822
|
+
"FunctionExpression",
|
|
1823
|
+
"FunctionDeclaration",
|
|
1824
|
+
"MethodProperty",
|
|
1825
|
+
"GetterProperty",
|
|
1826
|
+
"SetterProperty",
|
|
1827
|
+
"ClassExpression",
|
|
1828
|
+
"ClassDeclaration"
|
|
1829
|
+
].includes(node.type)) return node;
|
|
1830
|
+
const result = {
|
|
1831
|
+
...node
|
|
1832
|
+
};
|
|
1833
|
+
for (const key of Object.keys(node)){
|
|
1834
|
+
if (![
|
|
1835
|
+
"span",
|
|
1836
|
+
"ctxt"
|
|
1837
|
+
].includes(key)) result[key] = rewriteStoreThis(node[key], binding, false);
|
|
1838
|
+
}
|
|
1839
|
+
return result;
|
|
1840
|
+
}
|
|
1841
|
+
function createStoreDataSource(binding, state, snapshot = false) {
|
|
1842
|
+
const root = createStoreTreeNode();
|
|
1843
|
+
for (const path of binding.branchPaths){
|
|
1844
|
+
let branch = root;
|
|
1845
|
+
for (const key of JSON.parse(path)){
|
|
1846
|
+
let next = branch.branches.get(key);
|
|
1847
|
+
if (!next) branch.branches.set(key, next = createStoreTreeNode());
|
|
1848
|
+
branch = next;
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
for (const leaf of binding.leaves)insertStoreLeaf(root, leaf.parts, leaf);
|
|
1852
|
+
const render = (node)=>{
|
|
1853
|
+
const entries = [
|
|
1854
|
+
...node.branches
|
|
1855
|
+
].map(([key, branch])=>({
|
|
1856
|
+
key,
|
|
1857
|
+
value: render(branch)
|
|
1858
|
+
}));
|
|
1859
|
+
for (const [key, leaf] of node.leaves){
|
|
1860
|
+
let value = getLeafNames(leaf, state).read + "()";
|
|
1861
|
+
if (snapshot) {
|
|
1862
|
+
value = "data";
|
|
1863
|
+
for (const part of leaf.parts)value = formatMemberAccess(value, part);
|
|
1864
|
+
value = "copy(" + value + ")";
|
|
1865
|
+
}
|
|
1866
|
+
entries.push({
|
|
1867
|
+
key,
|
|
1868
|
+
value
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
if (snapshot) {
|
|
1872
|
+
// Match Reflect.ownKeys ordering: array-index keys precede other strings.
|
|
1873
|
+
const indexOf = (key)=>{
|
|
1874
|
+
const index = Number(key);
|
|
1875
|
+
return Number.isInteger(index) && index >= 0 && index < 0xffffffff && String(index) === key ? index : Infinity;
|
|
1876
|
+
};
|
|
1877
|
+
entries.sort((a, b)=>indexOf(a.key) - indexOf(b.key));
|
|
1878
|
+
}
|
|
1879
|
+
const object = "{" + entries.map(({ key, value })=>formatObjectKey(key) + ": " + value).join(", ") + "}";
|
|
1880
|
+
return snapshot ? "Object.freeze(" + object + ")" : object;
|
|
1881
|
+
};
|
|
1882
|
+
return render(root);
|
|
1883
|
+
}
|
|
1884
|
+
function createStoreScopeSource(binding, context, emitFacade) {
|
|
1885
|
+
const members = [
|
|
1886
|
+
...emitFacade ? [
|
|
1887
|
+
binding.lifetimeName + ": () => !" + context + ".disposed"
|
|
1888
|
+
] : [],
|
|
1889
|
+
...binding.methods.map((method)=>method.internalName + ": " + method.internalName),
|
|
1890
|
+
...binding.getters.map((getter)=>getter.internalName + ": " + getter.internalName)
|
|
1891
|
+
];
|
|
1892
|
+
return members.length === 0 ? "{}" : "{ " + members.join(", ") + " }";
|
|
1893
|
+
}
|
|
1894
|
+
function createStoreObjectSource(binding, state, scopeName) {
|
|
1895
|
+
const root = createStoreTreeNode();
|
|
1896
|
+
for (const path of binding.branchPaths){
|
|
1897
|
+
let branch = root;
|
|
1898
|
+
for (const key of JSON.parse(path)){
|
|
1899
|
+
let next = branch.branches.get(key);
|
|
1900
|
+
if (!next) {
|
|
1901
|
+
next = createStoreTreeNode();
|
|
1902
|
+
branch.branches.set(key, next);
|
|
1903
|
+
}
|
|
1904
|
+
branch = next;
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
for (const leaf of binding.leaves){
|
|
1908
|
+
insertStoreLeaf(root, leaf.parts, leaf);
|
|
1909
|
+
}
|
|
1910
|
+
return createStoreTreeObjectSource(root, state, 2, binding, scopeName);
|
|
1911
|
+
}
|
|
1912
|
+
function createStoreTreeNode() {
|
|
1913
|
+
return {
|
|
1914
|
+
branches: new Map(),
|
|
1915
|
+
leaves: new Map()
|
|
1916
|
+
};
|
|
1917
|
+
}
|
|
1918
|
+
function insertStoreLeaf(node, parts, leaf) {
|
|
1919
|
+
const [head, ...tail] = parts;
|
|
1920
|
+
if (head === undefined) {
|
|
1921
|
+
return;
|
|
1922
|
+
}
|
|
1923
|
+
if (tail.length === 0) {
|
|
1924
|
+
node.leaves.set(head, leaf);
|
|
1925
|
+
return;
|
|
1926
|
+
}
|
|
1927
|
+
let branch = node.branches.get(head);
|
|
1928
|
+
if (branch === undefined) {
|
|
1929
|
+
branch = createStoreTreeNode();
|
|
1930
|
+
node.branches.set(head, branch);
|
|
1931
|
+
}
|
|
1932
|
+
insertStoreLeaf(branch, tail, leaf);
|
|
1933
|
+
}
|
|
1934
|
+
function createStoreTreeObjectSource(node, state, indent, rootBinding, scopeName) {
|
|
1935
|
+
const pad = " ".repeat(indent);
|
|
1936
|
+
const childPad = " ".repeat(indent + 2);
|
|
1937
|
+
const entries = [];
|
|
1938
|
+
for (const [key, branch] of node.branches){
|
|
1939
|
+
entries.push(childPad + formatObjectKey(key) + ": " + createStoreTreeObjectSource(branch, state, indent + 2));
|
|
1940
|
+
}
|
|
1941
|
+
for (const [key, leaf] of node.leaves){
|
|
1942
|
+
const names = getLeafNames(leaf, state);
|
|
1943
|
+
entries.push([
|
|
1944
|
+
childPad + "get " + formatObjectKey(key) + "() {",
|
|
1945
|
+
childPad + " return " + names.read + "();",
|
|
1946
|
+
childPad + "},",
|
|
1947
|
+
childPad + "set " + formatObjectKey(key) + "(" + state.target.identifiers.value + ") {",
|
|
1948
|
+
childPad + " " + names.write + "(" + state.target.identifiers.value + ");",
|
|
1949
|
+
childPad + "}"
|
|
1950
|
+
].join("\n"));
|
|
1951
|
+
}
|
|
1952
|
+
if (rootBinding && scopeName) {
|
|
1953
|
+
for (const method of rootBinding.methods){
|
|
1954
|
+
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); }");
|
|
1955
|
+
}
|
|
1956
|
+
for (const getter of rootBinding.getters){
|
|
1957
|
+
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) + "(); }");
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
if (entries.length === 0) {
|
|
1961
|
+
return "{}";
|
|
1962
|
+
}
|
|
1963
|
+
return "{\n" + entries.join(",\n") + "\n" + pad + "}";
|
|
1964
|
+
}
|
|
1965
|
+
function formatObjectKey(key) {
|
|
1966
|
+
return isIdentifierName(key) ? key : JSON.stringify(key);
|
|
1967
|
+
}
|
|
1968
|
+
function formatMemberAccess(object, property) {
|
|
1969
|
+
return isIdentifierName(property) ? `${object}.${property}` : `${object}[${JSON.stringify(property)}]`;
|
|
1970
|
+
}
|
|
1971
|
+
function allocateName(preferred, state) {
|
|
1972
|
+
if (!isIdentifierName(preferred)) throw new Error("Invalid generated identifier: " + preferred);
|
|
1973
|
+
let name = preferred;
|
|
1974
|
+
let suffix = 0;
|
|
1975
|
+
while(state.identifiers.has(name))name = preferred + "_" + ++suffix;
|
|
1976
|
+
state.identifiers.add(name);
|
|
1977
|
+
return name;
|
|
1978
|
+
}
|
|
1979
|
+
function getLeafNames(leaf, state) {
|
|
1980
|
+
if (leaf.names) return leaf.names;
|
|
1981
|
+
const context = {
|
|
1982
|
+
path: leaf.parts,
|
|
1983
|
+
mangledPath: leaf.mangled
|
|
1984
|
+
};
|
|
1985
|
+
return leaf.names = {
|
|
1986
|
+
read: allocateName(state.target.identifiers.read(context), state),
|
|
1987
|
+
set: allocateName(state.target.identifiers.set(context), state),
|
|
1988
|
+
write: allocateName(state.target.identifiers.write(context), state)
|
|
1989
|
+
};
|
|
1990
|
+
}
|
|
1991
|
+
function printExpression(expression) {
|
|
1992
|
+
const output = printModule({
|
|
1993
|
+
type: "Module",
|
|
1994
|
+
span: DUMMY_SPAN,
|
|
1995
|
+
body: [
|
|
1996
|
+
{
|
|
1997
|
+
type: "ExpressionStatement",
|
|
1998
|
+
span: DUMMY_SPAN,
|
|
1999
|
+
expression
|
|
2000
|
+
}
|
|
2001
|
+
],
|
|
2002
|
+
interpreter: null
|
|
2003
|
+
}, {
|
|
2004
|
+
sourceMaps: false
|
|
2005
|
+
}).code.trim();
|
|
2006
|
+
return output.endsWith(";") ? output.slice(0, -1) : output;
|
|
2007
|
+
}
|
|
2008
|
+
function transformExpression(node, state) {
|
|
2009
|
+
if (node.type === "FunctionExpression") {
|
|
2010
|
+
return {
|
|
2011
|
+
...node,
|
|
2012
|
+
body: transformBlockStatement(node.body, state)
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2015
|
+
if (node.type === "ArrowFunctionExpression") {
|
|
2016
|
+
return {
|
|
2017
|
+
...node,
|
|
2018
|
+
body: node.body.type === "BlockStatement" ? transformBlockStatement(node.body, state) : transformExpression(node.body, state)
|
|
2019
|
+
};
|
|
2020
|
+
}
|
|
2021
|
+
let result = node;
|
|
2022
|
+
const stack = [
|
|
2023
|
+
{
|
|
2024
|
+
phase: "enter",
|
|
2025
|
+
node,
|
|
2026
|
+
assign (expression) {
|
|
2027
|
+
result = expression;
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
];
|
|
2031
|
+
while(stack.length > 0){
|
|
2032
|
+
const frame = stack.pop();
|
|
2033
|
+
if (frame === undefined) continue;
|
|
2034
|
+
if (frame.phase === "exit") {
|
|
2035
|
+
frame.assign(finalizeExpression(frame.node, frame.slots, state));
|
|
2036
|
+
continue;
|
|
2037
|
+
}
|
|
2038
|
+
const expression = frame.node;
|
|
2039
|
+
if (expression.type === "FunctionExpression" || expression.type === "ArrowFunctionExpression") {
|
|
2040
|
+
frame.assign(transformExpression(expression, state));
|
|
2041
|
+
continue;
|
|
2042
|
+
}
|
|
2043
|
+
const childCount = countTransformChildren(expression, state);
|
|
2044
|
+
if (childCount === 0) {
|
|
2045
|
+
const withNestedFunctions = transformNestedFunctions(expression, state);
|
|
2046
|
+
frame.assign(finalizeExpression(withNestedFunctions, EMPTY_SLOTS, state));
|
|
2047
|
+
continue;
|
|
2048
|
+
}
|
|
2049
|
+
const slots = createSlots(childCount);
|
|
2050
|
+
stack.push({
|
|
2051
|
+
phase: "exit",
|
|
2052
|
+
node: expression,
|
|
2053
|
+
assign: frame.assign,
|
|
2054
|
+
slots
|
|
2055
|
+
});
|
|
2056
|
+
pushExpressionChildren(expression, state, slots, stack);
|
|
2057
|
+
}
|
|
2058
|
+
return result;
|
|
2059
|
+
}
|
|
2060
|
+
function nextTemp(state, label) {
|
|
2061
|
+
state.tempCounter += 1;
|
|
2062
|
+
return allocateName(state.target.identifiers.temporary({
|
|
2063
|
+
index: state.tempCounter,
|
|
2064
|
+
label
|
|
2065
|
+
}), state);
|
|
2066
|
+
}
|
|
2067
|
+
function isIdentifierName(value) {
|
|
2068
|
+
return /^[$A-Z_a-z][$\w]*$/.test(value);
|
|
2069
|
+
}
|
|
2070
|
+
function getLeafPathForMember(node, stores) {
|
|
2071
|
+
const parts = collectStaticMemberPath(node);
|
|
2072
|
+
if (parts === null || parts.length < 2) {
|
|
2073
|
+
return null;
|
|
2074
|
+
}
|
|
2075
|
+
const [root, ...path] = parts;
|
|
2076
|
+
if (root === undefined) {
|
|
2077
|
+
return null;
|
|
2078
|
+
}
|
|
2079
|
+
const rootNode = memberRoot(node);
|
|
2080
|
+
const store = rootNode ? stores.get(bindingKey(rootNode)) : undefined;
|
|
2081
|
+
if (!store) {
|
|
2082
|
+
return null;
|
|
2083
|
+
}
|
|
2084
|
+
return store.leafPaths.get(pathKey(path)) ?? null;
|
|
2085
|
+
}
|
|
2086
|
+
function getLeafPathForTarget(node, stores) {
|
|
2087
|
+
if (node?.type === "MemberExpression") {
|
|
2088
|
+
return getLeafPathForMember(node, stores);
|
|
2089
|
+
}
|
|
2090
|
+
if (node?.type === "SimpleAssignmentTarget" && node.value?.type === "MemberExpression") {
|
|
2091
|
+
return getLeafPathForMember(node.value, stores);
|
|
2092
|
+
}
|
|
2093
|
+
return null;
|
|
2094
|
+
}
|
|
2095
|
+
function createReadCall(leaf, state) {
|
|
2096
|
+
return createCallExpression(getLeafNames(leaf, state).read, []);
|
|
2097
|
+
}
|
|
2098
|
+
function createWriteCall(leaf, value, state) {
|
|
2099
|
+
return createCallExpression(getLeafNames(leaf, state).write, [
|
|
2100
|
+
value
|
|
2101
|
+
]);
|
|
2102
|
+
}
|
|
2103
|
+
function createCompoundAssignment(leaf, operator, right, rhsTemp, nextTempName, state) {
|
|
2104
|
+
const previous = nextTemp(state, "previous");
|
|
2105
|
+
return createIIFE([
|
|
2106
|
+
createConstDeclaration(previous, createReadCall(leaf, state)),
|
|
2107
|
+
createConstDeclaration(rhsTemp, right),
|
|
2108
|
+
createConstDeclaration(nextTempName, createBinaryExpression(createIdentifierExpression(previous), operator, createIdentifierExpression(rhsTemp))),
|
|
2109
|
+
createExpressionStatement(createWriteCall(leaf, createIdentifierExpression(nextTempName), state)),
|
|
2110
|
+
createReturnStatement(createIdentifierExpression(nextTempName))
|
|
2111
|
+
]);
|
|
2112
|
+
}
|
|
2113
|
+
function createUpdateExpressionLowering(leaf, operator, tempName, prefix, state) {
|
|
2114
|
+
const declaration = createConstDeclaration(tempName, createReadCall(leaf, state));
|
|
2115
|
+
declaration.kind = "let";
|
|
2116
|
+
const result = nextTemp(state, "result");
|
|
2117
|
+
return createIIFE([
|
|
2118
|
+
declaration,
|
|
2119
|
+
createConstDeclaration(result, {
|
|
2120
|
+
type: "UpdateExpression",
|
|
2121
|
+
span: DUMMY_SPAN,
|
|
2122
|
+
operator: operator === "+" ? "++" : "--",
|
|
2123
|
+
prefix,
|
|
2124
|
+
argument: createIdentifierExpression(tempName)
|
|
2125
|
+
}),
|
|
2126
|
+
createExpressionStatement(createWriteCall(leaf, createIdentifierExpression(tempName), state)),
|
|
2127
|
+
createReturnStatement(createIdentifierExpression(result))
|
|
2128
|
+
]);
|
|
2129
|
+
}
|
|
2130
|
+
function createIdentifierExpression(name) {
|
|
2131
|
+
return {
|
|
2132
|
+
type: "Identifier",
|
|
2133
|
+
span: DUMMY_SPAN,
|
|
2134
|
+
ctxt: 0,
|
|
2135
|
+
value: name,
|
|
2136
|
+
optional: false
|
|
2137
|
+
};
|
|
2138
|
+
}
|
|
2139
|
+
function createCallExpression(calleeName, args) {
|
|
2140
|
+
return {
|
|
2141
|
+
type: "CallExpression",
|
|
2142
|
+
span: DUMMY_SPAN,
|
|
2143
|
+
ctxt: 0,
|
|
2144
|
+
callee: createIdentifierExpression(calleeName),
|
|
2145
|
+
arguments: args.map((expression)=>({
|
|
2146
|
+
expression
|
|
2147
|
+
})),
|
|
2148
|
+
typeArguments: undefined
|
|
2149
|
+
};
|
|
2150
|
+
}
|
|
2151
|
+
function createBinaryExpression(left, operator, right) {
|
|
2152
|
+
return {
|
|
2153
|
+
type: "BinaryExpression",
|
|
2154
|
+
span: DUMMY_SPAN,
|
|
2155
|
+
operator,
|
|
2156
|
+
left,
|
|
2157
|
+
right
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
function createConstDeclaration(name, init) {
|
|
2161
|
+
return {
|
|
2162
|
+
type: "VariableDeclaration",
|
|
2163
|
+
span: DUMMY_SPAN,
|
|
2164
|
+
ctxt: 0,
|
|
2165
|
+
kind: "const",
|
|
2166
|
+
declare: false,
|
|
2167
|
+
declarations: [
|
|
2168
|
+
{
|
|
2169
|
+
type: "VariableDeclarator",
|
|
2170
|
+
span: DUMMY_SPAN,
|
|
2171
|
+
definite: false,
|
|
2172
|
+
id: {
|
|
2173
|
+
type: "Identifier",
|
|
2174
|
+
span: DUMMY_SPAN,
|
|
2175
|
+
ctxt: 0,
|
|
2176
|
+
value: name,
|
|
2177
|
+
optional: false,
|
|
2178
|
+
typeAnnotation: undefined
|
|
2179
|
+
},
|
|
2180
|
+
init
|
|
2181
|
+
}
|
|
2182
|
+
]
|
|
2183
|
+
};
|
|
2184
|
+
}
|
|
2185
|
+
function createExpressionStatement(expression) {
|
|
2186
|
+
return {
|
|
2187
|
+
type: "ExpressionStatement",
|
|
2188
|
+
span: DUMMY_SPAN,
|
|
2189
|
+
expression
|
|
2190
|
+
};
|
|
2191
|
+
}
|
|
2192
|
+
function createReturnStatement(argument) {
|
|
2193
|
+
return {
|
|
2194
|
+
type: "ReturnStatement",
|
|
2195
|
+
span: DUMMY_SPAN,
|
|
2196
|
+
argument
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
function createIIFE(statements) {
|
|
2200
|
+
return {
|
|
2201
|
+
type: "CallExpression",
|
|
2202
|
+
span: DUMMY_SPAN,
|
|
2203
|
+
ctxt: 0,
|
|
2204
|
+
callee: {
|
|
2205
|
+
type: "ParenthesisExpression",
|
|
2206
|
+
span: DUMMY_SPAN,
|
|
2207
|
+
expression: {
|
|
2208
|
+
type: "ArrowFunctionExpression",
|
|
2209
|
+
span: DUMMY_SPAN,
|
|
2210
|
+
ctxt: 0,
|
|
2211
|
+
params: [],
|
|
2212
|
+
body: {
|
|
2213
|
+
type: "BlockStatement",
|
|
2214
|
+
span: DUMMY_SPAN,
|
|
2215
|
+
ctxt: 0,
|
|
2216
|
+
stmts: statements
|
|
2217
|
+
},
|
|
2218
|
+
async: false,
|
|
2219
|
+
generator: false,
|
|
2220
|
+
typeParameters: undefined,
|
|
2221
|
+
returnType: undefined
|
|
2222
|
+
}
|
|
2223
|
+
},
|
|
2224
|
+
arguments: [],
|
|
2225
|
+
typeArguments: undefined
|
|
2226
|
+
};
|
|
2227
|
+
}
|
|
2228
|
+
const EMPTY_SLOTS = [];
|
|
2229
|
+
const SIMPLE_CHILDREN = new Set([
|
|
2230
|
+
"BinaryExpression",
|
|
2231
|
+
"ParenthesisExpression",
|
|
2232
|
+
"UnaryExpression",
|
|
2233
|
+
"ConditionalExpression",
|
|
2234
|
+
"SequenceExpression",
|
|
2235
|
+
"TemplateLiteral"
|
|
2236
|
+
]);
|
|
2237
|
+
function createSlots(size) {
|
|
2238
|
+
return new Array(size);
|
|
2239
|
+
}
|
|
2240
|
+
function countTransformChildren(node, state) {
|
|
2241
|
+
switch(node.type){
|
|
2242
|
+
case "AssignmentExpression":
|
|
2243
|
+
return 1;
|
|
2244
|
+
case "UpdateExpression":
|
|
2245
|
+
return getLeafPathForTarget(node.argument, state.stores) === null ? 1 : 0;
|
|
2246
|
+
case "MemberExpression":
|
|
2247
|
+
return 1;
|
|
2248
|
+
case "CallExpression":
|
|
2249
|
+
return getCallExpressionChildCount(node);
|
|
2250
|
+
default:
|
|
2251
|
+
return SIMPLE_CHILDREN.has(node.type) ? getSimpleChildSpecs(node).length : 0;
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
function pushExpressionChildren(node, state, slots, stack) {
|
|
2255
|
+
switch(node.type){
|
|
2256
|
+
case "AssignmentExpression":
|
|
2257
|
+
pushChild(stack, node.right, slots, 0);
|
|
2258
|
+
return;
|
|
2259
|
+
case "UpdateExpression":
|
|
2260
|
+
if (getLeafPathForTarget(node.argument, state.stores) === null) {
|
|
2261
|
+
pushChild(stack, node.argument, slots, 0);
|
|
2262
|
+
}
|
|
2263
|
+
return;
|
|
2264
|
+
case "MemberExpression":
|
|
2265
|
+
pushChild(stack, node.object, slots, 0);
|
|
2266
|
+
return;
|
|
2267
|
+
case "CallExpression":
|
|
2268
|
+
{
|
|
2269
|
+
for(let argIndex = node.arguments.length - 1; argIndex >= 0; argIndex--){
|
|
2270
|
+
const arg = node.arguments[argIndex];
|
|
2271
|
+
if (arg?.expression === undefined) {
|
|
2272
|
+
continue;
|
|
2273
|
+
}
|
|
2274
|
+
const slotIndex = getCallExpressionSlotIndex(node, argIndex);
|
|
2275
|
+
pushChild(stack, arg.expression, slots, slotIndex);
|
|
2276
|
+
}
|
|
2277
|
+
const index = getCallExpressionCalleeSlotIndex(node);
|
|
2278
|
+
if (index !== -1) {
|
|
2279
|
+
const calleeExpression = getCalleeExpression(node.callee);
|
|
2280
|
+
if (calleeExpression !== null) {
|
|
2281
|
+
pushChild(stack, calleeExpression, slots, index);
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
return;
|
|
2285
|
+
}
|
|
2286
|
+
default:
|
|
2287
|
+
const specs = getSimpleChildSpecs(node);
|
|
2288
|
+
for(let i = specs.length - 1; i >= 0; i--){
|
|
2289
|
+
const [index, expression] = specs[i];
|
|
2290
|
+
pushChild(stack, expression, slots, index);
|
|
2291
|
+
}
|
|
2292
|
+
return;
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
function finalizeExpression(node, slots, state) {
|
|
2296
|
+
switch(node.type){
|
|
2297
|
+
case "AssignmentExpression":
|
|
2298
|
+
return finalizeAssignmentExpression(node, slots, state);
|
|
2299
|
+
case "UpdateExpression":
|
|
2300
|
+
return finalizeUpdateExpression(node, slots, state);
|
|
2301
|
+
case "MemberExpression":
|
|
2302
|
+
return finalizeMemberExpression(node, slots, state);
|
|
2303
|
+
case "CallExpression":
|
|
2304
|
+
return finalizeCallExpression(node, slots);
|
|
2305
|
+
default:
|
|
2306
|
+
return SIMPLE_CHILDREN.has(node.type) ? finalizeSimpleExpression(node, slots) : node;
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2309
|
+
function getSimpleChildSpecs(node) {
|
|
2310
|
+
switch(node.type){
|
|
2311
|
+
case "BinaryExpression":
|
|
2312
|
+
return [
|
|
2313
|
+
[
|
|
2314
|
+
0,
|
|
2315
|
+
node.left
|
|
2316
|
+
],
|
|
2317
|
+
[
|
|
2318
|
+
1,
|
|
2319
|
+
node.right
|
|
2320
|
+
]
|
|
2321
|
+
];
|
|
2322
|
+
case "ParenthesisExpression":
|
|
2323
|
+
return [
|
|
2324
|
+
[
|
|
2325
|
+
0,
|
|
2326
|
+
node.expression
|
|
2327
|
+
]
|
|
2328
|
+
];
|
|
2329
|
+
case "UnaryExpression":
|
|
2330
|
+
return [
|
|
2331
|
+
[
|
|
2332
|
+
0,
|
|
2333
|
+
node.argument
|
|
2334
|
+
]
|
|
2335
|
+
];
|
|
2336
|
+
case "ConditionalExpression":
|
|
2337
|
+
return [
|
|
2338
|
+
[
|
|
2339
|
+
0,
|
|
2340
|
+
node.test
|
|
2341
|
+
],
|
|
2342
|
+
[
|
|
2343
|
+
1,
|
|
2344
|
+
node.consequent
|
|
2345
|
+
],
|
|
2346
|
+
[
|
|
2347
|
+
2,
|
|
2348
|
+
node.alternate
|
|
2349
|
+
]
|
|
2350
|
+
];
|
|
2351
|
+
case "SequenceExpression":
|
|
2352
|
+
case "TemplateLiteral":
|
|
2353
|
+
return node.expressions.map((expression, index)=>[
|
|
2354
|
+
index,
|
|
2355
|
+
expression
|
|
2356
|
+
]);
|
|
2357
|
+
default:
|
|
2358
|
+
return [];
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
function finalizeSimpleExpression(node, slots) {
|
|
2362
|
+
switch(node.type){
|
|
2363
|
+
case "BinaryExpression":
|
|
2364
|
+
return {
|
|
2365
|
+
...node,
|
|
2366
|
+
left: slots[0] ?? node.left,
|
|
2367
|
+
right: slots[1] ?? node.right
|
|
2368
|
+
};
|
|
2369
|
+
case "ParenthesisExpression":
|
|
2370
|
+
return {
|
|
2371
|
+
...node,
|
|
2372
|
+
expression: slots[0] ?? node.expression
|
|
2373
|
+
};
|
|
2374
|
+
case "UnaryExpression":
|
|
2375
|
+
return {
|
|
2376
|
+
...node,
|
|
2377
|
+
argument: slots[0] ?? node.argument
|
|
2378
|
+
};
|
|
2379
|
+
case "ConditionalExpression":
|
|
2380
|
+
return {
|
|
2381
|
+
...node,
|
|
2382
|
+
test: slots[0] ?? node.test,
|
|
2383
|
+
consequent: slots[1] ?? node.consequent,
|
|
2384
|
+
alternate: slots[2] ?? node.alternate
|
|
2385
|
+
};
|
|
2386
|
+
case "SequenceExpression":
|
|
2387
|
+
case "TemplateLiteral":
|
|
2388
|
+
return {
|
|
2389
|
+
...node,
|
|
2390
|
+
expressions: node.expressions.map((expression, index)=>slots[index] ?? expression)
|
|
2391
|
+
};
|
|
2392
|
+
default:
|
|
2393
|
+
return node;
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
function finalizeAssignmentExpression(node, slots, state) {
|
|
2397
|
+
const leafPath = getLeafPathForTarget(node.left, state.stores);
|
|
2398
|
+
const right = slots[0] ?? node.right;
|
|
2399
|
+
if (leafPath === null) {
|
|
2400
|
+
return {
|
|
2401
|
+
...node,
|
|
2402
|
+
right
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
switch(node.operator){
|
|
2406
|
+
case "=":
|
|
2407
|
+
return createWriteCall(leafPath, right, state);
|
|
2408
|
+
case "+=":
|
|
2409
|
+
return createCompoundAssignment(leafPath, "+", right, nextTemp(state, "rhs"), nextTemp(state, "next"), state);
|
|
2410
|
+
case "-=":
|
|
2411
|
+
return createCompoundAssignment(leafPath, "-", right, nextTemp(state, "rhs"), nextTemp(state, "next"), state);
|
|
2412
|
+
default:
|
|
2413
|
+
return {
|
|
2414
|
+
...node,
|
|
2415
|
+
right
|
|
2416
|
+
};
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
function finalizeUpdateExpression(node, slots, state) {
|
|
2420
|
+
const leafPath = getLeafPathForTarget(node.argument, state.stores);
|
|
2421
|
+
if (leafPath === null) {
|
|
2422
|
+
return {
|
|
2423
|
+
...node,
|
|
2424
|
+
argument: slots[0] ?? node.argument
|
|
2425
|
+
};
|
|
2426
|
+
}
|
|
2427
|
+
const operator = node.operator === "++" ? "+" : node.operator === "--" ? "-" : null;
|
|
2428
|
+
if (operator === null) {
|
|
2429
|
+
return node;
|
|
2430
|
+
}
|
|
2431
|
+
return createUpdateExpressionLowering(leafPath, operator, nextTemp(state, node.prefix ? "next" : "prev"), node.prefix, state);
|
|
2432
|
+
}
|
|
2433
|
+
function finalizeMemberExpression(node, slots, state) {
|
|
2434
|
+
const next = {
|
|
2435
|
+
...node,
|
|
2436
|
+
object: slots[0] ?? node.object
|
|
2437
|
+
};
|
|
2438
|
+
const leafPath = getLeafPathForMember(next, state.stores);
|
|
2439
|
+
if (leafPath === null) {
|
|
2440
|
+
return next;
|
|
2441
|
+
}
|
|
2442
|
+
return createReadCall(leafPath, state);
|
|
2443
|
+
}
|
|
2444
|
+
function finalizeCallExpression(node, slots, state) {
|
|
2445
|
+
const nextArgs = node.arguments.map((arg, index)=>{
|
|
2446
|
+
if (arg?.expression === undefined) {
|
|
2447
|
+
return arg;
|
|
2448
|
+
}
|
|
2449
|
+
const slotIndex = getCallExpressionSlotIndex(node, index);
|
|
2450
|
+
return {
|
|
2451
|
+
...arg,
|
|
2452
|
+
expression: slotIndex === -1 ? arg.expression : slots[slotIndex] ?? arg.expression
|
|
2453
|
+
};
|
|
2454
|
+
});
|
|
2455
|
+
const calleeSlotIndex = getCallExpressionCalleeSlotIndex(node);
|
|
2456
|
+
const calleeExpression = getCalleeExpression(node.callee);
|
|
2457
|
+
const nextCallee = calleeSlotIndex === -1 || calleeExpression === null ? node.callee : setCalleeExpression(node.callee, slots[calleeSlotIndex] ?? calleeExpression);
|
|
2458
|
+
return {
|
|
2459
|
+
...node,
|
|
2460
|
+
callee: nextCallee,
|
|
2461
|
+
arguments: nextArgs
|
|
2462
|
+
};
|
|
2463
|
+
}
|
|
2464
|
+
function getCallExpressionChildCount(node) {
|
|
2465
|
+
let count = 0;
|
|
2466
|
+
if (getCalleeExpression(node.callee) !== null) {
|
|
2467
|
+
count += 1;
|
|
2468
|
+
}
|
|
2469
|
+
for (const arg of node.arguments ?? []){
|
|
2470
|
+
if (arg?.expression !== undefined) {
|
|
2471
|
+
count += 1;
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
return count;
|
|
2475
|
+
}
|
|
2476
|
+
function getCallExpressionCalleeSlotIndex(node, _state) {
|
|
2477
|
+
return getCalleeExpression(node.callee) === null ? -1 : 0;
|
|
2478
|
+
}
|
|
2479
|
+
function getCallExpressionSlotIndex(node, argumentIndex, _state) {
|
|
2480
|
+
let index = getCallExpressionCalleeSlotIndex(node) === -1 ? 0 : 1;
|
|
2481
|
+
for(let i = 0; i < argumentIndex; i++){
|
|
2482
|
+
if (node.arguments[i]?.expression !== undefined) {
|
|
2483
|
+
index += 1;
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
return node.arguments[argumentIndex]?.expression === undefined ? -1 : index;
|
|
2487
|
+
}
|
|
2488
|
+
function getCalleeExpression(callee) {
|
|
2489
|
+
if (callee?.type === "Super") {
|
|
2490
|
+
return null;
|
|
2491
|
+
}
|
|
2492
|
+
if (callee?.type === "Expression") {
|
|
2493
|
+
return callee.expression;
|
|
2494
|
+
}
|
|
2495
|
+
return callee;
|
|
2496
|
+
}
|
|
2497
|
+
function setCalleeExpression(callee, expression) {
|
|
2498
|
+
if (callee?.type === "Expression") {
|
|
2499
|
+
return {
|
|
2500
|
+
...callee,
|
|
2501
|
+
expression
|
|
2502
|
+
};
|
|
2503
|
+
}
|
|
2504
|
+
return expression;
|
|
2505
|
+
}
|
|
2506
|
+
function pushChild(stack, node, slots, index) {
|
|
2507
|
+
stack.push({
|
|
2508
|
+
phase: "enter",
|
|
2509
|
+
node,
|
|
2510
|
+
assign (expression) {
|
|
2511
|
+
slots[index] = expression;
|
|
2512
|
+
}
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
export { CompiledStoreTransformError as C, compileStore as c, transformCompiledStore as t };
|