seroval 0.6.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/README.md +15 -3
- package/dist/cjs/development/index.cjs +1431 -991
- package/dist/cjs/development/index.cjs.map +4 -4
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +1431 -991
- 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/compat.d.ts +1 -1
- package/dist/types/context.d.ts +13 -7
- package/dist/types/index.d.ts +3 -4
- package/dist/types/string.d.ts +3 -0
- 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 +11 -14
- 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 +106 -70
- package/dist/types/tree/web-api.d.ts +4 -2
- package/dist/types/types.d.ts +4 -4
- package/package.json +11 -8
- package/src/assert.ts +2 -2
- package/src/compat.ts +1 -2
- package/src/context.ts +24 -13
- package/src/get-identifier.ts +1 -1
- package/src/index.ts +35 -26
- package/src/string.ts +53 -0
- package/src/tree/UnsupportedTypeError.ts +8 -0
- package/src/tree/async.ts +313 -222
- package/src/tree/constants.ts +72 -0
- package/src/tree/deserialize.ts +239 -119
- package/src/tree/primitives.ts +154 -143
- package/src/tree/reference.ts +4 -3
- package/src/tree/serialize.ts +394 -170
- package/src/tree/shared.ts +31 -22
- package/src/tree/symbols.ts +13 -13
- package/src/tree/sync.ts +288 -191
- package/src/tree/types.ts +173 -91
- package/src/tree/web-api.ts +59 -6
- package/src/types.ts +7 -3
- package/dist/types/quote.d.ts +0 -2
- package/src/quote.ts +0 -56
|
@@ -51,7 +51,7 @@ var Feature = /* @__PURE__ */ ((Feature2) => {
|
|
|
51
51
|
Feature2[Feature2["WebAPI"] = 8192] = "WebAPI";
|
|
52
52
|
return Feature2;
|
|
53
53
|
})(Feature || {});
|
|
54
|
-
var ALL_ENABLED =
|
|
54
|
+
var ALL_ENABLED = 16383;
|
|
55
55
|
|
|
56
56
|
// src/get-identifier.ts
|
|
57
57
|
var REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_";
|
|
@@ -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,43 +131,47 @@ 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
|
|
|
138
|
-
// src/
|
|
139
|
-
function
|
|
138
|
+
// src/string.ts
|
|
139
|
+
function serializeChar(str) {
|
|
140
|
+
switch (str) {
|
|
141
|
+
case '"':
|
|
142
|
+
return '\\"';
|
|
143
|
+
case "\\":
|
|
144
|
+
return "\\\\";
|
|
145
|
+
case "\n":
|
|
146
|
+
return "\\n";
|
|
147
|
+
case "\r":
|
|
148
|
+
return "\\r";
|
|
149
|
+
case "\b":
|
|
150
|
+
return "\\b";
|
|
151
|
+
case " ":
|
|
152
|
+
return "\\t";
|
|
153
|
+
case "\f":
|
|
154
|
+
return "\\f";
|
|
155
|
+
case "<":
|
|
156
|
+
return "\\x3C";
|
|
157
|
+
case "\u2028":
|
|
158
|
+
return "\\u2028";
|
|
159
|
+
case "\u2029":
|
|
160
|
+
return "\\u2029";
|
|
161
|
+
default:
|
|
162
|
+
return void 0;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function serializeString(str) {
|
|
140
166
|
let result = "";
|
|
141
167
|
let lastPos = 0;
|
|
168
|
+
let replacement;
|
|
142
169
|
for (let i = 0, len = str.length; i < len; i++) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
break;
|
|
148
|
-
case "\\":
|
|
149
|
-
replacement = "\\\\";
|
|
150
|
-
break;
|
|
151
|
-
case "<":
|
|
152
|
-
replacement = "\\x3C";
|
|
153
|
-
break;
|
|
154
|
-
case "\n":
|
|
155
|
-
replacement = "\\n";
|
|
156
|
-
break;
|
|
157
|
-
case "\r":
|
|
158
|
-
replacement = "\\r";
|
|
159
|
-
break;
|
|
160
|
-
case "\u2028":
|
|
161
|
-
replacement = "\\u2028";
|
|
162
|
-
break;
|
|
163
|
-
case "\u2029":
|
|
164
|
-
replacement = "\\u2029";
|
|
165
|
-
break;
|
|
166
|
-
default:
|
|
167
|
-
continue;
|
|
170
|
+
replacement = serializeChar(str[i]);
|
|
171
|
+
if (replacement) {
|
|
172
|
+
result += str.slice(lastPos, i) + replacement;
|
|
173
|
+
lastPos = i + 1;
|
|
168
174
|
}
|
|
169
|
-
result += str.slice(lastPos, i) + replacement;
|
|
170
|
-
lastPos = i + 1;
|
|
171
175
|
}
|
|
172
176
|
if (lastPos === 0) {
|
|
173
177
|
result = str;
|
|
@@ -176,8 +180,84 @@ function quote(str) {
|
|
|
176
180
|
}
|
|
177
181
|
return result;
|
|
178
182
|
}
|
|
179
|
-
function
|
|
180
|
-
return str.replace(/\\"/g, '"').replace(/\\\\/g, "\\").replace(/\\
|
|
183
|
+
function deserializeString(str) {
|
|
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
|
+
}
|
|
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
|
+
}
|
|
181
261
|
}
|
|
182
262
|
|
|
183
263
|
// src/tree/reference.ts
|
|
@@ -195,11 +275,11 @@ function hasReference(id) {
|
|
|
195
275
|
return INV_REFERENCE.has(id);
|
|
196
276
|
}
|
|
197
277
|
function getReferenceID(value) {
|
|
198
|
-
assert(hasReferenceID(value), "Missing reference id");
|
|
278
|
+
assert(hasReferenceID(value), new Error("Missing reference id"));
|
|
199
279
|
return REFERENCE.get(value);
|
|
200
280
|
}
|
|
201
281
|
function getReference(id) {
|
|
202
|
-
assert(hasReference(id), "Missing reference for id:" + id);
|
|
282
|
+
assert(hasReference(id), new Error("Missing reference for id:" + id));
|
|
203
283
|
return INV_REFERENCE.get(id);
|
|
204
284
|
}
|
|
205
285
|
var GLOBAL_KEY = "__SEROVAL__";
|
|
@@ -281,124 +361,51 @@ var SYMBOL_REF = {
|
|
|
281
361
|
};
|
|
282
362
|
|
|
283
363
|
// src/tree/primitives.ts
|
|
284
|
-
var TRUE_NODE = {
|
|
285
|
-
t: 2 /* Boolean */,
|
|
286
|
-
i: void 0,
|
|
287
|
-
s: true,
|
|
288
|
-
l: void 0,
|
|
289
|
-
c: void 0,
|
|
290
|
-
m: void 0,
|
|
291
|
-
d: void 0,
|
|
292
|
-
a: void 0,
|
|
293
|
-
f: void 0
|
|
294
|
-
};
|
|
295
|
-
var FALSE_NODE = {
|
|
296
|
-
t: 2 /* Boolean */,
|
|
297
|
-
i: void 0,
|
|
298
|
-
s: false,
|
|
299
|
-
l: void 0,
|
|
300
|
-
c: void 0,
|
|
301
|
-
m: void 0,
|
|
302
|
-
d: void 0,
|
|
303
|
-
a: void 0,
|
|
304
|
-
f: void 0
|
|
305
|
-
};
|
|
306
|
-
var UNDEFINED_NODE = {
|
|
307
|
-
t: 4 /* Undefined */,
|
|
308
|
-
i: void 0,
|
|
309
|
-
s: void 0,
|
|
310
|
-
l: void 0,
|
|
311
|
-
c: void 0,
|
|
312
|
-
m: void 0,
|
|
313
|
-
d: void 0,
|
|
314
|
-
a: void 0,
|
|
315
|
-
f: void 0
|
|
316
|
-
};
|
|
317
|
-
var NULL_NODE = {
|
|
318
|
-
t: 3 /* Null */,
|
|
319
|
-
i: void 0,
|
|
320
|
-
s: void 0,
|
|
321
|
-
l: void 0,
|
|
322
|
-
c: void 0,
|
|
323
|
-
m: void 0,
|
|
324
|
-
d: void 0,
|
|
325
|
-
a: void 0,
|
|
326
|
-
f: void 0
|
|
327
|
-
};
|
|
328
|
-
var NEG_ZERO_NODE = {
|
|
329
|
-
t: 5 /* NegativeZero */,
|
|
330
|
-
i: void 0,
|
|
331
|
-
s: void 0,
|
|
332
|
-
l: void 0,
|
|
333
|
-
c: void 0,
|
|
334
|
-
m: void 0,
|
|
335
|
-
d: void 0,
|
|
336
|
-
a: void 0,
|
|
337
|
-
f: void 0
|
|
338
|
-
};
|
|
339
|
-
var INFINITY_NODE = {
|
|
340
|
-
t: 6 /* Infinity */,
|
|
341
|
-
i: void 0,
|
|
342
|
-
s: void 0,
|
|
343
|
-
l: void 0,
|
|
344
|
-
c: void 0,
|
|
345
|
-
m: void 0,
|
|
346
|
-
d: void 0,
|
|
347
|
-
a: void 0,
|
|
348
|
-
f: void 0
|
|
349
|
-
};
|
|
350
|
-
var NEG_INFINITY_NODE = {
|
|
351
|
-
t: 7 /* NegativeInfinity */,
|
|
352
|
-
i: void 0,
|
|
353
|
-
s: void 0,
|
|
354
|
-
l: void 0,
|
|
355
|
-
c: void 0,
|
|
356
|
-
m: void 0,
|
|
357
|
-
d: void 0,
|
|
358
|
-
a: void 0,
|
|
359
|
-
f: void 0
|
|
360
|
-
};
|
|
361
|
-
var NAN_NODE = {
|
|
362
|
-
t: 8 /* NaN */,
|
|
363
|
-
i: void 0,
|
|
364
|
-
s: void 0,
|
|
365
|
-
l: void 0,
|
|
366
|
-
c: void 0,
|
|
367
|
-
m: void 0,
|
|
368
|
-
d: void 0,
|
|
369
|
-
a: void 0,
|
|
370
|
-
f: void 0
|
|
371
|
-
};
|
|
372
364
|
function createNumberNode(value) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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
|
+
}
|
|
384
390
|
}
|
|
385
391
|
function createStringNode(value) {
|
|
386
392
|
return {
|
|
387
393
|
t: 1 /* String */,
|
|
388
394
|
i: void 0,
|
|
389
|
-
s:
|
|
395
|
+
s: serializeString(value),
|
|
390
396
|
l: void 0,
|
|
391
397
|
c: void 0,
|
|
392
398
|
m: void 0,
|
|
393
399
|
d: void 0,
|
|
394
400
|
a: void 0,
|
|
395
|
-
f: void 0
|
|
401
|
+
f: void 0,
|
|
402
|
+
b: void 0
|
|
396
403
|
};
|
|
397
404
|
}
|
|
398
405
|
function createBigIntNode(ctx, current) {
|
|
399
|
-
assert(ctx.features & 8 /* BigInt */,
|
|
406
|
+
assert(ctx.features & 8 /* BigInt */, new UnsupportedTypeError(current));
|
|
400
407
|
return {
|
|
401
|
-
t:
|
|
408
|
+
t: 3 /* BigInt */,
|
|
402
409
|
i: void 0,
|
|
403
410
|
s: "" + current,
|
|
404
411
|
l: void 0,
|
|
@@ -406,12 +413,13 @@ function createBigIntNode(ctx, current) {
|
|
|
406
413
|
m: void 0,
|
|
407
414
|
d: void 0,
|
|
408
415
|
a: void 0,
|
|
409
|
-
f: void 0
|
|
416
|
+
f: void 0,
|
|
417
|
+
b: void 0
|
|
410
418
|
};
|
|
411
419
|
}
|
|
412
420
|
function createIndexedValueNode(id) {
|
|
413
421
|
return {
|
|
414
|
-
t:
|
|
422
|
+
t: 4 /* IndexedValue */,
|
|
415
423
|
i: id,
|
|
416
424
|
s: void 0,
|
|
417
425
|
l: void 0,
|
|
@@ -419,12 +427,13 @@ function createIndexedValueNode(id) {
|
|
|
419
427
|
m: void 0,
|
|
420
428
|
d: void 0,
|
|
421
429
|
a: void 0,
|
|
422
|
-
f: void 0
|
|
430
|
+
f: void 0,
|
|
431
|
+
b: void 0
|
|
423
432
|
};
|
|
424
433
|
}
|
|
425
434
|
function createDateNode(id, current) {
|
|
426
435
|
return {
|
|
427
|
-
t:
|
|
436
|
+
t: 5 /* Date */,
|
|
428
437
|
i: id,
|
|
429
438
|
s: current.toISOString(),
|
|
430
439
|
l: void 0,
|
|
@@ -432,12 +441,13 @@ function createDateNode(id, current) {
|
|
|
432
441
|
m: void 0,
|
|
433
442
|
d: void 0,
|
|
434
443
|
f: void 0,
|
|
435
|
-
a: void 0
|
|
444
|
+
a: void 0,
|
|
445
|
+
b: void 0
|
|
436
446
|
};
|
|
437
447
|
}
|
|
438
448
|
function createRegExpNode(id, current) {
|
|
439
449
|
return {
|
|
440
|
-
t:
|
|
450
|
+
t: 6 /* RegExp */,
|
|
441
451
|
i: id,
|
|
442
452
|
s: void 0,
|
|
443
453
|
l: void 0,
|
|
@@ -445,81 +455,133 @@ function createRegExpNode(id, current) {
|
|
|
445
455
|
m: current.flags,
|
|
446
456
|
d: void 0,
|
|
447
457
|
a: void 0,
|
|
448
|
-
f: void 0
|
|
458
|
+
f: void 0,
|
|
459
|
+
b: void 0
|
|
449
460
|
};
|
|
450
461
|
}
|
|
451
|
-
function
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
const len = current.length;
|
|
462
|
+
function createArrayBufferNode(id, current) {
|
|
463
|
+
const bytes = new Uint8Array(current);
|
|
464
|
+
const len = bytes.length;
|
|
455
465
|
const values = new Array(len);
|
|
456
466
|
for (let i = 0; i < len; i++) {
|
|
457
|
-
values[i] =
|
|
467
|
+
values[i] = bytes[i];
|
|
458
468
|
}
|
|
459
469
|
return {
|
|
460
|
-
t:
|
|
470
|
+
t: 21 /* ArrayBuffer */,
|
|
461
471
|
i: id,
|
|
462
472
|
s: values,
|
|
463
|
-
l:
|
|
464
|
-
c:
|
|
473
|
+
l: void 0,
|
|
474
|
+
c: void 0,
|
|
475
|
+
m: void 0,
|
|
476
|
+
d: void 0,
|
|
477
|
+
a: void 0,
|
|
478
|
+
f: void 0,
|
|
479
|
+
b: void 0
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
function serializeArrayBuffer(ctx, current) {
|
|
483
|
+
const id = createIndexedValue(ctx, current);
|
|
484
|
+
if (ctx.markedRefs.has(id)) {
|
|
485
|
+
return createIndexedValueNode(id);
|
|
486
|
+
}
|
|
487
|
+
return createArrayBufferNode(id, current);
|
|
488
|
+
}
|
|
489
|
+
function createTypedArrayNode(ctx, id, current) {
|
|
490
|
+
assert(ctx.features & 2048 /* TypedArray */, new UnsupportedTypeError(current));
|
|
491
|
+
return {
|
|
492
|
+
t: 15 /* TypedArray */,
|
|
493
|
+
i: id,
|
|
494
|
+
s: void 0,
|
|
495
|
+
l: current.length,
|
|
496
|
+
c: current.constructor.name,
|
|
465
497
|
m: void 0,
|
|
466
498
|
d: void 0,
|
|
467
499
|
a: void 0,
|
|
468
|
-
f:
|
|
500
|
+
f: serializeArrayBuffer(ctx, current.buffer),
|
|
501
|
+
b: current.byteOffset
|
|
469
502
|
};
|
|
470
503
|
}
|
|
471
504
|
var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
|
|
472
505
|
function createBigIntTypedArrayNode(ctx, id, current) {
|
|
473
|
-
const constructor = current.constructor.name;
|
|
474
506
|
assert(
|
|
475
507
|
(ctx.features & BIGINT_FLAG) === BIGINT_FLAG,
|
|
476
|
-
|
|
508
|
+
new UnsupportedTypeError(current)
|
|
477
509
|
);
|
|
478
|
-
const len = current.length;
|
|
479
|
-
const values = new Array(len);
|
|
480
|
-
for (let i = 0; i < len; i++) {
|
|
481
|
-
values[i] = "" + current[i];
|
|
482
|
-
}
|
|
483
510
|
return {
|
|
484
|
-
t:
|
|
511
|
+
t: 16 /* BigIntTypedArray */,
|
|
485
512
|
i: id,
|
|
486
|
-
s:
|
|
487
|
-
l: current.
|
|
488
|
-
c: constructor,
|
|
513
|
+
s: void 0,
|
|
514
|
+
l: current.length,
|
|
515
|
+
c: current.constructor.name,
|
|
489
516
|
m: void 0,
|
|
490
517
|
d: void 0,
|
|
491
518
|
a: void 0,
|
|
492
|
-
f:
|
|
519
|
+
f: serializeArrayBuffer(ctx, current.buffer),
|
|
520
|
+
b: current.byteOffset
|
|
493
521
|
};
|
|
494
522
|
}
|
|
495
|
-
function createWKSymbolNode(ctx, current) {
|
|
496
|
-
assert(ctx.features & 1024 /* Symbol */,
|
|
497
|
-
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."));
|
|
498
526
|
return {
|
|
499
|
-
t:
|
|
500
|
-
i:
|
|
527
|
+
t: 17 /* WKSymbol */,
|
|
528
|
+
i: id,
|
|
501
529
|
s: INV_SYMBOL_REF[current],
|
|
502
530
|
l: void 0,
|
|
503
531
|
c: void 0,
|
|
504
532
|
m: void 0,
|
|
505
533
|
d: void 0,
|
|
506
534
|
a: void 0,
|
|
507
|
-
f: void 0
|
|
535
|
+
f: void 0,
|
|
536
|
+
b: void 0
|
|
508
537
|
};
|
|
509
538
|
}
|
|
510
539
|
function createReferenceNode(id, ref) {
|
|
511
540
|
return {
|
|
512
|
-
t:
|
|
541
|
+
t: 20 /* Reference */,
|
|
513
542
|
i: id,
|
|
514
|
-
s:
|
|
543
|
+
s: serializeString(getReferenceID(ref)),
|
|
515
544
|
l: void 0,
|
|
516
545
|
c: void 0,
|
|
517
546
|
m: void 0,
|
|
518
547
|
d: void 0,
|
|
519
548
|
a: void 0,
|
|
520
|
-
f: void 0
|
|
549
|
+
f: void 0,
|
|
550
|
+
b: void 0
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
function createDataViewNode(ctx, id, current) {
|
|
554
|
+
return {
|
|
555
|
+
t: 22 /* DataView */,
|
|
556
|
+
i: id,
|
|
557
|
+
s: void 0,
|
|
558
|
+
l: current.byteLength,
|
|
559
|
+
c: void 0,
|
|
560
|
+
m: void 0,
|
|
561
|
+
d: void 0,
|
|
562
|
+
a: void 0,
|
|
563
|
+
f: serializeArrayBuffer(ctx, current.buffer),
|
|
564
|
+
b: current.byteOffset
|
|
521
565
|
};
|
|
522
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
|
+
}
|
|
523
585
|
|
|
524
586
|
// src/tree/shared.ts
|
|
525
587
|
function getErrorConstructorName(error) {
|
|
@@ -587,17 +649,6 @@ function getErrorOptions(ctx, error) {
|
|
|
587
649
|
}
|
|
588
650
|
return options;
|
|
589
651
|
}
|
|
590
|
-
function getIterableOptions(obj) {
|
|
591
|
-
const names = Object.getOwnPropertyNames(obj);
|
|
592
|
-
if (names.length) {
|
|
593
|
-
const options = {};
|
|
594
|
-
for (const name of names) {
|
|
595
|
-
options[name] = obj[name];
|
|
596
|
-
}
|
|
597
|
-
return options;
|
|
598
|
-
}
|
|
599
|
-
return void 0;
|
|
600
|
-
}
|
|
601
652
|
function isIterable(value) {
|
|
602
653
|
if (!value || typeof value !== "object") {
|
|
603
654
|
return false;
|
|
@@ -661,36 +712,68 @@ function isValidIdentifier(name) {
|
|
|
661
712
|
|
|
662
713
|
// src/tree/web-api.ts
|
|
663
714
|
function createURLNode(ctx, id, current) {
|
|
664
|
-
assert(ctx.features & 8192 /* WebAPI */,
|
|
715
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
665
716
|
return {
|
|
666
|
-
t:
|
|
717
|
+
t: 18 /* URL */,
|
|
667
718
|
i: id,
|
|
668
|
-
s: current.href,
|
|
719
|
+
s: serializeString(current.href),
|
|
669
720
|
l: void 0,
|
|
670
721
|
c: void 0,
|
|
671
722
|
m: void 0,
|
|
672
723
|
d: void 0,
|
|
673
724
|
f: void 0,
|
|
674
|
-
a: void 0
|
|
725
|
+
a: void 0,
|
|
726
|
+
b: void 0
|
|
675
727
|
};
|
|
676
728
|
}
|
|
677
729
|
function createURLSearchParamsNode(ctx, id, current) {
|
|
678
|
-
assert(ctx.features & 8192 /* WebAPI */,
|
|
730
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
679
731
|
return {
|
|
680
|
-
t:
|
|
732
|
+
t: 19 /* URLSearchParams */,
|
|
681
733
|
i: id,
|
|
682
|
-
s: current.toString(),
|
|
734
|
+
s: serializeString(current.toString()),
|
|
683
735
|
l: void 0,
|
|
684
736
|
c: void 0,
|
|
685
737
|
m: void 0,
|
|
686
738
|
d: void 0,
|
|
687
739
|
f: void 0,
|
|
688
|
-
a: void 0
|
|
740
|
+
a: void 0,
|
|
741
|
+
b: void 0
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
async function createBlobNode(ctx, id, current) {
|
|
745
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
746
|
+
return {
|
|
747
|
+
t: 23 /* Blob */,
|
|
748
|
+
i: id,
|
|
749
|
+
s: void 0,
|
|
750
|
+
l: void 0,
|
|
751
|
+
c: serializeString(current.type),
|
|
752
|
+
m: void 0,
|
|
753
|
+
d: void 0,
|
|
754
|
+
f: serializeArrayBuffer(ctx, await current.arrayBuffer()),
|
|
755
|
+
a: void 0,
|
|
756
|
+
b: void 0
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
async function createFileNode(ctx, id, current) {
|
|
760
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
761
|
+
return {
|
|
762
|
+
t: 24 /* File */,
|
|
763
|
+
i: id,
|
|
764
|
+
s: void 0,
|
|
765
|
+
l: void 0,
|
|
766
|
+
c: serializeString(current.type),
|
|
767
|
+
m: serializeString(current.name),
|
|
768
|
+
d: void 0,
|
|
769
|
+
f: serializeArrayBuffer(ctx, await current.arrayBuffer()),
|
|
770
|
+
a: void 0,
|
|
771
|
+
b: current.lastModified
|
|
689
772
|
};
|
|
690
773
|
}
|
|
691
774
|
|
|
692
|
-
// src/tree/
|
|
693
|
-
|
|
775
|
+
// src/tree/sync.ts
|
|
776
|
+
function generateNodeList(ctx, current) {
|
|
694
777
|
const size = current.length;
|
|
695
778
|
const nodes = new Array(size);
|
|
696
779
|
const deferred = new Array(size);
|
|
@@ -701,32 +784,33 @@ async function generateNodeList(ctx, current) {
|
|
|
701
784
|
if (isIterable(item)) {
|
|
702
785
|
deferred[i] = item;
|
|
703
786
|
} else {
|
|
704
|
-
nodes[i] =
|
|
787
|
+
nodes[i] = parseSync(ctx, item);
|
|
705
788
|
}
|
|
706
789
|
}
|
|
707
790
|
}
|
|
708
791
|
for (let i = 0; i < size; i++) {
|
|
709
792
|
if (i in deferred) {
|
|
710
|
-
nodes[i] =
|
|
793
|
+
nodes[i] = parseSync(ctx, deferred[i]);
|
|
711
794
|
}
|
|
712
795
|
}
|
|
713
796
|
return nodes;
|
|
714
797
|
}
|
|
715
|
-
|
|
798
|
+
function generateArrayNode(ctx, id, current) {
|
|
716
799
|
return {
|
|
717
|
-
t:
|
|
800
|
+
t: 9 /* Array */,
|
|
718
801
|
i: id,
|
|
719
802
|
s: void 0,
|
|
720
803
|
l: current.length,
|
|
721
804
|
c: void 0,
|
|
722
805
|
m: void 0,
|
|
723
806
|
d: void 0,
|
|
724
|
-
a:
|
|
725
|
-
f: void 0
|
|
807
|
+
a: generateNodeList(ctx, current),
|
|
808
|
+
f: void 0,
|
|
809
|
+
b: void 0
|
|
726
810
|
};
|
|
727
811
|
}
|
|
728
|
-
|
|
729
|
-
assert(ctx.features & 32 /* Map */,
|
|
812
|
+
function generateMapNode(ctx, id, current) {
|
|
813
|
+
assert(ctx.features & 32 /* Map */, new UnsupportedTypeError(current));
|
|
730
814
|
const len = current.size;
|
|
731
815
|
const keyNodes = new Array(len);
|
|
732
816
|
const valueNodes = new Array(len);
|
|
@@ -740,17 +824,17 @@ async function generateMapNode(ctx, id, current) {
|
|
|
740
824
|
deferredValue[deferredSize] = value;
|
|
741
825
|
deferredSize++;
|
|
742
826
|
} else {
|
|
743
|
-
keyNodes[nodeSize] =
|
|
744
|
-
valueNodes[nodeSize] =
|
|
827
|
+
keyNodes[nodeSize] = parseSync(ctx, key);
|
|
828
|
+
valueNodes[nodeSize] = parseSync(ctx, value);
|
|
745
829
|
nodeSize++;
|
|
746
830
|
}
|
|
747
831
|
}
|
|
748
832
|
for (let i = 0; i < deferredSize; i++) {
|
|
749
|
-
keyNodes[nodeSize + i] =
|
|
750
|
-
valueNodes[nodeSize + i] =
|
|
833
|
+
keyNodes[nodeSize + i] = parseSync(ctx, deferredKey[i]);
|
|
834
|
+
valueNodes[nodeSize + i] = parseSync(ctx, deferredValue[i]);
|
|
751
835
|
}
|
|
752
836
|
return {
|
|
753
|
-
t:
|
|
837
|
+
t: 8 /* Map */,
|
|
754
838
|
i: id,
|
|
755
839
|
s: void 0,
|
|
756
840
|
l: void 0,
|
|
@@ -758,11 +842,12 @@ async function generateMapNode(ctx, id, current) {
|
|
|
758
842
|
m: void 0,
|
|
759
843
|
d: { k: keyNodes, v: valueNodes, s: len },
|
|
760
844
|
a: void 0,
|
|
761
|
-
f: void 0
|
|
845
|
+
f: void 0,
|
|
846
|
+
b: void 0
|
|
762
847
|
};
|
|
763
848
|
}
|
|
764
|
-
|
|
765
|
-
assert(ctx.features & 512 /* Set */,
|
|
849
|
+
function generateSetNode(ctx, id, current) {
|
|
850
|
+
assert(ctx.features & 512 /* Set */, new UnsupportedTypeError(current));
|
|
766
851
|
const len = current.size;
|
|
767
852
|
const nodes = new Array(len);
|
|
768
853
|
const deferred = new Array(len);
|
|
@@ -772,14 +857,14 @@ async function generateSetNode(ctx, id, current) {
|
|
|
772
857
|
if (isIterable(item)) {
|
|
773
858
|
deferred[deferredSize++] = item;
|
|
774
859
|
} else {
|
|
775
|
-
nodes[nodeSize++] =
|
|
860
|
+
nodes[nodeSize++] = parseSync(ctx, item);
|
|
776
861
|
}
|
|
777
862
|
}
|
|
778
863
|
for (let i = 0; i < deferredSize; i++) {
|
|
779
|
-
nodes[nodeSize + i] =
|
|
864
|
+
nodes[nodeSize + i] = parseSync(ctx, deferred[i]);
|
|
780
865
|
}
|
|
781
866
|
return {
|
|
782
|
-
t:
|
|
867
|
+
t: 7 /* Set */,
|
|
783
868
|
i: id,
|
|
784
869
|
s: void 0,
|
|
785
870
|
l: len,
|
|
@@ -787,10 +872,54 @@ async function generateSetNode(ctx, id, current) {
|
|
|
787
872
|
m: void 0,
|
|
788
873
|
d: void 0,
|
|
789
874
|
a: nodes,
|
|
790
|
-
f: void 0
|
|
875
|
+
f: void 0,
|
|
876
|
+
b: void 0
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
function generateProperties(ctx, properties) {
|
|
880
|
+
const keys = Object.keys(properties);
|
|
881
|
+
let size = keys.length;
|
|
882
|
+
const keyNodes = new Array(size);
|
|
883
|
+
const valueNodes = new Array(size);
|
|
884
|
+
const deferredKeys = new Array(size);
|
|
885
|
+
const deferredValues = new Array(size);
|
|
886
|
+
let deferredSize = 0;
|
|
887
|
+
let nodesSize = 0;
|
|
888
|
+
let item;
|
|
889
|
+
let escaped;
|
|
890
|
+
for (const key of keys) {
|
|
891
|
+
item = properties[key];
|
|
892
|
+
escaped = serializeString(key);
|
|
893
|
+
if (isIterable(item)) {
|
|
894
|
+
deferredKeys[deferredSize] = escaped;
|
|
895
|
+
deferredValues[deferredSize] = item;
|
|
896
|
+
deferredSize++;
|
|
897
|
+
} else {
|
|
898
|
+
keyNodes[nodesSize] = escaped;
|
|
899
|
+
valueNodes[nodesSize] = parseSync(ctx, item);
|
|
900
|
+
nodesSize++;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
for (let i = 0; i < deferredSize; i++) {
|
|
904
|
+
keyNodes[nodesSize + i] = deferredKeys[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
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return {
|
|
917
|
+
k: keyNodes,
|
|
918
|
+
v: valueNodes,
|
|
919
|
+
s: size
|
|
791
920
|
};
|
|
792
921
|
}
|
|
793
|
-
|
|
922
|
+
function generatePlainProperties(ctx, properties) {
|
|
794
923
|
const keys = Object.keys(properties);
|
|
795
924
|
const size = keys.length;
|
|
796
925
|
const keyNodes = new Array(size);
|
|
@@ -800,21 +929,23 @@ async function generateProperties(ctx, properties) {
|
|
|
800
929
|
let deferredSize = 0;
|
|
801
930
|
let nodesSize = 0;
|
|
802
931
|
let item;
|
|
932
|
+
let escaped;
|
|
803
933
|
for (const key of keys) {
|
|
804
934
|
item = properties[key];
|
|
935
|
+
escaped = serializeString(key);
|
|
805
936
|
if (isIterable(item)) {
|
|
806
|
-
deferredKeys[deferredSize] =
|
|
937
|
+
deferredKeys[deferredSize] = escaped;
|
|
807
938
|
deferredValues[deferredSize] = item;
|
|
808
939
|
deferredSize++;
|
|
809
940
|
} else {
|
|
810
|
-
keyNodes[nodesSize] =
|
|
811
|
-
valueNodes[nodesSize] =
|
|
941
|
+
keyNodes[nodesSize] = escaped;
|
|
942
|
+
valueNodes[nodesSize] = parseSync(ctx, item);
|
|
812
943
|
nodesSize++;
|
|
813
944
|
}
|
|
814
945
|
}
|
|
815
946
|
for (let i = 0; i < deferredSize; i++) {
|
|
816
947
|
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
817
|
-
valueNodes[nodesSize + i] =
|
|
948
|
+
valueNodes[nodesSize + i] = parseSync(ctx, deferredValues[i]);
|
|
818
949
|
}
|
|
819
950
|
return {
|
|
820
951
|
k: keyNodes,
|
|
@@ -822,88 +953,204 @@ async function generateProperties(ctx, properties) {
|
|
|
822
953
|
s: size
|
|
823
954
|
};
|
|
824
955
|
}
|
|
825
|
-
|
|
826
|
-
assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "Iterable"');
|
|
827
|
-
const options = getIterableOptions(current);
|
|
828
|
-
const array = Array.from(current);
|
|
956
|
+
function generateObjectNode(ctx, id, current, empty) {
|
|
829
957
|
return {
|
|
830
|
-
t:
|
|
958
|
+
t: empty ? 11 /* NullConstructor */ : 10 /* Object */,
|
|
831
959
|
i: id,
|
|
832
960
|
s: void 0,
|
|
833
|
-
l:
|
|
961
|
+
l: void 0,
|
|
834
962
|
c: void 0,
|
|
835
963
|
m: void 0,
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
964
|
+
d: generateProperties(ctx, current),
|
|
965
|
+
a: void 0,
|
|
966
|
+
f: void 0,
|
|
967
|
+
b: void 0
|
|
840
968
|
};
|
|
841
969
|
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
970
|
+
function generateAggregateErrorNode(ctx, id, current) {
|
|
971
|
+
const options = getErrorOptions(ctx, current);
|
|
972
|
+
const optionsNode = options ? generateProperties(ctx, options) : void 0;
|
|
973
|
+
return {
|
|
974
|
+
t: 14 /* AggregateError */,
|
|
846
975
|
i: id,
|
|
847
976
|
s: void 0,
|
|
848
977
|
l: void 0,
|
|
849
978
|
c: void 0,
|
|
850
|
-
m:
|
|
851
|
-
|
|
852
|
-
d: void 0,
|
|
979
|
+
m: serializeString(current.message),
|
|
980
|
+
d: optionsNode,
|
|
853
981
|
a: void 0,
|
|
854
|
-
f:
|
|
855
|
-
|
|
982
|
+
f: void 0,
|
|
983
|
+
b: void 0
|
|
984
|
+
};
|
|
856
985
|
}
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
986
|
+
function generateErrorNode(ctx, id, current) {
|
|
987
|
+
const options = getErrorOptions(ctx, current);
|
|
988
|
+
const optionsNode = options ? generateProperties(ctx, options) : void 0;
|
|
989
|
+
return {
|
|
990
|
+
t: 13 /* Error */,
|
|
991
|
+
i: id,
|
|
992
|
+
s: void 0,
|
|
993
|
+
l: void 0,
|
|
994
|
+
c: getErrorConstructorName(current),
|
|
995
|
+
m: serializeString(current.message),
|
|
996
|
+
d: optionsNode,
|
|
997
|
+
a: void 0,
|
|
998
|
+
f: void 0,
|
|
999
|
+
b: void 0
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
function generateHeadersNode(ctx, id, current) {
|
|
1003
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
1004
|
+
const items = {};
|
|
1005
|
+
current.forEach((value, key) => {
|
|
1006
|
+
items[key] = value;
|
|
1007
|
+
});
|
|
864
1008
|
return {
|
|
865
|
-
t:
|
|
1009
|
+
t: 25 /* Headers */,
|
|
866
1010
|
i: id,
|
|
867
1011
|
s: void 0,
|
|
868
1012
|
l: void 0,
|
|
869
1013
|
c: void 0,
|
|
870
1014
|
m: void 0,
|
|
871
|
-
d:
|
|
1015
|
+
d: generatePlainProperties(ctx, items),
|
|
872
1016
|
a: void 0,
|
|
873
|
-
f: void 0
|
|
1017
|
+
f: void 0,
|
|
1018
|
+
b: void 0
|
|
874
1019
|
};
|
|
875
1020
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
const
|
|
1021
|
+
function generateFormDataNode(ctx, id, current) {
|
|
1022
|
+
assert(ctx.features & 8192 /* WebAPI */, new UnsupportedTypeError(current));
|
|
1023
|
+
const items = {};
|
|
1024
|
+
current.forEach((value, key) => {
|
|
1025
|
+
items[key] = value;
|
|
1026
|
+
});
|
|
879
1027
|
return {
|
|
880
|
-
t:
|
|
1028
|
+
t: 26 /* FormData */,
|
|
881
1029
|
i: id,
|
|
882
1030
|
s: void 0,
|
|
883
|
-
l:
|
|
1031
|
+
l: void 0,
|
|
884
1032
|
c: void 0,
|
|
885
|
-
m:
|
|
886
|
-
d:
|
|
887
|
-
a:
|
|
888
|
-
f: void 0
|
|
1033
|
+
m: void 0,
|
|
1034
|
+
d: generatePlainProperties(ctx, items),
|
|
1035
|
+
a: void 0,
|
|
1036
|
+
f: void 0,
|
|
1037
|
+
b: void 0
|
|
889
1038
|
};
|
|
890
1039
|
}
|
|
891
|
-
|
|
892
|
-
const options = getErrorOptions(ctx, current);
|
|
893
|
-
const optionsNode = options ? await generateProperties(ctx, options) : void 0;
|
|
1040
|
+
function generateBoxedNode(ctx, id, current) {
|
|
894
1041
|
return {
|
|
895
|
-
t:
|
|
1042
|
+
t: 27 /* Boxed */,
|
|
896
1043
|
i: id,
|
|
897
1044
|
s: void 0,
|
|
898
1045
|
l: void 0,
|
|
899
|
-
c:
|
|
900
|
-
m:
|
|
901
|
-
d:
|
|
1046
|
+
c: void 0,
|
|
1047
|
+
m: void 0,
|
|
1048
|
+
d: void 0,
|
|
902
1049
|
a: void 0,
|
|
903
|
-
f:
|
|
1050
|
+
f: parseSync(ctx, current.valueOf()),
|
|
1051
|
+
b: void 0
|
|
904
1052
|
};
|
|
905
1053
|
}
|
|
906
|
-
|
|
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) {
|
|
907
1154
|
switch (typeof current) {
|
|
908
1155
|
case "boolean":
|
|
909
1156
|
return current ? TRUE_NODE : FALSE_NODE;
|
|
@@ -912,157 +1159,473 @@ async function parse(ctx, current) {
|
|
|
912
1159
|
case "string":
|
|
913
1160
|
return createStringNode(current);
|
|
914
1161
|
case "number":
|
|
915
|
-
|
|
916
|
-
case Infinity:
|
|
917
|
-
return INFINITY_NODE;
|
|
918
|
-
case -Infinity:
|
|
919
|
-
return NEG_INFINITY_NODE;
|
|
920
|
-
default:
|
|
921
|
-
if (current !== current) {
|
|
922
|
-
return NAN_NODE;
|
|
923
|
-
}
|
|
924
|
-
if (Object.is(current, -0)) {
|
|
925
|
-
return NEG_ZERO_NODE;
|
|
926
|
-
}
|
|
927
|
-
return createNumberNode(current);
|
|
928
|
-
}
|
|
1162
|
+
return createNumberNode(current);
|
|
929
1163
|
case "bigint":
|
|
930
1164
|
return createBigIntNode(ctx, current);
|
|
931
|
-
case "object":
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
1165
|
+
case "object":
|
|
1166
|
+
return parseObject(ctx, current);
|
|
1167
|
+
case "symbol":
|
|
1168
|
+
return createSymbolNode(ctx, current);
|
|
1169
|
+
case "function":
|
|
1170
|
+
return createFunctionNode(ctx, current);
|
|
1171
|
+
default:
|
|
1172
|
+
throw new UnsupportedTypeError(current);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
|
|
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);
|
|
1181
|
+
let item;
|
|
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);
|
|
941
1189
|
}
|
|
942
|
-
if (Array.isArray(current)) {
|
|
943
|
-
return generateArrayNode(ctx, id, current);
|
|
944
|
-
}
|
|
945
|
-
switch (current.constructor) {
|
|
946
|
-
case Date:
|
|
947
|
-
return createDateNode(id, current);
|
|
948
|
-
case RegExp:
|
|
949
|
-
return createRegExpNode(id, current);
|
|
950
|
-
case Promise:
|
|
951
|
-
return generatePromiseNode(ctx, id, current);
|
|
952
|
-
case Int8Array:
|
|
953
|
-
case Int16Array:
|
|
954
|
-
case Int32Array:
|
|
955
|
-
case Uint8Array:
|
|
956
|
-
case Uint16Array:
|
|
957
|
-
case Uint32Array:
|
|
958
|
-
case Uint8ClampedArray:
|
|
959
|
-
case Float32Array:
|
|
960
|
-
case Float64Array:
|
|
961
|
-
return createTypedArrayNode(ctx, id, current);
|
|
962
|
-
case BigInt64Array:
|
|
963
|
-
case BigUint64Array:
|
|
964
|
-
return createBigIntTypedArrayNode(ctx, id, current);
|
|
965
|
-
case Map:
|
|
966
|
-
return generateMapNode(
|
|
967
|
-
ctx,
|
|
968
|
-
id,
|
|
969
|
-
current
|
|
970
|
-
);
|
|
971
|
-
case Set:
|
|
972
|
-
return generateSetNode(
|
|
973
|
-
ctx,
|
|
974
|
-
id,
|
|
975
|
-
current
|
|
976
|
-
);
|
|
977
|
-
case Object:
|
|
978
|
-
return generateObjectNode(
|
|
979
|
-
ctx,
|
|
980
|
-
id,
|
|
981
|
-
current,
|
|
982
|
-
false
|
|
983
|
-
);
|
|
984
|
-
case void 0:
|
|
985
|
-
return generateObjectNode(
|
|
986
|
-
ctx,
|
|
987
|
-
id,
|
|
988
|
-
current,
|
|
989
|
-
true
|
|
990
|
-
);
|
|
991
|
-
case AggregateError:
|
|
992
|
-
if (ctx.features & 1 /* AggregateError */) {
|
|
993
|
-
return generateAggregateErrorNode(ctx, id, current);
|
|
994
|
-
}
|
|
995
|
-
return generateErrorNode(ctx, id, current);
|
|
996
|
-
case Error:
|
|
997
|
-
case EvalError:
|
|
998
|
-
case RangeError:
|
|
999
|
-
case ReferenceError:
|
|
1000
|
-
case SyntaxError:
|
|
1001
|
-
case TypeError:
|
|
1002
|
-
case URIError:
|
|
1003
|
-
return generateErrorNode(ctx, id, current);
|
|
1004
|
-
case URL:
|
|
1005
|
-
return createURLNode(ctx, id, current);
|
|
1006
|
-
case URLSearchParams:
|
|
1007
|
-
return createURLSearchParamsNode(ctx, id, current);
|
|
1008
|
-
default:
|
|
1009
|
-
break;
|
|
1010
|
-
}
|
|
1011
|
-
if (current instanceof AggregateError) {
|
|
1012
|
-
if (ctx.features & 1 /* AggregateError */) {
|
|
1013
|
-
return generateAggregateErrorNode(ctx, id, current);
|
|
1014
|
-
}
|
|
1015
|
-
return generateErrorNode(ctx, id, current);
|
|
1016
|
-
}
|
|
1017
|
-
if (current instanceof Error) {
|
|
1018
|
-
return generateErrorNode(ctx, id, current);
|
|
1019
|
-
}
|
|
1020
|
-
if (current instanceof Promise) {
|
|
1021
|
-
return generatePromiseNode(ctx, id, current);
|
|
1022
|
-
}
|
|
1023
|
-
if (Symbol.iterator in current) {
|
|
1024
|
-
return generateIterableNode(ctx, id, current);
|
|
1025
|
-
}
|
|
1026
|
-
if ("then" in current && typeof current.then === "function") {
|
|
1027
|
-
return generatePromiseNode(ctx, id, current);
|
|
1028
|
-
}
|
|
1029
|
-
throw new Error("Unsupported type");
|
|
1030
1190
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1191
|
+
}
|
|
1192
|
+
for (let i = 0; i < size; i++) {
|
|
1193
|
+
if (i in deferred) {
|
|
1194
|
+
nodes[i] = await parseAsync(ctx, deferred[i]);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
return nodes;
|
|
1198
|
+
}
|
|
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
|
+
};
|
|
1212
|
+
}
|
|
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++;
|
|
1047
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);
|
|
1048
1570
|
default:
|
|
1049
|
-
|
|
1571
|
+
break;
|
|
1050
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);
|
|
1051
1589
|
}
|
|
1052
1590
|
async function parseAsync(ctx, current) {
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
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
|
+
}
|
|
1056
1611
|
}
|
|
1057
1612
|
|
|
1058
1613
|
// src/tree/deserialize.ts
|
|
1059
1614
|
function assignIndexedValue(ctx, index, value) {
|
|
1060
|
-
ctx.
|
|
1615
|
+
if (ctx.markedRefs.has(index)) {
|
|
1616
|
+
ctx.valueMap.set(index, value);
|
|
1617
|
+
}
|
|
1061
1618
|
return value;
|
|
1062
1619
|
}
|
|
1063
|
-
function
|
|
1620
|
+
function deserializeArray(ctx, node) {
|
|
1621
|
+
const len = node.l;
|
|
1622
|
+
const result = assignIndexedValue(
|
|
1623
|
+
ctx,
|
|
1624
|
+
node.i,
|
|
1625
|
+
new Array(len)
|
|
1626
|
+
);
|
|
1064
1627
|
let item;
|
|
1065
|
-
for (let i = 0
|
|
1628
|
+
for (let i = 0; i < len; i++) {
|
|
1066
1629
|
item = node.a[i];
|
|
1067
1630
|
if (item) {
|
|
1068
1631
|
result[i] = deserializeTree(ctx, item);
|
|
@@ -1070,51 +1633,46 @@ function deserializeNodeList(ctx, node, result) {
|
|
|
1070
1633
|
}
|
|
1071
1634
|
return result;
|
|
1072
1635
|
}
|
|
1073
|
-
function deserializeArray(ctx, node) {
|
|
1074
|
-
const result = assignIndexedValue(
|
|
1075
|
-
ctx,
|
|
1076
|
-
node.i,
|
|
1077
|
-
new Array(node.l)
|
|
1078
|
-
);
|
|
1079
|
-
ctx.stack.push(node.i);
|
|
1080
|
-
deserializeNodeList(ctx, node, result);
|
|
1081
|
-
ctx.stack.pop();
|
|
1082
|
-
return result;
|
|
1083
|
-
}
|
|
1084
1636
|
function deserializeProperties(ctx, node, result) {
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
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
|
+
}
|
|
1090
1658
|
}
|
|
1091
1659
|
return result;
|
|
1092
1660
|
}
|
|
1093
|
-
function
|
|
1661
|
+
function deserializeObject(ctx, node) {
|
|
1094
1662
|
const result = assignIndexedValue(
|
|
1095
1663
|
ctx,
|
|
1096
1664
|
node.i,
|
|
1097
|
-
/* @__PURE__ */ Object.create(null)
|
|
1665
|
+
node.t === 10 /* Object */ ? {} : /* @__PURE__ */ Object.create(null)
|
|
1098
1666
|
);
|
|
1099
|
-
ctx.stack.push(node.i);
|
|
1100
|
-
deserializeProperties(ctx, node.d, result);
|
|
1101
|
-
ctx.stack.pop();
|
|
1102
|
-
return result;
|
|
1103
|
-
}
|
|
1104
|
-
function deserializeObject(ctx, node) {
|
|
1105
|
-
const result = assignIndexedValue(ctx, node.i, {});
|
|
1106
|
-
ctx.stack.push(node.i);
|
|
1107
1667
|
deserializeProperties(ctx, node.d, result);
|
|
1108
|
-
ctx.stack.pop();
|
|
1109
1668
|
return result;
|
|
1110
1669
|
}
|
|
1111
1670
|
function deserializeSet(ctx, node) {
|
|
1112
1671
|
const result = assignIndexedValue(ctx, node.i, /* @__PURE__ */ new Set());
|
|
1113
|
-
|
|
1114
|
-
for (let i = 0, len = node.
|
|
1115
|
-
result.add(deserializeTree(ctx,
|
|
1672
|
+
const items = node.a;
|
|
1673
|
+
for (let i = 0, len = node.l; i < len; i++) {
|
|
1674
|
+
result.add(deserializeTree(ctx, items[i]));
|
|
1116
1675
|
}
|
|
1117
|
-
ctx.stack.pop();
|
|
1118
1676
|
return result;
|
|
1119
1677
|
}
|
|
1120
1678
|
function deserializeMap(ctx, node) {
|
|
@@ -1123,35 +1681,34 @@ function deserializeMap(ctx, node) {
|
|
|
1123
1681
|
node.i,
|
|
1124
1682
|
/* @__PURE__ */ new Map()
|
|
1125
1683
|
);
|
|
1126
|
-
|
|
1127
|
-
|
|
1684
|
+
const keys = node.d.k;
|
|
1685
|
+
const vals = node.d.v;
|
|
1686
|
+
for (let i = 0, len = node.d.s; i < len; i++) {
|
|
1128
1687
|
result.set(
|
|
1129
|
-
deserializeTree(ctx,
|
|
1130
|
-
deserializeTree(ctx,
|
|
1688
|
+
deserializeTree(ctx, keys[i]),
|
|
1689
|
+
deserializeTree(ctx, vals[i])
|
|
1131
1690
|
);
|
|
1132
1691
|
}
|
|
1133
|
-
ctx.stack.pop();
|
|
1134
1692
|
return result;
|
|
1135
1693
|
}
|
|
1136
1694
|
function deserializeDictionary(ctx, node, result) {
|
|
1137
1695
|
if (node.d) {
|
|
1138
|
-
ctx.stack.push(node.i);
|
|
1139
1696
|
const fields = deserializeProperties(ctx, node.d, {});
|
|
1140
|
-
ctx.stack.pop();
|
|
1141
1697
|
Object.assign(result, fields);
|
|
1142
1698
|
}
|
|
1143
1699
|
return result;
|
|
1144
1700
|
}
|
|
1145
1701
|
function deserializeAggregateError(ctx, node) {
|
|
1146
|
-
const result = assignIndexedValue(
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1702
|
+
const result = assignIndexedValue(
|
|
1703
|
+
ctx,
|
|
1704
|
+
node.i,
|
|
1705
|
+
new AggregateError([], deserializeString(node.m))
|
|
1706
|
+
);
|
|
1150
1707
|
return deserializeDictionary(ctx, node, result);
|
|
1151
1708
|
}
|
|
1152
1709
|
function deserializeError(ctx, node) {
|
|
1153
1710
|
const ErrorConstructor = getErrorConstructor(node.c);
|
|
1154
|
-
const result = assignIndexedValue(ctx, node.i, new ErrorConstructor(
|
|
1711
|
+
const result = assignIndexedValue(ctx, node.i, new ErrorConstructor(deserializeString(node.m)));
|
|
1155
1712
|
return deserializeDictionary(ctx, node, result);
|
|
1156
1713
|
}
|
|
1157
1714
|
function createDeferred() {
|
|
@@ -1165,90 +1722,157 @@ function createDeferred() {
|
|
|
1165
1722
|
})
|
|
1166
1723
|
};
|
|
1167
1724
|
}
|
|
1168
|
-
function deserializePromise(ctx, node) {
|
|
1725
|
+
async function deserializePromise(ctx, node) {
|
|
1169
1726
|
const deferred = createDeferred();
|
|
1170
1727
|
const result = assignIndexedValue(ctx, node.i, deferred.promise);
|
|
1171
1728
|
deferred.resolve(deserializeTree(ctx, node.f));
|
|
1172
1729
|
return result;
|
|
1173
1730
|
}
|
|
1731
|
+
function deserializeArrayBuffer(ctx, node) {
|
|
1732
|
+
const bytes = new Uint8Array(node.s);
|
|
1733
|
+
const result = assignIndexedValue(ctx, node.i, bytes.buffer);
|
|
1734
|
+
return result;
|
|
1735
|
+
}
|
|
1174
1736
|
function deserializeTypedArray(ctx, node) {
|
|
1175
1737
|
const TypedArray = getTypedArrayConstructor(node.c);
|
|
1176
|
-
const
|
|
1738
|
+
const source = deserializeTree(ctx, node.f);
|
|
1177
1739
|
const result = assignIndexedValue(ctx, node.i, new TypedArray(
|
|
1178
|
-
|
|
1740
|
+
source,
|
|
1741
|
+
node.b,
|
|
1742
|
+
node.l
|
|
1743
|
+
));
|
|
1744
|
+
return result;
|
|
1745
|
+
}
|
|
1746
|
+
function deserializeDate(ctx, node) {
|
|
1747
|
+
return assignIndexedValue(ctx, node.i, new Date(node.s));
|
|
1748
|
+
}
|
|
1749
|
+
function deserializeRegExp(ctx, node) {
|
|
1750
|
+
return assignIndexedValue(ctx, node.i, new RegExp(node.c, node.m));
|
|
1751
|
+
}
|
|
1752
|
+
function deserializeURL(ctx, node) {
|
|
1753
|
+
return assignIndexedValue(ctx, node.i, new URL(deserializeString(node.s)));
|
|
1754
|
+
}
|
|
1755
|
+
function deserializeURLSearchParams(ctx, node) {
|
|
1756
|
+
return assignIndexedValue(ctx, node.i, new URLSearchParams(deserializeString(node.s)));
|
|
1757
|
+
}
|
|
1758
|
+
function deserializeReference(ctx, node) {
|
|
1759
|
+
return assignIndexedValue(ctx, node.i, getReference(deserializeString(node.s)));
|
|
1760
|
+
}
|
|
1761
|
+
function deserializeDataView(ctx, node) {
|
|
1762
|
+
const source = deserializeTree(ctx, node.f);
|
|
1763
|
+
const result = assignIndexedValue(ctx, node.i, new DataView(
|
|
1764
|
+
source,
|
|
1765
|
+
node.b,
|
|
1179
1766
|
node.l
|
|
1180
1767
|
));
|
|
1181
|
-
|
|
1182
|
-
|
|
1768
|
+
return result;
|
|
1769
|
+
}
|
|
1770
|
+
function deserializeBlob(ctx, node) {
|
|
1771
|
+
const source = deserializeTree(ctx, node.f);
|
|
1772
|
+
const result = assignIndexedValue(ctx, node.i, new Blob(
|
|
1773
|
+
[source],
|
|
1774
|
+
{ type: deserializeString(node.c) }
|
|
1775
|
+
));
|
|
1776
|
+
return result;
|
|
1777
|
+
}
|
|
1778
|
+
function deserializeFile(ctx, node) {
|
|
1779
|
+
const source = deserializeTree(ctx, node.f);
|
|
1780
|
+
const result = assignIndexedValue(ctx, node.i, new File(
|
|
1781
|
+
[source],
|
|
1782
|
+
deserializeString(node.m),
|
|
1783
|
+
{ type: deserializeString(node.c), lastModified: node.b }
|
|
1784
|
+
));
|
|
1785
|
+
return result;
|
|
1786
|
+
}
|
|
1787
|
+
function deserializeHeaders(ctx, node) {
|
|
1788
|
+
const result = assignIndexedValue(ctx, node.i, new Headers());
|
|
1789
|
+
const keys = node.d.k;
|
|
1790
|
+
const vals = node.d.v;
|
|
1791
|
+
for (let i = 0, len = node.d.s; i < len; i++) {
|
|
1792
|
+
result.set(
|
|
1793
|
+
deserializeString(keys[i]),
|
|
1794
|
+
deserializeTree(ctx, vals[i])
|
|
1795
|
+
);
|
|
1183
1796
|
}
|
|
1184
1797
|
return result;
|
|
1185
1798
|
}
|
|
1186
|
-
function
|
|
1187
|
-
const
|
|
1188
|
-
|
|
1189
|
-
const
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1799
|
+
function deserializeFormData(ctx, node) {
|
|
1800
|
+
const result = assignIndexedValue(ctx, node.i, new FormData());
|
|
1801
|
+
const keys = node.d.k;
|
|
1802
|
+
const vals = node.d.v;
|
|
1803
|
+
for (let i = 0, len = node.d.s; i < len; i++) {
|
|
1804
|
+
result.set(
|
|
1805
|
+
deserializeString(keys[i]),
|
|
1806
|
+
deserializeTree(ctx, vals[i])
|
|
1807
|
+
);
|
|
1808
|
+
}
|
|
1809
|
+
return result;
|
|
1810
|
+
}
|
|
1811
|
+
function deserializeBoxed(ctx, node) {
|
|
1812
|
+
return assignIndexedValue(
|
|
1813
|
+
ctx,
|
|
1814
|
+
node.i,
|
|
1815
|
+
Object(deserializeTree(ctx, node.f))
|
|
1816
|
+
);
|
|
1193
1817
|
}
|
|
1194
1818
|
function deserializeTree(ctx, node) {
|
|
1195
1819
|
switch (node.t) {
|
|
1820
|
+
case 2 /* Constant */:
|
|
1821
|
+
return deserializeConstant(node);
|
|
1196
1822
|
case 0 /* Number */:
|
|
1197
|
-
case 2 /* Boolean */:
|
|
1198
1823
|
return node.s;
|
|
1199
1824
|
case 1 /* String */:
|
|
1200
|
-
return
|
|
1201
|
-
case
|
|
1202
|
-
return void 0;
|
|
1203
|
-
case 3 /* Null */:
|
|
1204
|
-
return null;
|
|
1205
|
-
case 5 /* NegativeZero */:
|
|
1206
|
-
return -0;
|
|
1207
|
-
case 6 /* Infinity */:
|
|
1208
|
-
return Infinity;
|
|
1209
|
-
case 7 /* NegativeInfinity */:
|
|
1210
|
-
return -Infinity;
|
|
1211
|
-
case 8 /* NaN */:
|
|
1212
|
-
return NaN;
|
|
1213
|
-
case 9 /* BigInt */:
|
|
1825
|
+
return deserializeString(node.s);
|
|
1826
|
+
case 3 /* BigInt */:
|
|
1214
1827
|
return BigInt(node.s);
|
|
1215
|
-
case
|
|
1828
|
+
case 4 /* IndexedValue */:
|
|
1216
1829
|
return ctx.valueMap.get(node.i);
|
|
1217
|
-
case
|
|
1830
|
+
case 9 /* Array */:
|
|
1218
1831
|
return deserializeArray(ctx, node);
|
|
1219
|
-
case
|
|
1832
|
+
case 10 /* Object */:
|
|
1833
|
+
case 11 /* NullConstructor */:
|
|
1220
1834
|
return deserializeObject(ctx, node);
|
|
1221
|
-
case
|
|
1222
|
-
return
|
|
1223
|
-
case
|
|
1224
|
-
return
|
|
1225
|
-
case
|
|
1226
|
-
return assignIndexedValue(ctx, node.i, new RegExp(node.c, node.m));
|
|
1227
|
-
case 13 /* Set */:
|
|
1835
|
+
case 5 /* Date */:
|
|
1836
|
+
return deserializeDate(ctx, node);
|
|
1837
|
+
case 6 /* RegExp */:
|
|
1838
|
+
return deserializeRegExp(ctx, node);
|
|
1839
|
+
case 7 /* Set */:
|
|
1228
1840
|
return deserializeSet(ctx, node);
|
|
1229
|
-
case
|
|
1841
|
+
case 8 /* Map */:
|
|
1230
1842
|
return deserializeMap(ctx, node);
|
|
1231
|
-
case
|
|
1232
|
-
|
|
1843
|
+
case 21 /* ArrayBuffer */:
|
|
1844
|
+
return deserializeArrayBuffer(ctx, node);
|
|
1845
|
+
case 16 /* BigIntTypedArray */:
|
|
1846
|
+
case 15 /* TypedArray */:
|
|
1233
1847
|
return deserializeTypedArray(ctx, node);
|
|
1234
|
-
case
|
|
1848
|
+
case 22 /* DataView */:
|
|
1849
|
+
return deserializeDataView(ctx, node);
|
|
1850
|
+
case 14 /* AggregateError */:
|
|
1235
1851
|
return deserializeAggregateError(ctx, node);
|
|
1236
|
-
case
|
|
1852
|
+
case 13 /* Error */:
|
|
1237
1853
|
return deserializeError(ctx, node);
|
|
1238
|
-
case
|
|
1239
|
-
return deserializeIterable(ctx, node);
|
|
1240
|
-
case 18 /* Promise */:
|
|
1854
|
+
case 12 /* Promise */:
|
|
1241
1855
|
return deserializePromise(ctx, node);
|
|
1242
|
-
case
|
|
1856
|
+
case 17 /* WKSymbol */:
|
|
1243
1857
|
return SYMBOL_REF[node.s];
|
|
1244
|
-
case
|
|
1245
|
-
return
|
|
1246
|
-
case
|
|
1247
|
-
return
|
|
1248
|
-
case
|
|
1249
|
-
return
|
|
1858
|
+
case 18 /* URL */:
|
|
1859
|
+
return deserializeURL(ctx, node);
|
|
1860
|
+
case 19 /* URLSearchParams */:
|
|
1861
|
+
return deserializeURLSearchParams(ctx, node);
|
|
1862
|
+
case 20 /* Reference */:
|
|
1863
|
+
return deserializeReference(ctx, node);
|
|
1864
|
+
case 23 /* Blob */:
|
|
1865
|
+
return deserializeBlob(ctx, node);
|
|
1866
|
+
case 24 /* File */:
|
|
1867
|
+
return deserializeFile(ctx, node);
|
|
1868
|
+
case 25 /* Headers */:
|
|
1869
|
+
return deserializeHeaders(ctx, node);
|
|
1870
|
+
case 26 /* FormData */:
|
|
1871
|
+
return deserializeFormData(ctx, node);
|
|
1872
|
+
case 27 /* Boxed */:
|
|
1873
|
+
return deserializeBoxed(ctx, node);
|
|
1250
1874
|
default:
|
|
1251
|
-
throw new Error("
|
|
1875
|
+
throw new Error("invariant");
|
|
1252
1876
|
}
|
|
1253
1877
|
}
|
|
1254
1878
|
|
|
@@ -1257,10 +1881,12 @@ function getAssignmentExpression(assignment) {
|
|
|
1257
1881
|
switch (assignment.t) {
|
|
1258
1882
|
case "index":
|
|
1259
1883
|
return assignment.s + "=" + assignment.v;
|
|
1260
|
-
case "map":
|
|
1261
|
-
return assignment.s + ".set(" + assignment.k + "," + assignment.v + ")";
|
|
1262
1884
|
case "set":
|
|
1885
|
+
return assignment.s + ".set(" + assignment.k + "," + assignment.v + ")";
|
|
1886
|
+
case "add":
|
|
1263
1887
|
return assignment.s + ".add(" + assignment.v + ")";
|
|
1888
|
+
case "append":
|
|
1889
|
+
return assignment.s + ".append(" + assignment.k + "," + assignment.v + ")";
|
|
1264
1890
|
default:
|
|
1265
1891
|
return "";
|
|
1266
1892
|
}
|
|
@@ -1287,10 +1913,10 @@ function mergeAssignments(assignments) {
|
|
|
1287
1913
|
current = item;
|
|
1288
1914
|
}
|
|
1289
1915
|
break;
|
|
1290
|
-
case "
|
|
1916
|
+
case "set":
|
|
1291
1917
|
if (item.s === prev.s) {
|
|
1292
1918
|
current = {
|
|
1293
|
-
t: "
|
|
1919
|
+
t: "set",
|
|
1294
1920
|
s: getAssignmentExpression(current),
|
|
1295
1921
|
k: item.k,
|
|
1296
1922
|
v: item.v
|
|
@@ -1300,10 +1926,10 @@ function mergeAssignments(assignments) {
|
|
|
1300
1926
|
current = item;
|
|
1301
1927
|
}
|
|
1302
1928
|
break;
|
|
1303
|
-
case "
|
|
1929
|
+
case "add":
|
|
1304
1930
|
if (item.s === prev.s) {
|
|
1305
1931
|
current = {
|
|
1306
|
-
t: "
|
|
1932
|
+
t: "add",
|
|
1307
1933
|
s: getAssignmentExpression(current),
|
|
1308
1934
|
k: void 0,
|
|
1309
1935
|
v: item.v
|
|
@@ -1313,6 +1939,10 @@ function mergeAssignments(assignments) {
|
|
|
1313
1939
|
current = item;
|
|
1314
1940
|
}
|
|
1315
1941
|
break;
|
|
1942
|
+
case "append":
|
|
1943
|
+
newAssignments.push(current);
|
|
1944
|
+
current = item;
|
|
1945
|
+
break;
|
|
1316
1946
|
default:
|
|
1317
1947
|
break;
|
|
1318
1948
|
}
|
|
@@ -1347,26 +1977,31 @@ function createAssignment(ctx, source, value) {
|
|
|
1347
1977
|
v: value
|
|
1348
1978
|
});
|
|
1349
1979
|
}
|
|
1350
|
-
function
|
|
1351
|
-
markRef(ctx, ref);
|
|
1980
|
+
function createAddAssignment(ctx, ref, value) {
|
|
1352
1981
|
ctx.assignments.push({
|
|
1353
|
-
t: "
|
|
1982
|
+
t: "add",
|
|
1354
1983
|
s: getRefParam(ctx, ref),
|
|
1355
1984
|
k: void 0,
|
|
1356
1985
|
v: value
|
|
1357
1986
|
});
|
|
1358
1987
|
}
|
|
1359
|
-
function
|
|
1360
|
-
|
|
1988
|
+
function createSetAssignment(ctx, ref, key, value) {
|
|
1989
|
+
ctx.assignments.push({
|
|
1990
|
+
t: "set",
|
|
1991
|
+
s: getRefParam(ctx, ref),
|
|
1992
|
+
k: key,
|
|
1993
|
+
v: value
|
|
1994
|
+
});
|
|
1995
|
+
}
|
|
1996
|
+
function createAppendAssignment(ctx, ref, key, value) {
|
|
1361
1997
|
ctx.assignments.push({
|
|
1362
|
-
t: "
|
|
1998
|
+
t: "append",
|
|
1363
1999
|
s: getRefParam(ctx, ref),
|
|
1364
2000
|
k: key,
|
|
1365
2001
|
v: value
|
|
1366
2002
|
});
|
|
1367
2003
|
}
|
|
1368
2004
|
function createArrayAssign(ctx, ref, index, value) {
|
|
1369
|
-
markRef(ctx, ref);
|
|
1370
2005
|
createAssignment(ctx, getRefParam(ctx, ref) + "[" + index + "]", value);
|
|
1371
2006
|
}
|
|
1372
2007
|
function createObjectAssign(ctx, ref, key, value) {
|
|
@@ -1380,21 +2015,24 @@ function assignIndexedValue2(ctx, index, value) {
|
|
|
1380
2015
|
return value;
|
|
1381
2016
|
}
|
|
1382
2017
|
function isIndexedValueInStack(ctx, node) {
|
|
1383
|
-
return node.t ===
|
|
2018
|
+
return node.t === 4 /* IndexedValue */ && ctx.stack.includes(node.i);
|
|
1384
2019
|
}
|
|
1385
|
-
function
|
|
1386
|
-
const
|
|
2020
|
+
function serializeArray(ctx, node) {
|
|
2021
|
+
const id = node.i;
|
|
2022
|
+
ctx.stack.push(id);
|
|
1387
2023
|
let values = "";
|
|
1388
2024
|
let item;
|
|
1389
2025
|
let isHoley = false;
|
|
1390
|
-
|
|
2026
|
+
const list = node.a;
|
|
2027
|
+
for (let i = 0, len = node.l; i < len; i++) {
|
|
1391
2028
|
if (i !== 0) {
|
|
1392
2029
|
values += ",";
|
|
1393
2030
|
}
|
|
1394
|
-
item =
|
|
2031
|
+
item = list[i];
|
|
1395
2032
|
if (item) {
|
|
1396
2033
|
if (isIndexedValueInStack(ctx, item)) {
|
|
1397
|
-
|
|
2034
|
+
markRef(ctx, id);
|
|
2035
|
+
createArrayAssign(ctx, id, i, getRefParam(ctx, item.i));
|
|
1398
2036
|
isHoley = true;
|
|
1399
2037
|
} else {
|
|
1400
2038
|
values += serializeTree(ctx, item);
|
|
@@ -1404,16 +2042,29 @@ function serializeNodeList(ctx, node) {
|
|
|
1404
2042
|
isHoley = true;
|
|
1405
2043
|
}
|
|
1406
2044
|
}
|
|
1407
|
-
return "[" + values + (isHoley ? ",]" : "]");
|
|
1408
|
-
}
|
|
1409
|
-
function serializeArray(ctx, node) {
|
|
1410
|
-
ctx.stack.push(node.i);
|
|
1411
|
-
const result = serializeNodeList(ctx, node);
|
|
1412
2045
|
ctx.stack.pop();
|
|
1413
|
-
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;
|
|
1414
2064
|
}
|
|
1415
2065
|
function serializeProperties(ctx, sourceID, node) {
|
|
1416
|
-
|
|
2066
|
+
const len = node.s;
|
|
2067
|
+
if (len === 0) {
|
|
1417
2068
|
return "{}";
|
|
1418
2069
|
}
|
|
1419
2070
|
let result = "";
|
|
@@ -1424,21 +2075,32 @@ function serializeProperties(ctx, sourceID, node) {
|
|
|
1424
2075
|
let isIdentifier;
|
|
1425
2076
|
let refParam;
|
|
1426
2077
|
let hasPrev = false;
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
2078
|
+
const keys = node.k;
|
|
2079
|
+
const values = node.v;
|
|
2080
|
+
for (let i = 0; i < len; i++) {
|
|
2081
|
+
key = keys[i];
|
|
2082
|
+
val = values[i];
|
|
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;
|
|
1442
2104
|
}
|
|
1443
2105
|
}
|
|
1444
2106
|
ctx.stack.pop();
|
|
@@ -1454,26 +2116,41 @@ function serializeWithObjectAssign(ctx, value, id, serialized) {
|
|
|
1454
2116
|
function serializeAssignments(ctx, sourceID, node) {
|
|
1455
2117
|
ctx.stack.push(sourceID);
|
|
1456
2118
|
const mainAssignments = [];
|
|
1457
|
-
let parentStack;
|
|
1458
|
-
let refParam;
|
|
1459
2119
|
let key;
|
|
1460
|
-
let
|
|
2120
|
+
let value;
|
|
1461
2121
|
let parentAssignment;
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
ctx.stack = parentStack;
|
|
1468
|
-
key = node.k[i];
|
|
1469
|
-
check = Number(key);
|
|
2122
|
+
const keys = node.k;
|
|
2123
|
+
const values = node.v;
|
|
2124
|
+
for (let i = 0, len = node.s; i < len; i++) {
|
|
2125
|
+
key = keys[i];
|
|
2126
|
+
value = values[i];
|
|
1470
2127
|
parentAssignment = ctx.assignments;
|
|
1471
2128
|
ctx.assignments = mainAssignments;
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
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
|
+
}
|
|
1477
2154
|
}
|
|
1478
2155
|
ctx.assignments = parentAssignment;
|
|
1479
2156
|
}
|
|
@@ -1494,8 +2171,9 @@ function serializeDictionary(ctx, i, d, init) {
|
|
|
1494
2171
|
}
|
|
1495
2172
|
return assignIndexedValue2(ctx, i, init);
|
|
1496
2173
|
}
|
|
2174
|
+
var NULL_CONSTRUCTOR = "Object.create(null)";
|
|
1497
2175
|
function serializeNullConstructor(ctx, node) {
|
|
1498
|
-
return serializeDictionary(ctx, node.i, node.d,
|
|
2176
|
+
return serializeDictionary(ctx, node.i, node.d, NULL_CONSTRUCTOR);
|
|
1499
2177
|
}
|
|
1500
2178
|
function serializeObject(ctx, node) {
|
|
1501
2179
|
return assignIndexedValue2(ctx, node.i, serializeProperties(ctx, node.i, node.d));
|
|
@@ -1503,15 +2181,18 @@ function serializeObject(ctx, node) {
|
|
|
1503
2181
|
function serializeSet(ctx, node) {
|
|
1504
2182
|
let serialized = "new Set";
|
|
1505
2183
|
const size = node.l;
|
|
2184
|
+
const id = node.i;
|
|
1506
2185
|
if (size) {
|
|
1507
2186
|
let result = "";
|
|
1508
|
-
ctx.stack.push(node.i);
|
|
1509
2187
|
let item;
|
|
1510
2188
|
let hasPrev = false;
|
|
2189
|
+
const items = node.a;
|
|
2190
|
+
ctx.stack.push(id);
|
|
1511
2191
|
for (let i = 0; i < size; i++) {
|
|
1512
|
-
item =
|
|
2192
|
+
item = items[i];
|
|
1513
2193
|
if (isIndexedValueInStack(ctx, item)) {
|
|
1514
|
-
|
|
2194
|
+
markRef(ctx, id);
|
|
2195
|
+
createAddAssignment(ctx, id, getRefParam(ctx, item.i));
|
|
1515
2196
|
} else {
|
|
1516
2197
|
result += (hasPrev ? "," : "") + serializeTree(ctx, item);
|
|
1517
2198
|
hasPrev = true;
|
|
@@ -1522,38 +2203,44 @@ function serializeSet(ctx, node) {
|
|
|
1522
2203
|
serialized += "([" + result + "])";
|
|
1523
2204
|
}
|
|
1524
2205
|
}
|
|
1525
|
-
return assignIndexedValue2(ctx,
|
|
2206
|
+
return assignIndexedValue2(ctx, id, serialized);
|
|
1526
2207
|
}
|
|
1527
2208
|
function serializeMap(ctx, node) {
|
|
1528
2209
|
let serialized = "new Map";
|
|
1529
|
-
|
|
2210
|
+
const size = node.d.s;
|
|
2211
|
+
const id = node.i;
|
|
2212
|
+
if (size) {
|
|
1530
2213
|
let result = "";
|
|
1531
|
-
ctx.stack.push(node.i);
|
|
1532
2214
|
let key;
|
|
1533
2215
|
let val;
|
|
1534
2216
|
let keyRef;
|
|
1535
2217
|
let valueRef;
|
|
1536
2218
|
let parent;
|
|
1537
2219
|
let hasPrev = false;
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
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];
|
|
1541
2226
|
if (isIndexedValueInStack(ctx, key)) {
|
|
1542
|
-
keyRef = getRefParam(ctx,
|
|
2227
|
+
keyRef = getRefParam(ctx, id);
|
|
2228
|
+
markRef(ctx, id);
|
|
1543
2229
|
if (isIndexedValueInStack(ctx, val)) {
|
|
1544
2230
|
valueRef = getRefParam(ctx, val.i);
|
|
1545
|
-
|
|
2231
|
+
createSetAssignment(ctx, id, keyRef, valueRef);
|
|
1546
2232
|
} else {
|
|
1547
2233
|
parent = ctx.stack;
|
|
1548
2234
|
ctx.stack = [];
|
|
1549
|
-
|
|
2235
|
+
createSetAssignment(ctx, id, keyRef, serializeTree(ctx, val));
|
|
1550
2236
|
ctx.stack = parent;
|
|
1551
2237
|
}
|
|
1552
2238
|
} else if (isIndexedValueInStack(ctx, val)) {
|
|
1553
2239
|
valueRef = getRefParam(ctx, val.i);
|
|
2240
|
+
markRef(ctx, id);
|
|
1554
2241
|
parent = ctx.stack;
|
|
1555
2242
|
ctx.stack = [];
|
|
1556
|
-
|
|
2243
|
+
createSetAssignment(ctx, id, serializeTree(ctx, key), valueRef);
|
|
1557
2244
|
ctx.stack = parent;
|
|
1558
2245
|
} else {
|
|
1559
2246
|
result += (hasPrev ? ",[" : "[") + serializeTree(ctx, key) + "," + serializeTree(ctx, val) + "]";
|
|
@@ -1565,63 +2252,142 @@ function serializeMap(ctx, node) {
|
|
|
1565
2252
|
serialized += "([" + result + "])";
|
|
1566
2253
|
}
|
|
1567
2254
|
}
|
|
1568
|
-
return assignIndexedValue2(ctx,
|
|
2255
|
+
return assignIndexedValue2(ctx, id, serialized);
|
|
1569
2256
|
}
|
|
1570
2257
|
function serializeAggregateError(ctx, node) {
|
|
1571
|
-
|
|
1572
|
-
|
|
2258
|
+
const id = node.i;
|
|
2259
|
+
ctx.stack.push(id);
|
|
2260
|
+
const serialized = 'new AggregateError([],"' + node.m + '")';
|
|
1573
2261
|
ctx.stack.pop();
|
|
1574
|
-
return serializeDictionary(ctx,
|
|
2262
|
+
return serializeDictionary(ctx, id, node.d, serialized);
|
|
1575
2263
|
}
|
|
1576
2264
|
function serializeError(ctx, node) {
|
|
1577
|
-
|
|
1578
|
-
return serializeDictionary(ctx, node.i, node.d, serialized);
|
|
2265
|
+
return serializeDictionary(ctx, node.i, node.d, "new " + node.c + '("' + node.m + '")');
|
|
1579
2266
|
}
|
|
1580
2267
|
function serializePromise(ctx, node) {
|
|
1581
2268
|
let serialized;
|
|
1582
|
-
|
|
1583
|
-
|
|
2269
|
+
const fulfilled = node.f;
|
|
2270
|
+
const id = node.i;
|
|
2271
|
+
if (isIndexedValueInStack(ctx, fulfilled)) {
|
|
2272
|
+
const ref = getRefParam(ctx, fulfilled.i);
|
|
1584
2273
|
if (ctx.features & 4 /* ArrowFunction */) {
|
|
1585
2274
|
serialized = "Promise.resolve().then(()=>" + ref + ")";
|
|
1586
2275
|
} else {
|
|
1587
2276
|
serialized = "Promise.resolve().then(function(){return " + ref + "})";
|
|
1588
2277
|
}
|
|
1589
2278
|
} else {
|
|
1590
|
-
ctx.stack.push(
|
|
1591
|
-
const result = serializeTree(ctx,
|
|
2279
|
+
ctx.stack.push(id);
|
|
2280
|
+
const result = serializeTree(ctx, fulfilled);
|
|
1592
2281
|
ctx.stack.pop();
|
|
1593
2282
|
serialized = "Promise.resolve(" + result + ")";
|
|
1594
2283
|
}
|
|
1595
|
-
return assignIndexedValue2(ctx,
|
|
2284
|
+
return assignIndexedValue2(ctx, id, serialized);
|
|
2285
|
+
}
|
|
2286
|
+
function serializeArrayBuffer2(ctx, node) {
|
|
2287
|
+
let result = "new Uint8Array(";
|
|
2288
|
+
const buffer = node.s;
|
|
2289
|
+
const len = buffer.length;
|
|
2290
|
+
if (len) {
|
|
2291
|
+
result += "[";
|
|
2292
|
+
for (let i = 0; i < len; i++) {
|
|
2293
|
+
result += (i > 0 ? "," : "") + buffer[i];
|
|
2294
|
+
}
|
|
2295
|
+
result += "]";
|
|
2296
|
+
}
|
|
2297
|
+
return assignIndexedValue2(ctx, node.i, result + ").buffer");
|
|
1596
2298
|
}
|
|
1597
2299
|
function serializeTypedArray(ctx, node) {
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
2300
|
+
return assignIndexedValue2(
|
|
2301
|
+
ctx,
|
|
2302
|
+
node.i,
|
|
2303
|
+
"new " + node.c + "(" + serializeTree(ctx, node.f) + "," + node.b + "," + node.l + ")"
|
|
2304
|
+
);
|
|
2305
|
+
}
|
|
2306
|
+
function serializeDate(ctx, node) {
|
|
2307
|
+
return assignIndexedValue2(ctx, node.i, 'new Date("' + node.s + '")');
|
|
2308
|
+
}
|
|
2309
|
+
function serializeRegExp(ctx, node) {
|
|
2310
|
+
return assignIndexedValue2(ctx, node.i, "/" + node.c + "/" + node.m);
|
|
2311
|
+
}
|
|
2312
|
+
function serializeURL(ctx, node) {
|
|
2313
|
+
return assignIndexedValue2(ctx, node.i, 'new URL("' + node.s + '")');
|
|
2314
|
+
}
|
|
2315
|
+
function serializeURLSearchParams(ctx, node) {
|
|
2316
|
+
return assignIndexedValue2(
|
|
2317
|
+
ctx,
|
|
2318
|
+
node.i,
|
|
2319
|
+
node.s ? 'new URLSearchParams("' + node.s + '")' : "new URLSearchParams"
|
|
2320
|
+
);
|
|
2321
|
+
}
|
|
2322
|
+
function serializeReference(ctx, node) {
|
|
2323
|
+
return assignIndexedValue2(ctx, node.i, GLOBAL_KEY + '.get("' + node.s + '")');
|
|
2324
|
+
}
|
|
2325
|
+
function serializeDataView(ctx, node) {
|
|
2326
|
+
return assignIndexedValue2(
|
|
2327
|
+
ctx,
|
|
2328
|
+
node.i,
|
|
2329
|
+
"new DataView(" + serializeTree(ctx, node.f) + "," + node.b + "," + node.l + ")"
|
|
2330
|
+
);
|
|
2331
|
+
}
|
|
2332
|
+
function serializeBlob(ctx, node) {
|
|
2333
|
+
return assignIndexedValue2(
|
|
2334
|
+
ctx,
|
|
2335
|
+
node.i,
|
|
2336
|
+
"new Blob([" + serializeTree(ctx, node.f) + '],{type:"' + node.c + '"})'
|
|
2337
|
+
);
|
|
2338
|
+
}
|
|
2339
|
+
function serializeFile(ctx, node) {
|
|
2340
|
+
return assignIndexedValue2(
|
|
2341
|
+
ctx,
|
|
2342
|
+
node.i,
|
|
2343
|
+
"new File([" + serializeTree(ctx, node.f) + '],"' + node.m + '",{type:"' + node.c + '",lastModified:' + node.b + "})"
|
|
2344
|
+
);
|
|
2345
|
+
}
|
|
2346
|
+
function serializeHeaders(ctx, node) {
|
|
2347
|
+
return assignIndexedValue2(
|
|
2348
|
+
ctx,
|
|
2349
|
+
node.i,
|
|
2350
|
+
"new Headers(" + serializeProperties(ctx, node.i, node.d) + ")"
|
|
2351
|
+
);
|
|
2352
|
+
}
|
|
2353
|
+
function serializeFormDataEntries(ctx, node) {
|
|
2354
|
+
let value;
|
|
2355
|
+
let key;
|
|
2356
|
+
const keys = node.d.k;
|
|
2357
|
+
const vals = node.d.v;
|
|
2358
|
+
const id = node.i;
|
|
2359
|
+
const mainAssignments = [];
|
|
2360
|
+
let parentAssignment;
|
|
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]);
|
|
2365
|
+
parentAssignment = ctx.assignments;
|
|
2366
|
+
ctx.assignments = mainAssignments;
|
|
2367
|
+
createAppendAssignment(ctx, id, '"' + key + '"', value);
|
|
2368
|
+
ctx.assignments = parentAssignment;
|
|
1602
2369
|
}
|
|
1603
|
-
|
|
1604
|
-
return
|
|
2370
|
+
ctx.stack.pop();
|
|
2371
|
+
return resolveAssignments(mainAssignments);
|
|
1605
2372
|
}
|
|
1606
|
-
function
|
|
1607
|
-
const
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
let serialized = values;
|
|
1612
|
-
if (ctx.features & 2 /* ArrayPrototypeValues */) {
|
|
1613
|
-
serialized += ".values()";
|
|
1614
|
-
} else {
|
|
1615
|
-
serialized += "[Symbol.iterator]()";
|
|
2373
|
+
function serializeFormData(ctx, node) {
|
|
2374
|
+
const size = node.d.s;
|
|
2375
|
+
const id = node.i;
|
|
2376
|
+
if (size) {
|
|
2377
|
+
markRef(ctx, id);
|
|
1616
2378
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
} else {
|
|
1622
|
-
serialized = "{[Symbol.iterator]:function(){return " + serialized + "}}";
|
|
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) + ")";
|
|
1623
2383
|
}
|
|
1624
|
-
return
|
|
2384
|
+
return result;
|
|
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]);
|
|
1625
2391
|
}
|
|
1626
2392
|
function serializeTree(ctx, node) {
|
|
1627
2393
|
switch (node.t) {
|
|
@@ -1629,393 +2395,61 @@ function serializeTree(ctx, node) {
|
|
|
1629
2395
|
return "" + node.s;
|
|
1630
2396
|
case 1 /* String */:
|
|
1631
2397
|
return '"' + node.s + '"';
|
|
1632
|
-
case 2 /*
|
|
1633
|
-
return node
|
|
1634
|
-
case
|
|
1635
|
-
return "void 0";
|
|
1636
|
-
case 3 /* Null */:
|
|
1637
|
-
return "null";
|
|
1638
|
-
case 5 /* NegativeZero */:
|
|
1639
|
-
return "-0";
|
|
1640
|
-
case 6 /* Infinity */:
|
|
1641
|
-
return "1/0";
|
|
1642
|
-
case 7 /* NegativeInfinity */:
|
|
1643
|
-
return "-1/0";
|
|
1644
|
-
case 8 /* NaN */:
|
|
1645
|
-
return "NaN";
|
|
1646
|
-
case 9 /* BigInt */:
|
|
2398
|
+
case 2 /* Constant */:
|
|
2399
|
+
return serializeConstant(node);
|
|
2400
|
+
case 3 /* BigInt */:
|
|
1647
2401
|
return node.s + "n";
|
|
1648
|
-
case
|
|
2402
|
+
case 4 /* IndexedValue */:
|
|
1649
2403
|
return getRefParam(ctx, node.i);
|
|
1650
|
-
case
|
|
2404
|
+
case 9 /* Array */:
|
|
1651
2405
|
return serializeArray(ctx, node);
|
|
1652
|
-
case
|
|
2406
|
+
case 10 /* Object */:
|
|
1653
2407
|
return serializeObject(ctx, node);
|
|
1654
|
-
case
|
|
2408
|
+
case 11 /* NullConstructor */:
|
|
1655
2409
|
return serializeNullConstructor(ctx, node);
|
|
1656
|
-
case
|
|
1657
|
-
return
|
|
1658
|
-
case
|
|
1659
|
-
return
|
|
1660
|
-
case
|
|
2410
|
+
case 5 /* Date */:
|
|
2411
|
+
return serializeDate(ctx, node);
|
|
2412
|
+
case 6 /* RegExp */:
|
|
2413
|
+
return serializeRegExp(ctx, node);
|
|
2414
|
+
case 7 /* Set */:
|
|
1661
2415
|
return serializeSet(ctx, node);
|
|
1662
|
-
case
|
|
2416
|
+
case 8 /* Map */:
|
|
1663
2417
|
return serializeMap(ctx, node);
|
|
1664
|
-
case
|
|
1665
|
-
|
|
2418
|
+
case 21 /* ArrayBuffer */:
|
|
2419
|
+
return serializeArrayBuffer2(ctx, node);
|
|
2420
|
+
case 16 /* BigIntTypedArray */:
|
|
2421
|
+
case 15 /* TypedArray */:
|
|
1666
2422
|
return serializeTypedArray(ctx, node);
|
|
1667
|
-
case
|
|
2423
|
+
case 22 /* DataView */:
|
|
2424
|
+
return serializeDataView(ctx, node);
|
|
2425
|
+
case 14 /* AggregateError */:
|
|
1668
2426
|
return serializeAggregateError(ctx, node);
|
|
1669
|
-
case
|
|
2427
|
+
case 13 /* Error */:
|
|
1670
2428
|
return serializeError(ctx, node);
|
|
1671
|
-
case
|
|
1672
|
-
return serializeIterable(ctx, node);
|
|
1673
|
-
case 18 /* Promise */:
|
|
2429
|
+
case 12 /* Promise */:
|
|
1674
2430
|
return serializePromise(ctx, node);
|
|
1675
|
-
case
|
|
1676
|
-
return
|
|
1677
|
-
case
|
|
1678
|
-
return
|
|
1679
|
-
case
|
|
1680
|
-
return
|
|
1681
|
-
case
|
|
1682
|
-
return
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
let item;
|
|
1694
|
-
for (let i = 0; i < size; i++) {
|
|
1695
|
-
if (i in current) {
|
|
1696
|
-
item = current[i];
|
|
1697
|
-
if (isIterable(item)) {
|
|
1698
|
-
deferred[i] = item;
|
|
1699
|
-
} else {
|
|
1700
|
-
nodes[i] = parse2(ctx, item);
|
|
1701
|
-
}
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
for (let i = 0; i < size; i++) {
|
|
1705
|
-
if (i in deferred) {
|
|
1706
|
-
nodes[i] = parse2(ctx, deferred[i]);
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
return nodes;
|
|
1710
|
-
}
|
|
1711
|
-
function generateArrayNode2(ctx, id, current) {
|
|
1712
|
-
return {
|
|
1713
|
-
t: 15 /* Array */,
|
|
1714
|
-
i: id,
|
|
1715
|
-
s: void 0,
|
|
1716
|
-
l: current.length,
|
|
1717
|
-
c: void 0,
|
|
1718
|
-
m: void 0,
|
|
1719
|
-
d: void 0,
|
|
1720
|
-
a: generateNodeList2(ctx, current),
|
|
1721
|
-
f: void 0
|
|
1722
|
-
};
|
|
1723
|
-
}
|
|
1724
|
-
function generateMapNode2(ctx, id, current) {
|
|
1725
|
-
assert(ctx.features & 32 /* Map */, 'Unsupported type "Map"');
|
|
1726
|
-
const len = current.size;
|
|
1727
|
-
const keyNodes = new Array(len);
|
|
1728
|
-
const valueNodes = new Array(len);
|
|
1729
|
-
const deferredKey = new Array(len);
|
|
1730
|
-
const deferredValue = new Array(len);
|
|
1731
|
-
let deferredSize = 0;
|
|
1732
|
-
let nodeSize = 0;
|
|
1733
|
-
for (const [key, value] of current.entries()) {
|
|
1734
|
-
if (isIterable(key) || isIterable(value)) {
|
|
1735
|
-
deferredKey[deferredSize] = key;
|
|
1736
|
-
deferredValue[deferredSize] = value;
|
|
1737
|
-
deferredSize++;
|
|
1738
|
-
} else {
|
|
1739
|
-
keyNodes[nodeSize] = parse2(ctx, key);
|
|
1740
|
-
valueNodes[nodeSize] = parse2(ctx, value);
|
|
1741
|
-
nodeSize++;
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
for (let i = 0; i < deferredSize; i++) {
|
|
1745
|
-
keyNodes[nodeSize + i] = parse2(ctx, deferredKey[i]);
|
|
1746
|
-
valueNodes[nodeSize + i] = parse2(ctx, deferredValue[i]);
|
|
1747
|
-
}
|
|
1748
|
-
return {
|
|
1749
|
-
t: 14 /* Map */,
|
|
1750
|
-
i: id,
|
|
1751
|
-
s: void 0,
|
|
1752
|
-
l: void 0,
|
|
1753
|
-
c: void 0,
|
|
1754
|
-
m: void 0,
|
|
1755
|
-
d: { k: keyNodes, v: valueNodes, s: len },
|
|
1756
|
-
a: void 0,
|
|
1757
|
-
f: void 0
|
|
1758
|
-
};
|
|
1759
|
-
}
|
|
1760
|
-
function generateSetNode2(ctx, id, current) {
|
|
1761
|
-
assert(ctx.features & 512 /* Set */, 'Unsupported type "Set"');
|
|
1762
|
-
const len = current.size;
|
|
1763
|
-
const nodes = new Array(len);
|
|
1764
|
-
const deferred = new Array(len);
|
|
1765
|
-
let deferredSize = 0;
|
|
1766
|
-
let nodeSize = 0;
|
|
1767
|
-
for (const item of current.keys()) {
|
|
1768
|
-
if (isIterable(item)) {
|
|
1769
|
-
deferred[deferredSize++] = item;
|
|
1770
|
-
} else {
|
|
1771
|
-
nodes[nodeSize++] = parse2(ctx, item);
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
for (let i = 0; i < deferredSize; i++) {
|
|
1775
|
-
nodes[nodeSize + i] = parse2(ctx, deferred[i]);
|
|
1776
|
-
}
|
|
1777
|
-
return {
|
|
1778
|
-
t: 13 /* Set */,
|
|
1779
|
-
i: id,
|
|
1780
|
-
s: void 0,
|
|
1781
|
-
l: len,
|
|
1782
|
-
c: void 0,
|
|
1783
|
-
m: void 0,
|
|
1784
|
-
d: void 0,
|
|
1785
|
-
a: nodes,
|
|
1786
|
-
f: void 0
|
|
1787
|
-
};
|
|
1788
|
-
}
|
|
1789
|
-
function generateProperties2(ctx, properties) {
|
|
1790
|
-
const keys = Object.keys(properties);
|
|
1791
|
-
const size = keys.length;
|
|
1792
|
-
const keyNodes = new Array(size);
|
|
1793
|
-
const valueNodes = new Array(size);
|
|
1794
|
-
const deferredKeys = new Array(size);
|
|
1795
|
-
const deferredValues = new Array(size);
|
|
1796
|
-
let deferredSize = 0;
|
|
1797
|
-
let nodesSize = 0;
|
|
1798
|
-
let item;
|
|
1799
|
-
for (const key of keys) {
|
|
1800
|
-
item = properties[key];
|
|
1801
|
-
if (isIterable(item)) {
|
|
1802
|
-
deferredKeys[deferredSize] = key;
|
|
1803
|
-
deferredValues[deferredSize] = item;
|
|
1804
|
-
deferredSize++;
|
|
1805
|
-
} else {
|
|
1806
|
-
keyNodes[nodesSize] = key;
|
|
1807
|
-
valueNodes[nodesSize] = parse2(ctx, item);
|
|
1808
|
-
nodesSize++;
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
|
-
for (let i = 0; i < deferredSize; i++) {
|
|
1812
|
-
keyNodes[nodesSize + i] = deferredKeys[i];
|
|
1813
|
-
valueNodes[nodesSize + i] = parse2(ctx, deferredValues[i]);
|
|
1814
|
-
}
|
|
1815
|
-
return {
|
|
1816
|
-
k: keyNodes,
|
|
1817
|
-
v: valueNodes,
|
|
1818
|
-
s: size
|
|
1819
|
-
};
|
|
1820
|
-
}
|
|
1821
|
-
function generateIterableNode2(ctx, id, current) {
|
|
1822
|
-
assert(ctx.features & 1024 /* Symbol */, 'Unsupported type "Iterable"');
|
|
1823
|
-
const options = getIterableOptions(current);
|
|
1824
|
-
const array = Array.from(current);
|
|
1825
|
-
return {
|
|
1826
|
-
t: 21 /* Iterable */,
|
|
1827
|
-
i: id,
|
|
1828
|
-
s: void 0,
|
|
1829
|
-
l: array.length,
|
|
1830
|
-
c: void 0,
|
|
1831
|
-
m: void 0,
|
|
1832
|
-
// Parse options first before the items
|
|
1833
|
-
d: options ? generateProperties2(ctx, options) : void 0,
|
|
1834
|
-
a: generateNodeList2(ctx, array),
|
|
1835
|
-
f: void 0
|
|
1836
|
-
};
|
|
1837
|
-
}
|
|
1838
|
-
function generateObjectNode2(ctx, id, current, empty) {
|
|
1839
|
-
if (Symbol.iterator in current) {
|
|
1840
|
-
return generateIterableNode2(ctx, id, current);
|
|
1841
|
-
}
|
|
1842
|
-
return {
|
|
1843
|
-
t: empty ? 17 /* NullConstructor */ : 16 /* Object */,
|
|
1844
|
-
i: id,
|
|
1845
|
-
s: void 0,
|
|
1846
|
-
l: void 0,
|
|
1847
|
-
c: void 0,
|
|
1848
|
-
m: void 0,
|
|
1849
|
-
d: generateProperties2(ctx, current),
|
|
1850
|
-
a: void 0,
|
|
1851
|
-
f: void 0
|
|
1852
|
-
};
|
|
1853
|
-
}
|
|
1854
|
-
function generateAggregateErrorNode2(ctx, id, current) {
|
|
1855
|
-
const options = getErrorOptions(ctx, current);
|
|
1856
|
-
const optionsNode = options ? generateProperties2(ctx, options) : void 0;
|
|
1857
|
-
return {
|
|
1858
|
-
t: 20 /* AggregateError */,
|
|
1859
|
-
i: id,
|
|
1860
|
-
s: void 0,
|
|
1861
|
-
l: current.errors.length,
|
|
1862
|
-
c: void 0,
|
|
1863
|
-
m: quote(current.message),
|
|
1864
|
-
d: optionsNode,
|
|
1865
|
-
a: generateNodeList2(ctx, current.errors),
|
|
1866
|
-
f: void 0
|
|
1867
|
-
};
|
|
1868
|
-
}
|
|
1869
|
-
function generateErrorNode2(ctx, id, current) {
|
|
1870
|
-
const options = getErrorOptions(ctx, current);
|
|
1871
|
-
const optionsNode = options ? generateProperties2(ctx, options) : void 0;
|
|
1872
|
-
return {
|
|
1873
|
-
t: 19 /* Error */,
|
|
1874
|
-
i: id,
|
|
1875
|
-
s: void 0,
|
|
1876
|
-
l: void 0,
|
|
1877
|
-
c: getErrorConstructorName(current),
|
|
1878
|
-
m: quote(current.message),
|
|
1879
|
-
d: optionsNode,
|
|
1880
|
-
a: void 0,
|
|
1881
|
-
f: void 0
|
|
1882
|
-
};
|
|
1883
|
-
}
|
|
1884
|
-
function parse2(ctx, current) {
|
|
1885
|
-
switch (typeof current) {
|
|
1886
|
-
case "boolean":
|
|
1887
|
-
return current ? TRUE_NODE : FALSE_NODE;
|
|
1888
|
-
case "undefined":
|
|
1889
|
-
return UNDEFINED_NODE;
|
|
1890
|
-
case "string":
|
|
1891
|
-
return createStringNode(current);
|
|
1892
|
-
case "number":
|
|
1893
|
-
switch (current) {
|
|
1894
|
-
case Infinity:
|
|
1895
|
-
return INFINITY_NODE;
|
|
1896
|
-
case -Infinity:
|
|
1897
|
-
return NEG_INFINITY_NODE;
|
|
1898
|
-
default:
|
|
1899
|
-
if (current !== current) {
|
|
1900
|
-
return NAN_NODE;
|
|
1901
|
-
}
|
|
1902
|
-
if (Object.is(current, -0)) {
|
|
1903
|
-
return NEG_ZERO_NODE;
|
|
1904
|
-
}
|
|
1905
|
-
return createNumberNode(current);
|
|
1906
|
-
}
|
|
1907
|
-
case "bigint":
|
|
1908
|
-
return createBigIntNode(ctx, current);
|
|
1909
|
-
case "object": {
|
|
1910
|
-
if (!current) {
|
|
1911
|
-
return NULL_NODE;
|
|
1912
|
-
}
|
|
1913
|
-
const id = createIndexedValue(ctx, current);
|
|
1914
|
-
if (ctx.markedRefs.has(id)) {
|
|
1915
|
-
return createIndexedValueNode(id);
|
|
1916
|
-
}
|
|
1917
|
-
if (hasReferenceID(current)) {
|
|
1918
|
-
return createReferenceNode(id, current);
|
|
1919
|
-
}
|
|
1920
|
-
if (Array.isArray(current)) {
|
|
1921
|
-
return generateArrayNode2(ctx, id, current);
|
|
1922
|
-
}
|
|
1923
|
-
switch (current.constructor) {
|
|
1924
|
-
case Date:
|
|
1925
|
-
return createDateNode(id, current);
|
|
1926
|
-
case RegExp:
|
|
1927
|
-
return createRegExpNode(id, current);
|
|
1928
|
-
case Int8Array:
|
|
1929
|
-
case Int16Array:
|
|
1930
|
-
case Int32Array:
|
|
1931
|
-
case Uint8Array:
|
|
1932
|
-
case Uint16Array:
|
|
1933
|
-
case Uint32Array:
|
|
1934
|
-
case Uint8ClampedArray:
|
|
1935
|
-
case Float32Array:
|
|
1936
|
-
case Float64Array:
|
|
1937
|
-
return createTypedArrayNode(ctx, id, current);
|
|
1938
|
-
case BigInt64Array:
|
|
1939
|
-
case BigUint64Array:
|
|
1940
|
-
return createBigIntTypedArrayNode(ctx, id, current);
|
|
1941
|
-
case Map:
|
|
1942
|
-
return generateMapNode2(ctx, id, current);
|
|
1943
|
-
case Set:
|
|
1944
|
-
return generateSetNode2(ctx, id, current);
|
|
1945
|
-
case Object:
|
|
1946
|
-
return generateObjectNode2(
|
|
1947
|
-
ctx,
|
|
1948
|
-
id,
|
|
1949
|
-
current,
|
|
1950
|
-
false
|
|
1951
|
-
);
|
|
1952
|
-
case void 0:
|
|
1953
|
-
return generateObjectNode2(
|
|
1954
|
-
ctx,
|
|
1955
|
-
id,
|
|
1956
|
-
current,
|
|
1957
|
-
true
|
|
1958
|
-
);
|
|
1959
|
-
case AggregateError:
|
|
1960
|
-
if (ctx.features & 1 /* AggregateError */) {
|
|
1961
|
-
return generateAggregateErrorNode2(ctx, id, current);
|
|
1962
|
-
}
|
|
1963
|
-
return generateErrorNode2(ctx, id, current);
|
|
1964
|
-
case Error:
|
|
1965
|
-
case EvalError:
|
|
1966
|
-
case RangeError:
|
|
1967
|
-
case ReferenceError:
|
|
1968
|
-
case SyntaxError:
|
|
1969
|
-
case TypeError:
|
|
1970
|
-
case URIError:
|
|
1971
|
-
return generateErrorNode2(ctx, id, current);
|
|
1972
|
-
case URL:
|
|
1973
|
-
return createURLNode(ctx, id, current);
|
|
1974
|
-
case URLSearchParams:
|
|
1975
|
-
return createURLSearchParamsNode(ctx, id, current);
|
|
1976
|
-
default:
|
|
1977
|
-
break;
|
|
1978
|
-
}
|
|
1979
|
-
if (current instanceof AggregateError) {
|
|
1980
|
-
if (ctx.features & 1 /* AggregateError */) {
|
|
1981
|
-
return generateAggregateErrorNode2(ctx, id, current);
|
|
1982
|
-
}
|
|
1983
|
-
return generateErrorNode2(ctx, id, current);
|
|
1984
|
-
}
|
|
1985
|
-
if (current instanceof Error) {
|
|
1986
|
-
return generateErrorNode2(ctx, id, current);
|
|
1987
|
-
}
|
|
1988
|
-
if (Symbol.iterator in current) {
|
|
1989
|
-
return generateIterableNode2(ctx, id, current);
|
|
1990
|
-
}
|
|
1991
|
-
throw new Error("Unsupported type");
|
|
1992
|
-
}
|
|
1993
|
-
case "symbol":
|
|
1994
|
-
if (hasReferenceID(current)) {
|
|
1995
|
-
const id = createIndexedValue(ctx, current);
|
|
1996
|
-
if (ctx.markedRefs.has(id)) {
|
|
1997
|
-
return createIndexedValueNode(id);
|
|
1998
|
-
}
|
|
1999
|
-
return createReferenceNode(id, current);
|
|
2000
|
-
}
|
|
2001
|
-
return createWKSymbolNode(ctx, current);
|
|
2002
|
-
case "function": {
|
|
2003
|
-
assert(hasReferenceID(current), "Cannot serialize function without reference ID.");
|
|
2004
|
-
const id = createIndexedValue(ctx, current);
|
|
2005
|
-
if (ctx.markedRefs.has(id)) {
|
|
2006
|
-
return createIndexedValueNode(id);
|
|
2007
|
-
}
|
|
2008
|
-
return createReferenceNode(id, current);
|
|
2009
|
-
}
|
|
2431
|
+
case 17 /* WKSymbol */:
|
|
2432
|
+
return serializeWKSymbol(ctx, node);
|
|
2433
|
+
case 18 /* URL */:
|
|
2434
|
+
return serializeURL(ctx, node);
|
|
2435
|
+
case 19 /* URLSearchParams */:
|
|
2436
|
+
return serializeURLSearchParams(ctx, node);
|
|
2437
|
+
case 20 /* Reference */:
|
|
2438
|
+
return serializeReference(ctx, node);
|
|
2439
|
+
case 23 /* Blob */:
|
|
2440
|
+
return serializeBlob(ctx, node);
|
|
2441
|
+
case 24 /* File */:
|
|
2442
|
+
return serializeFile(ctx, node);
|
|
2443
|
+
case 25 /* Headers */:
|
|
2444
|
+
return serializeHeaders(ctx, node);
|
|
2445
|
+
case 26 /* FormData */:
|
|
2446
|
+
return serializeFormData(ctx, node);
|
|
2447
|
+
case 27 /* Boxed */:
|
|
2448
|
+
return serializeBoxed(ctx, node);
|
|
2010
2449
|
default:
|
|
2011
|
-
throw new Error("
|
|
2450
|
+
throw new Error("invariant");
|
|
2012
2451
|
}
|
|
2013
2452
|
}
|
|
2014
|
-
function parseSync(ctx, current) {
|
|
2015
|
-
const result = parse2(ctx, current);
|
|
2016
|
-
const isObject = result.t === 16 /* Object */ || result.t === 21 /* Iterable */;
|
|
2017
|
-
return [result, getRootID(ctx, current), isObject];
|
|
2018
|
-
}
|
|
2019
2453
|
|
|
2020
2454
|
// src/index.ts
|
|
2021
2455
|
function finalize(ctx, rootID, isObject, result) {
|
|
@@ -2043,39 +2477,45 @@ function finalize(ctx, rootID, isObject, result) {
|
|
|
2043
2477
|
}
|
|
2044
2478
|
function serialize(source, options) {
|
|
2045
2479
|
const ctx = createParserContext(options);
|
|
2046
|
-
const
|
|
2480
|
+
const tree = parseSync(ctx, source);
|
|
2047
2481
|
const serial = createSerializationContext(ctx);
|
|
2048
2482
|
const result = serializeTree(serial, tree);
|
|
2049
|
-
return finalize(
|
|
2483
|
+
return finalize(
|
|
2484
|
+
serial,
|
|
2485
|
+
getRootID(ctx, source),
|
|
2486
|
+
tree.t === 10 /* Object */,
|
|
2487
|
+
result
|
|
2488
|
+
);
|
|
2050
2489
|
}
|
|
2051
2490
|
async function serializeAsync(source, options) {
|
|
2052
2491
|
const ctx = createParserContext(options);
|
|
2053
|
-
const
|
|
2492
|
+
const tree = await parseAsync(ctx, source);
|
|
2054
2493
|
const serial = createSerializationContext(ctx);
|
|
2055
2494
|
const result = serializeTree(serial, tree);
|
|
2056
|
-
return finalize(
|
|
2495
|
+
return finalize(
|
|
2496
|
+
serial,
|
|
2497
|
+
getRootID(ctx, source),
|
|
2498
|
+
tree.t === 10 /* Object */,
|
|
2499
|
+
result
|
|
2500
|
+
);
|
|
2057
2501
|
}
|
|
2058
2502
|
function deserialize(source) {
|
|
2059
2503
|
return (0, eval)(source);
|
|
2060
2504
|
}
|
|
2061
2505
|
function toJSON(source, options) {
|
|
2062
2506
|
const ctx = createParserContext(options);
|
|
2063
|
-
const [tree, root, isObject] = parseSync(ctx, source);
|
|
2064
2507
|
return {
|
|
2065
|
-
t:
|
|
2066
|
-
r:
|
|
2067
|
-
i: isObject,
|
|
2508
|
+
t: parseSync(ctx, source),
|
|
2509
|
+
r: getRootID(ctx, source),
|
|
2068
2510
|
f: ctx.features,
|
|
2069
2511
|
m: Array.from(ctx.markedRefs)
|
|
2070
2512
|
};
|
|
2071
2513
|
}
|
|
2072
2514
|
async function toJSONAsync(source, options) {
|
|
2073
2515
|
const ctx = createParserContext(options);
|
|
2074
|
-
const [tree, root, isObject] = await parseAsync(ctx, source);
|
|
2075
2516
|
return {
|
|
2076
|
-
t:
|
|
2077
|
-
r:
|
|
2078
|
-
i: isObject,
|
|
2517
|
+
t: await parseAsync(ctx, source),
|
|
2518
|
+
r: getRootID(ctx, source),
|
|
2079
2519
|
f: ctx.features,
|
|
2080
2520
|
m: Array.from(ctx.markedRefs)
|
|
2081
2521
|
};
|
|
@@ -2086,7 +2526,7 @@ function compileJSON(source) {
|
|
|
2086
2526
|
markedRefs: source.m
|
|
2087
2527
|
});
|
|
2088
2528
|
const result = serializeTree(serial, source.t);
|
|
2089
|
-
return finalize(serial, source.r, source.i
|
|
2529
|
+
return finalize(serial, source.r, source.t.i === 10 /* Object */, result);
|
|
2090
2530
|
}
|
|
2091
2531
|
function fromJSON(source) {
|
|
2092
2532
|
const serial = createSerializationContext({
|