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