seroval 0.7.0 → 0.8.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/dist/cjs/development/index.cjs +1109 -1039
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +1109 -1039
- package/dist/esm/development/index.mjs.map +4 -4
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/assert.d.ts +1 -1
- package/dist/types/context.d.ts +2 -2
- package/dist/types/index.d.ts +3 -4
- package/dist/types/string.d.ts +1 -1
- package/dist/types/tree/UnsupportedTypeError.d.ts +3 -0
- package/dist/types/tree/async.d.ts +3 -3
- package/dist/types/tree/constants.d.ts +11 -0
- package/dist/types/tree/deserialize.d.ts +2 -2
- package/dist/types/tree/primitives.d.ts +9 -15
- package/dist/types/tree/serialize.d.ts +2 -2
- package/dist/types/tree/shared.d.ts +10 -8
- package/dist/types/tree/sync.d.ts +3 -3
- package/dist/types/tree/types.d.ts +64 -71
- package/dist/types/tree/web-api.d.ts +2 -2
- package/dist/types/types.d.ts +4 -4
- package/package.json +10 -8
- package/src/assert.ts +2 -2
- package/src/compat.ts +0 -1
- package/src/context.ts +10 -7
- package/src/get-identifier.ts +1 -1
- package/src/index.ts +35 -26
- package/src/string.ts +2 -2
- package/src/tree/UnsupportedTypeError.ts +8 -0
- package/src/tree/async.ts +245 -233
- package/src/tree/constants.ts +72 -0
- package/src/tree/deserialize.ts +96 -93
- package/src/tree/primitives.ts +81 -134
- package/src/tree/reference.ts +4 -3
- package/src/tree/serialize.ts +251 -197
- package/src/tree/shared.ts +31 -22
- package/src/tree/symbols.ts +13 -13
- package/src/tree/sync.ts +226 -198
- package/src/tree/types.ts +74 -93
- package/src/tree/web-api.ts +10 -7
- package/src/types.ts +7 -3
|
@@ -75,7 +75,7 @@ var DEFAULT_OPTIONS = {
|
|
|
75
75
|
disabledFeatures: 0
|
|
76
76
|
};
|
|
77
77
|
function createParserContext(options = {}) {
|
|
78
|
-
const result = Object.assign({}, DEFAULT_OPTIONS, options
|
|
78
|
+
const result = Object.assign({}, DEFAULT_OPTIONS, options);
|
|
79
79
|
return {
|
|
80
80
|
markedRefs: /* @__PURE__ */ new Set(),
|
|
81
81
|
refs: /* @__PURE__ */ new Map(),
|
|
@@ -131,7 +131,7 @@ function createIndexedValue(ctx, current) {
|
|
|
131
131
|
// src/assert.ts
|
|
132
132
|
function assert(cond, error) {
|
|
133
133
|
if (!cond) {
|
|
134
|
-
throw
|
|
134
|
+
throw error;
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
|
|
@@ -184,6 +184,82 @@ function deserializeString(str) {
|
|
|
184
184
|
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");
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
// src/tree/UnsupportedTypeError.ts
|
|
188
|
+
var { toString } = Object.prototype;
|
|
189
|
+
var UnsupportedTypeError = class extends Error {
|
|
190
|
+
constructor(value) {
|
|
191
|
+
super('Unsupported type "' + toString.call(value) + '"');
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// src/tree/constants.ts
|
|
196
|
+
function createConstantNode(value) {
|
|
197
|
+
return {
|
|
198
|
+
t: 2 /* Constant */,
|
|
199
|
+
i: void 0,
|
|
200
|
+
s: value,
|
|
201
|
+
l: void 0,
|
|
202
|
+
c: void 0,
|
|
203
|
+
m: void 0,
|
|
204
|
+
d: void 0,
|
|
205
|
+
a: void 0,
|
|
206
|
+
f: void 0,
|
|
207
|
+
b: void 0
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
var TRUE_NODE = createConstantNode(2 /* True */);
|
|
211
|
+
var FALSE_NODE = createConstantNode(3 /* False */);
|
|
212
|
+
var UNDEFINED_NODE = createConstantNode(1 /* Undefined */);
|
|
213
|
+
var NULL_NODE = createConstantNode(0 /* Null */);
|
|
214
|
+
var NEG_ZERO_NODE = createConstantNode(4 /* NegativeZero */);
|
|
215
|
+
var INFINITY_NODE = createConstantNode(5 /* Infinity */);
|
|
216
|
+
var NEG_INFINITY_NODE = createConstantNode(6 /* NegativeInfinity */);
|
|
217
|
+
var NAN_NODE = createConstantNode(7 /* NaN */);
|
|
218
|
+
function serializeConstant(node) {
|
|
219
|
+
switch (node.s) {
|
|
220
|
+
case 2 /* True */:
|
|
221
|
+
return "!0";
|
|
222
|
+
case 3 /* False */:
|
|
223
|
+
return "!1";
|
|
224
|
+
case 1 /* Undefined */:
|
|
225
|
+
return "void 0";
|
|
226
|
+
case 0 /* Null */:
|
|
227
|
+
return "null";
|
|
228
|
+
case 4 /* NegativeZero */:
|
|
229
|
+
return "-0";
|
|
230
|
+
case 5 /* Infinity */:
|
|
231
|
+
return "1/0";
|
|
232
|
+
case 6 /* NegativeInfinity */:
|
|
233
|
+
return "-1/0";
|
|
234
|
+
case 7 /* NaN */:
|
|
235
|
+
return "NaN";
|
|
236
|
+
default:
|
|
237
|
+
throw new Error("invariant");
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function deserializeConstant(node) {
|
|
241
|
+
switch (node.s) {
|
|
242
|
+
case 2 /* True */:
|
|
243
|
+
return true;
|
|
244
|
+
case 3 /* False */:
|
|
245
|
+
return false;
|
|
246
|
+
case 1 /* Undefined */:
|
|
247
|
+
return void 0;
|
|
248
|
+
case 0 /* Null */:
|
|
249
|
+
return null;
|
|
250
|
+
case 4 /* NegativeZero */:
|
|
251
|
+
return -0;
|
|
252
|
+
case 5 /* Infinity */:
|
|
253
|
+
return Infinity;
|
|
254
|
+
case 6 /* NegativeInfinity */:
|
|
255
|
+
return -Infinity;
|
|
256
|
+
case 7 /* NaN */:
|
|
257
|
+
return NaN;
|
|
258
|
+
default:
|
|
259
|
+
throw new Error("invariant");
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
187
263
|
// src/tree/reference.ts
|
|
188
264
|
var REFERENCE = /* @__PURE__ */ new Map();
|
|
189
265
|
var INV_REFERENCE = /* @__PURE__ */ new Map();
|
|
@@ -199,11 +275,11 @@ function hasReference(id) {
|
|
|
199
275
|
return INV_REFERENCE.has(id);
|
|
200
276
|
}
|
|
201
277
|
function getReferenceID(value) {
|
|
202
|
-
assert(hasReferenceID(value), "Missing reference id");
|
|
278
|
+
assert(hasReferenceID(value), new Error("Missing reference id"));
|
|
203
279
|
return REFERENCE.get(value);
|
|
204
280
|
}
|
|
205
281
|
function getReference(id) {
|
|
206
|
-
assert(hasReference(id), "Missing reference for id:" + id);
|
|
282
|
+
assert(hasReference(id), new Error("Missing reference for id:" + id));
|
|
207
283
|
return INV_REFERENCE.get(id);
|
|
208
284
|
}
|
|
209
285
|
var GLOBAL_KEY = "__SEROVAL__";
|
|
@@ -285,115 +361,32 @@ var SYMBOL_REF = {
|
|
|
285
361
|
};
|
|
286
362
|
|
|
287
363
|
// src/tree/primitives.ts
|
|
288
|
-
var TRUE_NODE = {
|
|
289
|
-
t: 2 /* Boolean */,
|
|
290
|
-
i: void 0,
|
|
291
|
-
s: true,
|
|
292
|
-
l: void 0,
|
|
293
|
-
c: void 0,
|
|
294
|
-
m: void 0,
|
|
295
|
-
d: void 0,
|
|
296
|
-
a: void 0,
|
|
297
|
-
f: void 0,
|
|
298
|
-
b: void 0
|
|
299
|
-
};
|
|
300
|
-
var FALSE_NODE = {
|
|
301
|
-
t: 2 /* Boolean */,
|
|
302
|
-
i: void 0,
|
|
303
|
-
s: false,
|
|
304
|
-
l: void 0,
|
|
305
|
-
c: void 0,
|
|
306
|
-
m: void 0,
|
|
307
|
-
d: void 0,
|
|
308
|
-
a: void 0,
|
|
309
|
-
f: void 0,
|
|
310
|
-
b: void 0
|
|
311
|
-
};
|
|
312
|
-
var UNDEFINED_NODE = {
|
|
313
|
-
t: 4 /* Undefined */,
|
|
314
|
-
i: void 0,
|
|
315
|
-
s: void 0,
|
|
316
|
-
l: void 0,
|
|
317
|
-
c: void 0,
|
|
318
|
-
m: void 0,
|
|
319
|
-
d: void 0,
|
|
320
|
-
a: void 0,
|
|
321
|
-
f: void 0,
|
|
322
|
-
b: void 0
|
|
323
|
-
};
|
|
324
|
-
var NULL_NODE = {
|
|
325
|
-
t: 3 /* Null */,
|
|
326
|
-
i: void 0,
|
|
327
|
-
s: void 0,
|
|
328
|
-
l: void 0,
|
|
329
|
-
c: void 0,
|
|
330
|
-
m: void 0,
|
|
331
|
-
d: void 0,
|
|
332
|
-
a: void 0,
|
|
333
|
-
f: void 0,
|
|
334
|
-
b: void 0
|
|
335
|
-
};
|
|
336
|
-
var NEG_ZERO_NODE = {
|
|
337
|
-
t: 5 /* NegativeZero */,
|
|
338
|
-
i: void 0,
|
|
339
|
-
s: void 0,
|
|
340
|
-
l: void 0,
|
|
341
|
-
c: void 0,
|
|
342
|
-
m: void 0,
|
|
343
|
-
d: void 0,
|
|
344
|
-
a: void 0,
|
|
345
|
-
f: void 0,
|
|
346
|
-
b: void 0
|
|
347
|
-
};
|
|
348
|
-
var INFINITY_NODE = {
|
|
349
|
-
t: 6 /* Infinity */,
|
|
350
|
-
i: void 0,
|
|
351
|
-
s: void 0,
|
|
352
|
-
l: void 0,
|
|
353
|
-
c: void 0,
|
|
354
|
-
m: void 0,
|
|
355
|
-
d: void 0,
|
|
356
|
-
a: void 0,
|
|
357
|
-
f: void 0,
|
|
358
|
-
b: void 0
|
|
359
|
-
};
|
|
360
|
-
var NEG_INFINITY_NODE = {
|
|
361
|
-
t: 7 /* NegativeInfinity */,
|
|
362
|
-
i: void 0,
|
|
363
|
-
s: void 0,
|
|
364
|
-
l: void 0,
|
|
365
|
-
c: void 0,
|
|
366
|
-
m: void 0,
|
|
367
|
-
d: void 0,
|
|
368
|
-
a: void 0,
|
|
369
|
-
f: void 0,
|
|
370
|
-
b: void 0
|
|
371
|
-
};
|
|
372
|
-
var NAN_NODE = {
|
|
373
|
-
t: 8 /* NaN */,
|
|
374
|
-
i: void 0,
|
|
375
|
-
s: void 0,
|
|
376
|
-
l: void 0,
|
|
377
|
-
c: void 0,
|
|
378
|
-
m: void 0,
|
|
379
|
-
d: void 0,
|
|
380
|
-
a: void 0,
|
|
381
|
-
f: void 0,
|
|
382
|
-
b: void 0
|
|
383
|
-
};
|
|
384
364
|
function createNumberNode(value) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
365
|
+
switch (value) {
|
|
366
|
+
case Infinity:
|
|
367
|
+
return INFINITY_NODE;
|
|
368
|
+
case -Infinity:
|
|
369
|
+
return NEG_INFINITY_NODE;
|
|
370
|
+
default:
|
|
371
|
+
if (value !== value) {
|
|
372
|
+
return NAN_NODE;
|
|
373
|
+
}
|
|
374
|
+
if (Object.is(value, -0)) {
|
|
375
|
+
return NEG_ZERO_NODE;
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
t: 0 /* Number */,
|
|
379
|
+
i: void 0,
|
|
380
|
+
s: value,
|
|
381
|
+
l: void 0,
|
|
382
|
+
c: void 0,
|
|
383
|
+
m: void 0,
|
|
384
|
+
d: void 0,
|
|
385
|
+
a: void 0,
|
|
386
|
+
f: void 0,
|
|
387
|
+
b: void 0
|
|
388
|
+
};
|
|
389
|
+
}
|
|
397
390
|
}
|
|
398
391
|
function createStringNode(value) {
|
|
399
392
|
return {
|
|
@@ -410,9 +403,9 @@ function createStringNode(value) {
|
|
|
410
403
|
};
|
|
411
404
|
}
|
|
412
405
|
function createBigIntNode(ctx, current) {
|
|
413
|
-
assert(ctx.features & 8 /* BigInt */,
|
|
406
|
+
assert(ctx.features & 8 /* BigInt */, new UnsupportedTypeError(current));
|
|
414
407
|
return {
|
|
415
|
-
t:
|
|
408
|
+
t: 3 /* BigInt */,
|
|
416
409
|
i: void 0,
|
|
417
410
|
s: "" + current,
|
|
418
411
|
l: void 0,
|
|
@@ -426,7 +419,7 @@ function createBigIntNode(ctx, current) {
|
|
|
426
419
|
}
|
|
427
420
|
function createIndexedValueNode(id) {
|
|
428
421
|
return {
|
|
429
|
-
t:
|
|
422
|
+
t: 4 /* IndexedValue */,
|
|
430
423
|
i: id,
|
|
431
424
|
s: void 0,
|
|
432
425
|
l: void 0,
|
|
@@ -440,7 +433,7 @@ function createIndexedValueNode(id) {
|
|
|
440
433
|
}
|
|
441
434
|
function createDateNode(id, current) {
|
|
442
435
|
return {
|
|
443
|
-
t:
|
|
436
|
+
t: 5 /* Date */,
|
|
444
437
|
i: id,
|
|
445
438
|
s: current.toISOString(),
|
|
446
439
|
l: void 0,
|
|
@@ -454,7 +447,7 @@ function createDateNode(id, current) {
|
|
|
454
447
|
}
|
|
455
448
|
function createRegExpNode(id, current) {
|
|
456
449
|
return {
|
|
457
|
-
t:
|
|
450
|
+
t: 6 /* RegExp */,
|
|
458
451
|
i: id,
|
|
459
452
|
s: void 0,
|
|
460
453
|
l: void 0,
|
|
@@ -474,7 +467,7 @@ function createArrayBufferNode(id, current) {
|
|
|
474
467
|
values[i] = bytes[i];
|
|
475
468
|
}
|
|
476
469
|
return {
|
|
477
|
-
t:
|
|
470
|
+
t: 21 /* ArrayBuffer */,
|
|
478
471
|
i: id,
|
|
479
472
|
s: values,
|
|
480
473
|
l: void 0,
|
|
@@ -494,14 +487,13 @@ function serializeArrayBuffer(ctx, current) {
|
|
|
494
487
|
return createArrayBufferNode(id, current);
|
|
495
488
|
}
|
|
496
489
|
function createTypedArrayNode(ctx, id, current) {
|
|
497
|
-
|
|
498
|
-
assert(ctx.features & 2048 /* TypedArray */, `Unsupported value type "${constructor}"`);
|
|
490
|
+
assert(ctx.features & 2048 /* TypedArray */, new UnsupportedTypeError(current));
|
|
499
491
|
return {
|
|
500
|
-
t:
|
|
492
|
+
t: 15 /* TypedArray */,
|
|
501
493
|
i: id,
|
|
502
494
|
s: void 0,
|
|
503
495
|
l: current.length,
|
|
504
|
-
c: constructor,
|
|
496
|
+
c: current.constructor.name,
|
|
505
497
|
m: void 0,
|
|
506
498
|
d: void 0,
|
|
507
499
|
a: void 0,
|
|
@@ -511,17 +503,16 @@ function createTypedArrayNode(ctx, id, current) {
|
|
|
511
503
|
}
|
|
512
504
|
var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
|
|
513
505
|
function createBigIntTypedArrayNode(ctx, id, current) {
|
|
514
|
-
const constructor = current.constructor.name;
|
|
515
506
|
assert(
|
|
516
507
|
(ctx.features & BIGINT_FLAG) === BIGINT_FLAG,
|
|
517
|
-
|
|
508
|
+
new UnsupportedTypeError(current)
|
|
518
509
|
);
|
|
519
510
|
return {
|
|
520
|
-
t:
|
|
511
|
+
t: 16 /* BigIntTypedArray */,
|
|
521
512
|
i: id,
|
|
522
513
|
s: void 0,
|
|
523
514
|
l: current.length,
|
|
524
|
-
c: constructor,
|
|
515
|
+
c: current.constructor.name,
|
|
525
516
|
m: void 0,
|
|
526
517
|
d: void 0,
|
|
527
518
|
a: void 0,
|
|
@@ -529,12 +520,12 @@ function createBigIntTypedArrayNode(ctx, id, current) {
|
|
|
529
520
|
b: current.byteOffset
|
|
530
521
|
};
|
|
531
522
|
}
|
|
532
|
-
function createWKSymbolNode(ctx, current) {
|
|
533
|
-
assert(ctx.features & 1024 /* Symbol */,
|
|
534
|
-
assert(current in INV_SYMBOL_REF, "
|
|
523
|
+
function createWKSymbolNode(ctx, id, current) {
|
|
524
|
+
assert(ctx.features & 1024 /* Symbol */, new UnsupportedTypeError(current));
|
|
525
|
+
assert(current in INV_SYMBOL_REF, new Error("Only well-known symbols are supported."));
|
|
535
526
|
return {
|
|
536
|
-
t:
|
|
537
|
-
i:
|
|
527
|
+
t: 17 /* WKSymbol */,
|
|
528
|
+
i: id,
|
|
538
529
|
s: INV_SYMBOL_REF[current],
|
|
539
530
|
l: void 0,
|
|
540
531
|
c: void 0,
|
|
@@ -547,7 +538,7 @@ function createWKSymbolNode(ctx, current) {
|
|
|
547
538
|
}
|
|
548
539
|
function createReferenceNode(id, ref) {
|
|
549
540
|
return {
|
|
550
|
-
t:
|
|
541
|
+
t: 20 /* Reference */,
|
|
551
542
|
i: id,
|
|
552
543
|
s: serializeString(getReferenceID(ref)),
|
|
553
544
|
l: void 0,
|
|
@@ -561,7 +552,7 @@ function createReferenceNode(id, ref) {
|
|
|
561
552
|
}
|
|
562
553
|
function createDataViewNode(ctx, id, current) {
|
|
563
554
|
return {
|
|
564
|
-
t:
|
|
555
|
+
t: 22 /* DataView */,
|
|
565
556
|
i: id,
|
|
566
557
|
s: void 0,
|
|
567
558
|
l: current.byteLength,
|
|
@@ -573,6 +564,24 @@ function createDataViewNode(ctx, id, current) {
|
|
|
573
564
|
b: current.byteOffset
|
|
574
565
|
};
|
|
575
566
|
}
|
|
567
|
+
function createSymbolNode(ctx, current) {
|
|
568
|
+
const id = createIndexedValue(ctx, current);
|
|
569
|
+
if (ctx.markedRefs.has(id)) {
|
|
570
|
+
return createIndexedValueNode(id);
|
|
571
|
+
}
|
|
572
|
+
if (hasReferenceID(current)) {
|
|
573
|
+
return createReferenceNode(id, current);
|
|
574
|
+
}
|
|
575
|
+
return createWKSymbolNode(ctx, id, current);
|
|
576
|
+
}
|
|
577
|
+
function createFunctionNode(ctx, current) {
|
|
578
|
+
assert(hasReferenceID(current), new Error("Cannot serialize function without reference ID."));
|
|
579
|
+
const id = createIndexedValue(ctx, current);
|
|
580
|
+
if (ctx.markedRefs.has(id)) {
|
|
581
|
+
return createIndexedValueNode(id);
|
|
582
|
+
}
|
|
583
|
+
return createReferenceNode(id, current);
|
|
584
|
+
}
|
|
576
585
|
|
|
577
586
|
// src/tree/shared.ts
|
|
578
587
|
function getErrorConstructorName(error) {
|
|
@@ -640,17 +649,6 @@ function getErrorOptions(ctx, error) {
|
|
|
640
649
|
}
|
|
641
650
|
return options;
|
|
642
651
|
}
|
|
643
|
-
function getIterableOptions(obj) {
|
|
644
|
-
const names = Object.getOwnPropertyNames(obj);
|
|
645
|
-
if (names.length) {
|
|
646
|
-
const options = {};
|
|
647
|
-
for (const name of names) {
|
|
648
|
-
options[name] = obj[name];
|
|
649
|
-
}
|
|
650
|
-
return options;
|
|
651
|
-
}
|
|
652
|
-
return void 0;
|
|
653
|
-
}
|
|
654
652
|
function isIterable(value) {
|
|
655
653
|
if (!value || typeof value !== "object") {
|
|
656
654
|
return false;
|
|
@@ -714,9 +712,9 @@ function isValidIdentifier(name) {
|
|
|
714
712
|
|
|
715
713
|
// src/tree/web-api.ts
|
|
716
714
|
function createURLNode(ctx, id, current) {
|
|
717
|
-
assert(ctx.features & 8192 /* WebAPI */,
|
|
715
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
718
716
|
return {
|
|
719
|
-
t:
|
|
717
|
+
t: 18 /* URL */,
|
|
720
718
|
i: id,
|
|
721
719
|
s: serializeString(current.href),
|
|
722
720
|
l: void 0,
|
|
@@ -729,9 +727,9 @@ function createURLNode(ctx, id, current) {
|
|
|
729
727
|
};
|
|
730
728
|
}
|
|
731
729
|
function createURLSearchParamsNode(ctx, id, current) {
|
|
732
|
-
assert(ctx.features & 8192 /* WebAPI */,
|
|
730
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
733
731
|
return {
|
|
734
|
-
t:
|
|
732
|
+
t: 19 /* URLSearchParams */,
|
|
735
733
|
i: id,
|
|
736
734
|
s: serializeString(current.toString()),
|
|
737
735
|
l: void 0,
|
|
@@ -744,9 +742,9 @@ function createURLSearchParamsNode(ctx, id, current) {
|
|
|
744
742
|
};
|
|
745
743
|
}
|
|
746
744
|
async function createBlobNode(ctx, id, current) {
|
|
747
|
-
assert(ctx.features & 8192 /* WebAPI */,
|
|
745
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
748
746
|
return {
|
|
749
|
-
t:
|
|
747
|
+
t: 23 /* Blob */,
|
|
750
748
|
i: id,
|
|
751
749
|
s: void 0,
|
|
752
750
|
l: void 0,
|
|
@@ -759,9 +757,9 @@ async function createBlobNode(ctx, id, current) {
|
|
|
759
757
|
};
|
|
760
758
|
}
|
|
761
759
|
async function createFileNode(ctx, id, current) {
|
|
762
|
-
assert(ctx.features & 8192 /* WebAPI */,
|
|
760
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
763
761
|
return {
|
|
764
|
-
t:
|
|
762
|
+
t: 24 /* File */,
|
|
765
763
|
i: id,
|
|
766
764
|
s: void 0,
|
|
767
765
|
l: void 0,
|
|
@@ -774,8 +772,8 @@ async function createFileNode(ctx, id, current) {
|
|
|
774
772
|
};
|
|
775
773
|
}
|
|
776
774
|
|
|
777
|
-
// src/tree/
|
|
778
|
-
|
|
775
|
+
// src/tree/sync.ts
|
|
776
|
+
function generateNodeList(ctx, current) {
|
|
779
777
|
const size = current.length;
|
|
780
778
|
const nodes = new Array(size);
|
|
781
779
|
const deferred = new Array(size);
|
|
@@ -786,33 +784,33 @@ async function generateNodeList(ctx, current) {
|
|
|
786
784
|
if (isIterable(item)) {
|
|
787
785
|
deferred[i] = item;
|
|
788
786
|
} else {
|
|
789
|
-
nodes[i] =
|
|
787
|
+
nodes[i] = parseSync(ctx, item);
|
|
790
788
|
}
|
|
791
789
|
}
|
|
792
790
|
}
|
|
793
791
|
for (let i = 0; i < size; i++) {
|
|
794
792
|
if (i in deferred) {
|
|
795
|
-
nodes[i] =
|
|
793
|
+
nodes[i] = parseSync(ctx, deferred[i]);
|
|
796
794
|
}
|
|
797
795
|
}
|
|
798
796
|
return nodes;
|
|
799
797
|
}
|
|
800
|
-
|
|
798
|
+
function generateArrayNode(ctx, id, current) {
|
|
801
799
|
return {
|
|
802
|
-
t:
|
|
800
|
+
t: 9 /* Array */,
|
|
803
801
|
i: id,
|
|
804
802
|
s: void 0,
|
|
805
803
|
l: current.length,
|
|
806
804
|
c: void 0,
|
|
807
805
|
m: void 0,
|
|
808
806
|
d: void 0,
|
|
809
|
-
a:
|
|
807
|
+
a: generateNodeList(ctx, current),
|
|
810
808
|
f: void 0,
|
|
811
809
|
b: void 0
|
|
812
810
|
};
|
|
813
811
|
}
|
|
814
|
-
|
|
815
|
-
assert(ctx.features & 32 /* Map */,
|
|
812
|
+
function generateMapNode(ctx, id, current) {
|
|
813
|
+
assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
|
|
816
814
|
const len = current.size;
|
|
817
815
|
const keyNodes = new Array(len);
|
|
818
816
|
const valueNodes = new Array(len);
|
|
@@ -826,17 +824,17 @@ async function generateMapNode(ctx, id, current) {
|
|
|
826
824
|
deferredValue[deferredSize] = value;
|
|
827
825
|
deferredSize++;
|
|
828
826
|
} else {
|
|
829
|
-
keyNodes[nodeSize] =
|
|
830
|
-
valueNodes[nodeSize] =
|
|
827
|
+
keyNodes[nodeSize] = parseSync(ctx, key);
|
|
828
|
+
valueNodes[nodeSize] = parseSync(ctx, value);
|
|
831
829
|
nodeSize++;
|
|
832
830
|
}
|
|
833
831
|
}
|
|
834
832
|
for (let i = 0; i < deferredSize; i++) {
|
|
835
|
-
keyNodes[nodeSize + i] =
|
|
836
|
-
valueNodes[nodeSize + i] =
|
|
833
|
+
keyNodes[nodeSize + i] = parseSync(ctx, deferredKey[i]);
|
|
834
|
+
valueNodes[nodeSize + i] = parseSync(ctx, deferredValue[i]);
|
|
837
835
|
}
|
|
838
836
|
return {
|
|
839
|
-
t:
|
|
837
|
+
t: 8 /* Map */,
|
|
840
838
|
i: id,
|
|
841
839
|
s: void 0,
|
|
842
840
|
l: void 0,
|
|
@@ -848,8 +846,8 @@ async function generateMapNode(ctx, id, current) {
|
|
|
848
846
|
b: void 0
|
|
849
847
|
};
|
|
850
848
|
}
|
|
851
|
-
|
|
852
|
-
assert(ctx.features & 512 /* Set */,
|
|
849
|
+
function generateSetNode(ctx, id, current) {
|
|
850
|
+
assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
|
|
853
851
|
const len = current.size;
|
|
854
852
|
const nodes = new Array(len);
|
|
855
853
|
const deferred = new Array(len);
|
|
@@ -859,14 +857,14 @@ async function generateSetNode(ctx, id, current) {
|
|
|
859
857
|
if (isIterable(item)) {
|
|
860
858
|
deferred[deferredSize++] = item;
|
|
861
859
|
} else {
|
|
862
|
-
nodes[nodeSize++] =
|
|
860
|
+
nodes[nodeSize++] = parseSync(ctx, item);
|
|
863
861
|
}
|
|
864
862
|
}
|
|
865
863
|
for (let i = 0; i < deferredSize; i++) {
|
|
866
|
-
nodes[nodeSize + i] =
|
|
864
|
+
nodes[nodeSize + i] = parseSync(ctx, deferred[i]);
|
|
867
865
|
}
|
|
868
866
|
return {
|
|
869
|
-
t:
|
|
867
|
+
t: 7 /* Set */,
|
|
870
868
|
i: id,
|
|
871
869
|
s: void 0,
|
|
872
870
|
l: len,
|
|
@@ -878,9 +876,9 @@ async function generateSetNode(ctx, id, current) {
|
|
|
878
876
|
b: void 0
|
|
879
877
|
};
|
|
880
878
|
}
|
|
881
|
-
|
|
879
|
+
function generateProperties(ctx, properties) {
|
|
882
880
|
const keys = Object.keys(properties);
|
|
883
|
-
|
|
881
|
+
let size = keys.length;
|
|
884
882
|
const keyNodes = new Array(size);
|
|
885
883
|
const valueNodes = new Array(size);
|
|
886
884
|
const deferredKeys = new Array(size);
|
|
@@ -898,13 +896,22 @@ async function generateProperties(ctx, properties) {
|
|
|
898
896
|
deferredSize++;
|
|
899
897
|
} else {
|
|
900
898
|
keyNodes[nodesSize] = escaped;
|
|
901
|
-
valueNodes[nodesSize] =
|
|
899
|
+
valueNodes[nodesSize] = parseSync(ctx, item);
|
|
902
900
|
nodesSize++;
|
|
903
901
|
}
|
|
904
902
|
}
|
|
905
903
|
for (let i = 0; i < deferredSize; i++) {
|
|
906
904
|
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
907
|
-
valueNodes[nodesSize + i] =
|
|
905
|
+
valueNodes[nodesSize + i] = parseSync(ctx, deferredValues[i]);
|
|
906
|
+
}
|
|
907
|
+
if (ctx.features & 1024 /* Symbol */) {
|
|
908
|
+
if (Symbol.iterator in properties) {
|
|
909
|
+
keyNodes[size] = 0 /* SymbolIterator */;
|
|
910
|
+
const items = Array.from(properties);
|
|
911
|
+
const id = createIndexedValue(ctx, items);
|
|
912
|
+
valueNodes[size] = generateArrayNode(ctx, id, items);
|
|
913
|
+
size++;
|
|
914
|
+
}
|
|
908
915
|
}
|
|
909
916
|
return {
|
|
910
917
|
k: keyNodes,
|
|
@@ -912,65 +919,59 @@ async function generateProperties(ctx, properties) {
|
|
|
912
919
|
s: size
|
|
913
920
|
};
|
|
914
921
|
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
const
|
|
918
|
-
const
|
|
922
|
+
function generatePlainProperties(ctx, properties) {
|
|
923
|
+
const keys = Object.keys(properties);
|
|
924
|
+
const size = keys.length;
|
|
925
|
+
const keyNodes = new Array(size);
|
|
926
|
+
const valueNodes = new Array(size);
|
|
927
|
+
const deferredKeys = new Array(size);
|
|
928
|
+
const deferredValues = new Array(size);
|
|
929
|
+
let deferredSize = 0;
|
|
930
|
+
let nodesSize = 0;
|
|
931
|
+
let item;
|
|
932
|
+
let escaped;
|
|
933
|
+
for (const key of keys) {
|
|
934
|
+
item = properties[key];
|
|
935
|
+
escaped = serializeString(key);
|
|
936
|
+
if (isIterable(item)) {
|
|
937
|
+
deferredKeys[deferredSize] = escaped;
|
|
938
|
+
deferredValues[deferredSize] = item;
|
|
939
|
+
deferredSize++;
|
|
940
|
+
} else {
|
|
941
|
+
keyNodes[nodesSize] = escaped;
|
|
942
|
+
valueNodes[nodesSize] = parseSync(ctx, item);
|
|
943
|
+
nodesSize++;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
947
|
+
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
948
|
+
valueNodes[nodesSize + i] = parseSync(ctx, deferredValues[i]);
|
|
949
|
+
}
|
|
919
950
|
return {
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
s:
|
|
923
|
-
l: array.length,
|
|
924
|
-
c: void 0,
|
|
925
|
-
m: void 0,
|
|
926
|
-
// Parse options first before the items
|
|
927
|
-
d: options ? await generateProperties(ctx, options) : void 0,
|
|
928
|
-
a: await generateNodeList(ctx, array),
|
|
929
|
-
f: void 0,
|
|
930
|
-
b: void 0
|
|
951
|
+
k: keyNodes,
|
|
952
|
+
v: valueNodes,
|
|
953
|
+
s: size
|
|
931
954
|
};
|
|
932
955
|
}
|
|
933
|
-
|
|
934
|
-
assert(ctx.features & 256 /* Promise */, 'Unsupported type "Promise"');
|
|
935
|
-
return current.then(async (value) => ({
|
|
936
|
-
t: 18 /* Promise */,
|
|
937
|
-
i: id,
|
|
938
|
-
s: void 0,
|
|
939
|
-
l: void 0,
|
|
940
|
-
c: void 0,
|
|
941
|
-
m: void 0,
|
|
942
|
-
// Parse options first before the items
|
|
943
|
-
d: void 0,
|
|
944
|
-
a: void 0,
|
|
945
|
-
f: await parse(ctx, value),
|
|
946
|
-
b: void 0
|
|
947
|
-
}));
|
|
948
|
-
}
|
|
949
|
-
async function generateObjectNode(ctx, id, current, empty) {
|
|
950
|
-
if (Symbol.iterator in current) {
|
|
951
|
-
return generateIterableNode(ctx, id, current);
|
|
952
|
-
}
|
|
953
|
-
if ("then" in current && typeof current.then === "function") {
|
|
954
|
-
return generatePromiseNode(ctx, id, current);
|
|
955
|
-
}
|
|
956
|
+
function generateObjectNode(ctx, id, current, empty) {
|
|
956
957
|
return {
|
|
957
|
-
t: empty ?
|
|
958
|
+
t: empty ? 11 /* NullConstructor */ : 10 /* Object */,
|
|
958
959
|
i: id,
|
|
959
960
|
s: void 0,
|
|
960
961
|
l: void 0,
|
|
961
962
|
c: void 0,
|
|
962
963
|
m: void 0,
|
|
963
|
-
d:
|
|
964
|
+
d: generateProperties(ctx, current),
|
|
964
965
|
a: void 0,
|
|
965
966
|
f: void 0,
|
|
966
967
|
b: void 0
|
|
967
968
|
};
|
|
968
969
|
}
|
|
969
|
-
|
|
970
|
+
function generateAggregateErrorNode(ctx, id, current) {
|
|
970
971
|
const options = getErrorOptions(ctx, current);
|
|
971
|
-
const optionsNode = options ?
|
|
972
|
+
const optionsNode = options ? generateProperties(ctx, options) : void 0;
|
|
972
973
|
return {
|
|
973
|
-
t:
|
|
974
|
+
t: 14 /* AggregateError */,
|
|
974
975
|
i: id,
|
|
975
976
|
s: void 0,
|
|
976
977
|
l: void 0,
|
|
@@ -982,11 +983,11 @@ async function generateAggregateErrorNode(ctx, id, current) {
|
|
|
982
983
|
b: void 0
|
|
983
984
|
};
|
|
984
985
|
}
|
|
985
|
-
|
|
986
|
+
function generateErrorNode(ctx, id, current) {
|
|
986
987
|
const options = getErrorOptions(ctx, current);
|
|
987
|
-
const optionsNode = options ?
|
|
988
|
+
const optionsNode = options ? generateProperties(ctx, options) : void 0;
|
|
988
989
|
return {
|
|
989
|
-
t:
|
|
990
|
+
t: 13 /* Error */,
|
|
990
991
|
i: id,
|
|
991
992
|
s: void 0,
|
|
992
993
|
l: void 0,
|
|
@@ -998,45 +999,158 @@ async function generateErrorNode(ctx, id, current) {
|
|
|
998
999
|
b: void 0
|
|
999
1000
|
};
|
|
1000
1001
|
}
|
|
1001
|
-
|
|
1002
|
-
assert(ctx.features & 8192 /* WebAPI */,
|
|
1002
|
+
function generateHeadersNode(ctx, id, current) {
|
|
1003
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
1003
1004
|
const items = {};
|
|
1004
1005
|
current.forEach((value, key) => {
|
|
1005
1006
|
items[key] = value;
|
|
1006
1007
|
});
|
|
1007
1008
|
return {
|
|
1008
|
-
t:
|
|
1009
|
+
t: 25 /* Headers */,
|
|
1009
1010
|
i: id,
|
|
1010
1011
|
s: void 0,
|
|
1011
1012
|
l: void 0,
|
|
1012
1013
|
c: void 0,
|
|
1013
1014
|
m: void 0,
|
|
1014
|
-
d:
|
|
1015
|
+
d: generatePlainProperties(ctx, items),
|
|
1015
1016
|
a: void 0,
|
|
1016
1017
|
f: void 0,
|
|
1017
1018
|
b: void 0
|
|
1018
1019
|
};
|
|
1019
1020
|
}
|
|
1020
|
-
|
|
1021
|
-
assert(ctx.features & 8192 /* WebAPI */,
|
|
1021
|
+
function generateFormDataNode(ctx, id, current) {
|
|
1022
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
1022
1023
|
const items = {};
|
|
1023
1024
|
current.forEach((value, key) => {
|
|
1024
1025
|
items[key] = value;
|
|
1025
1026
|
});
|
|
1026
1027
|
return {
|
|
1027
|
-
t:
|
|
1028
|
+
t: 26 /* FormData */,
|
|
1028
1029
|
i: id,
|
|
1029
1030
|
s: void 0,
|
|
1030
1031
|
l: void 0,
|
|
1031
1032
|
c: void 0,
|
|
1032
1033
|
m: void 0,
|
|
1033
|
-
d:
|
|
1034
|
+
d: generatePlainProperties(ctx, items),
|
|
1034
1035
|
a: void 0,
|
|
1035
1036
|
f: void 0,
|
|
1036
1037
|
b: void 0
|
|
1037
1038
|
};
|
|
1038
1039
|
}
|
|
1039
|
-
|
|
1040
|
+
function generateBoxedNode(ctx, id, current) {
|
|
1041
|
+
return {
|
|
1042
|
+
t: 27 /* Boxed */,
|
|
1043
|
+
i: id,
|
|
1044
|
+
s: void 0,
|
|
1045
|
+
l: void 0,
|
|
1046
|
+
c: void 0,
|
|
1047
|
+
m: void 0,
|
|
1048
|
+
d: void 0,
|
|
1049
|
+
a: void 0,
|
|
1050
|
+
f: parseSync(ctx, current.valueOf()),
|
|
1051
|
+
b: void 0
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
function parseObject(ctx, current) {
|
|
1055
|
+
if (!current) {
|
|
1056
|
+
return NULL_NODE;
|
|
1057
|
+
}
|
|
1058
|
+
const id = createIndexedValue(ctx, current);
|
|
1059
|
+
if (ctx.markedRefs.has(id)) {
|
|
1060
|
+
return createIndexedValueNode(id);
|
|
1061
|
+
}
|
|
1062
|
+
if (hasReferenceID(current)) {
|
|
1063
|
+
return createReferenceNode(id, current);
|
|
1064
|
+
}
|
|
1065
|
+
if (Array.isArray(current)) {
|
|
1066
|
+
return generateArrayNode(ctx, id, current);
|
|
1067
|
+
}
|
|
1068
|
+
switch (current.constructor) {
|
|
1069
|
+
case Number:
|
|
1070
|
+
case Boolean:
|
|
1071
|
+
case String:
|
|
1072
|
+
case BigInt:
|
|
1073
|
+
case Function:
|
|
1074
|
+
case Symbol:
|
|
1075
|
+
return generateBoxedNode(ctx, id, current);
|
|
1076
|
+
case Date:
|
|
1077
|
+
return createDateNode(id, current);
|
|
1078
|
+
case RegExp:
|
|
1079
|
+
return createRegExpNode(id, current);
|
|
1080
|
+
case ArrayBuffer:
|
|
1081
|
+
return createArrayBufferNode(id, current);
|
|
1082
|
+
case Int8Array:
|
|
1083
|
+
case Int16Array:
|
|
1084
|
+
case Int32Array:
|
|
1085
|
+
case Uint8Array:
|
|
1086
|
+
case Uint16Array:
|
|
1087
|
+
case Uint32Array:
|
|
1088
|
+
case Uint8ClampedArray:
|
|
1089
|
+
case Float32Array:
|
|
1090
|
+
case Float64Array:
|
|
1091
|
+
return createTypedArrayNode(ctx, id, current);
|
|
1092
|
+
case BigInt64Array:
|
|
1093
|
+
case BigUint64Array:
|
|
1094
|
+
return createBigIntTypedArrayNode(ctx, id, current);
|
|
1095
|
+
case DataView:
|
|
1096
|
+
return createDataViewNode(ctx, id, current);
|
|
1097
|
+
case Map:
|
|
1098
|
+
return generateMapNode(ctx, id, current);
|
|
1099
|
+
case Set:
|
|
1100
|
+
return generateSetNode(ctx, id, current);
|
|
1101
|
+
case Object:
|
|
1102
|
+
return generateObjectNode(
|
|
1103
|
+
ctx,
|
|
1104
|
+
id,
|
|
1105
|
+
current,
|
|
1106
|
+
false
|
|
1107
|
+
);
|
|
1108
|
+
case void 0:
|
|
1109
|
+
return generateObjectNode(
|
|
1110
|
+
ctx,
|
|
1111
|
+
id,
|
|
1112
|
+
current,
|
|
1113
|
+
true
|
|
1114
|
+
);
|
|
1115
|
+
case AggregateError:
|
|
1116
|
+
if (ctx.features & 1 /* AggregateError */) {
|
|
1117
|
+
return generateAggregateErrorNode(ctx, id, current);
|
|
1118
|
+
}
|
|
1119
|
+
return generateErrorNode(ctx, id, current);
|
|
1120
|
+
case Error:
|
|
1121
|
+
case EvalError:
|
|
1122
|
+
case RangeError:
|
|
1123
|
+
case ReferenceError:
|
|
1124
|
+
case SyntaxError:
|
|
1125
|
+
case TypeError:
|
|
1126
|
+
case URIError:
|
|
1127
|
+
return generateErrorNode(ctx, id, current);
|
|
1128
|
+
case URL:
|
|
1129
|
+
return createURLNode(ctx, id, current);
|
|
1130
|
+
case URLSearchParams:
|
|
1131
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
1132
|
+
case Headers:
|
|
1133
|
+
return generateHeadersNode(ctx, id, current);
|
|
1134
|
+
case FormData:
|
|
1135
|
+
return generateFormDataNode(ctx, id, current);
|
|
1136
|
+
default:
|
|
1137
|
+
break;
|
|
1138
|
+
}
|
|
1139
|
+
if (current instanceof AggregateError) {
|
|
1140
|
+
if (ctx.features & 1 /* AggregateError */) {
|
|
1141
|
+
return generateAggregateErrorNode(ctx, id, current);
|
|
1142
|
+
}
|
|
1143
|
+
return generateErrorNode(ctx, id, current);
|
|
1144
|
+
}
|
|
1145
|
+
if (current instanceof Error) {
|
|
1146
|
+
return generateErrorNode(ctx, id, current);
|
|
1147
|
+
}
|
|
1148
|
+
if (Symbol.iterator in current) {
|
|
1149
|
+
return generateObjectNode(ctx, id, current, !!current.constructor);
|
|
1150
|
+
}
|
|
1151
|
+
throw new UnsupportedTypeError(current);
|
|
1152
|
+
}
|
|
1153
|
+
function parseSync(ctx, current) {
|
|
1040
1154
|
switch (typeof current) {
|
|
1041
1155
|
case "boolean":
|
|
1042
1156
|
return current ? TRUE_NODE : FALSE_NODE;
|
|
@@ -1045,210 +1159,519 @@ async function parse(ctx, current) {
|
|
|
1045
1159
|
case "string":
|
|
1046
1160
|
return createStringNode(current);
|
|
1047
1161
|
case "number":
|
|
1048
|
-
|
|
1049
|
-
case Infinity:
|
|
1050
|
-
return INFINITY_NODE;
|
|
1051
|
-
case -Infinity:
|
|
1052
|
-
return NEG_INFINITY_NODE;
|
|
1053
|
-
default:
|
|
1054
|
-
if (current !== current) {
|
|
1055
|
-
return NAN_NODE;
|
|
1056
|
-
}
|
|
1057
|
-
if (Object.is(current, -0)) {
|
|
1058
|
-
return NEG_ZERO_NODE;
|
|
1059
|
-
}
|
|
1060
|
-
return createNumberNode(current);
|
|
1061
|
-
}
|
|
1162
|
+
return createNumberNode(current);
|
|
1062
1163
|
case "bigint":
|
|
1063
1164
|
return createBigIntNode(ctx, current);
|
|
1064
|
-
case "object":
|
|
1065
|
-
|
|
1066
|
-
return NULL_NODE;
|
|
1067
|
-
}
|
|
1068
|
-
const id = createIndexedValue(ctx, current);
|
|
1069
|
-
if (ctx.markedRefs.has(id)) {
|
|
1070
|
-
return createIndexedValueNode(id);
|
|
1071
|
-
}
|
|
1072
|
-
if (hasReferenceID(current)) {
|
|
1073
|
-
return createReferenceNode(id, current);
|
|
1074
|
-
}
|
|
1075
|
-
if (Array.isArray(current)) {
|
|
1076
|
-
return generateArrayNode(ctx, id, current);
|
|
1077
|
-
}
|
|
1078
|
-
switch (current.constructor) {
|
|
1079
|
-
case Date:
|
|
1080
|
-
return createDateNode(id, current);
|
|
1081
|
-
case RegExp:
|
|
1082
|
-
return createRegExpNode(id, current);
|
|
1083
|
-
case Promise:
|
|
1084
|
-
return generatePromiseNode(ctx, id, current);
|
|
1085
|
-
case ArrayBuffer:
|
|
1086
|
-
return createArrayBufferNode(id, current);
|
|
1087
|
-
case Int8Array:
|
|
1088
|
-
case Int16Array:
|
|
1089
|
-
case Int32Array:
|
|
1090
|
-
case Uint8Array:
|
|
1091
|
-
case Uint16Array:
|
|
1092
|
-
case Uint32Array:
|
|
1093
|
-
case Uint8ClampedArray:
|
|
1094
|
-
case Float32Array:
|
|
1095
|
-
case Float64Array:
|
|
1096
|
-
return createTypedArrayNode(ctx, id, current);
|
|
1097
|
-
case BigInt64Array:
|
|
1098
|
-
case BigUint64Array:
|
|
1099
|
-
return createBigIntTypedArrayNode(ctx, id, current);
|
|
1100
|
-
case DataView:
|
|
1101
|
-
return createDataViewNode(ctx, id, current);
|
|
1102
|
-
case Map:
|
|
1103
|
-
return generateMapNode(
|
|
1104
|
-
ctx,
|
|
1105
|
-
id,
|
|
1106
|
-
current
|
|
1107
|
-
);
|
|
1108
|
-
case Set:
|
|
1109
|
-
return generateSetNode(
|
|
1110
|
-
ctx,
|
|
1111
|
-
id,
|
|
1112
|
-
current
|
|
1113
|
-
);
|
|
1114
|
-
case Object:
|
|
1115
|
-
return generateObjectNode(
|
|
1116
|
-
ctx,
|
|
1117
|
-
id,
|
|
1118
|
-
current,
|
|
1119
|
-
false
|
|
1120
|
-
);
|
|
1121
|
-
case void 0:
|
|
1122
|
-
return generateObjectNode(
|
|
1123
|
-
ctx,
|
|
1124
|
-
id,
|
|
1125
|
-
current,
|
|
1126
|
-
true
|
|
1127
|
-
);
|
|
1128
|
-
case AggregateError:
|
|
1129
|
-
if (ctx.features & 1 /* AggregateError */) {
|
|
1130
|
-
return generateAggregateErrorNode(ctx, id, current);
|
|
1131
|
-
}
|
|
1132
|
-
return generateErrorNode(ctx, id, current);
|
|
1133
|
-
case Error:
|
|
1134
|
-
case EvalError:
|
|
1135
|
-
case RangeError:
|
|
1136
|
-
case ReferenceError:
|
|
1137
|
-
case SyntaxError:
|
|
1138
|
-
case TypeError:
|
|
1139
|
-
case URIError:
|
|
1140
|
-
return generateErrorNode(ctx, id, current);
|
|
1141
|
-
case URL:
|
|
1142
|
-
return createURLNode(ctx, id, current);
|
|
1143
|
-
case URLSearchParams:
|
|
1144
|
-
return createURLSearchParamsNode(ctx, id, current);
|
|
1145
|
-
case Blob:
|
|
1146
|
-
return createBlobNode(ctx, id, current);
|
|
1147
|
-
case File:
|
|
1148
|
-
return createFileNode(ctx, id, current);
|
|
1149
|
-
case Headers:
|
|
1150
|
-
return generateHeadersNode(ctx, id, current);
|
|
1151
|
-
case FormData:
|
|
1152
|
-
return generateFormDataNode(ctx, id, current);
|
|
1153
|
-
default:
|
|
1154
|
-
break;
|
|
1155
|
-
}
|
|
1156
|
-
if (current instanceof AggregateError) {
|
|
1157
|
-
if (ctx.features & 1 /* AggregateError */) {
|
|
1158
|
-
return generateAggregateErrorNode(ctx, id, current);
|
|
1159
|
-
}
|
|
1160
|
-
return generateErrorNode(ctx, id, current);
|
|
1161
|
-
}
|
|
1162
|
-
if (current instanceof Error) {
|
|
1163
|
-
return generateErrorNode(ctx, id, current);
|
|
1164
|
-
}
|
|
1165
|
-
if (current instanceof Promise) {
|
|
1166
|
-
return generatePromiseNode(ctx, id, current);
|
|
1167
|
-
}
|
|
1168
|
-
if (Symbol.iterator in current) {
|
|
1169
|
-
return generateIterableNode(ctx, id, current);
|
|
1170
|
-
}
|
|
1171
|
-
if ("then" in current && typeof current.then === "function") {
|
|
1172
|
-
return generatePromiseNode(ctx, id, current);
|
|
1173
|
-
}
|
|
1174
|
-
throw new Error("Unsupported type");
|
|
1175
|
-
}
|
|
1165
|
+
case "object":
|
|
1166
|
+
return parseObject(ctx, current);
|
|
1176
1167
|
case "symbol":
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
return createIndexedValueNode(id);
|
|
1181
|
-
}
|
|
1182
|
-
return createReferenceNode(id, current);
|
|
1183
|
-
}
|
|
1184
|
-
return createWKSymbolNode(ctx, current);
|
|
1185
|
-
case "function": {
|
|
1186
|
-
assert(hasReferenceID(current), "Cannot serialize function without reference ID.");
|
|
1187
|
-
const id = createIndexedValue(ctx, current);
|
|
1188
|
-
if (ctx.markedRefs.has(id)) {
|
|
1189
|
-
return createIndexedValueNode(id);
|
|
1190
|
-
}
|
|
1191
|
-
return createReferenceNode(id, current);
|
|
1192
|
-
}
|
|
1168
|
+
return createSymbolNode(ctx, current);
|
|
1169
|
+
case "function":
|
|
1170
|
+
return createFunctionNode(ctx, current);
|
|
1193
1171
|
default:
|
|
1194
|
-
throw new
|
|
1172
|
+
throw new UnsupportedTypeError(current);
|
|
1195
1173
|
}
|
|
1196
1174
|
}
|
|
1197
|
-
async function parseAsync(ctx, current) {
|
|
1198
|
-
const result = await parse(ctx, current);
|
|
1199
|
-
const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
|
|
1200
|
-
return [result, getRootID(ctx, current), isObject];
|
|
1201
|
-
}
|
|
1202
1175
|
|
|
1203
|
-
// src/tree/
|
|
1204
|
-
function
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
return value;
|
|
1209
|
-
}
|
|
1210
|
-
function deserializeArray(ctx, node) {
|
|
1211
|
-
const result = assignIndexedValue(
|
|
1212
|
-
ctx,
|
|
1213
|
-
node.i,
|
|
1214
|
-
new Array(node.l)
|
|
1215
|
-
);
|
|
1176
|
+
// src/tree/async.ts
|
|
1177
|
+
async function generateNodeList2(ctx, current) {
|
|
1178
|
+
const size = current.length;
|
|
1179
|
+
const nodes = new Array(size);
|
|
1180
|
+
const deferred = new Array(size);
|
|
1216
1181
|
let item;
|
|
1217
|
-
for (let i = 0
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1182
|
+
for (let i = 0; i < size; i++) {
|
|
1183
|
+
if (i in current) {
|
|
1184
|
+
item = current[i];
|
|
1185
|
+
if (isIterable(item)) {
|
|
1186
|
+
deferred[i] = item;
|
|
1187
|
+
} else {
|
|
1188
|
+
nodes[i] = await parseAsync(ctx, item);
|
|
1189
|
+
}
|
|
1221
1190
|
}
|
|
1222
1191
|
}
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
return {};
|
|
1228
|
-
}
|
|
1229
|
-
for (let i = 0; i < node.s; i++) {
|
|
1230
|
-
result[deserializeString(node.k[i])] = deserializeTree(ctx, node.v[i]);
|
|
1192
|
+
for (let i = 0; i < size; i++) {
|
|
1193
|
+
if (i in deferred) {
|
|
1194
|
+
nodes[i] = await parseAsync(ctx, deferred[i]);
|
|
1195
|
+
}
|
|
1231
1196
|
}
|
|
1232
|
-
return
|
|
1197
|
+
return nodes;
|
|
1233
1198
|
}
|
|
1234
|
-
function
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1199
|
+
async function generateArrayNode2(ctx, id, current) {
|
|
1200
|
+
return {
|
|
1201
|
+
t: 9 /* Array */,
|
|
1202
|
+
i: id,
|
|
1203
|
+
s: void 0,
|
|
1204
|
+
l: current.length,
|
|
1205
|
+
c: void 0,
|
|
1206
|
+
m: void 0,
|
|
1207
|
+
d: void 0,
|
|
1208
|
+
a: await generateNodeList2(ctx, current),
|
|
1209
|
+
f: void 0,
|
|
1210
|
+
b: void 0
|
|
1211
|
+
};
|
|
1242
1212
|
}
|
|
1243
|
-
function
|
|
1244
|
-
|
|
1245
|
-
|
|
1213
|
+
async function generateMapNode2(ctx, id, current) {
|
|
1214
|
+
assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
|
|
1215
|
+
const len = current.size;
|
|
1216
|
+
const keyNodes = new Array(len);
|
|
1217
|
+
const valueNodes = new Array(len);
|
|
1218
|
+
const deferredKey = new Array(len);
|
|
1219
|
+
const deferredValue = new Array(len);
|
|
1220
|
+
let deferredSize = 0;
|
|
1221
|
+
let nodeSize = 0;
|
|
1222
|
+
for (const [key, value] of current.entries()) {
|
|
1223
|
+
if (isIterable(key) || isIterable(value)) {
|
|
1224
|
+
deferredKey[deferredSize] = key;
|
|
1225
|
+
deferredValue[deferredSize] = value;
|
|
1226
|
+
deferredSize++;
|
|
1227
|
+
} else {
|
|
1228
|
+
keyNodes[nodeSize] = await parseAsync(ctx, key);
|
|
1229
|
+
valueNodes[nodeSize] = await parseAsync(ctx, value);
|
|
1230
|
+
nodeSize++;
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
1234
|
+
keyNodes[nodeSize + i] = await parseAsync(ctx, deferredKey[i]);
|
|
1235
|
+
valueNodes[nodeSize + i] = await parseAsync(ctx, deferredValue[i]);
|
|
1236
|
+
}
|
|
1237
|
+
return {
|
|
1238
|
+
t: 8 /* Map */,
|
|
1239
|
+
i: id,
|
|
1240
|
+
s: void 0,
|
|
1241
|
+
l: void 0,
|
|
1242
|
+
c: void 0,
|
|
1243
|
+
m: void 0,
|
|
1244
|
+
d: { k: keyNodes, v: valueNodes, s: len },
|
|
1245
|
+
a: void 0,
|
|
1246
|
+
f: void 0,
|
|
1247
|
+
b: void 0
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
async function generateSetNode2(ctx, id, current) {
|
|
1251
|
+
assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
|
|
1252
|
+
const len = current.size;
|
|
1253
|
+
const nodes = new Array(len);
|
|
1254
|
+
const deferred = new Array(len);
|
|
1255
|
+
let deferredSize = 0;
|
|
1256
|
+
let nodeSize = 0;
|
|
1257
|
+
for (const item of current.keys()) {
|
|
1258
|
+
if (isIterable(item)) {
|
|
1259
|
+
deferred[deferredSize++] = item;
|
|
1260
|
+
} else {
|
|
1261
|
+
nodes[nodeSize++] = await parseAsync(ctx, item);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
1265
|
+
nodes[nodeSize + i] = await parseAsync(ctx, deferred[i]);
|
|
1266
|
+
}
|
|
1267
|
+
return {
|
|
1268
|
+
t: 7 /* Set */,
|
|
1269
|
+
i: id,
|
|
1270
|
+
s: void 0,
|
|
1271
|
+
l: len,
|
|
1272
|
+
c: void 0,
|
|
1273
|
+
m: void 0,
|
|
1274
|
+
d: void 0,
|
|
1275
|
+
a: nodes,
|
|
1276
|
+
f: void 0,
|
|
1277
|
+
b: void 0
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
async function generateProperties2(ctx, properties) {
|
|
1281
|
+
const keys = Object.keys(properties);
|
|
1282
|
+
let size = keys.length;
|
|
1283
|
+
const keyNodes = new Array(size);
|
|
1284
|
+
const valueNodes = new Array(size);
|
|
1285
|
+
const deferredKeys = new Array(size);
|
|
1286
|
+
const deferredValues = new Array(size);
|
|
1287
|
+
let deferredSize = 0;
|
|
1288
|
+
let nodesSize = 0;
|
|
1289
|
+
let item;
|
|
1290
|
+
let escaped;
|
|
1291
|
+
for (const key of keys) {
|
|
1292
|
+
item = properties[key];
|
|
1293
|
+
escaped = serializeString(key);
|
|
1294
|
+
if (isIterable(item)) {
|
|
1295
|
+
deferredKeys[deferredSize] = escaped;
|
|
1296
|
+
deferredValues[deferredSize] = item;
|
|
1297
|
+
deferredSize++;
|
|
1298
|
+
} else {
|
|
1299
|
+
keyNodes[nodesSize] = escaped;
|
|
1300
|
+
valueNodes[nodesSize] = await parseAsync(ctx, item);
|
|
1301
|
+
nodesSize++;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
1305
|
+
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
1306
|
+
valueNodes[nodesSize + i] = await parseAsync(ctx, deferredValues[i]);
|
|
1307
|
+
}
|
|
1308
|
+
if (ctx.features & 1024 /* Symbol */) {
|
|
1309
|
+
if (Symbol.iterator in properties) {
|
|
1310
|
+
keyNodes[size] = 0 /* SymbolIterator */;
|
|
1311
|
+
const items = Array.from(properties);
|
|
1312
|
+
valueNodes[size] = await generateArrayNode2(
|
|
1313
|
+
ctx,
|
|
1314
|
+
createIndexedValue(ctx, items),
|
|
1315
|
+
items
|
|
1316
|
+
);
|
|
1317
|
+
size++;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
return {
|
|
1321
|
+
k: keyNodes,
|
|
1322
|
+
v: valueNodes,
|
|
1323
|
+
s: size
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
async function generatePlainProperties2(ctx, properties) {
|
|
1327
|
+
const keys = Object.keys(properties);
|
|
1328
|
+
const size = keys.length;
|
|
1329
|
+
const keyNodes = new Array(size);
|
|
1330
|
+
const valueNodes = new Array(size);
|
|
1331
|
+
const deferredKeys = new Array(size);
|
|
1332
|
+
const deferredValues = new Array(size);
|
|
1333
|
+
let deferredSize = 0;
|
|
1334
|
+
let nodesSize = 0;
|
|
1335
|
+
let item;
|
|
1336
|
+
let escaped;
|
|
1337
|
+
for (const key of keys) {
|
|
1338
|
+
item = properties[key];
|
|
1339
|
+
escaped = serializeString(key);
|
|
1340
|
+
if (isIterable(item)) {
|
|
1341
|
+
deferredKeys[deferredSize] = escaped;
|
|
1342
|
+
deferredValues[deferredSize] = item;
|
|
1343
|
+
deferredSize++;
|
|
1344
|
+
} else {
|
|
1345
|
+
keyNodes[nodesSize] = escaped;
|
|
1346
|
+
valueNodes[nodesSize] = await parseAsync(ctx, item);
|
|
1347
|
+
nodesSize++;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
1351
|
+
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
1352
|
+
valueNodes[nodesSize + i] = await parseAsync(ctx, deferredValues[i]);
|
|
1353
|
+
}
|
|
1354
|
+
return {
|
|
1355
|
+
k: keyNodes,
|
|
1356
|
+
v: valueNodes,
|
|
1357
|
+
s: size
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
async function generatePromiseNode(ctx, id, current) {
|
|
1361
|
+
assert(ctx.features & 256 /* Promise */, new UnsupportedTypeError(current));
|
|
1362
|
+
return {
|
|
1363
|
+
t: 12 /* Promise */,
|
|
1364
|
+
i: id,
|
|
1365
|
+
s: void 0,
|
|
1366
|
+
l: void 0,
|
|
1367
|
+
c: void 0,
|
|
1368
|
+
m: void 0,
|
|
1369
|
+
// Parse options first before the items
|
|
1370
|
+
d: void 0,
|
|
1371
|
+
a: void 0,
|
|
1372
|
+
f: await parseAsync(ctx, await current),
|
|
1373
|
+
b: void 0
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
async function generateObjectNode2(ctx, id, current, empty) {
|
|
1377
|
+
return {
|
|
1378
|
+
t: empty ? 11 /* NullConstructor */ : 10 /* Object */,
|
|
1379
|
+
i: id,
|
|
1380
|
+
s: void 0,
|
|
1381
|
+
l: void 0,
|
|
1382
|
+
c: void 0,
|
|
1383
|
+
m: void 0,
|
|
1384
|
+
d: await generateProperties2(ctx, current),
|
|
1385
|
+
a: void 0,
|
|
1386
|
+
f: void 0,
|
|
1387
|
+
b: void 0
|
|
1388
|
+
};
|
|
1389
|
+
}
|
|
1390
|
+
async function generateAggregateErrorNode2(ctx, id, current) {
|
|
1391
|
+
const options = getErrorOptions(ctx, current);
|
|
1392
|
+
const optionsNode = options ? await generateProperties2(ctx, options) : void 0;
|
|
1393
|
+
return {
|
|
1394
|
+
t: 14 /* AggregateError */,
|
|
1395
|
+
i: id,
|
|
1396
|
+
s: void 0,
|
|
1397
|
+
l: void 0,
|
|
1398
|
+
c: void 0,
|
|
1399
|
+
m: serializeString(current.message),
|
|
1400
|
+
d: optionsNode,
|
|
1401
|
+
a: void 0,
|
|
1402
|
+
f: void 0,
|
|
1403
|
+
b: void 0
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
async function generateErrorNode2(ctx, id, current) {
|
|
1407
|
+
const options = getErrorOptions(ctx, current);
|
|
1408
|
+
const optionsNode = options ? await generateProperties2(ctx, options) : void 0;
|
|
1409
|
+
return {
|
|
1410
|
+
t: 13 /* Error */,
|
|
1411
|
+
i: id,
|
|
1412
|
+
s: void 0,
|
|
1413
|
+
l: void 0,
|
|
1414
|
+
c: getErrorConstructorName(current),
|
|
1415
|
+
m: serializeString(current.message),
|
|
1416
|
+
d: optionsNode,
|
|
1417
|
+
a: void 0,
|
|
1418
|
+
f: void 0,
|
|
1419
|
+
b: void 0
|
|
1420
|
+
};
|
|
1421
|
+
}
|
|
1422
|
+
async function generateHeadersNode2(ctx, id, current) {
|
|
1423
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
1424
|
+
const items = {};
|
|
1425
|
+
current.forEach((value, key) => {
|
|
1426
|
+
items[key] = value;
|
|
1427
|
+
});
|
|
1428
|
+
return {
|
|
1429
|
+
t: 25 /* Headers */,
|
|
1430
|
+
i: id,
|
|
1431
|
+
s: void 0,
|
|
1432
|
+
l: void 0,
|
|
1433
|
+
c: void 0,
|
|
1434
|
+
m: void 0,
|
|
1435
|
+
d: await generatePlainProperties2(ctx, items),
|
|
1436
|
+
a: void 0,
|
|
1437
|
+
f: void 0,
|
|
1438
|
+
b: void 0
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1441
|
+
async function generateFormDataNode2(ctx, id, current) {
|
|
1442
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
1443
|
+
const items = {};
|
|
1444
|
+
current.forEach((value, key) => {
|
|
1445
|
+
items[key] = value;
|
|
1446
|
+
});
|
|
1447
|
+
return {
|
|
1448
|
+
t: 26 /* FormData */,
|
|
1449
|
+
i: id,
|
|
1450
|
+
s: void 0,
|
|
1451
|
+
l: void 0,
|
|
1452
|
+
c: void 0,
|
|
1453
|
+
m: void 0,
|
|
1454
|
+
d: await generatePlainProperties2(ctx, items),
|
|
1455
|
+
a: void 0,
|
|
1456
|
+
f: void 0,
|
|
1457
|
+
b: void 0
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
async function generateBoxedNode2(ctx, id, current) {
|
|
1461
|
+
return {
|
|
1462
|
+
t: 27 /* Boxed */,
|
|
1463
|
+
i: id,
|
|
1464
|
+
s: void 0,
|
|
1465
|
+
l: void 0,
|
|
1466
|
+
c: void 0,
|
|
1467
|
+
m: void 0,
|
|
1468
|
+
d: void 0,
|
|
1469
|
+
a: void 0,
|
|
1470
|
+
f: await parseAsync(ctx, current.valueOf()),
|
|
1471
|
+
b: void 0
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
async function parseObject2(ctx, current) {
|
|
1475
|
+
if (!current) {
|
|
1476
|
+
return NULL_NODE;
|
|
1477
|
+
}
|
|
1478
|
+
const id = createIndexedValue(ctx, current);
|
|
1479
|
+
if (ctx.markedRefs.has(id)) {
|
|
1480
|
+
return createIndexedValueNode(id);
|
|
1481
|
+
}
|
|
1482
|
+
if (hasReferenceID(current)) {
|
|
1483
|
+
return createReferenceNode(id, current);
|
|
1484
|
+
}
|
|
1485
|
+
if (Array.isArray(current)) {
|
|
1486
|
+
return generateArrayNode2(ctx, id, current);
|
|
1487
|
+
}
|
|
1488
|
+
switch (current.constructor) {
|
|
1489
|
+
case Number:
|
|
1490
|
+
case Boolean:
|
|
1491
|
+
case String:
|
|
1492
|
+
case BigInt:
|
|
1493
|
+
case Function:
|
|
1494
|
+
case Symbol:
|
|
1495
|
+
return generateBoxedNode2(ctx, id, current);
|
|
1496
|
+
case Date:
|
|
1497
|
+
return createDateNode(id, current);
|
|
1498
|
+
case RegExp:
|
|
1499
|
+
return createRegExpNode(id, current);
|
|
1500
|
+
case Promise:
|
|
1501
|
+
return generatePromiseNode(ctx, id, current);
|
|
1502
|
+
case ArrayBuffer:
|
|
1503
|
+
return createArrayBufferNode(id, current);
|
|
1504
|
+
case Int8Array:
|
|
1505
|
+
case Int16Array:
|
|
1506
|
+
case Int32Array:
|
|
1507
|
+
case Uint8Array:
|
|
1508
|
+
case Uint16Array:
|
|
1509
|
+
case Uint32Array:
|
|
1510
|
+
case Uint8ClampedArray:
|
|
1511
|
+
case Float32Array:
|
|
1512
|
+
case Float64Array:
|
|
1513
|
+
return createTypedArrayNode(ctx, id, current);
|
|
1514
|
+
case BigInt64Array:
|
|
1515
|
+
case BigUint64Array:
|
|
1516
|
+
return createBigIntTypedArrayNode(ctx, id, current);
|
|
1517
|
+
case DataView:
|
|
1518
|
+
return createDataViewNode(ctx, id, current);
|
|
1519
|
+
case Map:
|
|
1520
|
+
return generateMapNode2(
|
|
1521
|
+
ctx,
|
|
1522
|
+
id,
|
|
1523
|
+
current
|
|
1524
|
+
);
|
|
1525
|
+
case Set:
|
|
1526
|
+
return generateSetNode2(
|
|
1527
|
+
ctx,
|
|
1528
|
+
id,
|
|
1529
|
+
current
|
|
1530
|
+
);
|
|
1531
|
+
case Object:
|
|
1532
|
+
return generateObjectNode2(
|
|
1533
|
+
ctx,
|
|
1534
|
+
id,
|
|
1535
|
+
current,
|
|
1536
|
+
false
|
|
1537
|
+
);
|
|
1538
|
+
case void 0:
|
|
1539
|
+
return generateObjectNode2(
|
|
1540
|
+
ctx,
|
|
1541
|
+
id,
|
|
1542
|
+
current,
|
|
1543
|
+
true
|
|
1544
|
+
);
|
|
1545
|
+
case AggregateError:
|
|
1546
|
+
if (ctx.features & 1 /* AggregateError */) {
|
|
1547
|
+
return generateAggregateErrorNode2(ctx, id, current);
|
|
1548
|
+
}
|
|
1549
|
+
return generateErrorNode2(ctx, id, current);
|
|
1550
|
+
case Error:
|
|
1551
|
+
case EvalError:
|
|
1552
|
+
case RangeError:
|
|
1553
|
+
case ReferenceError:
|
|
1554
|
+
case SyntaxError:
|
|
1555
|
+
case TypeError:
|
|
1556
|
+
case URIError:
|
|
1557
|
+
return generateErrorNode2(ctx, id, current);
|
|
1558
|
+
case URL:
|
|
1559
|
+
return createURLNode(ctx, id, current);
|
|
1560
|
+
case URLSearchParams:
|
|
1561
|
+
return createURLSearchParamsNode(ctx, id, current);
|
|
1562
|
+
case Blob:
|
|
1563
|
+
return createBlobNode(ctx, id, current);
|
|
1564
|
+
case File:
|
|
1565
|
+
return createFileNode(ctx, id, current);
|
|
1566
|
+
case Headers:
|
|
1567
|
+
return generateHeadersNode2(ctx, id, current);
|
|
1568
|
+
case FormData:
|
|
1569
|
+
return generateFormDataNode2(ctx, id, current);
|
|
1570
|
+
default:
|
|
1571
|
+
break;
|
|
1572
|
+
}
|
|
1573
|
+
if (current instanceof AggregateError) {
|
|
1574
|
+
if (ctx.features & 1 /* AggregateError */) {
|
|
1575
|
+
return generateAggregateErrorNode2(ctx, id, current);
|
|
1576
|
+
}
|
|
1577
|
+
return generateErrorNode2(ctx, id, current);
|
|
1578
|
+
}
|
|
1579
|
+
if (current instanceof Error) {
|
|
1580
|
+
return generateErrorNode2(ctx, id, current);
|
|
1581
|
+
}
|
|
1582
|
+
if (current instanceof Promise) {
|
|
1583
|
+
return generatePromiseNode(ctx, id, current);
|
|
1584
|
+
}
|
|
1585
|
+
if (Symbol.iterator in current) {
|
|
1586
|
+
return generateObjectNode2(ctx, id, current, !!current.constructor);
|
|
1587
|
+
}
|
|
1588
|
+
throw new UnsupportedTypeError(current);
|
|
1589
|
+
}
|
|
1590
|
+
async function parseAsync(ctx, current) {
|
|
1591
|
+
switch (typeof current) {
|
|
1592
|
+
case "boolean":
|
|
1593
|
+
return current ? TRUE_NODE : FALSE_NODE;
|
|
1594
|
+
case "undefined":
|
|
1595
|
+
return UNDEFINED_NODE;
|
|
1596
|
+
case "string":
|
|
1597
|
+
return createStringNode(current);
|
|
1598
|
+
case "number":
|
|
1599
|
+
return createNumberNode(current);
|
|
1600
|
+
case "bigint":
|
|
1601
|
+
return createBigIntNode(ctx, current);
|
|
1602
|
+
case "object":
|
|
1603
|
+
return parseObject2(ctx, current);
|
|
1604
|
+
case "symbol":
|
|
1605
|
+
return createSymbolNode(ctx, current);
|
|
1606
|
+
case "function":
|
|
1607
|
+
return createFunctionNode(ctx, current);
|
|
1608
|
+
default:
|
|
1609
|
+
throw new UnsupportedTypeError(current);
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
// src/tree/deserialize.ts
|
|
1614
|
+
function assignIndexedValue(ctx, index, value) {
|
|
1615
|
+
if (ctx.markedRefs.has(index)) {
|
|
1616
|
+
ctx.valueMap.set(index, value);
|
|
1617
|
+
}
|
|
1618
|
+
return value;
|
|
1619
|
+
}
|
|
1620
|
+
function deserializeArray(ctx, node) {
|
|
1621
|
+
const len = node.l;
|
|
1622
|
+
const result = assignIndexedValue(
|
|
1623
|
+
ctx,
|
|
1624
|
+
node.i,
|
|
1625
|
+
new Array(len)
|
|
1626
|
+
);
|
|
1627
|
+
let item;
|
|
1628
|
+
for (let i = 0; i < len; i++) {
|
|
1629
|
+
item = node.a[i];
|
|
1630
|
+
if (item) {
|
|
1631
|
+
result[i] = deserializeTree(ctx, item);
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
return result;
|
|
1635
|
+
}
|
|
1636
|
+
function deserializeProperties(ctx, node, result) {
|
|
1637
|
+
const len = node.s;
|
|
1638
|
+
if (len) {
|
|
1639
|
+
let key;
|
|
1640
|
+
let value;
|
|
1641
|
+
const keys = node.k;
|
|
1642
|
+
const vals = node.v;
|
|
1643
|
+
for (let i = 0; i < len; i++) {
|
|
1644
|
+
key = keys[i];
|
|
1645
|
+
value = deserializeTree(ctx, vals[i]);
|
|
1646
|
+
switch (key) {
|
|
1647
|
+
case 0 /* SymbolIterator */:
|
|
1648
|
+
{
|
|
1649
|
+
const current = value;
|
|
1650
|
+
result[Symbol.iterator] = () => current.values();
|
|
1651
|
+
}
|
|
1652
|
+
break;
|
|
1653
|
+
default:
|
|
1654
|
+
result[deserializeString(key)] = value;
|
|
1655
|
+
break;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
return result;
|
|
1660
|
+
}
|
|
1661
|
+
function deserializeObject(ctx, node) {
|
|
1662
|
+
const result = assignIndexedValue(
|
|
1663
|
+
ctx,
|
|
1664
|
+
node.i,
|
|
1665
|
+
node.t === 10 /* Object */ ? {} : /* @__PURE__ */ Object.create(null)
|
|
1666
|
+
);
|
|
1667
|
+
deserializeProperties(ctx, node.d, result);
|
|
1246
1668
|
return result;
|
|
1247
1669
|
}
|
|
1248
1670
|
function deserializeSet(ctx, node) {
|
|
1249
1671
|
const result = assignIndexedValue(ctx, node.i, /* @__PURE__ */ new Set());
|
|
1672
|
+
const items = node.a;
|
|
1250
1673
|
for (let i = 0, len = node.l; i < len; i++) {
|
|
1251
|
-
result.add(deserializeTree(ctx,
|
|
1674
|
+
result.add(deserializeTree(ctx, items[i]));
|
|
1252
1675
|
}
|
|
1253
1676
|
return result;
|
|
1254
1677
|
}
|
|
@@ -1258,10 +1681,12 @@ function deserializeMap(ctx, node) {
|
|
|
1258
1681
|
node.i,
|
|
1259
1682
|
/* @__PURE__ */ new Map()
|
|
1260
1683
|
);
|
|
1684
|
+
const keys = node.d.k;
|
|
1685
|
+
const vals = node.d.v;
|
|
1261
1686
|
for (let i = 0, len = node.d.s; i < len; i++) {
|
|
1262
1687
|
result.set(
|
|
1263
|
-
deserializeTree(ctx,
|
|
1264
|
-
deserializeTree(ctx,
|
|
1688
|
+
deserializeTree(ctx, keys[i]),
|
|
1689
|
+
deserializeTree(ctx, vals[i])
|
|
1265
1690
|
);
|
|
1266
1691
|
}
|
|
1267
1692
|
return result;
|
|
@@ -1297,7 +1722,7 @@ function createDeferred() {
|
|
|
1297
1722
|
})
|
|
1298
1723
|
};
|
|
1299
1724
|
}
|
|
1300
|
-
function deserializePromise(ctx, node) {
|
|
1725
|
+
async function deserializePromise(ctx, node) {
|
|
1301
1726
|
const deferred = createDeferred();
|
|
1302
1727
|
const result = assignIndexedValue(ctx, node.i, deferred.promise);
|
|
1303
1728
|
deferred.resolve(deserializeTree(ctx, node.f));
|
|
@@ -1318,20 +1743,6 @@ function deserializeTypedArray(ctx, node) {
|
|
|
1318
1743
|
));
|
|
1319
1744
|
return result;
|
|
1320
1745
|
}
|
|
1321
|
-
function deserializeIterable(ctx, node) {
|
|
1322
|
-
const values = [];
|
|
1323
|
-
let item;
|
|
1324
|
-
for (let i = 0, len = node.l; i < len; i++) {
|
|
1325
|
-
item = node.a[i];
|
|
1326
|
-
if (item) {
|
|
1327
|
-
values[i] = deserializeTree(ctx, item);
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
const result = assignIndexedValue(ctx, node.i, {
|
|
1331
|
-
[Symbol.iterator]: () => values.values()
|
|
1332
|
-
});
|
|
1333
|
-
return deserializeDictionary(ctx, node, result);
|
|
1334
|
-
}
|
|
1335
1746
|
function deserializeDate(ctx, node) {
|
|
1336
1747
|
return assignIndexedValue(ctx, node.i, new Date(node.s));
|
|
1337
1748
|
}
|
|
@@ -1375,94 +1786,93 @@ function deserializeFile(ctx, node) {
|
|
|
1375
1786
|
}
|
|
1376
1787
|
function deserializeHeaders(ctx, node) {
|
|
1377
1788
|
const result = assignIndexedValue(ctx, node.i, new Headers());
|
|
1789
|
+
const keys = node.d.k;
|
|
1790
|
+
const vals = node.d.v;
|
|
1378
1791
|
for (let i = 0, len = node.d.s; i < len; i++) {
|
|
1379
1792
|
result.set(
|
|
1380
|
-
deserializeString(
|
|
1381
|
-
deserializeTree(ctx,
|
|
1793
|
+
deserializeString(keys[i]),
|
|
1794
|
+
deserializeTree(ctx, vals[i])
|
|
1382
1795
|
);
|
|
1383
1796
|
}
|
|
1384
1797
|
return result;
|
|
1385
1798
|
}
|
|
1386
1799
|
function deserializeFormData(ctx, node) {
|
|
1387
1800
|
const result = assignIndexedValue(ctx, node.i, new FormData());
|
|
1801
|
+
const keys = node.d.k;
|
|
1802
|
+
const vals = node.d.v;
|
|
1388
1803
|
for (let i = 0, len = node.d.s; i < len; i++) {
|
|
1389
1804
|
result.set(
|
|
1390
|
-
deserializeString(
|
|
1391
|
-
deserializeTree(ctx,
|
|
1805
|
+
deserializeString(keys[i]),
|
|
1806
|
+
deserializeTree(ctx, vals[i])
|
|
1392
1807
|
);
|
|
1393
1808
|
}
|
|
1394
1809
|
return result;
|
|
1395
1810
|
}
|
|
1811
|
+
function deserializeBoxed(ctx, node) {
|
|
1812
|
+
return assignIndexedValue(
|
|
1813
|
+
ctx,
|
|
1814
|
+
node.i,
|
|
1815
|
+
Object(deserializeTree(ctx, node.f))
|
|
1816
|
+
);
|
|
1817
|
+
}
|
|
1396
1818
|
function deserializeTree(ctx, node) {
|
|
1397
1819
|
switch (node.t) {
|
|
1820
|
+
case 2 /* Constant */:
|
|
1821
|
+
return deserializeConstant(node);
|
|
1398
1822
|
case 0 /* Number */:
|
|
1399
|
-
case 2 /* Boolean */:
|
|
1400
1823
|
return node.s;
|
|
1401
1824
|
case 1 /* String */:
|
|
1402
1825
|
return deserializeString(node.s);
|
|
1403
|
-
case
|
|
1404
|
-
return void 0;
|
|
1405
|
-
case 3 /* Null */:
|
|
1406
|
-
return null;
|
|
1407
|
-
case 5 /* NegativeZero */:
|
|
1408
|
-
return -0;
|
|
1409
|
-
case 6 /* Infinity */:
|
|
1410
|
-
return Infinity;
|
|
1411
|
-
case 7 /* NegativeInfinity */:
|
|
1412
|
-
return -Infinity;
|
|
1413
|
-
case 8 /* NaN */:
|
|
1414
|
-
return NaN;
|
|
1415
|
-
case 9 /* BigInt */:
|
|
1826
|
+
case 3 /* BigInt */:
|
|
1416
1827
|
return BigInt(node.s);
|
|
1417
|
-
case
|
|
1828
|
+
case 4 /* IndexedValue */:
|
|
1418
1829
|
return ctx.valueMap.get(node.i);
|
|
1419
|
-
case
|
|
1830
|
+
case 9 /* Array */:
|
|
1420
1831
|
return deserializeArray(ctx, node);
|
|
1421
|
-
case
|
|
1832
|
+
case 10 /* Object */:
|
|
1833
|
+
case 11 /* NullConstructor */:
|
|
1422
1834
|
return deserializeObject(ctx, node);
|
|
1423
|
-
case
|
|
1424
|
-
return deserializeNullConstructor(ctx, node);
|
|
1425
|
-
case 11 /* Date */:
|
|
1835
|
+
case 5 /* Date */:
|
|
1426
1836
|
return deserializeDate(ctx, node);
|
|
1427
|
-
case
|
|
1837
|
+
case 6 /* RegExp */:
|
|
1428
1838
|
return deserializeRegExp(ctx, node);
|
|
1429
|
-
case
|
|
1839
|
+
case 7 /* Set */:
|
|
1430
1840
|
return deserializeSet(ctx, node);
|
|
1431
|
-
case
|
|
1841
|
+
case 8 /* Map */:
|
|
1432
1842
|
return deserializeMap(ctx, node);
|
|
1433
|
-
case
|
|
1843
|
+
case 21 /* ArrayBuffer */:
|
|
1434
1844
|
return deserializeArrayBuffer(ctx, node);
|
|
1435
|
-
case
|
|
1436
|
-
case
|
|
1845
|
+
case 16 /* BigIntTypedArray */:
|
|
1846
|
+
case 15 /* TypedArray */:
|
|
1437
1847
|
return deserializeTypedArray(ctx, node);
|
|
1438
|
-
case
|
|
1848
|
+
case 22 /* DataView */:
|
|
1439
1849
|
return deserializeDataView(ctx, node);
|
|
1440
|
-
case
|
|
1850
|
+
case 14 /* AggregateError */:
|
|
1441
1851
|
return deserializeAggregateError(ctx, node);
|
|
1442
|
-
case
|
|
1852
|
+
case 13 /* Error */:
|
|
1443
1853
|
return deserializeError(ctx, node);
|
|
1444
|
-
case
|
|
1445
|
-
return deserializeIterable(ctx, node);
|
|
1446
|
-
case 18 /* Promise */:
|
|
1854
|
+
case 12 /* Promise */:
|
|
1447
1855
|
return deserializePromise(ctx, node);
|
|
1448
|
-
case
|
|
1856
|
+
case 17 /* WKSymbol */:
|
|
1449
1857
|
return SYMBOL_REF[node.s];
|
|
1450
|
-
case
|
|
1858
|
+
case 18 /* URL */:
|
|
1451
1859
|
return deserializeURL(ctx, node);
|
|
1452
|
-
case
|
|
1860
|
+
case 19 /* URLSearchParams */:
|
|
1453
1861
|
return deserializeURLSearchParams(ctx, node);
|
|
1454
|
-
case
|
|
1862
|
+
case 20 /* Reference */:
|
|
1455
1863
|
return deserializeReference(ctx, node);
|
|
1456
|
-
case
|
|
1864
|
+
case 23 /* Blob */:
|
|
1457
1865
|
return deserializeBlob(ctx, node);
|
|
1458
|
-
case
|
|
1866
|
+
case 24 /* File */:
|
|
1459
1867
|
return deserializeFile(ctx, node);
|
|
1460
|
-
case
|
|
1868
|
+
case 25 /* Headers */:
|
|
1461
1869
|
return deserializeHeaders(ctx, node);
|
|
1462
|
-
case
|
|
1870
|
+
case 26 /* FormData */:
|
|
1463
1871
|
return deserializeFormData(ctx, node);
|
|
1872
|
+
case 27 /* Boxed */:
|
|
1873
|
+
return deserializeBoxed(ctx, node);
|
|
1464
1874
|
default:
|
|
1465
|
-
throw new Error("
|
|
1875
|
+
throw new Error("invariant");
|
|
1466
1876
|
}
|
|
1467
1877
|
}
|
|
1468
1878
|
|
|
@@ -1605,22 +2015,24 @@ function assignIndexedValue2(ctx, index, value) {
|
|
|
1605
2015
|
return value;
|
|
1606
2016
|
}
|
|
1607
2017
|
function isIndexedValueInStack(ctx, node) {
|
|
1608
|
-
return node.t ===
|
|
2018
|
+
return node.t === 4 /* IndexedValue */ && ctx.stack.includes(node.i);
|
|
1609
2019
|
}
|
|
1610
|
-
function
|
|
1611
|
-
const
|
|
2020
|
+
function serializeArray(ctx, node) {
|
|
2021
|
+
const id = node.i;
|
|
2022
|
+
ctx.stack.push(id);
|
|
1612
2023
|
let values = "";
|
|
1613
2024
|
let item;
|
|
1614
2025
|
let isHoley = false;
|
|
1615
|
-
|
|
2026
|
+
const list = node.a;
|
|
2027
|
+
for (let i = 0, len = node.l; i < len; i++) {
|
|
1616
2028
|
if (i !== 0) {
|
|
1617
2029
|
values += ",";
|
|
1618
2030
|
}
|
|
1619
|
-
item =
|
|
2031
|
+
item = list[i];
|
|
1620
2032
|
if (item) {
|
|
1621
2033
|
if (isIndexedValueInStack(ctx, item)) {
|
|
1622
|
-
markRef(ctx,
|
|
1623
|
-
createArrayAssign(ctx,
|
|
2034
|
+
markRef(ctx, id);
|
|
2035
|
+
createArrayAssign(ctx, id, i, getRefParam(ctx, item.i));
|
|
1624
2036
|
isHoley = true;
|
|
1625
2037
|
} else {
|
|
1626
2038
|
values += serializeTree(ctx, item);
|
|
@@ -1630,16 +2042,29 @@ function serializeNodeList(ctx, node) {
|
|
|
1630
2042
|
isHoley = true;
|
|
1631
2043
|
}
|
|
1632
2044
|
}
|
|
1633
|
-
return "[" + values + (isHoley ? ",]" : "]");
|
|
1634
|
-
}
|
|
1635
|
-
function serializeArray(ctx, node) {
|
|
1636
|
-
ctx.stack.push(node.i);
|
|
1637
|
-
const result = serializeNodeList(ctx, node);
|
|
1638
2045
|
ctx.stack.pop();
|
|
1639
|
-
return assignIndexedValue2(ctx,
|
|
2046
|
+
return assignIndexedValue2(ctx, id, "[" + values + (isHoley ? ",]" : "]"));
|
|
2047
|
+
}
|
|
2048
|
+
function getIterableAccess(ctx) {
|
|
2049
|
+
return ctx.features & 2 /* ArrayPrototypeValues */ ? ".values()" : "[Symbol.iterator]()";
|
|
2050
|
+
}
|
|
2051
|
+
function serializeIterable(ctx, node) {
|
|
2052
|
+
const parent = ctx.stack;
|
|
2053
|
+
ctx.stack = [];
|
|
2054
|
+
let serialized = serializeTree(ctx, node) + getIterableAccess(ctx);
|
|
2055
|
+
ctx.stack = parent;
|
|
2056
|
+
if (ctx.features & 4 /* ArrowFunction */) {
|
|
2057
|
+
serialized = "[Symbol.iterator]:()=>" + serialized;
|
|
2058
|
+
} else if (ctx.features & 64 /* MethodShorthand */) {
|
|
2059
|
+
serialized = "[Symbol.iterator](){return " + serialized + "}";
|
|
2060
|
+
} else {
|
|
2061
|
+
serialized = "[Symbol.iterator]:function(){return " + serialized + "}";
|
|
2062
|
+
}
|
|
2063
|
+
return serialized;
|
|
1640
2064
|
}
|
|
1641
2065
|
function serializeProperties(ctx, sourceID, node) {
|
|
1642
|
-
|
|
2066
|
+
const len = node.s;
|
|
2067
|
+
if (len === 0) {
|
|
1643
2068
|
return "{}";
|
|
1644
2069
|
}
|
|
1645
2070
|
let result = "";
|
|
@@ -1652,23 +2077,30 @@ function serializeProperties(ctx, sourceID, node) {
|
|
|
1652
2077
|
let hasPrev = false;
|
|
1653
2078
|
const keys = node.k;
|
|
1654
2079
|
const values = node.v;
|
|
1655
|
-
for (let i = 0
|
|
2080
|
+
for (let i = 0; i < len; i++) {
|
|
1656
2081
|
key = keys[i];
|
|
1657
2082
|
val = values[i];
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
2083
|
+
switch (key) {
|
|
2084
|
+
case 0 /* SymbolIterator */:
|
|
2085
|
+
result += (hasPrev ? "," : "") + serializeIterable(ctx, val);
|
|
2086
|
+
hasPrev = true;
|
|
2087
|
+
break;
|
|
2088
|
+
default:
|
|
2089
|
+
check = Number(key);
|
|
2090
|
+
isIdentifier = check >= 0 || isValidIdentifier(key);
|
|
2091
|
+
if (isIndexedValueInStack(ctx, val)) {
|
|
2092
|
+
refParam = getRefParam(ctx, val.i);
|
|
2093
|
+
markRef(ctx, sourceID);
|
|
2094
|
+
if (isIdentifier && Number.isNaN(check)) {
|
|
2095
|
+
createObjectAssign(ctx, sourceID, key, refParam);
|
|
2096
|
+
} else {
|
|
2097
|
+
createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + key + '"', refParam);
|
|
2098
|
+
}
|
|
2099
|
+
} else {
|
|
2100
|
+
result += (hasPrev ? "," : "") + (isIdentifier ? key : '"' + key + '"') + ":" + serializeTree(ctx, val);
|
|
2101
|
+
hasPrev = true;
|
|
2102
|
+
}
|
|
2103
|
+
break;
|
|
1672
2104
|
}
|
|
1673
2105
|
}
|
|
1674
2106
|
ctx.stack.pop();
|
|
@@ -1684,28 +2116,41 @@ function serializeWithObjectAssign(ctx, value, id, serialized) {
|
|
|
1684
2116
|
function serializeAssignments(ctx, sourceID, node) {
|
|
1685
2117
|
ctx.stack.push(sourceID);
|
|
1686
2118
|
const mainAssignments = [];
|
|
1687
|
-
let parentStack;
|
|
1688
|
-
let refParam;
|
|
1689
2119
|
let key;
|
|
1690
|
-
let
|
|
2120
|
+
let value;
|
|
1691
2121
|
let parentAssignment;
|
|
1692
|
-
let isIdentifier;
|
|
1693
2122
|
const keys = node.k;
|
|
1694
2123
|
const values = node.v;
|
|
1695
2124
|
for (let i = 0, len = node.s; i < len; i++) {
|
|
1696
|
-
parentStack = ctx.stack;
|
|
1697
|
-
ctx.stack = [];
|
|
1698
|
-
refParam = serializeTree(ctx, values[i]);
|
|
1699
|
-
ctx.stack = parentStack;
|
|
1700
2125
|
key = keys[i];
|
|
1701
|
-
|
|
2126
|
+
value = values[i];
|
|
1702
2127
|
parentAssignment = ctx.assignments;
|
|
1703
2128
|
ctx.assignments = mainAssignments;
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
2129
|
+
switch (key) {
|
|
2130
|
+
case 0 /* SymbolIterator */:
|
|
2131
|
+
{
|
|
2132
|
+
const parent = ctx.stack;
|
|
2133
|
+
ctx.stack = [];
|
|
2134
|
+
const serialized = serializeTree(ctx, value) + getIterableAccess(ctx);
|
|
2135
|
+
ctx.stack = parent;
|
|
2136
|
+
createArrayAssign(
|
|
2137
|
+
ctx,
|
|
2138
|
+
sourceID,
|
|
2139
|
+
"Symbol.iterator",
|
|
2140
|
+
ctx.features & 4 /* ArrowFunction */ ? "()=>" + serialized : "function(){return " + serialized + "}"
|
|
2141
|
+
);
|
|
2142
|
+
}
|
|
2143
|
+
break;
|
|
2144
|
+
default: {
|
|
2145
|
+
const serialized = serializeTree(ctx, value);
|
|
2146
|
+
const check = Number(key);
|
|
2147
|
+
const isIdentifier = check >= 0 || isValidIdentifier(key);
|
|
2148
|
+
if (isIdentifier && Number.isNaN(check)) {
|
|
2149
|
+
createObjectAssign(ctx, sourceID, key, serialized);
|
|
2150
|
+
} else {
|
|
2151
|
+
createArrayAssign(ctx, sourceID, isIdentifier ? key : '"' + key + '"', serialized);
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
1709
2154
|
}
|
|
1710
2155
|
ctx.assignments = parentAssignment;
|
|
1711
2156
|
}
|
|
@@ -1726,8 +2171,9 @@ function serializeDictionary(ctx, i, d, init) {
|
|
|
1726
2171
|
}
|
|
1727
2172
|
return assignIndexedValue2(ctx, i, init);
|
|
1728
2173
|
}
|
|
2174
|
+
var NULL_CONSTRUCTOR = "Object.create(null)";
|
|
1729
2175
|
function serializeNullConstructor(ctx, node) {
|
|
1730
|
-
return serializeDictionary(ctx, node.i, node.d,
|
|
2176
|
+
return serializeDictionary(ctx, node.i, node.d, NULL_CONSTRUCTOR);
|
|
1731
2177
|
}
|
|
1732
2178
|
function serializeObject(ctx, node) {
|
|
1733
2179
|
return assignIndexedValue2(ctx, node.i, serializeProperties(ctx, node.i, node.d));
|
|
@@ -1735,16 +2181,18 @@ function serializeObject(ctx, node) {
|
|
|
1735
2181
|
function serializeSet(ctx, node) {
|
|
1736
2182
|
let serialized = "new Set";
|
|
1737
2183
|
const size = node.l;
|
|
2184
|
+
const id = node.i;
|
|
1738
2185
|
if (size) {
|
|
1739
2186
|
let result = "";
|
|
1740
|
-
ctx.stack.push(node.i);
|
|
1741
2187
|
let item;
|
|
1742
2188
|
let hasPrev = false;
|
|
2189
|
+
const items = node.a;
|
|
2190
|
+
ctx.stack.push(id);
|
|
1743
2191
|
for (let i = 0; i < size; i++) {
|
|
1744
|
-
item =
|
|
2192
|
+
item = items[i];
|
|
1745
2193
|
if (isIndexedValueInStack(ctx, item)) {
|
|
1746
|
-
markRef(ctx,
|
|
1747
|
-
createAddAssignment(ctx,
|
|
2194
|
+
markRef(ctx, id);
|
|
2195
|
+
createAddAssignment(ctx, id, getRefParam(ctx, item.i));
|
|
1748
2196
|
} else {
|
|
1749
2197
|
result += (hasPrev ? "," : "") + serializeTree(ctx, item);
|
|
1750
2198
|
hasPrev = true;
|
|
@@ -1755,40 +2203,44 @@ function serializeSet(ctx, node) {
|
|
|
1755
2203
|
serialized += "([" + result + "])";
|
|
1756
2204
|
}
|
|
1757
2205
|
}
|
|
1758
|
-
return assignIndexedValue2(ctx,
|
|
2206
|
+
return assignIndexedValue2(ctx, id, serialized);
|
|
1759
2207
|
}
|
|
1760
2208
|
function serializeMap(ctx, node) {
|
|
1761
2209
|
let serialized = "new Map";
|
|
1762
|
-
|
|
2210
|
+
const size = node.d.s;
|
|
2211
|
+
const id = node.i;
|
|
2212
|
+
if (size) {
|
|
1763
2213
|
let result = "";
|
|
1764
|
-
ctx.stack.push(node.i);
|
|
1765
2214
|
let key;
|
|
1766
2215
|
let val;
|
|
1767
2216
|
let keyRef;
|
|
1768
2217
|
let valueRef;
|
|
1769
2218
|
let parent;
|
|
1770
2219
|
let hasPrev = false;
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
2220
|
+
const keys = node.d.k;
|
|
2221
|
+
const vals = node.d.v;
|
|
2222
|
+
ctx.stack.push(id);
|
|
2223
|
+
for (let i = 0; i < size; i++) {
|
|
2224
|
+
key = keys[i];
|
|
2225
|
+
val = vals[i];
|
|
1774
2226
|
if (isIndexedValueInStack(ctx, key)) {
|
|
1775
|
-
keyRef = getRefParam(ctx,
|
|
1776
|
-
markRef(ctx,
|
|
2227
|
+
keyRef = getRefParam(ctx, id);
|
|
2228
|
+
markRef(ctx, id);
|
|
1777
2229
|
if (isIndexedValueInStack(ctx, val)) {
|
|
1778
2230
|
valueRef = getRefParam(ctx, val.i);
|
|
1779
|
-
createSetAssignment(ctx,
|
|
2231
|
+
createSetAssignment(ctx, id, keyRef, valueRef);
|
|
1780
2232
|
} else {
|
|
1781
2233
|
parent = ctx.stack;
|
|
1782
2234
|
ctx.stack = [];
|
|
1783
|
-
createSetAssignment(ctx,
|
|
2235
|
+
createSetAssignment(ctx, id, keyRef, serializeTree(ctx, val));
|
|
1784
2236
|
ctx.stack = parent;
|
|
1785
2237
|
}
|
|
1786
2238
|
} else if (isIndexedValueInStack(ctx, val)) {
|
|
1787
2239
|
valueRef = getRefParam(ctx, val.i);
|
|
1788
|
-
markRef(ctx,
|
|
2240
|
+
markRef(ctx, id);
|
|
1789
2241
|
parent = ctx.stack;
|
|
1790
2242
|
ctx.stack = [];
|
|
1791
|
-
createSetAssignment(ctx,
|
|
2243
|
+
createSetAssignment(ctx, id, serializeTree(ctx, key), valueRef);
|
|
1792
2244
|
ctx.stack = parent;
|
|
1793
2245
|
} else {
|
|
1794
2246
|
result += (hasPrev ? ",[" : "[") + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
|
|
@@ -1800,69 +2252,56 @@ function serializeMap(ctx, node) {
|
|
|
1800
2252
|
serialized += "([" + result + "])";
|
|
1801
2253
|
}
|
|
1802
2254
|
}
|
|
1803
|
-
return assignIndexedValue2(ctx,
|
|
2255
|
+
return assignIndexedValue2(ctx, id, serialized);
|
|
1804
2256
|
}
|
|
1805
2257
|
function serializeAggregateError(ctx, node) {
|
|
1806
|
-
|
|
2258
|
+
const id = node.i;
|
|
2259
|
+
ctx.stack.push(id);
|
|
1807
2260
|
const serialized = 'new AggregateError([],"' + node.m + '")';
|
|
1808
2261
|
ctx.stack.pop();
|
|
1809
|
-
return serializeDictionary(ctx,
|
|
2262
|
+
return serializeDictionary(ctx, id, node.d, serialized);
|
|
1810
2263
|
}
|
|
1811
2264
|
function serializeError(ctx, node) {
|
|
1812
|
-
|
|
1813
|
-
return serializeDictionary(ctx, node.i, node.d, serialized);
|
|
2265
|
+
return serializeDictionary(ctx, node.i, node.d, "new " + node.c + '("' + node.m + '")');
|
|
1814
2266
|
}
|
|
1815
2267
|
function serializePromise(ctx, node) {
|
|
1816
2268
|
let serialized;
|
|
1817
|
-
|
|
1818
|
-
|
|
2269
|
+
const fulfilled = node.f;
|
|
2270
|
+
const id = node.i;
|
|
2271
|
+
if (isIndexedValueInStack(ctx, fulfilled)) {
|
|
2272
|
+
const ref = getRefParam(ctx, fulfilled.i);
|
|
1819
2273
|
if (ctx.features & 4 /* ArrowFunction */) {
|
|
1820
2274
|
serialized = "Promise.resolve().then(()=>" + ref + ")";
|
|
1821
2275
|
} else {
|
|
1822
2276
|
serialized = "Promise.resolve().then(function(){return " + ref + "})";
|
|
1823
2277
|
}
|
|
1824
2278
|
} else {
|
|
1825
|
-
ctx.stack.push(
|
|
1826
|
-
const result = serializeTree(ctx,
|
|
2279
|
+
ctx.stack.push(id);
|
|
2280
|
+
const result = serializeTree(ctx, fulfilled);
|
|
1827
2281
|
ctx.stack.pop();
|
|
1828
2282
|
serialized = "Promise.resolve(" + result + ")";
|
|
1829
2283
|
}
|
|
1830
|
-
return assignIndexedValue2(ctx,
|
|
2284
|
+
return assignIndexedValue2(ctx, id, serialized);
|
|
1831
2285
|
}
|
|
1832
2286
|
function serializeArrayBuffer2(ctx, node) {
|
|
1833
2287
|
let result = "new Uint8Array(";
|
|
1834
|
-
|
|
2288
|
+
const buffer = node.s;
|
|
2289
|
+
const len = buffer.length;
|
|
2290
|
+
if (len) {
|
|
1835
2291
|
result += "[";
|
|
1836
|
-
for (let i = 0
|
|
1837
|
-
result += (i > 0 ? "," : "") +
|
|
2292
|
+
for (let i = 0; i < len; i++) {
|
|
2293
|
+
result += (i > 0 ? "," : "") + buffer[i];
|
|
1838
2294
|
}
|
|
1839
2295
|
result += "]";
|
|
1840
2296
|
}
|
|
1841
2297
|
return assignIndexedValue2(ctx, node.i, result + ").buffer");
|
|
1842
2298
|
}
|
|
1843
2299
|
function serializeTypedArray(ctx, node) {
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
ctx.stack = [];
|
|
1850
|
-
const values = serializeNodeList(ctx, node);
|
|
1851
|
-
ctx.stack = parent;
|
|
1852
|
-
let serialized = values;
|
|
1853
|
-
if (ctx.features & 2 /* ArrayPrototypeValues */) {
|
|
1854
|
-
serialized += ".values()";
|
|
1855
|
-
} else {
|
|
1856
|
-
serialized += "[Symbol.iterator]()";
|
|
1857
|
-
}
|
|
1858
|
-
if (ctx.features & 4 /* ArrowFunction */) {
|
|
1859
|
-
serialized = "{[Symbol.iterator]:()=>" + serialized + "}";
|
|
1860
|
-
} else if (ctx.features & 64 /* MethodShorthand */) {
|
|
1861
|
-
serialized = "{[Symbol.iterator](){return " + serialized + "}}";
|
|
1862
|
-
} else {
|
|
1863
|
-
serialized = "{[Symbol.iterator]:function(){return " + serialized + "}}";
|
|
1864
|
-
}
|
|
1865
|
-
return serializeDictionary(ctx, node.i, node.d, serialized);
|
|
2300
|
+
return assignIndexedValue2(
|
|
2301
|
+
ctx,
|
|
2302
|
+
node.i,
|
|
2303
|
+
"new " + node.c + "(" + serializeTree(ctx, node.f) + "," + node.b + "," + node.l + ")"
|
|
2304
|
+
);
|
|
1866
2305
|
}
|
|
1867
2306
|
function serializeDate(ctx, node) {
|
|
1868
2307
|
return assignIndexedValue2(ctx, node.i, 'new Date("' + node.s + '")');
|
|
@@ -1874,518 +2313,143 @@ function serializeURL(ctx, node) {
|
|
|
1874
2313
|
return assignIndexedValue2(ctx, node.i, 'new URL("' + node.s + '")');
|
|
1875
2314
|
}
|
|
1876
2315
|
function serializeURLSearchParams(ctx, node) {
|
|
1877
|
-
return assignIndexedValue2(
|
|
2316
|
+
return assignIndexedValue2(
|
|
2317
|
+
ctx,
|
|
2318
|
+
node.i,
|
|
2319
|
+
node.s ? 'new URLSearchParams("' + node.s + '")' : "new URLSearchParams"
|
|
2320
|
+
);
|
|
1878
2321
|
}
|
|
1879
2322
|
function serializeReference(ctx, node) {
|
|
1880
2323
|
return assignIndexedValue2(ctx, node.i, GLOBAL_KEY + '.get("' + node.s + '")');
|
|
1881
2324
|
}
|
|
1882
2325
|
function serializeDataView(ctx, node) {
|
|
1883
|
-
|
|
1884
|
-
|
|
2326
|
+
return assignIndexedValue2(
|
|
2327
|
+
ctx,
|
|
2328
|
+
node.i,
|
|
2329
|
+
"new DataView(" + serializeTree(ctx, node.f) + "," + node.b + "," + node.l + ")"
|
|
2330
|
+
);
|
|
1885
2331
|
}
|
|
1886
2332
|
function serializeBlob(ctx, node) {
|
|
1887
|
-
|
|
1888
|
-
|
|
2333
|
+
return assignIndexedValue2(
|
|
2334
|
+
ctx,
|
|
2335
|
+
node.i,
|
|
2336
|
+
"new Blob([" + serializeTree(ctx, node.f) + '],{type:"' + node.c + '"})'
|
|
2337
|
+
);
|
|
1889
2338
|
}
|
|
1890
2339
|
function serializeFile(ctx, node) {
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
2340
|
+
return assignIndexedValue2(
|
|
2341
|
+
ctx,
|
|
2342
|
+
node.i,
|
|
2343
|
+
"new File([" + serializeTree(ctx, node.f) + '],"' + node.m + '",{type:"' + node.c + '",lastModified:' + node.b + "})"
|
|
2344
|
+
);
|
|
1894
2345
|
}
|
|
1895
2346
|
function serializeHeaders(ctx, node) {
|
|
1896
|
-
return assignIndexedValue2(
|
|
2347
|
+
return assignIndexedValue2(
|
|
2348
|
+
ctx,
|
|
2349
|
+
node.i,
|
|
2350
|
+
"new Headers(" + serializeProperties(ctx, node.i, node.d) + ")"
|
|
2351
|
+
);
|
|
1897
2352
|
}
|
|
1898
2353
|
function serializeFormDataEntries(ctx, node) {
|
|
1899
|
-
ctx.stack.push(node.i);
|
|
1900
|
-
const mainAssignments = [];
|
|
1901
|
-
let parentStack;
|
|
1902
2354
|
let value;
|
|
1903
2355
|
let key;
|
|
2356
|
+
const keys = node.d.k;
|
|
2357
|
+
const vals = node.d.v;
|
|
2358
|
+
const id = node.i;
|
|
2359
|
+
const mainAssignments = [];
|
|
1904
2360
|
let parentAssignment;
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
value = serializeTree(ctx,
|
|
1909
|
-
key = node.d.k[i];
|
|
1910
|
-
ctx.stack = parentStack;
|
|
2361
|
+
ctx.stack.push(id);
|
|
2362
|
+
for (let i = 0, len = node.d.s; i < len; i++) {
|
|
2363
|
+
key = keys[i];
|
|
2364
|
+
value = serializeTree(ctx, vals[i]);
|
|
1911
2365
|
parentAssignment = ctx.assignments;
|
|
1912
2366
|
ctx.assignments = mainAssignments;
|
|
1913
|
-
createAppendAssignment(ctx,
|
|
2367
|
+
createAppendAssignment(ctx, id, '"' + key + '"', value);
|
|
1914
2368
|
ctx.assignments = parentAssignment;
|
|
1915
2369
|
}
|
|
1916
2370
|
ctx.stack.pop();
|
|
1917
2371
|
return resolveAssignments(mainAssignments);
|
|
1918
2372
|
}
|
|
1919
2373
|
function serializeFormData(ctx, node) {
|
|
1920
|
-
|
|
1921
|
-
|
|
2374
|
+
const size = node.d.s;
|
|
2375
|
+
const id = node.i;
|
|
2376
|
+
if (size) {
|
|
2377
|
+
markRef(ctx, id);
|
|
1922
2378
|
}
|
|
1923
|
-
const result = assignIndexedValue2(ctx,
|
|
1924
|
-
if (
|
|
1925
|
-
|
|
2379
|
+
const result = assignIndexedValue2(ctx, id, "new FormData()");
|
|
2380
|
+
if (size) {
|
|
2381
|
+
const entries = serializeFormDataEntries(ctx, node);
|
|
2382
|
+
return "(" + result + "," + (entries == null ? "" : entries) + getRefParam(ctx, id) + ")";
|
|
1926
2383
|
}
|
|
1927
2384
|
return result;
|
|
1928
2385
|
}
|
|
2386
|
+
function serializeBoxed(ctx, node) {
|
|
2387
|
+
return assignIndexedValue2(ctx, node.i, "Object(" + serializeTree(ctx, node.f) + ")");
|
|
2388
|
+
}
|
|
2389
|
+
function serializeWKSymbol(ctx, node) {
|
|
2390
|
+
return assignIndexedValue2(ctx, node.i, SYMBOL_STRING[node.s]);
|
|
2391
|
+
}
|
|
1929
2392
|
function serializeTree(ctx, node) {
|
|
1930
2393
|
switch (node.t) {
|
|
1931
2394
|
case 0 /* Number */:
|
|
1932
2395
|
return "" + node.s;
|
|
1933
2396
|
case 1 /* String */:
|
|
1934
2397
|
return '"' + node.s + '"';
|
|
1935
|
-
case 2 /*
|
|
1936
|
-
return node
|
|
1937
|
-
case
|
|
1938
|
-
return "void 0";
|
|
1939
|
-
case 3 /* Null */:
|
|
1940
|
-
return "null";
|
|
1941
|
-
case 5 /* NegativeZero */:
|
|
1942
|
-
return "-0";
|
|
1943
|
-
case 6 /* Infinity */:
|
|
1944
|
-
return "1/0";
|
|
1945
|
-
case 7 /* NegativeInfinity */:
|
|
1946
|
-
return "-1/0";
|
|
1947
|
-
case 8 /* NaN */:
|
|
1948
|
-
return "NaN";
|
|
1949
|
-
case 9 /* BigInt */:
|
|
2398
|
+
case 2 /* Constant */:
|
|
2399
|
+
return serializeConstant(node);
|
|
2400
|
+
case 3 /* BigInt */:
|
|
1950
2401
|
return node.s + "n";
|
|
1951
|
-
case
|
|
2402
|
+
case 4 /* IndexedValue */:
|
|
1952
2403
|
return getRefParam(ctx, node.i);
|
|
1953
|
-
case
|
|
2404
|
+
case 9 /* Array */:
|
|
1954
2405
|
return serializeArray(ctx, node);
|
|
1955
|
-
case
|
|
2406
|
+
case 10 /* Object */:
|
|
1956
2407
|
return serializeObject(ctx, node);
|
|
1957
|
-
case
|
|
2408
|
+
case 11 /* NullConstructor */:
|
|
1958
2409
|
return serializeNullConstructor(ctx, node);
|
|
1959
|
-
case
|
|
2410
|
+
case 5 /* Date */:
|
|
1960
2411
|
return serializeDate(ctx, node);
|
|
1961
|
-
case
|
|
2412
|
+
case 6 /* RegExp */:
|
|
1962
2413
|
return serializeRegExp(ctx, node);
|
|
1963
|
-
case
|
|
2414
|
+
case 7 /* Set */:
|
|
1964
2415
|
return serializeSet(ctx, node);
|
|
1965
|
-
case
|
|
2416
|
+
case 8 /* Map */:
|
|
1966
2417
|
return serializeMap(ctx, node);
|
|
1967
|
-
case
|
|
2418
|
+
case 21 /* ArrayBuffer */:
|
|
1968
2419
|
return serializeArrayBuffer2(ctx, node);
|
|
1969
|
-
case
|
|
1970
|
-
case
|
|
2420
|
+
case 16 /* BigIntTypedArray */:
|
|
2421
|
+
case 15 /* TypedArray */:
|
|
1971
2422
|
return serializeTypedArray(ctx, node);
|
|
1972
|
-
case
|
|
2423
|
+
case 22 /* DataView */:
|
|
1973
2424
|
return serializeDataView(ctx, node);
|
|
1974
|
-
case
|
|
2425
|
+
case 14 /* AggregateError */:
|
|
1975
2426
|
return serializeAggregateError(ctx, node);
|
|
1976
|
-
case
|
|
2427
|
+
case 13 /* Error */:
|
|
1977
2428
|
return serializeError(ctx, node);
|
|
1978
|
-
case
|
|
1979
|
-
return serializeIterable(ctx, node);
|
|
1980
|
-
case 18 /* Promise */:
|
|
2429
|
+
case 12 /* Promise */:
|
|
1981
2430
|
return serializePromise(ctx, node);
|
|
1982
|
-
case
|
|
1983
|
-
return
|
|
1984
|
-
case
|
|
2431
|
+
case 17 /* WKSymbol */:
|
|
2432
|
+
return serializeWKSymbol(ctx, node);
|
|
2433
|
+
case 18 /* URL */:
|
|
1985
2434
|
return serializeURL(ctx, node);
|
|
1986
|
-
case
|
|
2435
|
+
case 19 /* URLSearchParams */:
|
|
1987
2436
|
return serializeURLSearchParams(ctx, node);
|
|
1988
|
-
case
|
|
2437
|
+
case 20 /* Reference */:
|
|
1989
2438
|
return serializeReference(ctx, node);
|
|
1990
|
-
case
|
|
2439
|
+
case 23 /* Blob */:
|
|
1991
2440
|
return serializeBlob(ctx, node);
|
|
1992
|
-
case
|
|
2441
|
+
case 24 /* File */:
|
|
1993
2442
|
return serializeFile(ctx, node);
|
|
1994
|
-
case
|
|
2443
|
+
case 25 /* Headers */:
|
|
1995
2444
|
return serializeHeaders(ctx, node);
|
|
1996
|
-
case
|
|
2445
|
+
case 26 /* FormData */:
|
|
1997
2446
|
return serializeFormData(ctx, node);
|
|
2447
|
+
case 27 /* Boxed */:
|
|
2448
|
+
return serializeBoxed(ctx, node);
|
|
1998
2449
|
default:
|
|
1999
|
-
throw new Error("
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
|
|
2003
|
-
// src/tree/sync.ts
|
|
2004
|
-
function generateNodeList2(ctx, current) {
|
|
2005
|
-
const size = current.length;
|
|
2006
|
-
const nodes = new Array(size);
|
|
2007
|
-
const deferred = new Array(size);
|
|
2008
|
-
let item;
|
|
2009
|
-
for (let i = 0; i < size; i++) {
|
|
2010
|
-
if (i in current) {
|
|
2011
|
-
item = current[i];
|
|
2012
|
-
if (isIterable(item)) {
|
|
2013
|
-
deferred[i] = item;
|
|
2014
|
-
} else {
|
|
2015
|
-
nodes[i] = parse2(ctx, item);
|
|
2016
|
-
}
|
|
2017
|
-
}
|
|
2018
|
-
}
|
|
2019
|
-
for (let i = 0; i < size; i++) {
|
|
2020
|
-
if (i in deferred) {
|
|
2021
|
-
nodes[i] = parse2(ctx, deferred[i]);
|
|
2022
|
-
}
|
|
2023
|
-
}
|
|
2024
|
-
return nodes;
|
|
2025
|
-
}
|
|
2026
|
-
function generateArrayNode2(ctx, id, current) {
|
|
2027
|
-
return {
|
|
2028
|
-
t: 15 /* Array */,
|
|
2029
|
-
i: id,
|
|
2030
|
-
s: void 0,
|
|
2031
|
-
l: current.length,
|
|
2032
|
-
c: void 0,
|
|
2033
|
-
m: void 0,
|
|
2034
|
-
d: void 0,
|
|
2035
|
-
a: generateNodeList2(ctx, current),
|
|
2036
|
-
f: void 0,
|
|
2037
|
-
b: void 0
|
|
2038
|
-
};
|
|
2039
|
-
}
|
|
2040
|
-
function generateMapNode2(ctx, id, current) {
|
|
2041
|
-
assert(ctx.features & 32 /* Map */, 'Unsupported type "Map"');
|
|
2042
|
-
const len = current.size;
|
|
2043
|
-
const keyNodes = new Array(len);
|
|
2044
|
-
const valueNodes = new Array(len);
|
|
2045
|
-
const deferredKey = new Array(len);
|
|
2046
|
-
const deferredValue = new Array(len);
|
|
2047
|
-
let deferredSize = 0;
|
|
2048
|
-
let nodeSize = 0;
|
|
2049
|
-
for (const [key, value] of current.entries()) {
|
|
2050
|
-
if (isIterable(key) || isIterable(value)) {
|
|
2051
|
-
deferredKey[deferredSize] = key;
|
|
2052
|
-
deferredValue[deferredSize] = value;
|
|
2053
|
-
deferredSize++;
|
|
2054
|
-
} else {
|
|
2055
|
-
keyNodes[nodeSize] = parse2(ctx, key);
|
|
2056
|
-
valueNodes[nodeSize] = parse2(ctx, value);
|
|
2057
|
-
nodeSize++;
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
for (let i = 0; i < deferredSize; i++) {
|
|
2061
|
-
keyNodes[nodeSize + i] = parse2(ctx, deferredKey[i]);
|
|
2062
|
-
valueNodes[nodeSize + i] = parse2(ctx, deferredValue[i]);
|
|
2063
|
-
}
|
|
2064
|
-
return {
|
|
2065
|
-
t: 14 /* Map */,
|
|
2066
|
-
i: id,
|
|
2067
|
-
s: void 0,
|
|
2068
|
-
l: void 0,
|
|
2069
|
-
c: void 0,
|
|
2070
|
-
m: void 0,
|
|
2071
|
-
d: { k: keyNodes, v: valueNodes, s: len },
|
|
2072
|
-
a: void 0,
|
|
2073
|
-
f: void 0,
|
|
2074
|
-
b: void 0
|
|
2075
|
-
};
|
|
2076
|
-
}
|
|
2077
|
-
function generateSetNode2(ctx, id, current) {
|
|
2078
|
-
assert(ctx.features & 512 /* Set */, 'Unsupported type "Set"');
|
|
2079
|
-
const len = current.size;
|
|
2080
|
-
const nodes = new Array(len);
|
|
2081
|
-
const deferred = new Array(len);
|
|
2082
|
-
let deferredSize = 0;
|
|
2083
|
-
let nodeSize = 0;
|
|
2084
|
-
for (const item of current.keys()) {
|
|
2085
|
-
if (isIterable(item)) {
|
|
2086
|
-
deferred[deferredSize++] = item;
|
|
2087
|
-
} else {
|
|
2088
|
-
nodes[nodeSize++] = parse2(ctx, item);
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
for (let i = 0; i < deferredSize; i++) {
|
|
2092
|
-
nodes[nodeSize + i] = parse2(ctx, deferred[i]);
|
|
2093
|
-
}
|
|
2094
|
-
return {
|
|
2095
|
-
t: 13 /* Set */,
|
|
2096
|
-
i: id,
|
|
2097
|
-
s: void 0,
|
|
2098
|
-
l: len,
|
|
2099
|
-
c: void 0,
|
|
2100
|
-
m: void 0,
|
|
2101
|
-
d: void 0,
|
|
2102
|
-
a: nodes,
|
|
2103
|
-
f: void 0,
|
|
2104
|
-
b: void 0
|
|
2105
|
-
};
|
|
2106
|
-
}
|
|
2107
|
-
function generateProperties2(ctx, properties) {
|
|
2108
|
-
const keys = Object.keys(properties);
|
|
2109
|
-
const size = keys.length;
|
|
2110
|
-
const keyNodes = new Array(size);
|
|
2111
|
-
const valueNodes = new Array(size);
|
|
2112
|
-
const deferredKeys = new Array(size);
|
|
2113
|
-
const deferredValues = new Array(size);
|
|
2114
|
-
let deferredSize = 0;
|
|
2115
|
-
let nodesSize = 0;
|
|
2116
|
-
let item;
|
|
2117
|
-
let escaped;
|
|
2118
|
-
for (const key of keys) {
|
|
2119
|
-
item = properties[key];
|
|
2120
|
-
escaped = serializeString(key);
|
|
2121
|
-
if (isIterable(item)) {
|
|
2122
|
-
deferredKeys[deferredSize] = escaped;
|
|
2123
|
-
deferredValues[deferredSize] = item;
|
|
2124
|
-
deferredSize++;
|
|
2125
|
-
} else {
|
|
2126
|
-
keyNodes[nodesSize] = escaped;
|
|
2127
|
-
valueNodes[nodesSize] = parse2(ctx, item);
|
|
2128
|
-
nodesSize++;
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
|
-
for (let i = 0; i < deferredSize; i++) {
|
|
2132
|
-
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
2133
|
-
valueNodes[nodesSize + i] = parse2(ctx, deferredValues[i]);
|
|
2134
|
-
}
|
|
2135
|
-
return {
|
|
2136
|
-
k: keyNodes,
|
|
2137
|
-
v: valueNodes,
|
|
2138
|
-
s: size
|
|
2139
|
-
};
|
|
2140
|
-
}
|
|
2141
|
-
function generateIterableNode2(ctx, id, current) {
|
|
2142
|
-
assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "Iterable"');
|
|
2143
|
-
const options = getIterableOptions(current);
|
|
2144
|
-
const array = Array.from(current);
|
|
2145
|
-
return {
|
|
2146
|
-
t: 21 /* Iterable */,
|
|
2147
|
-
i: id,
|
|
2148
|
-
s: void 0,
|
|
2149
|
-
l: array.length,
|
|
2150
|
-
c: void 0,
|
|
2151
|
-
m: void 0,
|
|
2152
|
-
// Parse options first before the items
|
|
2153
|
-
d: options ? generateProperties2(ctx, options) : void 0,
|
|
2154
|
-
a: generateNodeList2(ctx, array),
|
|
2155
|
-
f: void 0,
|
|
2156
|
-
b: void 0
|
|
2157
|
-
};
|
|
2158
|
-
}
|
|
2159
|
-
function generateObjectNode2(ctx, id, current, empty) {
|
|
2160
|
-
if (Symbol.iterator in current) {
|
|
2161
|
-
return generateIterableNode2(ctx, id, current);
|
|
2162
|
-
}
|
|
2163
|
-
return {
|
|
2164
|
-
t: empty ? 17 /* NullConstructor */ : 16 /* Object */,
|
|
2165
|
-
i: id,
|
|
2166
|
-
s: void 0,
|
|
2167
|
-
l: void 0,
|
|
2168
|
-
c: void 0,
|
|
2169
|
-
m: void 0,
|
|
2170
|
-
d: generateProperties2(ctx, current),
|
|
2171
|
-
a: void 0,
|
|
2172
|
-
f: void 0,
|
|
2173
|
-
b: void 0
|
|
2174
|
-
};
|
|
2175
|
-
}
|
|
2176
|
-
function generateAggregateErrorNode2(ctx, id, current) {
|
|
2177
|
-
const options = getErrorOptions(ctx, current);
|
|
2178
|
-
const optionsNode = options ? generateProperties2(ctx, options) : void 0;
|
|
2179
|
-
return {
|
|
2180
|
-
t: 20 /* AggregateError */,
|
|
2181
|
-
i: id,
|
|
2182
|
-
s: void 0,
|
|
2183
|
-
l: void 0,
|
|
2184
|
-
c: void 0,
|
|
2185
|
-
m: serializeString(current.message),
|
|
2186
|
-
d: optionsNode,
|
|
2187
|
-
a: void 0,
|
|
2188
|
-
f: void 0,
|
|
2189
|
-
b: void 0
|
|
2190
|
-
};
|
|
2191
|
-
}
|
|
2192
|
-
function generateErrorNode2(ctx, id, current) {
|
|
2193
|
-
const options = getErrorOptions(ctx, current);
|
|
2194
|
-
const optionsNode = options ? generateProperties2(ctx, options) : void 0;
|
|
2195
|
-
return {
|
|
2196
|
-
t: 19 /* Error */,
|
|
2197
|
-
i: id,
|
|
2198
|
-
s: void 0,
|
|
2199
|
-
l: void 0,
|
|
2200
|
-
c: getErrorConstructorName(current),
|
|
2201
|
-
m: serializeString(current.message),
|
|
2202
|
-
d: optionsNode,
|
|
2203
|
-
a: void 0,
|
|
2204
|
-
f: void 0,
|
|
2205
|
-
b: void 0
|
|
2206
|
-
};
|
|
2207
|
-
}
|
|
2208
|
-
function generateHeadersNode2(ctx, id, current) {
|
|
2209
|
-
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "Headers"');
|
|
2210
|
-
const items = {};
|
|
2211
|
-
current.forEach((value, key) => {
|
|
2212
|
-
items[key] = value;
|
|
2213
|
-
});
|
|
2214
|
-
return {
|
|
2215
|
-
t: 32 /* Headers */,
|
|
2216
|
-
i: id,
|
|
2217
|
-
s: void 0,
|
|
2218
|
-
l: void 0,
|
|
2219
|
-
c: void 0,
|
|
2220
|
-
m: void 0,
|
|
2221
|
-
d: generateProperties2(ctx, items),
|
|
2222
|
-
a: void 0,
|
|
2223
|
-
f: void 0,
|
|
2224
|
-
b: void 0
|
|
2225
|
-
};
|
|
2226
|
-
}
|
|
2227
|
-
function generateFormDataNode2(ctx, id, current) {
|
|
2228
|
-
assert(ctx.features & 8192 /* WebAPI */, 'Unsupported type "FormData"');
|
|
2229
|
-
const items = {};
|
|
2230
|
-
current.forEach((value, key) => {
|
|
2231
|
-
items[key] = value;
|
|
2232
|
-
});
|
|
2233
|
-
return {
|
|
2234
|
-
t: 33 /* FormData */,
|
|
2235
|
-
i: id,
|
|
2236
|
-
s: void 0,
|
|
2237
|
-
l: void 0,
|
|
2238
|
-
c: void 0,
|
|
2239
|
-
m: void 0,
|
|
2240
|
-
d: generateProperties2(ctx, items),
|
|
2241
|
-
a: void 0,
|
|
2242
|
-
f: void 0,
|
|
2243
|
-
b: void 0
|
|
2244
|
-
};
|
|
2245
|
-
}
|
|
2246
|
-
function parse2(ctx, current) {
|
|
2247
|
-
switch (typeof current) {
|
|
2248
|
-
case "boolean":
|
|
2249
|
-
return current ? TRUE_NODE : FALSE_NODE;
|
|
2250
|
-
case "undefined":
|
|
2251
|
-
return UNDEFINED_NODE;
|
|
2252
|
-
case "string":
|
|
2253
|
-
return createStringNode(current);
|
|
2254
|
-
case "number":
|
|
2255
|
-
switch (current) {
|
|
2256
|
-
case Infinity:
|
|
2257
|
-
return INFINITY_NODE;
|
|
2258
|
-
case -Infinity:
|
|
2259
|
-
return NEG_INFINITY_NODE;
|
|
2260
|
-
default:
|
|
2261
|
-
if (current !== current) {
|
|
2262
|
-
return NAN_NODE;
|
|
2263
|
-
}
|
|
2264
|
-
if (Object.is(current, -0)) {
|
|
2265
|
-
return NEG_ZERO_NODE;
|
|
2266
|
-
}
|
|
2267
|
-
return createNumberNode(current);
|
|
2268
|
-
}
|
|
2269
|
-
case "bigint":
|
|
2270
|
-
return createBigIntNode(ctx, current);
|
|
2271
|
-
case "object": {
|
|
2272
|
-
if (!current) {
|
|
2273
|
-
return NULL_NODE;
|
|
2274
|
-
}
|
|
2275
|
-
const id = createIndexedValue(ctx, current);
|
|
2276
|
-
if (ctx.markedRefs.has(id)) {
|
|
2277
|
-
return createIndexedValueNode(id);
|
|
2278
|
-
}
|
|
2279
|
-
if (hasReferenceID(current)) {
|
|
2280
|
-
return createReferenceNode(id, current);
|
|
2281
|
-
}
|
|
2282
|
-
if (Array.isArray(current)) {
|
|
2283
|
-
return generateArrayNode2(ctx, id, current);
|
|
2284
|
-
}
|
|
2285
|
-
switch (current.constructor) {
|
|
2286
|
-
case Date:
|
|
2287
|
-
return createDateNode(id, current);
|
|
2288
|
-
case RegExp:
|
|
2289
|
-
return createRegExpNode(id, current);
|
|
2290
|
-
case ArrayBuffer:
|
|
2291
|
-
return createArrayBufferNode(id, current);
|
|
2292
|
-
case Int8Array:
|
|
2293
|
-
case Int16Array:
|
|
2294
|
-
case Int32Array:
|
|
2295
|
-
case Uint8Array:
|
|
2296
|
-
case Uint16Array:
|
|
2297
|
-
case Uint32Array:
|
|
2298
|
-
case Uint8ClampedArray:
|
|
2299
|
-
case Float32Array:
|
|
2300
|
-
case Float64Array:
|
|
2301
|
-
return createTypedArrayNode(ctx, id, current);
|
|
2302
|
-
case BigInt64Array:
|
|
2303
|
-
case BigUint64Array:
|
|
2304
|
-
return createBigIntTypedArrayNode(ctx, id, current);
|
|
2305
|
-
case DataView:
|
|
2306
|
-
return createDataViewNode(ctx, id, current);
|
|
2307
|
-
case Map:
|
|
2308
|
-
return generateMapNode2(ctx, id, current);
|
|
2309
|
-
case Set:
|
|
2310
|
-
return generateSetNode2(ctx, id, current);
|
|
2311
|
-
case Object:
|
|
2312
|
-
return generateObjectNode2(
|
|
2313
|
-
ctx,
|
|
2314
|
-
id,
|
|
2315
|
-
current,
|
|
2316
|
-
false
|
|
2317
|
-
);
|
|
2318
|
-
case void 0:
|
|
2319
|
-
return generateObjectNode2(
|
|
2320
|
-
ctx,
|
|
2321
|
-
id,
|
|
2322
|
-
current,
|
|
2323
|
-
true
|
|
2324
|
-
);
|
|
2325
|
-
case AggregateError:
|
|
2326
|
-
if (ctx.features & 1 /* AggregateError */) {
|
|
2327
|
-
return generateAggregateErrorNode2(ctx, id, current);
|
|
2328
|
-
}
|
|
2329
|
-
return generateErrorNode2(ctx, id, current);
|
|
2330
|
-
case Error:
|
|
2331
|
-
case EvalError:
|
|
2332
|
-
case RangeError:
|
|
2333
|
-
case ReferenceError:
|
|
2334
|
-
case SyntaxError:
|
|
2335
|
-
case TypeError:
|
|
2336
|
-
case URIError:
|
|
2337
|
-
return generateErrorNode2(ctx, id, current);
|
|
2338
|
-
case URL:
|
|
2339
|
-
return createURLNode(ctx, id, current);
|
|
2340
|
-
case URLSearchParams:
|
|
2341
|
-
return createURLSearchParamsNode(ctx, id, current);
|
|
2342
|
-
case Headers:
|
|
2343
|
-
return generateHeadersNode2(ctx, id, current);
|
|
2344
|
-
case FormData:
|
|
2345
|
-
return generateFormDataNode2(ctx, id, current);
|
|
2346
|
-
default:
|
|
2347
|
-
break;
|
|
2348
|
-
}
|
|
2349
|
-
if (current instanceof AggregateError) {
|
|
2350
|
-
if (ctx.features & 1 /* AggregateError */) {
|
|
2351
|
-
return generateAggregateErrorNode2(ctx, id, current);
|
|
2352
|
-
}
|
|
2353
|
-
return generateErrorNode2(ctx, id, current);
|
|
2354
|
-
}
|
|
2355
|
-
if (current instanceof Error) {
|
|
2356
|
-
return generateErrorNode2(ctx, id, current);
|
|
2357
|
-
}
|
|
2358
|
-
if (Symbol.iterator in current) {
|
|
2359
|
-
return generateIterableNode2(ctx, id, current);
|
|
2360
|
-
}
|
|
2361
|
-
throw new Error("Unsupported type");
|
|
2362
|
-
}
|
|
2363
|
-
case "symbol":
|
|
2364
|
-
if (hasReferenceID(current)) {
|
|
2365
|
-
const id = createIndexedValue(ctx, current);
|
|
2366
|
-
if (ctx.markedRefs.has(id)) {
|
|
2367
|
-
return createIndexedValueNode(id);
|
|
2368
|
-
}
|
|
2369
|
-
return createReferenceNode(id, current);
|
|
2370
|
-
}
|
|
2371
|
-
return createWKSymbolNode(ctx, current);
|
|
2372
|
-
case "function": {
|
|
2373
|
-
assert(hasReferenceID(current), "Cannot serialize function without reference ID.");
|
|
2374
|
-
const id = createIndexedValue(ctx, current);
|
|
2375
|
-
if (ctx.markedRefs.has(id)) {
|
|
2376
|
-
return createIndexedValueNode(id);
|
|
2377
|
-
}
|
|
2378
|
-
return createReferenceNode(id, current);
|
|
2379
|
-
}
|
|
2380
|
-
default:
|
|
2381
|
-
throw new Error("Unsupported type");
|
|
2450
|
+
throw new Error("invariant");
|
|
2382
2451
|
}
|
|
2383
2452
|
}
|
|
2384
|
-
function parseSync(ctx, current) {
|
|
2385
|
-
const result = parse2(ctx, current);
|
|
2386
|
-
const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
|
|
2387
|
-
return [result, getRootID(ctx, current), isObject];
|
|
2388
|
-
}
|
|
2389
2453
|
|
|
2390
2454
|
// src/index.ts
|
|
2391
2455
|
function finalize(ctx, rootID, isObject, result) {
|
|
@@ -2413,39 +2477,45 @@ function finalize(ctx, rootID, isObject, result) {
|
|
|
2413
2477
|
}
|
|
2414
2478
|
function serialize(source, options) {
|
|
2415
2479
|
const ctx = createParserContext(options);
|
|
2416
|
-
const
|
|
2480
|
+
const tree = parseSync(ctx, source);
|
|
2417
2481
|
const serial = createSerializationContext(ctx);
|
|
2418
2482
|
const result = serializeTree(serial, tree);
|
|
2419
|
-
return finalize(
|
|
2483
|
+
return finalize(
|
|
2484
|
+
serial,
|
|
2485
|
+
getRootID(ctx, source),
|
|
2486
|
+
tree.t === 10 /* Object */,
|
|
2487
|
+
result
|
|
2488
|
+
);
|
|
2420
2489
|
}
|
|
2421
2490
|
async function serializeAsync(source, options) {
|
|
2422
2491
|
const ctx = createParserContext(options);
|
|
2423
|
-
const
|
|
2492
|
+
const tree = await parseAsync(ctx, source);
|
|
2424
2493
|
const serial = createSerializationContext(ctx);
|
|
2425
2494
|
const result = serializeTree(serial, tree);
|
|
2426
|
-
return finalize(
|
|
2495
|
+
return finalize(
|
|
2496
|
+
serial,
|
|
2497
|
+
getRootID(ctx, source),
|
|
2498
|
+
tree.t === 10 /* Object */,
|
|
2499
|
+
result
|
|
2500
|
+
);
|
|
2427
2501
|
}
|
|
2428
2502
|
function deserialize(source) {
|
|
2429
2503
|
return (0, eval)(source);
|
|
2430
2504
|
}
|
|
2431
2505
|
function toJSON(source, options) {
|
|
2432
2506
|
const ctx = createParserContext(options);
|
|
2433
|
-
const [tree, root, isObject] = parseSync(ctx, source);
|
|
2434
2507
|
return {
|
|
2435
|
-
t:
|
|
2436
|
-
r:
|
|
2437
|
-
i: isObject,
|
|
2508
|
+
t: parseSync(ctx, source),
|
|
2509
|
+
r: getRootID(ctx, source),
|
|
2438
2510
|
f: ctx.features,
|
|
2439
2511
|
m: Array.from(ctx.markedRefs)
|
|
2440
2512
|
};
|
|
2441
2513
|
}
|
|
2442
2514
|
async function toJSONAsync(source, options) {
|
|
2443
2515
|
const ctx = createParserContext(options);
|
|
2444
|
-
const [tree, root, isObject] = await parseAsync(ctx, source);
|
|
2445
2516
|
return {
|
|
2446
|
-
t:
|
|
2447
|
-
r:
|
|
2448
|
-
i: isObject,
|
|
2517
|
+
t: await parseAsync(ctx, source),
|
|
2518
|
+
r: getRootID(ctx, source),
|
|
2449
2519
|
f: ctx.features,
|
|
2450
2520
|
m: Array.from(ctx.markedRefs)
|
|
2451
2521
|
};
|
|
@@ -2456,7 +2526,7 @@ function compileJSON(source) {
|
|
|
2456
2526
|
markedRefs: source.m
|
|
2457
2527
|
});
|
|
2458
2528
|
const result = serializeTree(serial, source.t);
|
|
2459
|
-
return finalize(serial, source.r, source.i
|
|
2529
|
+
return finalize(serial, source.r, source.t.i === 10 /* Object */, result);
|
|
2460
2530
|
}
|
|
2461
2531
|
function fromJSON(source) {
|
|
2462
2532
|
const serial = createSerializationContext({
|