seroval 0.5.1 → 0.7.0
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/README.md +51 -1
- package/dist/cjs/development/index.cjs +762 -228
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +762 -228
- package/dist/esm/development/index.mjs.map +4 -4
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/compat.d.ts +3 -2
- package/dist/types/context.d.ts +14 -9
- package/dist/types/index.d.ts +9 -9
- package/dist/types/string.d.ts +3 -0
- package/dist/types/tree/async.d.ts +1 -2
- package/dist/types/tree/deserialize.d.ts +1 -2
- package/dist/types/tree/primitives.d.ts +7 -3
- package/dist/types/tree/reference.d.ts +6 -0
- package/dist/types/tree/sync.d.ts +1 -2
- package/dist/types/tree/types.d.ts +73 -12
- package/dist/types/tree/web-api.d.ts +6 -0
- package/dist/types/types.d.ts +2 -1
- package/package.json +4 -3
- package/src/compat.ts +2 -1
- package/src/context.ts +19 -12
- package/src/index.ts +10 -16
- package/src/{quote.ts → string.ts} +27 -30
- package/src/tree/async.ts +164 -62
- package/src/tree/deserialize.ts +195 -67
- package/src/tree/primitives.ts +108 -22
- package/src/tree/reference.ts +61 -0
- package/src/tree/serialize.ts +236 -59
- package/src/tree/sync.ts +160 -55
- package/src/tree/types.ts +139 -14
- package/src/tree/web-api.ts +92 -0
- package/src/types.ts +6 -1
- package/dist/types/quote.d.ts +0 -2
|
@@ -13,9 +13,10 @@ var Feature = /* @__PURE__ */ ((Feature2) => {
|
|
|
13
13
|
Feature2[Feature2["Symbol"] = 1024] = "Symbol";
|
|
14
14
|
Feature2[Feature2["TypedArray"] = 2048] = "TypedArray";
|
|
15
15
|
Feature2[Feature2["BigIntTypedArray"] = 4096] = "BigIntTypedArray";
|
|
16
|
+
Feature2[Feature2["WebAPI"] = 8192] = "WebAPI";
|
|
16
17
|
return Feature2;
|
|
17
18
|
})(Feature || {});
|
|
18
|
-
var ALL_ENABLED =
|
|
19
|
+
var ALL_ENABLED = 16383;
|
|
19
20
|
|
|
20
21
|
// src/get-identifier.ts
|
|
21
22
|
var REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_";
|
|
@@ -81,7 +82,7 @@ function getRootID(ctx, current) {
|
|
|
81
82
|
}
|
|
82
83
|
return ref;
|
|
83
84
|
}
|
|
84
|
-
function
|
|
85
|
+
function createIndexedValue(ctx, current) {
|
|
85
86
|
const ref = ctx.refs.get(current);
|
|
86
87
|
if (ref == null) {
|
|
87
88
|
const id = ctx.refs.size;
|
|
@@ -99,39 +100,43 @@ function assert(cond, error) {
|
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
// src/
|
|
103
|
-
function
|
|
103
|
+
// src/string.ts
|
|
104
|
+
function serializeChar(str) {
|
|
105
|
+
switch (str) {
|
|
106
|
+
case '"':
|
|
107
|
+
return '\\"';
|
|
108
|
+
case "\\":
|
|
109
|
+
return "\\\\";
|
|
110
|
+
case "\n":
|
|
111
|
+
return "\\n";
|
|
112
|
+
case "\r":
|
|
113
|
+
return "\\r";
|
|
114
|
+
case "\b":
|
|
115
|
+
return "\\b";
|
|
116
|
+
case " ":
|
|
117
|
+
return "\\t";
|
|
118
|
+
case "\f":
|
|
119
|
+
return "\\f";
|
|
120
|
+
case "<":
|
|
121
|
+
return "\\x3C";
|
|
122
|
+
case "\u2028":
|
|
123
|
+
return "\\u2028";
|
|
124
|
+
case "\u2029":
|
|
125
|
+
return "\\u2029";
|
|
126
|
+
default:
|
|
127
|
+
return void 0;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function serializeString(str) {
|
|
104
131
|
let result = "";
|
|
105
132
|
let lastPos = 0;
|
|
133
|
+
let replacement;
|
|
106
134
|
for (let i = 0, len = str.length; i < len; i++) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
break;
|
|
112
|
-
case "\\":
|
|
113
|
-
replacement = "\\\\";
|
|
114
|
-
break;
|
|
115
|
-
case "<":
|
|
116
|
-
replacement = "\\x3C";
|
|
117
|
-
break;
|
|
118
|
-
case "\n":
|
|
119
|
-
replacement = "\\n";
|
|
120
|
-
break;
|
|
121
|
-
case "\r":
|
|
122
|
-
replacement = "\\r";
|
|
123
|
-
break;
|
|
124
|
-
case "\u2028":
|
|
125
|
-
replacement = "\\u2028";
|
|
126
|
-
break;
|
|
127
|
-
case "\u2029":
|
|
128
|
-
replacement = "\\u2029";
|
|
129
|
-
break;
|
|
130
|
-
default:
|
|
131
|
-
continue;
|
|
135
|
+
replacement = serializeChar(str[i]);
|
|
136
|
+
if (replacement) {
|
|
137
|
+
result += str.slice(lastPos, i) + replacement;
|
|
138
|
+
lastPos = i + 1;
|
|
132
139
|
}
|
|
133
|
-
result += str.slice(lastPos, i) + replacement;
|
|
134
|
-
lastPos = i + 1;
|
|
135
140
|
}
|
|
136
141
|
if (lastPos === 0) {
|
|
137
142
|
result = str;
|
|
@@ -140,8 +145,61 @@ function quote(str) {
|
|
|
140
145
|
}
|
|
141
146
|
return result;
|
|
142
147
|
}
|
|
143
|
-
function
|
|
144
|
-
return str.replace(/\\"/g, '"').replace(/\\\\/g, "\\").replace(/\\
|
|
148
|
+
function deserializeString(str) {
|
|
149
|
+
return str.replace(/\\"/g, '"').replace(/\\\\/g, "\\").replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\b/g, "\b").replace(/\\t/g, " ").replace(/\\f/g, "\f").replace(/\\x3C/g, "<").replace(/\\u2028/g, "\u2028").replace(/\\u2029/g, "\u2029");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/tree/reference.ts
|
|
153
|
+
var REFERENCE = /* @__PURE__ */ new Map();
|
|
154
|
+
var INV_REFERENCE = /* @__PURE__ */ new Map();
|
|
155
|
+
function createReference(id, value) {
|
|
156
|
+
REFERENCE.set(value, id);
|
|
157
|
+
INV_REFERENCE.set(id, value);
|
|
158
|
+
return value;
|
|
159
|
+
}
|
|
160
|
+
function hasReferenceID(value) {
|
|
161
|
+
return REFERENCE.has(value);
|
|
162
|
+
}
|
|
163
|
+
function hasReference(id) {
|
|
164
|
+
return INV_REFERENCE.has(id);
|
|
165
|
+
}
|
|
166
|
+
function getReferenceID(value) {
|
|
167
|
+
assert(hasReferenceID(value), "Missing reference id");
|
|
168
|
+
return REFERENCE.get(value);
|
|
169
|
+
}
|
|
170
|
+
function getReference(id) {
|
|
171
|
+
assert(hasReference(id), "Missing reference for id:" + id);
|
|
172
|
+
return INV_REFERENCE.get(id);
|
|
173
|
+
}
|
|
174
|
+
var GLOBAL_KEY = "__SEROVAL__";
|
|
175
|
+
if (typeof globalThis !== void 0) {
|
|
176
|
+
Object.defineProperty(globalThis, GLOBAL_KEY, {
|
|
177
|
+
value: INV_REFERENCE,
|
|
178
|
+
configurable: true,
|
|
179
|
+
writable: false,
|
|
180
|
+
enumerable: false
|
|
181
|
+
});
|
|
182
|
+
} else if (typeof window !== void 0) {
|
|
183
|
+
Object.defineProperty(window, GLOBAL_KEY, {
|
|
184
|
+
value: INV_REFERENCE,
|
|
185
|
+
configurable: true,
|
|
186
|
+
writable: false,
|
|
187
|
+
enumerable: false
|
|
188
|
+
});
|
|
189
|
+
} else if (typeof self !== void 0) {
|
|
190
|
+
Object.defineProperty(self, GLOBAL_KEY, {
|
|
191
|
+
value: INV_REFERENCE,
|
|
192
|
+
configurable: true,
|
|
193
|
+
writable: false,
|
|
194
|
+
enumerable: false
|
|
195
|
+
});
|
|
196
|
+
} else if (typeof global !== void 0) {
|
|
197
|
+
Object.defineProperty(global, GLOBAL_KEY, {
|
|
198
|
+
value: INV_REFERENCE,
|
|
199
|
+
configurable: true,
|
|
200
|
+
writable: false,
|
|
201
|
+
enumerable: false
|
|
202
|
+
});
|
|
145
203
|
}
|
|
146
204
|
|
|
147
205
|
// src/tree/symbols.ts
|
|
@@ -201,7 +259,8 @@ var TRUE_NODE = {
|
|
|
201
259
|
m: void 0,
|
|
202
260
|
d: void 0,
|
|
203
261
|
a: void 0,
|
|
204
|
-
f: void 0
|
|
262
|
+
f: void 0,
|
|
263
|
+
b: void 0
|
|
205
264
|
};
|
|
206
265
|
var FALSE_NODE = {
|
|
207
266
|
t: 2 /* Boolean */,
|
|
@@ -212,7 +271,8 @@ var FALSE_NODE = {
|
|
|
212
271
|
m: void 0,
|
|
213
272
|
d: void 0,
|
|
214
273
|
a: void 0,
|
|
215
|
-
f: void 0
|
|
274
|
+
f: void 0,
|
|
275
|
+
b: void 0
|
|
216
276
|
};
|
|
217
277
|
var UNDEFINED_NODE = {
|
|
218
278
|
t: 4 /* Undefined */,
|
|
@@ -223,7 +283,8 @@ var UNDEFINED_NODE = {
|
|
|
223
283
|
m: void 0,
|
|
224
284
|
d: void 0,
|
|
225
285
|
a: void 0,
|
|
226
|
-
f: void 0
|
|
286
|
+
f: void 0,
|
|
287
|
+
b: void 0
|
|
227
288
|
};
|
|
228
289
|
var NULL_NODE = {
|
|
229
290
|
t: 3 /* Null */,
|
|
@@ -234,7 +295,8 @@ var NULL_NODE = {
|
|
|
234
295
|
m: void 0,
|
|
235
296
|
d: void 0,
|
|
236
297
|
a: void 0,
|
|
237
|
-
f: void 0
|
|
298
|
+
f: void 0,
|
|
299
|
+
b: void 0
|
|
238
300
|
};
|
|
239
301
|
var NEG_ZERO_NODE = {
|
|
240
302
|
t: 5 /* NegativeZero */,
|
|
@@ -245,7 +307,8 @@ var NEG_ZERO_NODE = {
|
|
|
245
307
|
m: void 0,
|
|
246
308
|
d: void 0,
|
|
247
309
|
a: void 0,
|
|
248
|
-
f: void 0
|
|
310
|
+
f: void 0,
|
|
311
|
+
b: void 0
|
|
249
312
|
};
|
|
250
313
|
var INFINITY_NODE = {
|
|
251
314
|
t: 6 /* Infinity */,
|
|
@@ -256,7 +319,8 @@ var INFINITY_NODE = {
|
|
|
256
319
|
m: void 0,
|
|
257
320
|
d: void 0,
|
|
258
321
|
a: void 0,
|
|
259
|
-
f: void 0
|
|
322
|
+
f: void 0,
|
|
323
|
+
b: void 0
|
|
260
324
|
};
|
|
261
325
|
var NEG_INFINITY_NODE = {
|
|
262
326
|
t: 7 /* NegativeInfinity */,
|
|
@@ -267,7 +331,8 @@ var NEG_INFINITY_NODE = {
|
|
|
267
331
|
m: void 0,
|
|
268
332
|
d: void 0,
|
|
269
333
|
a: void 0,
|
|
270
|
-
f: void 0
|
|
334
|
+
f: void 0,
|
|
335
|
+
b: void 0
|
|
271
336
|
};
|
|
272
337
|
var NAN_NODE = {
|
|
273
338
|
t: 8 /* NaN */,
|
|
@@ -278,7 +343,8 @@ var NAN_NODE = {
|
|
|
278
343
|
m: void 0,
|
|
279
344
|
d: void 0,
|
|
280
345
|
a: void 0,
|
|
281
|
-
f: void 0
|
|
346
|
+
f: void 0,
|
|
347
|
+
b: void 0
|
|
282
348
|
};
|
|
283
349
|
function createNumberNode(value) {
|
|
284
350
|
return {
|
|
@@ -290,20 +356,22 @@ function createNumberNode(value) {
|
|
|
290
356
|
m: void 0,
|
|
291
357
|
d: void 0,
|
|
292
358
|
a: void 0,
|
|
293
|
-
f: void 0
|
|
359
|
+
f: void 0,
|
|
360
|
+
b: void 0
|
|
294
361
|
};
|
|
295
362
|
}
|
|
296
363
|
function createStringNode(value) {
|
|
297
364
|
return {
|
|
298
365
|
t: 1 /* String */,
|
|
299
366
|
i: void 0,
|
|
300
|
-
s:
|
|
367
|
+
s: serializeString(value),
|
|
301
368
|
l: void 0,
|
|
302
369
|
c: void 0,
|
|
303
370
|
m: void 0,
|
|
304
371
|
d: void 0,
|
|
305
372
|
a: void 0,
|
|
306
|
-
f: void 0
|
|
373
|
+
f: void 0,
|
|
374
|
+
b: void 0
|
|
307
375
|
};
|
|
308
376
|
}
|
|
309
377
|
function createBigIntNode(ctx, current) {
|
|
@@ -317,12 +385,13 @@ function createBigIntNode(ctx, current) {
|
|
|
317
385
|
m: void 0,
|
|
318
386
|
d: void 0,
|
|
319
387
|
a: void 0,
|
|
320
|
-
f: void 0
|
|
388
|
+
f: void 0,
|
|
389
|
+
b: void 0
|
|
321
390
|
};
|
|
322
391
|
}
|
|
323
|
-
function
|
|
392
|
+
function createIndexedValueNode(id) {
|
|
324
393
|
return {
|
|
325
|
-
t: 10 /*
|
|
394
|
+
t: 10 /* IndexedValue */,
|
|
326
395
|
i: id,
|
|
327
396
|
s: void 0,
|
|
328
397
|
l: void 0,
|
|
@@ -330,7 +399,8 @@ function createReferenceNode(id) {
|
|
|
330
399
|
m: void 0,
|
|
331
400
|
d: void 0,
|
|
332
401
|
a: void 0,
|
|
333
|
-
f: void 0
|
|
402
|
+
f: void 0,
|
|
403
|
+
b: void 0
|
|
334
404
|
};
|
|
335
405
|
}
|
|
336
406
|
function createDateNode(id, current) {
|
|
@@ -343,7 +413,8 @@ function createDateNode(id, current) {
|
|
|
343
413
|
m: void 0,
|
|
344
414
|
d: void 0,
|
|
345
415
|
f: void 0,
|
|
346
|
-
a: void 0
|
|
416
|
+
a: void 0,
|
|
417
|
+
b: void 0
|
|
347
418
|
};
|
|
348
419
|
}
|
|
349
420
|
function createRegExpNode(id, current) {
|
|
@@ -356,27 +427,51 @@ function createRegExpNode(id, current) {
|
|
|
356
427
|
m: current.flags,
|
|
357
428
|
d: void 0,
|
|
358
429
|
a: void 0,
|
|
359
|
-
f: void 0
|
|
430
|
+
f: void 0,
|
|
431
|
+
b: void 0
|
|
360
432
|
};
|
|
361
433
|
}
|
|
362
|
-
function
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
const len = current.length;
|
|
434
|
+
function createArrayBufferNode(id, current) {
|
|
435
|
+
const bytes = new Uint8Array(current);
|
|
436
|
+
const len = bytes.length;
|
|
366
437
|
const values = new Array(len);
|
|
367
438
|
for (let i = 0; i < len; i++) {
|
|
368
|
-
values[i] =
|
|
439
|
+
values[i] = bytes[i];
|
|
369
440
|
}
|
|
370
441
|
return {
|
|
371
|
-
t:
|
|
442
|
+
t: 28 /* ArrayBuffer */,
|
|
372
443
|
i: id,
|
|
373
444
|
s: values,
|
|
374
|
-
l:
|
|
445
|
+
l: void 0,
|
|
446
|
+
c: void 0,
|
|
447
|
+
m: void 0,
|
|
448
|
+
d: void 0,
|
|
449
|
+
a: void 0,
|
|
450
|
+
f: void 0,
|
|
451
|
+
b: void 0
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
function serializeArrayBuffer(ctx, current) {
|
|
455
|
+
const id = createIndexedValue(ctx, current);
|
|
456
|
+
if (ctx.markedRefs.has(id)) {
|
|
457
|
+
return createIndexedValueNode(id);
|
|
458
|
+
}
|
|
459
|
+
return createArrayBufferNode(id, current);
|
|
460
|
+
}
|
|
461
|
+
function createTypedArrayNode(ctx, id, current) {
|
|
462
|
+
const constructor = current.constructor.name;
|
|
463
|
+
assert(ctx.features & 2048 /* TypedArray */, `Unsupported value type "${constructor}"`);
|
|
464
|
+
return {
|
|
465
|
+
t: 22 /* TypedArray */,
|
|
466
|
+
i: id,
|
|
467
|
+
s: void 0,
|
|
468
|
+
l: current.length,
|
|
375
469
|
c: constructor,
|
|
376
470
|
m: void 0,
|
|
377
471
|
d: void 0,
|
|
378
472
|
a: void 0,
|
|
379
|
-
f:
|
|
473
|
+
f: serializeArrayBuffer(ctx, current.buffer),
|
|
474
|
+
b: current.byteOffset
|
|
380
475
|
};
|
|
381
476
|
}
|
|
382
477
|
var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
|
|
@@ -386,24 +481,22 @@ function createBigIntTypedArrayNode(ctx, id, current) {
|
|
|
386
481
|
(ctx.features & BIGINT_FLAG) === BIGINT_FLAG,
|
|
387
482
|
`Unsupported value type "${constructor}"`
|
|
388
483
|
);
|
|
389
|
-
const len = current.length;
|
|
390
|
-
const values = new Array(len);
|
|
391
|
-
for (let i = 0; i < len; i++) {
|
|
392
|
-
values[i] = "" + current[i];
|
|
393
|
-
}
|
|
394
484
|
return {
|
|
395
485
|
t: 23 /* BigIntTypedArray */,
|
|
396
486
|
i: id,
|
|
397
|
-
s:
|
|
398
|
-
l: current.
|
|
487
|
+
s: void 0,
|
|
488
|
+
l: current.length,
|
|
399
489
|
c: constructor,
|
|
400
490
|
m: void 0,
|
|
401
491
|
d: void 0,
|
|
402
492
|
a: void 0,
|
|
403
|
-
f:
|
|
493
|
+
f: serializeArrayBuffer(ctx, current.buffer),
|
|
494
|
+
b: current.byteOffset
|
|
404
495
|
};
|
|
405
496
|
}
|
|
406
|
-
function createWKSymbolNode(current) {
|
|
497
|
+
function createWKSymbolNode(ctx, current) {
|
|
498
|
+
assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "symbol"');
|
|
499
|
+
assert(current in INV_SYMBOL_REF, "seroval only supports well-known symbols");
|
|
407
500
|
return {
|
|
408
501
|
t: 24 /* WKSymbol */,
|
|
409
502
|
i: void 0,
|
|
@@ -413,7 +506,36 @@ function createWKSymbolNode(current) {
|
|
|
413
506
|
m: void 0,
|
|
414
507
|
d: void 0,
|
|
415
508
|
a: void 0,
|
|
416
|
-
f: void 0
|
|
509
|
+
f: void 0,
|
|
510
|
+
b: void 0
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
function createReferenceNode(id, ref) {
|
|
514
|
+
return {
|
|
515
|
+
t: 27 /* Reference */,
|
|
516
|
+
i: id,
|
|
517
|
+
s: serializeString(getReferenceID(ref)),
|
|
518
|
+
l: void 0,
|
|
519
|
+
c: void 0,
|
|
520
|
+
m: void 0,
|
|
521
|
+
d: void 0,
|
|
522
|
+
a: void 0,
|
|
523
|
+
f: void 0,
|
|
524
|
+
b: void 0
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function createDataViewNode(ctx, id, current) {
|
|
528
|
+
return {
|
|
529
|
+
t: 29 /* DataView */,
|
|
530
|
+
i: id,
|
|
531
|
+
s: void 0,
|
|
532
|
+
l: current.byteLength,
|
|
533
|
+
c: void 0,
|
|
534
|
+
m: void 0,
|
|
535
|
+
d: void 0,
|
|
536
|
+
a: void 0,
|
|
537
|
+
f: serializeArrayBuffer(ctx, current.buffer),
|
|
538
|
+
b: current.byteOffset
|
|
417
539
|
};
|
|
418
540
|
}
|
|
419
541
|
|
|
@@ -555,6 +677,68 @@ function isValidIdentifier(name) {
|
|
|
555
677
|
return (char === "$" || char === "_" || char >= "A" && char <= "Z" || char >= "a" && char <= "z") && IDENTIFIER_CHECK.test(name);
|
|
556
678
|
}
|
|
557
679
|
|
|
680
|
+
// src/tree/web-api.ts
|
|
681
|
+
function createURLNode(ctx, id, current) {
|
|
682
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "URL"');
|
|
683
|
+
return {
|
|
684
|
+
t: 25 /* URL */,
|
|
685
|
+
i: id,
|
|
686
|
+
s: serializeString(current.href),
|
|
687
|
+
l: void 0,
|
|
688
|
+
c: void 0,
|
|
689
|
+
m: void 0,
|
|
690
|
+
d: void 0,
|
|
691
|
+
f: void 0,
|
|
692
|
+
a: void 0,
|
|
693
|
+
b: void 0
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
function createURLSearchParamsNode(ctx, id, current) {
|
|
697
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "URLSearchParams"');
|
|
698
|
+
return {
|
|
699
|
+
t: 26 /* URLSearchParams */,
|
|
700
|
+
i: id,
|
|
701
|
+
s: serializeString(current.toString()),
|
|
702
|
+
l: void 0,
|
|
703
|
+
c: void 0,
|
|
704
|
+
m: void 0,
|
|
705
|
+
d: void 0,
|
|
706
|
+
f: void 0,
|
|
707
|
+
a: void 0,
|
|
708
|
+
b: void 0
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
async function createBlobNode(ctx, id, current) {
|
|
712
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "Blob"');
|
|
713
|
+
return {
|
|
714
|
+
t: 30 /* Blob */,
|
|
715
|
+
i: id,
|
|
716
|
+
s: void 0,
|
|
717
|
+
l: void 0,
|
|
718
|
+
c: serializeString(current.type),
|
|
719
|
+
m: void 0,
|
|
720
|
+
d: void 0,
|
|
721
|
+
f: serializeArrayBuffer(ctx, await current.arrayBuffer()),
|
|
722
|
+
a: void 0,
|
|
723
|
+
b: void 0
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
async function createFileNode(ctx, id, current) {
|
|
727
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "File"');
|
|
728
|
+
return {
|
|
729
|
+
t: 31 /* File */,
|
|
730
|
+
i: id,
|
|
731
|
+
s: void 0,
|
|
732
|
+
l: void 0,
|
|
733
|
+
c: serializeString(current.type),
|
|
734
|
+
m: serializeString(current.name),
|
|
735
|
+
d: void 0,
|
|
736
|
+
f: serializeArrayBuffer(ctx, await current.arrayBuffer()),
|
|
737
|
+
a: void 0,
|
|
738
|
+
b: current.lastModified
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
|
|
558
742
|
// src/tree/async.ts
|
|
559
743
|
async function generateNodeList(ctx, current) {
|
|
560
744
|
const size = current.length;
|
|
@@ -588,7 +772,8 @@ async function generateArrayNode(ctx, id, current) {
|
|
|
588
772
|
m: void 0,
|
|
589
773
|
d: void 0,
|
|
590
774
|
a: await generateNodeList(ctx, current),
|
|
591
|
-
f: void 0
|
|
775
|
+
f: void 0,
|
|
776
|
+
b: void 0
|
|
592
777
|
};
|
|
593
778
|
}
|
|
594
779
|
async function generateMapNode(ctx, id, current) {
|
|
@@ -624,7 +809,8 @@ async function generateMapNode(ctx, id, current) {
|
|
|
624
809
|
m: void 0,
|
|
625
810
|
d: { k: keyNodes, v: valueNodes, s: len },
|
|
626
811
|
a: void 0,
|
|
627
|
-
f: void 0
|
|
812
|
+
f: void 0,
|
|
813
|
+
b: void 0
|
|
628
814
|
};
|
|
629
815
|
}
|
|
630
816
|
async function generateSetNode(ctx, id, current) {
|
|
@@ -653,7 +839,8 @@ async function generateSetNode(ctx, id, current) {
|
|
|
653
839
|
m: void 0,
|
|
654
840
|
d: void 0,
|
|
655
841
|
a: nodes,
|
|
656
|
-
f: void 0
|
|
842
|
+
f: void 0,
|
|
843
|
+
b: void 0
|
|
657
844
|
};
|
|
658
845
|
}
|
|
659
846
|
async function generateProperties(ctx, properties) {
|
|
@@ -666,14 +853,16 @@ async function generateProperties(ctx, properties) {
|
|
|
666
853
|
let deferredSize = 0;
|
|
667
854
|
let nodesSize = 0;
|
|
668
855
|
let item;
|
|
856
|
+
let escaped;
|
|
669
857
|
for (const key of keys) {
|
|
670
858
|
item = properties[key];
|
|
859
|
+
escaped = serializeString(key);
|
|
671
860
|
if (isIterable(item)) {
|
|
672
|
-
deferredKeys[deferredSize] =
|
|
861
|
+
deferredKeys[deferredSize] = escaped;
|
|
673
862
|
deferredValues[deferredSize] = item;
|
|
674
863
|
deferredSize++;
|
|
675
864
|
} else {
|
|
676
|
-
keyNodes[nodesSize] =
|
|
865
|
+
keyNodes[nodesSize] = escaped;
|
|
677
866
|
valueNodes[nodesSize] = await parse(ctx, item);
|
|
678
867
|
nodesSize++;
|
|
679
868
|
}
|
|
@@ -702,7 +891,8 @@ async function generateIterableNode(ctx, id, current) {
|
|
|
702
891
|
// Parse options first before the items
|
|
703
892
|
d: options ? await generateProperties(ctx, options) : void 0,
|
|
704
893
|
a: await generateNodeList(ctx, array),
|
|
705
|
-
f: void 0
|
|
894
|
+
f: void 0,
|
|
895
|
+
b: void 0
|
|
706
896
|
};
|
|
707
897
|
}
|
|
708
898
|
async function generatePromiseNode(ctx, id, current) {
|
|
@@ -717,7 +907,8 @@ async function generatePromiseNode(ctx, id, current) {
|
|
|
717
907
|
// Parse options first before the items
|
|
718
908
|
d: void 0,
|
|
719
909
|
a: void 0,
|
|
720
|
-
f: await parse(ctx, value)
|
|
910
|
+
f: await parse(ctx, value),
|
|
911
|
+
b: void 0
|
|
721
912
|
}));
|
|
722
913
|
}
|
|
723
914
|
async function generateObjectNode(ctx, id, current, empty) {
|
|
@@ -736,7 +927,8 @@ async function generateObjectNode(ctx, id, current, empty) {
|
|
|
736
927
|
m: void 0,
|
|
737
928
|
d: await generateProperties(ctx, current),
|
|
738
929
|
a: void 0,
|
|
739
|
-
f: void 0
|
|
930
|
+
f: void 0,
|
|
931
|
+
b: void 0
|
|
740
932
|
};
|
|
741
933
|
}
|
|
742
934
|
async function generateAggregateErrorNode(ctx, id, current) {
|
|
@@ -746,12 +938,13 @@ async function generateAggregateErrorNode(ctx, id, current) {
|
|
|
746
938
|
t: 20 /* AggregateError */,
|
|
747
939
|
i: id,
|
|
748
940
|
s: void 0,
|
|
749
|
-
l:
|
|
941
|
+
l: void 0,
|
|
750
942
|
c: void 0,
|
|
751
|
-
m: current.message,
|
|
943
|
+
m: serializeString(current.message),
|
|
752
944
|
d: optionsNode,
|
|
753
|
-
a:
|
|
754
|
-
f: void 0
|
|
945
|
+
a: void 0,
|
|
946
|
+
f: void 0,
|
|
947
|
+
b: void 0
|
|
755
948
|
};
|
|
756
949
|
}
|
|
757
950
|
async function generateErrorNode(ctx, id, current) {
|
|
@@ -763,10 +956,49 @@ async function generateErrorNode(ctx, id, current) {
|
|
|
763
956
|
s: void 0,
|
|
764
957
|
l: void 0,
|
|
765
958
|
c: getErrorConstructorName(current),
|
|
766
|
-
m: current.message,
|
|
959
|
+
m: serializeString(current.message),
|
|
767
960
|
d: optionsNode,
|
|
768
961
|
a: void 0,
|
|
769
|
-
f: void 0
|
|
962
|
+
f: void 0,
|
|
963
|
+
b: void 0
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
async function generateHeadersNode(ctx, id, current) {
|
|
967
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "Headers"');
|
|
968
|
+
const items = {};
|
|
969
|
+
current.forEach((value, key) => {
|
|
970
|
+
items[key] = value;
|
|
971
|
+
});
|
|
972
|
+
return {
|
|
973
|
+
t: 32 /* Headers */,
|
|
974
|
+
i: id,
|
|
975
|
+
s: void 0,
|
|
976
|
+
l: void 0,
|
|
977
|
+
c: void 0,
|
|
978
|
+
m: void 0,
|
|
979
|
+
d: await generateProperties(ctx, items),
|
|
980
|
+
a: void 0,
|
|
981
|
+
f: void 0,
|
|
982
|
+
b: void 0
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
async function generateFormDataNode(ctx, id, current) {
|
|
986
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "FormData"');
|
|
987
|
+
const items = {};
|
|
988
|
+
current.forEach((value, key) => {
|
|
989
|
+
items[key] = value;
|
|
990
|
+
});
|
|
991
|
+
return {
|
|
992
|
+
t: 33 /* FormData */,
|
|
993
|
+
i: id,
|
|
994
|
+
s: void 0,
|
|
995
|
+
l: void 0,
|
|
996
|
+
c: void 0,
|
|
997
|
+
m: void 0,
|
|
998
|
+
d: await generateProperties(ctx, items),
|
|
999
|
+
a: void 0,
|
|
1000
|
+
f: void 0,
|
|
1001
|
+
b: void 0
|
|
770
1002
|
};
|
|
771
1003
|
}
|
|
772
1004
|
async function parse(ctx, current) {
|
|
@@ -784,24 +1016,26 @@ async function parse(ctx, current) {
|
|
|
784
1016
|
case -Infinity:
|
|
785
1017
|
return NEG_INFINITY_NODE;
|
|
786
1018
|
default:
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
1019
|
+
if (current !== current) {
|
|
1020
|
+
return NAN_NODE;
|
|
1021
|
+
}
|
|
1022
|
+
if (Object.is(current, -0)) {
|
|
1023
|
+
return NEG_ZERO_NODE;
|
|
1024
|
+
}
|
|
1025
|
+
return createNumberNode(current);
|
|
794
1026
|
}
|
|
795
|
-
return createNumberNode(current);
|
|
796
1027
|
case "bigint":
|
|
797
1028
|
return createBigIntNode(ctx, current);
|
|
798
1029
|
case "object": {
|
|
799
1030
|
if (!current) {
|
|
800
1031
|
return NULL_NODE;
|
|
801
1032
|
}
|
|
802
|
-
const id =
|
|
1033
|
+
const id = createIndexedValue(ctx, current);
|
|
803
1034
|
if (ctx.markedRefs.has(id)) {
|
|
804
|
-
return
|
|
1035
|
+
return createIndexedValueNode(id);
|
|
1036
|
+
}
|
|
1037
|
+
if (hasReferenceID(current)) {
|
|
1038
|
+
return createReferenceNode(id, current);
|
|
805
1039
|
}
|
|
806
1040
|
if (Array.isArray(current)) {
|
|
807
1041
|
return generateArrayNode(ctx, id, current);
|
|
@@ -813,6 +1047,8 @@ async function parse(ctx, current) {
|
|
|
813
1047
|
return createRegExpNode(id, current);
|
|
814
1048
|
case Promise:
|
|
815
1049
|
return generatePromiseNode(ctx, id, current);
|
|
1050
|
+
case ArrayBuffer:
|
|
1051
|
+
return createArrayBufferNode(id, current);
|
|
816
1052
|
case Int8Array:
|
|
817
1053
|
case Int16Array:
|
|
818
1054
|
case Int32Array:
|
|
@@ -826,6 +1062,8 @@ async function parse(ctx, current) {
|
|
|
826
1062
|
case BigInt64Array:
|
|
827
1063
|
case BigUint64Array:
|
|
828
1064
|
return createBigIntTypedArrayNode(ctx, id, current);
|
|
1065
|
+
case DataView:
|
|
1066
|
+
return createDataViewNode(ctx, id, current);
|
|
829
1067
|
case Map:
|
|
830
1068
|
return generateMapNode(
|
|
831
1069
|
ctx,
|
|
@@ -865,6 +1103,18 @@ async function parse(ctx, current) {
|
|
|
865
1103
|
case TypeError:
|
|
866
1104
|
case URIError:
|
|
867
1105
|
return generateErrorNode(ctx, id, current);
|
|
1106
|
+
case URL:
|
|
1107
|
+
return createURLNode(ctx, id, current);
|
|
1108
|
+
case URLSearchParams:
|
|
1109
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
1110
|
+
case Blob:
|
|
1111
|
+
return createBlobNode(ctx, id, current);
|
|
1112
|
+
case File:
|
|
1113
|
+
return createFileNode(ctx, id, current);
|
|
1114
|
+
case Headers:
|
|
1115
|
+
return generateHeadersNode(ctx, id, current);
|
|
1116
|
+
case FormData:
|
|
1117
|
+
return generateFormDataNode(ctx, id, current);
|
|
868
1118
|
default:
|
|
869
1119
|
break;
|
|
870
1120
|
}
|
|
@@ -889,9 +1139,22 @@ async function parse(ctx, current) {
|
|
|
889
1139
|
throw new Error("Unsupported type");
|
|
890
1140
|
}
|
|
891
1141
|
case "symbol":
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
1142
|
+
if (hasReferenceID(current)) {
|
|
1143
|
+
const id = createIndexedValue(ctx, current);
|
|
1144
|
+
if (ctx.markedRefs.has(id)) {
|
|
1145
|
+
return createIndexedValueNode(id);
|
|
1146
|
+
}
|
|
1147
|
+
return createReferenceNode(id, current);
|
|
1148
|
+
}
|
|
1149
|
+
return createWKSymbolNode(ctx, current);
|
|
1150
|
+
case "function": {
|
|
1151
|
+
assert(hasReferenceID(current), "Cannot serialize function without reference ID.");
|
|
1152
|
+
const id = createIndexedValue(ctx, current);
|
|
1153
|
+
if (ctx.markedRefs.has(id)) {
|
|
1154
|
+
return createIndexedValueNode(id);
|
|
1155
|
+
}
|
|
1156
|
+
return createReferenceNode(id, current);
|
|
1157
|
+
}
|
|
895
1158
|
default:
|
|
896
1159
|
throw new Error("Unsupported type");
|
|
897
1160
|
}
|
|
@@ -903,13 +1166,20 @@ async function parseAsync(ctx, current) {
|
|
|
903
1166
|
}
|
|
904
1167
|
|
|
905
1168
|
// src/tree/deserialize.ts
|
|
906
|
-
function
|
|
907
|
-
ctx.
|
|
1169
|
+
function assignIndexedValue(ctx, index, value) {
|
|
1170
|
+
if (ctx.markedRefs.has(index)) {
|
|
1171
|
+
ctx.valueMap.set(index, value);
|
|
1172
|
+
}
|
|
908
1173
|
return value;
|
|
909
1174
|
}
|
|
910
|
-
function
|
|
1175
|
+
function deserializeArray(ctx, node) {
|
|
1176
|
+
const result = assignIndexedValue(
|
|
1177
|
+
ctx,
|
|
1178
|
+
node.i,
|
|
1179
|
+
new Array(node.l)
|
|
1180
|
+
);
|
|
911
1181
|
let item;
|
|
912
|
-
for (let i = 0, len = node.
|
|
1182
|
+
for (let i = 0, len = node.l; i < len; i++) {
|
|
913
1183
|
item = node.a[i];
|
|
914
1184
|
if (item) {
|
|
915
1185
|
result[i] = deserializeTree(ctx, item);
|
|
@@ -917,84 +1187,68 @@ function deserializeNodeList(ctx, node, result) {
|
|
|
917
1187
|
}
|
|
918
1188
|
return result;
|
|
919
1189
|
}
|
|
920
|
-
function deserializeArray(ctx, node) {
|
|
921
|
-
const result = assignRef(
|
|
922
|
-
ctx,
|
|
923
|
-
node.i,
|
|
924
|
-
new Array(node.l)
|
|
925
|
-
);
|
|
926
|
-
ctx.stack.push(node.i);
|
|
927
|
-
deserializeNodeList(ctx, node, result);
|
|
928
|
-
ctx.stack.pop();
|
|
929
|
-
return result;
|
|
930
|
-
}
|
|
931
1190
|
function deserializeProperties(ctx, node, result) {
|
|
932
1191
|
if (node.s === 0) {
|
|
933
1192
|
return {};
|
|
934
1193
|
}
|
|
935
1194
|
for (let i = 0; i < node.s; i++) {
|
|
936
|
-
result[node.k[i]] = deserializeTree(ctx, node.v[i]);
|
|
1195
|
+
result[deserializeString(node.k[i])] = deserializeTree(ctx, node.v[i]);
|
|
937
1196
|
}
|
|
938
1197
|
return result;
|
|
939
1198
|
}
|
|
940
1199
|
function deserializeNullConstructor(ctx, node) {
|
|
941
|
-
const result =
|
|
942
|
-
|
|
1200
|
+
const result = assignIndexedValue(
|
|
1201
|
+
ctx,
|
|
1202
|
+
node.i,
|
|
1203
|
+
/* @__PURE__ */ Object.create(null)
|
|
1204
|
+
);
|
|
943
1205
|
deserializeProperties(ctx, node.d, result);
|
|
944
|
-
ctx.stack.pop();
|
|
945
1206
|
return result;
|
|
946
1207
|
}
|
|
947
1208
|
function deserializeObject(ctx, node) {
|
|
948
|
-
const result =
|
|
949
|
-
ctx.stack.push(node.i);
|
|
1209
|
+
const result = assignIndexedValue(ctx, node.i, {});
|
|
950
1210
|
deserializeProperties(ctx, node.d, result);
|
|
951
|
-
ctx.stack.pop();
|
|
952
1211
|
return result;
|
|
953
1212
|
}
|
|
954
1213
|
function deserializeSet(ctx, node) {
|
|
955
|
-
const result =
|
|
956
|
-
|
|
957
|
-
for (let i = 0, len = node.a.length; i < len; i++) {
|
|
1214
|
+
const result = assignIndexedValue(ctx, node.i, /* @__PURE__ */ new Set());
|
|
1215
|
+
for (let i = 0, len = node.l; i < len; i++) {
|
|
958
1216
|
result.add(deserializeTree(ctx, node.a[i]));
|
|
959
1217
|
}
|
|
960
|
-
ctx.stack.pop();
|
|
961
1218
|
return result;
|
|
962
1219
|
}
|
|
963
1220
|
function deserializeMap(ctx, node) {
|
|
964
|
-
const result =
|
|
1221
|
+
const result = assignIndexedValue(
|
|
965
1222
|
ctx,
|
|
966
1223
|
node.i,
|
|
967
1224
|
/* @__PURE__ */ new Map()
|
|
968
1225
|
);
|
|
969
|
-
|
|
970
|
-
for (let i = 0; i < node.d.s; i++) {
|
|
1226
|
+
for (let i = 0, len = node.d.s; i < len; i++) {
|
|
971
1227
|
result.set(
|
|
972
1228
|
deserializeTree(ctx, node.d.k[i]),
|
|
973
1229
|
deserializeTree(ctx, node.d.v[i])
|
|
974
1230
|
);
|
|
975
1231
|
}
|
|
976
|
-
ctx.stack.pop();
|
|
977
1232
|
return result;
|
|
978
1233
|
}
|
|
979
1234
|
function deserializeDictionary(ctx, node, result) {
|
|
980
1235
|
if (node.d) {
|
|
981
|
-
ctx.stack.push(node.i);
|
|
982
1236
|
const fields = deserializeProperties(ctx, node.d, {});
|
|
983
|
-
ctx.stack.pop();
|
|
984
1237
|
Object.assign(result, fields);
|
|
985
1238
|
}
|
|
986
1239
|
return result;
|
|
987
1240
|
}
|
|
988
1241
|
function deserializeAggregateError(ctx, node) {
|
|
989
|
-
const result =
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
1242
|
+
const result = assignIndexedValue(
|
|
1243
|
+
ctx,
|
|
1244
|
+
node.i,
|
|
1245
|
+
new AggregateError([], deserializeString(node.m))
|
|
1246
|
+
);
|
|
993
1247
|
return deserializeDictionary(ctx, node, result);
|
|
994
1248
|
}
|
|
995
1249
|
function deserializeError(ctx, node) {
|
|
996
1250
|
const ErrorConstructor = getErrorConstructor(node.c);
|
|
997
|
-
const result =
|
|
1251
|
+
const result = assignIndexedValue(ctx, node.i, new ErrorConstructor(deserializeString(node.m)));
|
|
998
1252
|
return deserializeDictionary(ctx, node, result);
|
|
999
1253
|
}
|
|
1000
1254
|
function createDeferred() {
|
|
@@ -1010,37 +1264,107 @@ function createDeferred() {
|
|
|
1010
1264
|
}
|
|
1011
1265
|
function deserializePromise(ctx, node) {
|
|
1012
1266
|
const deferred = createDeferred();
|
|
1013
|
-
const result =
|
|
1267
|
+
const result = assignIndexedValue(ctx, node.i, deferred.promise);
|
|
1014
1268
|
deferred.resolve(deserializeTree(ctx, node.f));
|
|
1015
1269
|
return result;
|
|
1016
1270
|
}
|
|
1271
|
+
function deserializeArrayBuffer(ctx, node) {
|
|
1272
|
+
const bytes = new Uint8Array(node.s);
|
|
1273
|
+
const result = assignIndexedValue(ctx, node.i, bytes.buffer);
|
|
1274
|
+
return result;
|
|
1275
|
+
}
|
|
1017
1276
|
function deserializeTypedArray(ctx, node) {
|
|
1018
1277
|
const TypedArray = getTypedArrayConstructor(node.c);
|
|
1019
|
-
const
|
|
1020
|
-
const result =
|
|
1021
|
-
|
|
1278
|
+
const source = deserializeTree(ctx, node.f);
|
|
1279
|
+
const result = assignIndexedValue(ctx, node.i, new TypedArray(
|
|
1280
|
+
source,
|
|
1281
|
+
node.b,
|
|
1022
1282
|
node.l
|
|
1023
1283
|
));
|
|
1024
|
-
for (let i = 0, len = node.s.length; i < len; i++) {
|
|
1025
|
-
result[i] = node.t === 23 /* BigIntTypedArray */ ? BigInt(node.s[i]) : Number(node.s[i]);
|
|
1026
|
-
}
|
|
1027
1284
|
return result;
|
|
1028
1285
|
}
|
|
1029
1286
|
function deserializeIterable(ctx, node) {
|
|
1030
1287
|
const values = [];
|
|
1031
|
-
|
|
1032
|
-
|
|
1288
|
+
let item;
|
|
1289
|
+
for (let i = 0, len = node.l; i < len; i++) {
|
|
1290
|
+
item = node.a[i];
|
|
1291
|
+
if (item) {
|
|
1292
|
+
values[i] = deserializeTree(ctx, item);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
const result = assignIndexedValue(ctx, node.i, {
|
|
1033
1296
|
[Symbol.iterator]: () => values.values()
|
|
1034
1297
|
});
|
|
1035
1298
|
return deserializeDictionary(ctx, node, result);
|
|
1036
1299
|
}
|
|
1300
|
+
function deserializeDate(ctx, node) {
|
|
1301
|
+
return assignIndexedValue(ctx, node.i, new Date(node.s));
|
|
1302
|
+
}
|
|
1303
|
+
function deserializeRegExp(ctx, node) {
|
|
1304
|
+
return assignIndexedValue(ctx, node.i, new RegExp(node.c, node.m));
|
|
1305
|
+
}
|
|
1306
|
+
function deserializeURL(ctx, node) {
|
|
1307
|
+
return assignIndexedValue(ctx, node.i, new URL(deserializeString(node.s)));
|
|
1308
|
+
}
|
|
1309
|
+
function deserializeURLSearchParams(ctx, node) {
|
|
1310
|
+
return assignIndexedValue(ctx, node.i, new URLSearchParams(deserializeString(node.s)));
|
|
1311
|
+
}
|
|
1312
|
+
function deserializeReference(ctx, node) {
|
|
1313
|
+
return assignIndexedValue(ctx, node.i, getReference(deserializeString(node.s)));
|
|
1314
|
+
}
|
|
1315
|
+
function deserializeDataView(ctx, node) {
|
|
1316
|
+
const source = deserializeTree(ctx, node.f);
|
|
1317
|
+
const result = assignIndexedValue(ctx, node.i, new DataView(
|
|
1318
|
+
source,
|
|
1319
|
+
node.b,
|
|
1320
|
+
node.l
|
|
1321
|
+
));
|
|
1322
|
+
return result;
|
|
1323
|
+
}
|
|
1324
|
+
function deserializeBlob(ctx, node) {
|
|
1325
|
+
const source = deserializeTree(ctx, node.f);
|
|
1326
|
+
const result = assignIndexedValue(ctx, node.i, new Blob(
|
|
1327
|
+
[source],
|
|
1328
|
+
{ type: deserializeString(node.c) }
|
|
1329
|
+
));
|
|
1330
|
+
return result;
|
|
1331
|
+
}
|
|
1332
|
+
function deserializeFile(ctx, node) {
|
|
1333
|
+
const source = deserializeTree(ctx, node.f);
|
|
1334
|
+
const result = assignIndexedValue(ctx, node.i, new File(
|
|
1335
|
+
[source],
|
|
1336
|
+
deserializeString(node.m),
|
|
1337
|
+
{ type: deserializeString(node.c), lastModified: node.b }
|
|
1338
|
+
));
|
|
1339
|
+
return result;
|
|
1340
|
+
}
|
|
1341
|
+
function deserializeHeaders(ctx, node) {
|
|
1342
|
+
const result = assignIndexedValue(ctx, node.i, new Headers());
|
|
1343
|
+
for (let i = 0, len = node.d.s; i < len; i++) {
|
|
1344
|
+
result.set(
|
|
1345
|
+
deserializeString(node.d.k[i]),
|
|
1346
|
+
deserializeTree(ctx, node.d.v[i])
|
|
1347
|
+
);
|
|
1348
|
+
}
|
|
1349
|
+
return result;
|
|
1350
|
+
}
|
|
1351
|
+
function deserializeFormData(ctx, node) {
|
|
1352
|
+
const result = assignIndexedValue(ctx, node.i, new FormData());
|
|
1353
|
+
for (let i = 0, len = node.d.s; i < len; i++) {
|
|
1354
|
+
result.set(
|
|
1355
|
+
deserializeString(node.d.k[i]),
|
|
1356
|
+
deserializeTree(ctx, node.d.v[i])
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
return result;
|
|
1360
|
+
}
|
|
1037
1361
|
function deserializeTree(ctx, node) {
|
|
1038
1362
|
switch (node.t) {
|
|
1039
1363
|
case 0 /* Number */:
|
|
1040
1364
|
case 2 /* Boolean */:
|
|
1041
1365
|
return node.s;
|
|
1042
1366
|
case 1 /* String */:
|
|
1043
|
-
return
|
|
1367
|
+
return deserializeString(node.s);
|
|
1044
1368
|
case 4 /* Undefined */:
|
|
1045
1369
|
return void 0;
|
|
1046
1370
|
case 3 /* Null */:
|
|
@@ -1055,7 +1379,7 @@ function deserializeTree(ctx, node) {
|
|
|
1055
1379
|
return NaN;
|
|
1056
1380
|
case 9 /* BigInt */:
|
|
1057
1381
|
return BigInt(node.s);
|
|
1058
|
-
case 10 /*
|
|
1382
|
+
case 10 /* IndexedValue */:
|
|
1059
1383
|
return ctx.valueMap.get(node.i);
|
|
1060
1384
|
case 15 /* Array */:
|
|
1061
1385
|
return deserializeArray(ctx, node);
|
|
@@ -1064,16 +1388,20 @@ function deserializeTree(ctx, node) {
|
|
|
1064
1388
|
case 17 /* NullConstructor */:
|
|
1065
1389
|
return deserializeNullConstructor(ctx, node);
|
|
1066
1390
|
case 11 /* Date */:
|
|
1067
|
-
return
|
|
1391
|
+
return deserializeDate(ctx, node);
|
|
1068
1392
|
case 12 /* RegExp */:
|
|
1069
|
-
return
|
|
1393
|
+
return deserializeRegExp(ctx, node);
|
|
1070
1394
|
case 13 /* Set */:
|
|
1071
1395
|
return deserializeSet(ctx, node);
|
|
1072
1396
|
case 14 /* Map */:
|
|
1073
1397
|
return deserializeMap(ctx, node);
|
|
1398
|
+
case 28 /* ArrayBuffer */:
|
|
1399
|
+
return deserializeArrayBuffer(ctx, node);
|
|
1074
1400
|
case 23 /* BigIntTypedArray */:
|
|
1075
1401
|
case 22 /* TypedArray */:
|
|
1076
1402
|
return deserializeTypedArray(ctx, node);
|
|
1403
|
+
case 29 /* DataView */:
|
|
1404
|
+
return deserializeDataView(ctx, node);
|
|
1077
1405
|
case 20 /* AggregateError */:
|
|
1078
1406
|
return deserializeAggregateError(ctx, node);
|
|
1079
1407
|
case 19 /* Error */:
|
|
@@ -1084,6 +1412,20 @@ function deserializeTree(ctx, node) {
|
|
|
1084
1412
|
return deserializePromise(ctx, node);
|
|
1085
1413
|
case 24 /* WKSymbol */:
|
|
1086
1414
|
return SYMBOL_REF[node.s];
|
|
1415
|
+
case 25 /* URL */:
|
|
1416
|
+
return deserializeURL(ctx, node);
|
|
1417
|
+
case 26 /* URLSearchParams */:
|
|
1418
|
+
return deserializeURLSearchParams(ctx, node);
|
|
1419
|
+
case 27 /* Reference */:
|
|
1420
|
+
return deserializeReference(ctx, node);
|
|
1421
|
+
case 30 /* Blob */:
|
|
1422
|
+
return deserializeBlob(ctx, node);
|
|
1423
|
+
case 31 /* File */:
|
|
1424
|
+
return deserializeFile(ctx, node);
|
|
1425
|
+
case 32 /* Headers */:
|
|
1426
|
+
return deserializeHeaders(ctx, node);
|
|
1427
|
+
case 33 /* FormData */:
|
|
1428
|
+
return deserializeFormData(ctx, node);
|
|
1087
1429
|
default:
|
|
1088
1430
|
throw new Error("Unsupported type");
|
|
1089
1431
|
}
|
|
@@ -1094,10 +1436,12 @@ function getAssignmentExpression(assignment) {
|
|
|
1094
1436
|
switch (assignment.t) {
|
|
1095
1437
|
case "index":
|
|
1096
1438
|
return assignment.s + "=" + assignment.v;
|
|
1097
|
-
case "map":
|
|
1098
|
-
return assignment.s + ".set(" + assignment.k + "," + assignment.v + ")";
|
|
1099
1439
|
case "set":
|
|
1440
|
+
return assignment.s + ".set(" + assignment.k + "," + assignment.v + ")";
|
|
1441
|
+
case "add":
|
|
1100
1442
|
return assignment.s + ".add(" + assignment.v + ")";
|
|
1443
|
+
case "append":
|
|
1444
|
+
return assignment.s + ".append(" + assignment.k + "," + assignment.v + ")";
|
|
1101
1445
|
default:
|
|
1102
1446
|
return "";
|
|
1103
1447
|
}
|
|
@@ -1124,10 +1468,10 @@ function mergeAssignments(assignments) {
|
|
|
1124
1468
|
current = item;
|
|
1125
1469
|
}
|
|
1126
1470
|
break;
|
|
1127
|
-
case "
|
|
1471
|
+
case "set":
|
|
1128
1472
|
if (item.s === prev.s) {
|
|
1129
1473
|
current = {
|
|
1130
|
-
t: "
|
|
1474
|
+
t: "set",
|
|
1131
1475
|
s: getAssignmentExpression(current),
|
|
1132
1476
|
k: item.k,
|
|
1133
1477
|
v: item.v
|
|
@@ -1137,10 +1481,10 @@ function mergeAssignments(assignments) {
|
|
|
1137
1481
|
current = item;
|
|
1138
1482
|
}
|
|
1139
1483
|
break;
|
|
1140
|
-
case "
|
|
1484
|
+
case "add":
|
|
1141
1485
|
if (item.s === prev.s) {
|
|
1142
1486
|
current = {
|
|
1143
|
-
t: "
|
|
1487
|
+
t: "add",
|
|
1144
1488
|
s: getAssignmentExpression(current),
|
|
1145
1489
|
k: void 0,
|
|
1146
1490
|
v: item.v
|
|
@@ -1150,6 +1494,10 @@ function mergeAssignments(assignments) {
|
|
|
1150
1494
|
current = item;
|
|
1151
1495
|
}
|
|
1152
1496
|
break;
|
|
1497
|
+
case "append":
|
|
1498
|
+
newAssignments.push(current);
|
|
1499
|
+
current = item;
|
|
1500
|
+
break;
|
|
1153
1501
|
default:
|
|
1154
1502
|
break;
|
|
1155
1503
|
}
|
|
@@ -1184,40 +1532,45 @@ function createAssignment(ctx, source, value) {
|
|
|
1184
1532
|
v: value
|
|
1185
1533
|
});
|
|
1186
1534
|
}
|
|
1187
|
-
function
|
|
1188
|
-
markRef(ctx, ref);
|
|
1535
|
+
function createAddAssignment(ctx, ref, value) {
|
|
1189
1536
|
ctx.assignments.push({
|
|
1190
|
-
t: "
|
|
1537
|
+
t: "add",
|
|
1191
1538
|
s: getRefParam(ctx, ref),
|
|
1192
1539
|
k: void 0,
|
|
1193
1540
|
v: value
|
|
1194
1541
|
});
|
|
1195
1542
|
}
|
|
1196
|
-
function
|
|
1197
|
-
|
|
1543
|
+
function createSetAssignment(ctx, ref, key, value) {
|
|
1544
|
+
ctx.assignments.push({
|
|
1545
|
+
t: "set",
|
|
1546
|
+
s: getRefParam(ctx, ref),
|
|
1547
|
+
k: key,
|
|
1548
|
+
v: value
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
function createAppendAssignment(ctx, ref, key, value) {
|
|
1198
1552
|
ctx.assignments.push({
|
|
1199
|
-
t: "
|
|
1553
|
+
t: "append",
|
|
1200
1554
|
s: getRefParam(ctx, ref),
|
|
1201
1555
|
k: key,
|
|
1202
1556
|
v: value
|
|
1203
1557
|
});
|
|
1204
1558
|
}
|
|
1205
1559
|
function createArrayAssign(ctx, ref, index, value) {
|
|
1206
|
-
markRef(ctx, ref);
|
|
1207
1560
|
createAssignment(ctx, getRefParam(ctx, ref) + "[" + index + "]", value);
|
|
1208
1561
|
}
|
|
1209
1562
|
function createObjectAssign(ctx, ref, key, value) {
|
|
1210
1563
|
markRef(ctx, ref);
|
|
1211
1564
|
createAssignment(ctx, getRefParam(ctx, ref) + "." + key, value);
|
|
1212
1565
|
}
|
|
1213
|
-
function
|
|
1566
|
+
function assignIndexedValue2(ctx, index, value) {
|
|
1214
1567
|
if (ctx.markedRefs.has(index)) {
|
|
1215
1568
|
return getRefParam(ctx, index) + "=" + value;
|
|
1216
1569
|
}
|
|
1217
1570
|
return value;
|
|
1218
1571
|
}
|
|
1219
|
-
function
|
|
1220
|
-
return node.t === 10 /*
|
|
1572
|
+
function isIndexedValueInStack(ctx, node) {
|
|
1573
|
+
return node.t === 10 /* IndexedValue */ && ctx.stack.includes(node.i);
|
|
1221
1574
|
}
|
|
1222
1575
|
function serializeNodeList(ctx, node) {
|
|
1223
1576
|
const size = node.l;
|
|
@@ -1230,7 +1583,8 @@ function serializeNodeList(ctx, node) {
|
|
|
1230
1583
|
}
|
|
1231
1584
|
item = node.a[i];
|
|
1232
1585
|
if (item) {
|
|
1233
|
-
if (
|
|
1586
|
+
if (isIndexedValueInStack(ctx, item)) {
|
|
1587
|
+
markRef(ctx, node.i);
|
|
1234
1588
|
createArrayAssign(ctx, node.i, i, getRefParam(ctx, item.i));
|
|
1235
1589
|
isHoley = true;
|
|
1236
1590
|
} else {
|
|
@@ -1247,7 +1601,7 @@ function serializeArray(ctx, node) {
|
|
|
1247
1601
|
ctx.stack.push(node.i);
|
|
1248
1602
|
const result = serializeNodeList(ctx, node);
|
|
1249
1603
|
ctx.stack.pop();
|
|
1250
|
-
return
|
|
1604
|
+
return assignIndexedValue2(ctx, node.i, result);
|
|
1251
1605
|
}
|
|
1252
1606
|
function serializeProperties(ctx, sourceID, node) {
|
|
1253
1607
|
if (node.s === 0) {
|
|
@@ -1261,20 +1615,24 @@ function serializeProperties(ctx, sourceID, node) {
|
|
|
1261
1615
|
let isIdentifier;
|
|
1262
1616
|
let refParam;
|
|
1263
1617
|
let hasPrev = false;
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1618
|
+
const keys = node.k;
|
|
1619
|
+
const values = node.v;
|
|
1620
|
+
for (let i = 0, len = node.s; i < len; i++) {
|
|
1621
|
+
key = keys[i];
|
|
1622
|
+
val = values[i];
|
|
1267
1623
|
check = Number(key);
|
|
1268
1624
|
isIdentifier = check >= 0 || isValidIdentifier(key);
|
|
1269
|
-
if (
|
|
1625
|
+
if (isIndexedValueInStack(ctx, val)) {
|
|
1270
1626
|
refParam = getRefParam(ctx, val.i);
|
|
1271
1627
|
if (isIdentifier && Number.isNaN(check)) {
|
|
1628
|
+
markRef(ctx, sourceID);
|
|
1272
1629
|
createObjectAssign(ctx, sourceID, key, refParam);
|
|
1273
1630
|
} else {
|
|
1274
|
-
|
|
1631
|
+
markRef(ctx, sourceID);
|
|
1632
|
+
createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + key + '"', refParam);
|
|
1275
1633
|
}
|
|
1276
1634
|
} else {
|
|
1277
|
-
result += (hasPrev ? "," : "") + (isIdentifier ? key : '"' +
|
|
1635
|
+
result += (hasPrev ? "," : "") + (isIdentifier ? key : '"' + key + '"') + ":" + serializeTree(ctx, val);
|
|
1278
1636
|
hasPrev = true;
|
|
1279
1637
|
}
|
|
1280
1638
|
}
|
|
@@ -1297,12 +1655,14 @@ function serializeAssignments(ctx, sourceID, node) {
|
|
|
1297
1655
|
let check;
|
|
1298
1656
|
let parentAssignment;
|
|
1299
1657
|
let isIdentifier;
|
|
1300
|
-
|
|
1658
|
+
const keys = node.k;
|
|
1659
|
+
const values = node.v;
|
|
1660
|
+
for (let i = 0, len = node.s; i < len; i++) {
|
|
1301
1661
|
parentStack = ctx.stack;
|
|
1302
1662
|
ctx.stack = [];
|
|
1303
|
-
refParam = serializeTree(ctx,
|
|
1663
|
+
refParam = serializeTree(ctx, values[i]);
|
|
1304
1664
|
ctx.stack = parentStack;
|
|
1305
|
-
key =
|
|
1665
|
+
key = keys[i];
|
|
1306
1666
|
check = Number(key);
|
|
1307
1667
|
parentAssignment = ctx.assignments;
|
|
1308
1668
|
ctx.assignments = mainAssignments;
|
|
@@ -1310,7 +1670,7 @@ function serializeAssignments(ctx, sourceID, node) {
|
|
|
1310
1670
|
if (isIdentifier && Number.isNaN(check)) {
|
|
1311
1671
|
createObjectAssign(ctx, sourceID, key, refParam);
|
|
1312
1672
|
} else {
|
|
1313
|
-
createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' +
|
|
1673
|
+
createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + key + '"', refParam);
|
|
1314
1674
|
}
|
|
1315
1675
|
ctx.assignments = parentAssignment;
|
|
1316
1676
|
}
|
|
@@ -1325,17 +1685,17 @@ function serializeDictionary(ctx, i, d, init) {
|
|
|
1325
1685
|
markRef(ctx, i);
|
|
1326
1686
|
const assignments = serializeAssignments(ctx, i, d);
|
|
1327
1687
|
if (assignments) {
|
|
1328
|
-
return "(" +
|
|
1688
|
+
return "(" + assignIndexedValue2(ctx, i, init) + "," + assignments + getRefParam(ctx, i) + ")";
|
|
1329
1689
|
}
|
|
1330
1690
|
}
|
|
1331
1691
|
}
|
|
1332
|
-
return
|
|
1692
|
+
return assignIndexedValue2(ctx, i, init);
|
|
1333
1693
|
}
|
|
1334
1694
|
function serializeNullConstructor(ctx, node) {
|
|
1335
1695
|
return serializeDictionary(ctx, node.i, node.d, "Object.create(null)");
|
|
1336
1696
|
}
|
|
1337
1697
|
function serializeObject(ctx, node) {
|
|
1338
|
-
return
|
|
1698
|
+
return assignIndexedValue2(ctx, node.i, serializeProperties(ctx, node.i, node.d));
|
|
1339
1699
|
}
|
|
1340
1700
|
function serializeSet(ctx, node) {
|
|
1341
1701
|
let serialized = "new Set";
|
|
@@ -1347,8 +1707,9 @@ function serializeSet(ctx, node) {
|
|
|
1347
1707
|
let hasPrev = false;
|
|
1348
1708
|
for (let i = 0; i < size; i++) {
|
|
1349
1709
|
item = node.a[i];
|
|
1350
|
-
if (
|
|
1351
|
-
|
|
1710
|
+
if (isIndexedValueInStack(ctx, item)) {
|
|
1711
|
+
markRef(ctx, node.i);
|
|
1712
|
+
createAddAssignment(ctx, node.i, getRefParam(ctx, item.i));
|
|
1352
1713
|
} else {
|
|
1353
1714
|
result += (hasPrev ? "," : "") + serializeTree(ctx, item);
|
|
1354
1715
|
hasPrev = true;
|
|
@@ -1359,7 +1720,7 @@ function serializeSet(ctx, node) {
|
|
|
1359
1720
|
serialized += "([" + result + "])";
|
|
1360
1721
|
}
|
|
1361
1722
|
}
|
|
1362
|
-
return
|
|
1723
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1363
1724
|
}
|
|
1364
1725
|
function serializeMap(ctx, node) {
|
|
1365
1726
|
let serialized = "new Map";
|
|
@@ -1375,22 +1736,24 @@ function serializeMap(ctx, node) {
|
|
|
1375
1736
|
for (let i = 0; i < node.d.s; i++) {
|
|
1376
1737
|
key = node.d.k[i];
|
|
1377
1738
|
val = node.d.v[i];
|
|
1378
|
-
if (
|
|
1739
|
+
if (isIndexedValueInStack(ctx, key)) {
|
|
1379
1740
|
keyRef = getRefParam(ctx, key.i);
|
|
1380
|
-
|
|
1741
|
+
markRef(ctx, node.i);
|
|
1742
|
+
if (isIndexedValueInStack(ctx, val)) {
|
|
1381
1743
|
valueRef = getRefParam(ctx, val.i);
|
|
1382
|
-
|
|
1744
|
+
createSetAssignment(ctx, node.i, keyRef, valueRef);
|
|
1383
1745
|
} else {
|
|
1384
1746
|
parent = ctx.stack;
|
|
1385
1747
|
ctx.stack = [];
|
|
1386
|
-
|
|
1748
|
+
createSetAssignment(ctx, node.i, keyRef, serializeTree(ctx, val));
|
|
1387
1749
|
ctx.stack = parent;
|
|
1388
1750
|
}
|
|
1389
|
-
} else if (
|
|
1751
|
+
} else if (isIndexedValueInStack(ctx, val)) {
|
|
1390
1752
|
valueRef = getRefParam(ctx, val.i);
|
|
1753
|
+
markRef(ctx, node.i);
|
|
1391
1754
|
parent = ctx.stack;
|
|
1392
1755
|
ctx.stack = [];
|
|
1393
|
-
|
|
1756
|
+
createSetAssignment(ctx, node.i, serializeTree(ctx, key), valueRef);
|
|
1394
1757
|
ctx.stack = parent;
|
|
1395
1758
|
} else {
|
|
1396
1759
|
result += (hasPrev ? ",[" : "[") + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
|
|
@@ -1402,21 +1765,21 @@ function serializeMap(ctx, node) {
|
|
|
1402
1765
|
serialized += "([" + result + "])";
|
|
1403
1766
|
}
|
|
1404
1767
|
}
|
|
1405
|
-
return
|
|
1768
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1406
1769
|
}
|
|
1407
1770
|
function serializeAggregateError(ctx, node) {
|
|
1408
1771
|
ctx.stack.push(node.i);
|
|
1409
|
-
const serialized =
|
|
1772
|
+
const serialized = 'new AggregateError([],"' + node.m + '")';
|
|
1410
1773
|
ctx.stack.pop();
|
|
1411
1774
|
return serializeDictionary(ctx, node.i, node.d, serialized);
|
|
1412
1775
|
}
|
|
1413
1776
|
function serializeError(ctx, node) {
|
|
1414
|
-
const serialized = "new " + node.c + '("' +
|
|
1777
|
+
const serialized = "new " + node.c + '("' + node.m + '")';
|
|
1415
1778
|
return serializeDictionary(ctx, node.i, node.d, serialized);
|
|
1416
1779
|
}
|
|
1417
1780
|
function serializePromise(ctx, node) {
|
|
1418
1781
|
let serialized;
|
|
1419
|
-
if (
|
|
1782
|
+
if (isIndexedValueInStack(ctx, node.f)) {
|
|
1420
1783
|
const ref = getRefParam(ctx, node.f.i);
|
|
1421
1784
|
if (ctx.features & 4 /* ArrowFunction */) {
|
|
1422
1785
|
serialized = "Promise.resolve().then(()=>" + ref + ")";
|
|
@@ -1429,16 +1792,22 @@ function serializePromise(ctx, node) {
|
|
|
1429
1792
|
ctx.stack.pop();
|
|
1430
1793
|
serialized = "Promise.resolve(" + result + ")";
|
|
1431
1794
|
}
|
|
1432
|
-
return
|
|
1795
|
+
return assignIndexedValue2(ctx, node.i, serialized);
|
|
1433
1796
|
}
|
|
1434
|
-
function
|
|
1435
|
-
let result = "";
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1797
|
+
function serializeArrayBuffer2(ctx, node) {
|
|
1798
|
+
let result = "new Uint8Array(";
|
|
1799
|
+
if (node.s.length) {
|
|
1800
|
+
result += "[";
|
|
1801
|
+
for (let i = 0, len = node.s.length; i < len; i++) {
|
|
1802
|
+
result += (i > 0 ? "," : "") + node.s[i];
|
|
1803
|
+
}
|
|
1804
|
+
result += "]";
|
|
1439
1805
|
}
|
|
1440
|
-
|
|
1441
|
-
|
|
1806
|
+
return assignIndexedValue2(ctx, node.i, result + ").buffer");
|
|
1807
|
+
}
|
|
1808
|
+
function serializeTypedArray(ctx, node) {
|
|
1809
|
+
const args = serializeTree(ctx, node.f) + "," + node.b + "," + node.l;
|
|
1810
|
+
return assignIndexedValue2(ctx, node.i, "new " + node.c + "(" + args + ")");
|
|
1442
1811
|
}
|
|
1443
1812
|
function serializeIterable(ctx, node) {
|
|
1444
1813
|
const parent = ctx.stack;
|
|
@@ -1460,6 +1829,68 @@ function serializeIterable(ctx, node) {
|
|
|
1460
1829
|
}
|
|
1461
1830
|
return serializeDictionary(ctx, node.i, node.d, serialized);
|
|
1462
1831
|
}
|
|
1832
|
+
function serializeDate(ctx, node) {
|
|
1833
|
+
return assignIndexedValue2(ctx, node.i, 'new Date("' + node.s + '")');
|
|
1834
|
+
}
|
|
1835
|
+
function serializeRegExp(ctx, node) {
|
|
1836
|
+
return assignIndexedValue2(ctx, node.i, "/" + node.c + "/" + node.m);
|
|
1837
|
+
}
|
|
1838
|
+
function serializeURL(ctx, node) {
|
|
1839
|
+
return assignIndexedValue2(ctx, node.i, 'new URL("' + node.s + '")');
|
|
1840
|
+
}
|
|
1841
|
+
function serializeURLSearchParams(ctx, node) {
|
|
1842
|
+
return assignIndexedValue2(ctx, node.i, node.s ? 'new URLSearchParams("' + node.s + '")' : "new URLSearchParams");
|
|
1843
|
+
}
|
|
1844
|
+
function serializeReference(ctx, node) {
|
|
1845
|
+
return assignIndexedValue2(ctx, node.i, GLOBAL_KEY + '.get("' + node.s + '")');
|
|
1846
|
+
}
|
|
1847
|
+
function serializeDataView(ctx, node) {
|
|
1848
|
+
const args = serializeTree(ctx, node.f) + "," + node.b + "," + node.l;
|
|
1849
|
+
return assignIndexedValue2(ctx, node.i, "new DataView(" + args + ")");
|
|
1850
|
+
}
|
|
1851
|
+
function serializeBlob(ctx, node) {
|
|
1852
|
+
const args = "[" + serializeTree(ctx, node.f) + '],{type:"' + node.c + '"}';
|
|
1853
|
+
return assignIndexedValue2(ctx, node.i, "new Blob(" + args + ")");
|
|
1854
|
+
}
|
|
1855
|
+
function serializeFile(ctx, node) {
|
|
1856
|
+
const options = '{type:"' + node.c + '",lastModified:' + node.b + "}";
|
|
1857
|
+
const args = "[" + serializeTree(ctx, node.f) + '],"' + node.m + '",' + options;
|
|
1858
|
+
return assignIndexedValue2(ctx, node.i, "new File(" + args + ")");
|
|
1859
|
+
}
|
|
1860
|
+
function serializeHeaders(ctx, node) {
|
|
1861
|
+
return assignIndexedValue2(ctx, node.i, "new Headers(" + serializeProperties(ctx, node.i, node.d) + ")");
|
|
1862
|
+
}
|
|
1863
|
+
function serializeFormDataEntries(ctx, node) {
|
|
1864
|
+
ctx.stack.push(node.i);
|
|
1865
|
+
const mainAssignments = [];
|
|
1866
|
+
let parentStack;
|
|
1867
|
+
let value;
|
|
1868
|
+
let key;
|
|
1869
|
+
let parentAssignment;
|
|
1870
|
+
for (let i = 0; i < node.d.s; i++) {
|
|
1871
|
+
parentStack = ctx.stack;
|
|
1872
|
+
ctx.stack = [];
|
|
1873
|
+
value = serializeTree(ctx, node.d.v[i]);
|
|
1874
|
+
key = node.d.k[i];
|
|
1875
|
+
ctx.stack = parentStack;
|
|
1876
|
+
parentAssignment = ctx.assignments;
|
|
1877
|
+
ctx.assignments = mainAssignments;
|
|
1878
|
+
createAppendAssignment(ctx, node.i, '"' + key + '"', value);
|
|
1879
|
+
ctx.assignments = parentAssignment;
|
|
1880
|
+
}
|
|
1881
|
+
ctx.stack.pop();
|
|
1882
|
+
return resolveAssignments(mainAssignments);
|
|
1883
|
+
}
|
|
1884
|
+
function serializeFormData(ctx, node) {
|
|
1885
|
+
if (node.d.s) {
|
|
1886
|
+
markRef(ctx, node.i);
|
|
1887
|
+
}
|
|
1888
|
+
const result = assignIndexedValue2(ctx, node.i, "new FormData()");
|
|
1889
|
+
if (node.d.s) {
|
|
1890
|
+
return "(" + result + "," + serializeFormDataEntries(ctx, node) + getRefParam(ctx, node.i) + ")";
|
|
1891
|
+
}
|
|
1892
|
+
return result;
|
|
1893
|
+
}
|
|
1463
1894
|
function serializeTree(ctx, node) {
|
|
1464
1895
|
switch (node.t) {
|
|
1465
1896
|
case 0 /* Number */:
|
|
@@ -1482,7 +1913,7 @@ function serializeTree(ctx, node) {
|
|
|
1482
1913
|
return "NaN";
|
|
1483
1914
|
case 9 /* BigInt */:
|
|
1484
1915
|
return node.s + "n";
|
|
1485
|
-
case 10 /*
|
|
1916
|
+
case 10 /* IndexedValue */:
|
|
1486
1917
|
return getRefParam(ctx, node.i);
|
|
1487
1918
|
case 15 /* Array */:
|
|
1488
1919
|
return serializeArray(ctx, node);
|
|
@@ -1491,16 +1922,20 @@ function serializeTree(ctx, node) {
|
|
|
1491
1922
|
case 17 /* NullConstructor */:
|
|
1492
1923
|
return serializeNullConstructor(ctx, node);
|
|
1493
1924
|
case 11 /* Date */:
|
|
1494
|
-
return
|
|
1925
|
+
return serializeDate(ctx, node);
|
|
1495
1926
|
case 12 /* RegExp */:
|
|
1496
|
-
return
|
|
1927
|
+
return serializeRegExp(ctx, node);
|
|
1497
1928
|
case 13 /* Set */:
|
|
1498
1929
|
return serializeSet(ctx, node);
|
|
1499
1930
|
case 14 /* Map */:
|
|
1500
1931
|
return serializeMap(ctx, node);
|
|
1932
|
+
case 28 /* ArrayBuffer */:
|
|
1933
|
+
return serializeArrayBuffer2(ctx, node);
|
|
1501
1934
|
case 23 /* BigIntTypedArray */:
|
|
1502
1935
|
case 22 /* TypedArray */:
|
|
1503
1936
|
return serializeTypedArray(ctx, node);
|
|
1937
|
+
case 29 /* DataView */:
|
|
1938
|
+
return serializeDataView(ctx, node);
|
|
1504
1939
|
case 20 /* AggregateError */:
|
|
1505
1940
|
return serializeAggregateError(ctx, node);
|
|
1506
1941
|
case 19 /* Error */:
|
|
@@ -1511,6 +1946,20 @@ function serializeTree(ctx, node) {
|
|
|
1511
1946
|
return serializePromise(ctx, node);
|
|
1512
1947
|
case 24 /* WKSymbol */:
|
|
1513
1948
|
return SYMBOL_STRING[node.s];
|
|
1949
|
+
case 25 /* URL */:
|
|
1950
|
+
return serializeURL(ctx, node);
|
|
1951
|
+
case 26 /* URLSearchParams */:
|
|
1952
|
+
return serializeURLSearchParams(ctx, node);
|
|
1953
|
+
case 27 /* Reference */:
|
|
1954
|
+
return serializeReference(ctx, node);
|
|
1955
|
+
case 30 /* Blob */:
|
|
1956
|
+
return serializeBlob(ctx, node);
|
|
1957
|
+
case 31 /* File */:
|
|
1958
|
+
return serializeFile(ctx, node);
|
|
1959
|
+
case 32 /* Headers */:
|
|
1960
|
+
return serializeHeaders(ctx, node);
|
|
1961
|
+
case 33 /* FormData */:
|
|
1962
|
+
return serializeFormData(ctx, node);
|
|
1514
1963
|
default:
|
|
1515
1964
|
throw new Error("Unsupported type");
|
|
1516
1965
|
}
|
|
@@ -1549,7 +1998,8 @@ function generateArrayNode2(ctx, id, current) {
|
|
|
1549
1998
|
m: void 0,
|
|
1550
1999
|
d: void 0,
|
|
1551
2000
|
a: generateNodeList2(ctx, current),
|
|
1552
|
-
f: void 0
|
|
2001
|
+
f: void 0,
|
|
2002
|
+
b: void 0
|
|
1553
2003
|
};
|
|
1554
2004
|
}
|
|
1555
2005
|
function generateMapNode2(ctx, id, current) {
|
|
@@ -1585,7 +2035,8 @@ function generateMapNode2(ctx, id, current) {
|
|
|
1585
2035
|
m: void 0,
|
|
1586
2036
|
d: { k: keyNodes, v: valueNodes, s: len },
|
|
1587
2037
|
a: void 0,
|
|
1588
|
-
f: void 0
|
|
2038
|
+
f: void 0,
|
|
2039
|
+
b: void 0
|
|
1589
2040
|
};
|
|
1590
2041
|
}
|
|
1591
2042
|
function generateSetNode2(ctx, id, current) {
|
|
@@ -1614,7 +2065,8 @@ function generateSetNode2(ctx, id, current) {
|
|
|
1614
2065
|
m: void 0,
|
|
1615
2066
|
d: void 0,
|
|
1616
2067
|
a: nodes,
|
|
1617
|
-
f: void 0
|
|
2068
|
+
f: void 0,
|
|
2069
|
+
b: void 0
|
|
1618
2070
|
};
|
|
1619
2071
|
}
|
|
1620
2072
|
function generateProperties2(ctx, properties) {
|
|
@@ -1627,14 +2079,16 @@ function generateProperties2(ctx, properties) {
|
|
|
1627
2079
|
let deferredSize = 0;
|
|
1628
2080
|
let nodesSize = 0;
|
|
1629
2081
|
let item;
|
|
2082
|
+
let escaped;
|
|
1630
2083
|
for (const key of keys) {
|
|
1631
2084
|
item = properties[key];
|
|
2085
|
+
escaped = serializeString(key);
|
|
1632
2086
|
if (isIterable(item)) {
|
|
1633
|
-
deferredKeys[deferredSize] =
|
|
2087
|
+
deferredKeys[deferredSize] = escaped;
|
|
1634
2088
|
deferredValues[deferredSize] = item;
|
|
1635
2089
|
deferredSize++;
|
|
1636
2090
|
} else {
|
|
1637
|
-
keyNodes[nodesSize] =
|
|
2091
|
+
keyNodes[nodesSize] = escaped;
|
|
1638
2092
|
valueNodes[nodesSize] = parse2(ctx, item);
|
|
1639
2093
|
nodesSize++;
|
|
1640
2094
|
}
|
|
@@ -1663,7 +2117,8 @@ function generateIterableNode2(ctx, id, current) {
|
|
|
1663
2117
|
// Parse options first before the items
|
|
1664
2118
|
d: options ? generateProperties2(ctx, options) : void 0,
|
|
1665
2119
|
a: generateNodeList2(ctx, array),
|
|
1666
|
-
f: void 0
|
|
2120
|
+
f: void 0,
|
|
2121
|
+
b: void 0
|
|
1667
2122
|
};
|
|
1668
2123
|
}
|
|
1669
2124
|
function generateObjectNode2(ctx, id, current, empty) {
|
|
@@ -1679,7 +2134,8 @@ function generateObjectNode2(ctx, id, current, empty) {
|
|
|
1679
2134
|
m: void 0,
|
|
1680
2135
|
d: generateProperties2(ctx, current),
|
|
1681
2136
|
a: void 0,
|
|
1682
|
-
f: void 0
|
|
2137
|
+
f: void 0,
|
|
2138
|
+
b: void 0
|
|
1683
2139
|
};
|
|
1684
2140
|
}
|
|
1685
2141
|
function generateAggregateErrorNode2(ctx, id, current) {
|
|
@@ -1689,12 +2145,13 @@ function generateAggregateErrorNode2(ctx, id, current) {
|
|
|
1689
2145
|
t: 20 /* AggregateError */,
|
|
1690
2146
|
i: id,
|
|
1691
2147
|
s: void 0,
|
|
1692
|
-
l:
|
|
2148
|
+
l: void 0,
|
|
1693
2149
|
c: void 0,
|
|
1694
|
-
m: current.message,
|
|
2150
|
+
m: serializeString(current.message),
|
|
1695
2151
|
d: optionsNode,
|
|
1696
|
-
a:
|
|
1697
|
-
f: void 0
|
|
2152
|
+
a: void 0,
|
|
2153
|
+
f: void 0,
|
|
2154
|
+
b: void 0
|
|
1698
2155
|
};
|
|
1699
2156
|
}
|
|
1700
2157
|
function generateErrorNode2(ctx, id, current) {
|
|
@@ -1706,10 +2163,49 @@ function generateErrorNode2(ctx, id, current) {
|
|
|
1706
2163
|
s: void 0,
|
|
1707
2164
|
l: void 0,
|
|
1708
2165
|
c: getErrorConstructorName(current),
|
|
1709
|
-
m: current.message,
|
|
2166
|
+
m: serializeString(current.message),
|
|
1710
2167
|
d: optionsNode,
|
|
1711
2168
|
a: void 0,
|
|
1712
|
-
f: void 0
|
|
2169
|
+
f: void 0,
|
|
2170
|
+
b: void 0
|
|
2171
|
+
};
|
|
2172
|
+
}
|
|
2173
|
+
function generateHeadersNode2(ctx, id, current) {
|
|
2174
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "Headers"');
|
|
2175
|
+
const items = {};
|
|
2176
|
+
current.forEach((value, key) => {
|
|
2177
|
+
items[key] = value;
|
|
2178
|
+
});
|
|
2179
|
+
return {
|
|
2180
|
+
t: 32 /* Headers */,
|
|
2181
|
+
i: id,
|
|
2182
|
+
s: void 0,
|
|
2183
|
+
l: void 0,
|
|
2184
|
+
c: void 0,
|
|
2185
|
+
m: void 0,
|
|
2186
|
+
d: generateProperties2(ctx, items),
|
|
2187
|
+
a: void 0,
|
|
2188
|
+
f: void 0,
|
|
2189
|
+
b: void 0
|
|
2190
|
+
};
|
|
2191
|
+
}
|
|
2192
|
+
function generateFormDataNode2(ctx, id, current) {
|
|
2193
|
+
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "FormData"');
|
|
2194
|
+
const items = {};
|
|
2195
|
+
current.forEach((value, key) => {
|
|
2196
|
+
items[key] = value;
|
|
2197
|
+
});
|
|
2198
|
+
return {
|
|
2199
|
+
t: 33 /* FormData */,
|
|
2200
|
+
i: id,
|
|
2201
|
+
s: void 0,
|
|
2202
|
+
l: void 0,
|
|
2203
|
+
c: void 0,
|
|
2204
|
+
m: void 0,
|
|
2205
|
+
d: generateProperties2(ctx, items),
|
|
2206
|
+
a: void 0,
|
|
2207
|
+
f: void 0,
|
|
2208
|
+
b: void 0
|
|
1713
2209
|
};
|
|
1714
2210
|
}
|
|
1715
2211
|
function parse2(ctx, current) {
|
|
@@ -1727,24 +2223,26 @@ function parse2(ctx, current) {
|
|
|
1727
2223
|
case -Infinity:
|
|
1728
2224
|
return NEG_INFINITY_NODE;
|
|
1729
2225
|
default:
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
2226
|
+
if (current !== current) {
|
|
2227
|
+
return NAN_NODE;
|
|
2228
|
+
}
|
|
2229
|
+
if (Object.is(current, -0)) {
|
|
2230
|
+
return NEG_ZERO_NODE;
|
|
2231
|
+
}
|
|
2232
|
+
return createNumberNode(current);
|
|
1737
2233
|
}
|
|
1738
|
-
return createNumberNode(current);
|
|
1739
2234
|
case "bigint":
|
|
1740
2235
|
return createBigIntNode(ctx, current);
|
|
1741
2236
|
case "object": {
|
|
1742
2237
|
if (!current) {
|
|
1743
2238
|
return NULL_NODE;
|
|
1744
2239
|
}
|
|
1745
|
-
const id =
|
|
2240
|
+
const id = createIndexedValue(ctx, current);
|
|
1746
2241
|
if (ctx.markedRefs.has(id)) {
|
|
1747
|
-
return
|
|
2242
|
+
return createIndexedValueNode(id);
|
|
2243
|
+
}
|
|
2244
|
+
if (hasReferenceID(current)) {
|
|
2245
|
+
return createReferenceNode(id, current);
|
|
1748
2246
|
}
|
|
1749
2247
|
if (Array.isArray(current)) {
|
|
1750
2248
|
return generateArrayNode2(ctx, id, current);
|
|
@@ -1754,6 +2252,8 @@ function parse2(ctx, current) {
|
|
|
1754
2252
|
return createDateNode(id, current);
|
|
1755
2253
|
case RegExp:
|
|
1756
2254
|
return createRegExpNode(id, current);
|
|
2255
|
+
case ArrayBuffer:
|
|
2256
|
+
return createArrayBufferNode(id, current);
|
|
1757
2257
|
case Int8Array:
|
|
1758
2258
|
case Int16Array:
|
|
1759
2259
|
case Int32Array:
|
|
@@ -1767,14 +2267,26 @@ function parse2(ctx, current) {
|
|
|
1767
2267
|
case BigInt64Array:
|
|
1768
2268
|
case BigUint64Array:
|
|
1769
2269
|
return createBigIntTypedArrayNode(ctx, id, current);
|
|
2270
|
+
case DataView:
|
|
2271
|
+
return createDataViewNode(ctx, id, current);
|
|
1770
2272
|
case Map:
|
|
1771
2273
|
return generateMapNode2(ctx, id, current);
|
|
1772
2274
|
case Set:
|
|
1773
2275
|
return generateSetNode2(ctx, id, current);
|
|
1774
2276
|
case Object:
|
|
1775
|
-
return generateObjectNode2(
|
|
2277
|
+
return generateObjectNode2(
|
|
2278
|
+
ctx,
|
|
2279
|
+
id,
|
|
2280
|
+
current,
|
|
2281
|
+
false
|
|
2282
|
+
);
|
|
1776
2283
|
case void 0:
|
|
1777
|
-
return generateObjectNode2(
|
|
2284
|
+
return generateObjectNode2(
|
|
2285
|
+
ctx,
|
|
2286
|
+
id,
|
|
2287
|
+
current,
|
|
2288
|
+
true
|
|
2289
|
+
);
|
|
1778
2290
|
case AggregateError:
|
|
1779
2291
|
if (ctx.features & 1 /* AggregateError */) {
|
|
1780
2292
|
return generateAggregateErrorNode2(ctx, id, current);
|
|
@@ -1788,6 +2300,14 @@ function parse2(ctx, current) {
|
|
|
1788
2300
|
case TypeError:
|
|
1789
2301
|
case URIError:
|
|
1790
2302
|
return generateErrorNode2(ctx, id, current);
|
|
2303
|
+
case URL:
|
|
2304
|
+
return createURLNode(ctx, id, current);
|
|
2305
|
+
case URLSearchParams:
|
|
2306
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
2307
|
+
case Headers:
|
|
2308
|
+
return generateHeadersNode2(ctx, id, current);
|
|
2309
|
+
case FormData:
|
|
2310
|
+
return generateFormDataNode2(ctx, id, current);
|
|
1791
2311
|
default:
|
|
1792
2312
|
break;
|
|
1793
2313
|
}
|
|
@@ -1806,9 +2326,22 @@ function parse2(ctx, current) {
|
|
|
1806
2326
|
throw new Error("Unsupported type");
|
|
1807
2327
|
}
|
|
1808
2328
|
case "symbol":
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
2329
|
+
if (hasReferenceID(current)) {
|
|
2330
|
+
const id = createIndexedValue(ctx, current);
|
|
2331
|
+
if (ctx.markedRefs.has(id)) {
|
|
2332
|
+
return createIndexedValueNode(id);
|
|
2333
|
+
}
|
|
2334
|
+
return createReferenceNode(id, current);
|
|
2335
|
+
}
|
|
2336
|
+
return createWKSymbolNode(ctx, current);
|
|
2337
|
+
case "function": {
|
|
2338
|
+
assert(hasReferenceID(current), "Cannot serialize function without reference ID.");
|
|
2339
|
+
const id = createIndexedValue(ctx, current);
|
|
2340
|
+
if (ctx.markedRefs.has(id)) {
|
|
2341
|
+
return createIndexedValueNode(id);
|
|
2342
|
+
}
|
|
2343
|
+
return createReferenceNode(id, current);
|
|
2344
|
+
}
|
|
1812
2345
|
default:
|
|
1813
2346
|
throw new Error("Unsupported type");
|
|
1814
2347
|
}
|
|
@@ -1901,6 +2434,7 @@ var src_default = serialize;
|
|
|
1901
2434
|
export {
|
|
1902
2435
|
Feature,
|
|
1903
2436
|
compileJSON,
|
|
2437
|
+
createReference,
|
|
1904
2438
|
src_default as default,
|
|
1905
2439
|
deserialize,
|
|
1906
2440
|
fromJSON,
|