seroval 0.15.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/development/index.cjs +1287 -1945
  3. package/dist/cjs/development/index.cjs.map +3 -3
  4. package/dist/cjs/production/index.cjs +3 -3
  5. package/dist/esm/development/index.mjs +1288 -1946
  6. package/dist/esm/development/index.mjs.map +3 -3
  7. package/dist/esm/production/index.mjs +3 -3
  8. package/dist/types/core/Serializer.d.ts +2 -1
  9. package/dist/types/core/Serializer.d.ts.map +1 -1
  10. package/dist/types/core/UnsupportedTypeError.d.ts.map +1 -1
  11. package/dist/types/core/base-primitives.d.ts +6 -2
  12. package/dist/types/core/base-primitives.d.ts.map +1 -1
  13. package/dist/types/core/compat.d.ts +5 -13
  14. package/dist/types/core/compat.d.ts.map +1 -1
  15. package/dist/types/core/constants.d.ts +17 -29
  16. package/dist/types/core/constants.d.ts.map +1 -1
  17. package/dist/types/core/context/deserializer.d.ts +6 -16
  18. package/dist/types/core/context/deserializer.d.ts.map +1 -1
  19. package/dist/types/core/context/parser/async.d.ts +2 -11
  20. package/dist/types/core/context/parser/async.d.ts.map +1 -1
  21. package/dist/types/core/context/parser/stream.d.ts +10 -10
  22. package/dist/types/core/context/parser/stream.d.ts.map +1 -1
  23. package/dist/types/core/context/parser/sync.d.ts +5 -7
  24. package/dist/types/core/context/parser/sync.d.ts.map +1 -1
  25. package/dist/types/core/context/parser.d.ts +26 -5
  26. package/dist/types/core/context/parser.d.ts.map +1 -1
  27. package/dist/types/core/context/serializer.d.ts +21 -30
  28. package/dist/types/core/context/serializer.d.ts.map +1 -1
  29. package/dist/types/core/cross/async.d.ts.map +1 -1
  30. package/dist/types/core/cross/deserializer.d.ts.map +1 -1
  31. package/dist/types/core/cross/index.d.ts.map +1 -1
  32. package/dist/types/core/cross/parser.d.ts.map +1 -1
  33. package/dist/types/core/cross/serializer.d.ts +1 -1
  34. package/dist/types/core/cross/serializer.d.ts.map +1 -1
  35. package/dist/types/core/cross/stream.d.ts.map +1 -1
  36. package/dist/types/core/cross/sync.d.ts.map +1 -1
  37. package/dist/types/core/keys.d.ts.map +1 -1
  38. package/dist/types/core/literals.d.ts.map +1 -1
  39. package/dist/types/core/plugin.d.ts +21 -0
  40. package/dist/types/core/plugin.d.ts.map +1 -1
  41. package/dist/types/core/reference.d.ts.map +1 -1
  42. package/dist/types/core/special-reference.d.ts +4 -9
  43. package/dist/types/core/special-reference.d.ts.map +1 -1
  44. package/dist/types/core/stream.d.ts +18 -0
  45. package/dist/types/core/stream.d.ts.map +1 -0
  46. package/dist/types/core/string.d.ts.map +1 -1
  47. package/dist/types/core/tree/async.d.ts.map +1 -1
  48. package/dist/types/core/tree/deserializer.d.ts.map +1 -1
  49. package/dist/types/core/tree/index.d.ts +1 -1
  50. package/dist/types/core/tree/index.d.ts.map +1 -1
  51. package/dist/types/core/tree/serializer.d.ts +3 -11
  52. package/dist/types/core/tree/serializer.d.ts.map +1 -1
  53. package/dist/types/core/types.d.ts +28 -122
  54. package/dist/types/core/types.d.ts.map +1 -1
  55. package/dist/types/core/utils/deferred.d.ts +0 -7
  56. package/dist/types/core/utils/deferred.d.ts.map +1 -1
  57. package/dist/types/core/utils/error.d.ts +2 -1
  58. package/dist/types/core/utils/error.d.ts.map +1 -1
  59. package/dist/types/core/utils/get-identifier.d.ts.map +1 -1
  60. package/dist/types/core/utils/is-valid-identifier.d.ts.map +1 -1
  61. package/dist/types/core/utils/iterator-to-sequence.d.ts +0 -12
  62. package/dist/types/core/utils/iterator-to-sequence.d.ts.map +1 -1
  63. package/dist/types/core/utils/typed-array.d.ts +2 -0
  64. package/dist/types/core/utils/typed-array.d.ts.map +1 -1
  65. package/dist/types/index.d.ts +2 -3
  66. package/dist/types/index.d.ts.map +1 -1
  67. package/package.json +7 -7
  68. package/src/core/Serializer.ts +44 -28
  69. package/src/core/UnsupportedTypeError.ts +2 -3
  70. package/src/core/base-primitives.ts +124 -38
  71. package/src/core/compat.ts +5 -14
  72. package/src/core/constants.ts +28 -39
  73. package/src/core/context/deserializer.ts +122 -308
  74. package/src/core/context/parser/async.ts +163 -375
  75. package/src/core/context/parser/stream.ts +110 -381
  76. package/src/core/context/parser/sync.ts +125 -266
  77. package/src/core/context/parser.ts +119 -68
  78. package/src/core/context/serializer.ts +396 -473
  79. package/src/core/cross/async.ts +1 -1
  80. package/src/core/cross/deserializer.ts +1 -4
  81. package/src/core/cross/index.ts +26 -20
  82. package/src/core/cross/parser.ts +1 -1
  83. package/src/core/cross/serializer.ts +30 -20
  84. package/src/core/cross/stream.ts +1 -1
  85. package/src/core/cross/sync.ts +1 -1
  86. package/src/core/keys.ts +3 -1
  87. package/src/core/literals.ts +22 -8
  88. package/src/core/plugin.ts +48 -10
  89. package/src/core/reference.ts +4 -5
  90. package/src/core/special-reference.ts +5 -15
  91. package/src/core/stream.ts +205 -0
  92. package/src/core/string.ts +53 -22
  93. package/src/core/tree/async.ts +1 -1
  94. package/src/core/tree/deserializer.ts +4 -9
  95. package/src/core/tree/index.ts +15 -10
  96. package/src/core/tree/serializer.ts +6 -50
  97. package/src/core/types.ts +39 -179
  98. package/src/core/utils/deferred.ts +0 -27
  99. package/src/core/utils/error.ts +26 -15
  100. package/src/core/utils/get-identifier.ts +5 -4
  101. package/src/core/utils/is-valid-identifier.ts +6 -5
  102. package/src/core/utils/iterator-to-sequence.ts +0 -174
  103. package/src/core/utils/typed-array.ts +35 -11
  104. package/src/index.ts +3 -12
  105. package/dist/types/core/utils/constructors.d.ts +0 -5
  106. package/dist/types/core/utils/constructors.d.ts.map +0 -1
  107. package/dist/types/core/web-api.d.ts +0 -8
  108. package/dist/types/core/web-api.d.ts.map +0 -1
  109. package/dist/types/types.d.ts +0 -21
  110. package/dist/types/types.d.ts.map +0 -1
  111. package/src/core/utils/constructors.ts +0 -49
  112. package/src/core/web-api.ts +0 -138
  113. package/src/example.ts +0 -25
  114. package/src/types.ts +0 -84
@@ -1,11 +1,13 @@
1
- // src/core/UnsupportedTypeError.ts
2
- var { toString } = Object.prototype;
3
- var UnsupportedTypeError = class extends Error {
4
- constructor(value) {
5
- super('Unsupported type "' + toString.call(value) + '"');
6
- this.value = value;
7
- }
8
- };
1
+ // src/core/compat.ts
2
+ var Feature = /* @__PURE__ */ ((Feature2) => {
3
+ Feature2[Feature2["AggregateError"] = 1] = "AggregateError";
4
+ Feature2[Feature2["ArrowFunction"] = 2] = "ArrowFunction";
5
+ Feature2[Feature2["ErrorPrototypeStack"] = 4] = "ErrorPrototypeStack";
6
+ Feature2[Feature2["ObjectAssign"] = 8] = "ObjectAssign";
7
+ Feature2[Feature2["BigIntTypedArray"] = 16] = "BigIntTypedArray";
8
+ return Feature2;
9
+ })(Feature || {});
10
+ var ALL_ENABLED = 31;
9
11
 
10
12
  // src/core/utils/assert.ts
11
13
  function assert(cond, error) {
@@ -14,117 +16,6 @@ function assert(cond, error) {
14
16
  }
15
17
  }
16
18
 
17
- // src/core/constants.ts
18
- var SYMBOL_STRING = {
19
- [0 /* AsyncIterator */]: "Symbol.asyncIterator",
20
- [1 /* HasInstance */]: "Symbol.hasInstance",
21
- [2 /* IsConcatSpreadable */]: "Symbol.isConcatSpreadable",
22
- [3 /* Iterator */]: "Symbol.iterator",
23
- [4 /* Match */]: "Symbol.match",
24
- [5 /* MatchAll */]: "Symbol.matchAll",
25
- [6 /* Replace */]: "Symbol.replace",
26
- [7 /* Search */]: "Symbol.search",
27
- [8 /* Species */]: "Symbol.species",
28
- [9 /* Split */]: "Symbol.split",
29
- [10 /* ToPrimitive */]: "Symbol.toPrimitive",
30
- [11 /* ToStringTag */]: "Symbol.toStringTag",
31
- [12 /* Unscopables */]: "Symbol.unscopables"
32
- };
33
- var INV_SYMBOL_REF = {
34
- [Symbol.asyncIterator]: 0 /* AsyncIterator */,
35
- [Symbol.hasInstance]: 1 /* HasInstance */,
36
- [Symbol.isConcatSpreadable]: 2 /* IsConcatSpreadable */,
37
- [Symbol.iterator]: 3 /* Iterator */,
38
- [Symbol.match]: 4 /* Match */,
39
- [Symbol.matchAll]: 5 /* MatchAll */,
40
- [Symbol.replace]: 6 /* Replace */,
41
- [Symbol.search]: 7 /* Search */,
42
- [Symbol.species]: 8 /* Species */,
43
- [Symbol.split]: 9 /* Split */,
44
- [Symbol.toPrimitive]: 10 /* ToPrimitive */,
45
- [Symbol.toStringTag]: 11 /* ToStringTag */,
46
- [Symbol.unscopables]: 12 /* Unscopables */
47
- };
48
- var SYMBOL_REF = {
49
- [0 /* AsyncIterator */]: Symbol.asyncIterator,
50
- [1 /* HasInstance */]: Symbol.hasInstance,
51
- [2 /* IsConcatSpreadable */]: Symbol.isConcatSpreadable,
52
- [3 /* Iterator */]: Symbol.iterator,
53
- [4 /* Match */]: Symbol.match,
54
- [5 /* MatchAll */]: Symbol.matchAll,
55
- [6 /* Replace */]: Symbol.replace,
56
- [7 /* Search */]: Symbol.search,
57
- [8 /* Species */]: Symbol.species,
58
- [9 /* Split */]: Symbol.split,
59
- [10 /* ToPrimitive */]: Symbol.toPrimitive,
60
- [11 /* ToStringTag */]: Symbol.toStringTag,
61
- [12 /* Unscopables */]: Symbol.unscopables
62
- };
63
- var CONSTANT_STRING = {
64
- [2 /* True */]: "!0",
65
- [3 /* False */]: "!1",
66
- [1 /* Undefined */]: "void 0",
67
- [0 /* Null */]: "null",
68
- [4 /* NegativeZero */]: "-0",
69
- [5 /* Infinity */]: "1/0",
70
- [6 /* NegativeInfinity */]: "-1/0",
71
- [7 /* NaN */]: "0/0"
72
- };
73
- var CONSTANT_VAL = {
74
- [2 /* True */]: true,
75
- [3 /* False */]: false,
76
- [1 /* Undefined */]: void 0,
77
- [0 /* Null */]: null,
78
- [4 /* NegativeZero */]: -0,
79
- [5 /* Infinity */]: Infinity,
80
- [6 /* NegativeInfinity */]: -Infinity,
81
- [7 /* NaN */]: NaN
82
- };
83
- var ERROR_CONSTRUCTOR_STRING = {
84
- [0 /* Error */]: "Error",
85
- [1 /* EvalError */]: "EvalError",
86
- [2 /* RangeError */]: "RangeError",
87
- [3 /* ReferenceError */]: "ReferenceError",
88
- [4 /* SyntaxError */]: "SyntaxError",
89
- [5 /* TypeError */]: "TypeError",
90
- [6 /* URIError */]: "URIError"
91
- };
92
- var ERROR_CONSTRUCTOR = {
93
- [0 /* Error */]: Error,
94
- [1 /* EvalError */]: EvalError,
95
- [2 /* RangeError */]: RangeError,
96
- [3 /* ReferenceError */]: ReferenceError,
97
- [4 /* SyntaxError */]: SyntaxError,
98
- [5 /* TypeError */]: TypeError,
99
- [6 /* URIError */]: URIError
100
- };
101
-
102
- // src/core/literals.ts
103
- function createConstantNode(value) {
104
- return {
105
- t: 2 /* Constant */,
106
- i: void 0,
107
- s: value,
108
- l: void 0,
109
- c: void 0,
110
- m: void 0,
111
- p: void 0,
112
- e: void 0,
113
- a: void 0,
114
- f: void 0,
115
- b: void 0,
116
- o: void 0
117
- };
118
- }
119
- var TRUE_NODE = createConstantNode(2 /* True */);
120
- var FALSE_NODE = createConstantNode(3 /* False */);
121
- var UNDEFINED_NODE = createConstantNode(1 /* Undefined */);
122
- var NULL_NODE = createConstantNode(0 /* Null */);
123
- var NEG_ZERO_NODE = createConstantNode(4 /* NegativeZero */);
124
- var INFINITY_NODE = createConstantNode(5 /* Infinity */);
125
- var NEG_INFINITY_NODE = createConstantNode(6 /* NegativeInfinity */);
126
- var NAN_NODE = createConstantNode(7 /* NaN */);
127
-
128
19
  // src/core/string.ts
129
20
  function serializeChar(str) {
130
21
  switch (str) {
@@ -170,8 +61,37 @@ function serializeString(str) {
170
61
  }
171
62
  return result;
172
63
  }
64
+ function deserializeReplacer(str) {
65
+ switch (str) {
66
+ case "\\\\":
67
+ return "\\";
68
+ case '\\"':
69
+ return '"';
70
+ case "\\n":
71
+ return "\n";
72
+ case "\\r":
73
+ return "\r";
74
+ case "\\b":
75
+ return "\b";
76
+ case "\\t":
77
+ return " ";
78
+ case "\\f":
79
+ return "\f";
80
+ case "\\x3C":
81
+ return "<";
82
+ case "\\u2028":
83
+ return "\u2028";
84
+ case "\\u2029":
85
+ return "\u2029";
86
+ default:
87
+ return str;
88
+ }
89
+ }
173
90
  function deserializeString(str) {
174
- 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");
91
+ return str.replace(
92
+ /(\\\\|\\"|\\n|\\r|\\b|\\t|\\f|\\u2028|\\u2029|\\x3C)/g,
93
+ deserializeReplacer
94
+ );
175
95
  }
176
96
 
177
97
  // src/core/keys.ts
@@ -182,7 +102,9 @@ function getCrossReferenceHeader(id) {
182
102
  if (id == null) {
183
103
  return `${GLOBAL_CONTEXT_R}=${GLOBAL_CONTEXT_R}||[]`;
184
104
  }
185
- return `(${GLOBAL_CONTEXT_R}=${GLOBAL_CONTEXT_R}||{})["${serializeString(id)}"]=[]`;
105
+ return `(${GLOBAL_CONTEXT_R}=${GLOBAL_CONTEXT_R}||{})["${serializeString(
106
+ id
107
+ )}"]=[]`;
186
108
  }
187
109
 
188
110
  // src/core/reference.ts
@@ -207,28 +129,28 @@ function getReference(id) {
207
129
  assert(hasReference(id), new Error("Missing reference for id:" + id));
208
130
  return INV_REFERENCE.get(id);
209
131
  }
210
- if (typeof globalThis !== void 0) {
132
+ if (typeof globalThis !== "undefined") {
211
133
  Object.defineProperty(globalThis, REFERENCES_KEY, {
212
134
  value: INV_REFERENCE,
213
135
  configurable: true,
214
136
  writable: false,
215
137
  enumerable: false
216
138
  });
217
- } else if (typeof window !== void 0) {
139
+ } else if (typeof window !== "undefined") {
218
140
  Object.defineProperty(window, REFERENCES_KEY, {
219
141
  value: INV_REFERENCE,
220
142
  configurable: true,
221
143
  writable: false,
222
144
  enumerable: false
223
145
  });
224
- } else if (typeof self !== void 0) {
146
+ } else if (typeof self !== "undefined") {
225
147
  Object.defineProperty(self, REFERENCES_KEY, {
226
148
  value: INV_REFERENCE,
227
149
  configurable: true,
228
150
  writable: false,
229
151
  enumerable: false
230
152
  });
231
- } else if (typeof global !== void 0) {
153
+ } else if (typeof global !== "undefined") {
232
154
  Object.defineProperty(global, REFERENCES_KEY, {
233
155
  value: INV_REFERENCE,
234
156
  configurable: true,
@@ -237,24 +159,163 @@ if (typeof globalThis !== void 0) {
237
159
  });
238
160
  }
239
161
 
240
- // src/core/compat.ts
241
- var Feature = /* @__PURE__ */ ((Feature2) => {
242
- Feature2[Feature2["AggregateError"] = 1] = "AggregateError";
243
- Feature2[Feature2["ArrowFunction"] = 4] = "ArrowFunction";
244
- Feature2[Feature2["BigInt"] = 8] = "BigInt";
245
- Feature2[Feature2["ErrorPrototypeStack"] = 16] = "ErrorPrototypeStack";
246
- Feature2[Feature2["Map"] = 32] = "Map";
247
- Feature2[Feature2["ObjectAssign"] = 128] = "ObjectAssign";
248
- Feature2[Feature2["Promise"] = 256] = "Promise";
249
- Feature2[Feature2["Set"] = 512] = "Set";
250
- Feature2[Feature2["Symbol"] = 1024] = "Symbol";
251
- Feature2[Feature2["TypedArray"] = 2048] = "TypedArray";
252
- Feature2[Feature2["BigIntTypedArray"] = 4096] = "BigIntTypedArray";
253
- Feature2[Feature2["WebAPI"] = 8192] = "WebAPI";
254
- return Feature2;
255
- })(Feature || {});
256
- var ALL_ENABLED = 16383;
257
- var BIGINT_FLAG = 4096 /* BigIntTypedArray */ | 8 /* BigInt */;
162
+ // src/core/plugin.ts
163
+ function createPlugin(plugin) {
164
+ return plugin;
165
+ }
166
+ function dedupePlugins(deduped, plugins) {
167
+ for (let i = 0, len = plugins.length; i < len; i++) {
168
+ const current = plugins[i];
169
+ if (!deduped.has(current)) {
170
+ deduped.add(current);
171
+ if (current.extends) {
172
+ dedupePlugins(deduped, current.extends);
173
+ }
174
+ }
175
+ }
176
+ }
177
+ function resolvePlugins(plugins) {
178
+ if (plugins) {
179
+ const deduped = /* @__PURE__ */ new Set();
180
+ dedupePlugins(deduped, plugins);
181
+ return [...deduped];
182
+ }
183
+ return void 0;
184
+ }
185
+
186
+ // src/core/UnsupportedTypeError.ts
187
+ var { toString: objectToString } = Object.prototype;
188
+ var UnsupportedTypeError = class extends Error {
189
+ constructor(value) {
190
+ super('Unsupported type "' + objectToString.call(value) + '"');
191
+ this.value = value;
192
+ }
193
+ };
194
+
195
+ // src/core/constants.ts
196
+ var SYMBOL_STRING = {
197
+ [0 /* AsyncIterator */]: "Symbol.asyncIterator",
198
+ [1 /* HasInstance */]: "Symbol.hasInstance",
199
+ [2 /* IsConcatSpreadable */]: "Symbol.isConcatSpreadable",
200
+ [3 /* Iterator */]: "Symbol.iterator",
201
+ [4 /* Match */]: "Symbol.match",
202
+ [5 /* MatchAll */]: "Symbol.matchAll",
203
+ [6 /* Replace */]: "Symbol.replace",
204
+ [7 /* Search */]: "Symbol.search",
205
+ [8 /* Species */]: "Symbol.species",
206
+ [9 /* Split */]: "Symbol.split",
207
+ [10 /* ToPrimitive */]: "Symbol.toPrimitive",
208
+ [11 /* ToStringTag */]: "Symbol.toStringTag",
209
+ [12 /* Unscopables */]: "Symbol.unscopables"
210
+ };
211
+ var INV_SYMBOL_REF = {
212
+ [Symbol.asyncIterator]: 0 /* AsyncIterator */,
213
+ [Symbol.hasInstance]: 1 /* HasInstance */,
214
+ [Symbol.isConcatSpreadable]: 2 /* IsConcatSpreadable */,
215
+ [Symbol.iterator]: 3 /* Iterator */,
216
+ [Symbol.match]: 4 /* Match */,
217
+ [Symbol.matchAll]: 5 /* MatchAll */,
218
+ [Symbol.replace]: 6 /* Replace */,
219
+ [Symbol.search]: 7 /* Search */,
220
+ [Symbol.species]: 8 /* Species */,
221
+ [Symbol.split]: 9 /* Split */,
222
+ [Symbol.toPrimitive]: 10 /* ToPrimitive */,
223
+ [Symbol.toStringTag]: 11 /* ToStringTag */,
224
+ [Symbol.unscopables]: 12 /* Unscopables */
225
+ };
226
+ var SYMBOL_REF = {
227
+ [0 /* AsyncIterator */]: Symbol.asyncIterator,
228
+ [1 /* HasInstance */]: Symbol.hasInstance,
229
+ [2 /* IsConcatSpreadable */]: Symbol.isConcatSpreadable,
230
+ [3 /* Iterator */]: Symbol.iterator,
231
+ [4 /* Match */]: Symbol.match,
232
+ [5 /* MatchAll */]: Symbol.matchAll,
233
+ [6 /* Replace */]: Symbol.replace,
234
+ [7 /* Search */]: Symbol.search,
235
+ [8 /* Species */]: Symbol.species,
236
+ [9 /* Split */]: Symbol.split,
237
+ [10 /* ToPrimitive */]: Symbol.toPrimitive,
238
+ [11 /* ToStringTag */]: Symbol.toStringTag,
239
+ [12 /* Unscopables */]: Symbol.unscopables
240
+ };
241
+ var CONSTANT_STRING = {
242
+ [2 /* True */]: "!0",
243
+ [3 /* False */]: "!1",
244
+ [1 /* Undefined */]: "void 0",
245
+ [0 /* Null */]: "null",
246
+ [4 /* NegativeZero */]: "-0",
247
+ [5 /* Infinity */]: "1/0",
248
+ [6 /* NegativeInfinity */]: "-1/0",
249
+ [7 /* NaN */]: "0/0"
250
+ };
251
+ var CONSTANT_VAL = {
252
+ [2 /* True */]: true,
253
+ [3 /* False */]: false,
254
+ [1 /* Undefined */]: void 0,
255
+ [0 /* Null */]: null,
256
+ [4 /* NegativeZero */]: -0,
257
+ [5 /* Infinity */]: Infinity,
258
+ [6 /* NegativeInfinity */]: -Infinity,
259
+ [7 /* NaN */]: NaN
260
+ };
261
+ var ERROR_CONSTRUCTOR_STRING = {
262
+ [0 /* Error */]: "Error",
263
+ [1 /* EvalError */]: "EvalError",
264
+ [2 /* RangeError */]: "RangeError",
265
+ [3 /* ReferenceError */]: "ReferenceError",
266
+ [4 /* SyntaxError */]: "SyntaxError",
267
+ [5 /* TypeError */]: "TypeError",
268
+ [6 /* URIError */]: "URIError"
269
+ };
270
+ var ERROR_CONSTRUCTOR = {
271
+ [0 /* Error */]: Error,
272
+ [1 /* EvalError */]: EvalError,
273
+ [2 /* RangeError */]: RangeError,
274
+ [3 /* ReferenceError */]: ReferenceError,
275
+ [4 /* SyntaxError */]: SyntaxError,
276
+ [5 /* TypeError */]: TypeError,
277
+ [6 /* URIError */]: URIError
278
+ };
279
+
280
+ // src/core/literals.ts
281
+ function createConstantNode(value) {
282
+ return {
283
+ t: 2 /* Constant */,
284
+ i: void 0,
285
+ s: value,
286
+ l: void 0,
287
+ c: void 0,
288
+ m: void 0,
289
+ p: void 0,
290
+ e: void 0,
291
+ a: void 0,
292
+ f: void 0,
293
+ b: void 0,
294
+ o: void 0
295
+ };
296
+ }
297
+ var TRUE_NODE = /* @__PURE__ */ createConstantNode(
298
+ 2 /* True */
299
+ );
300
+ var FALSE_NODE = /* @__PURE__ */ createConstantNode(
301
+ 3 /* False */
302
+ );
303
+ var UNDEFINED_NODE = /* @__PURE__ */ createConstantNode(
304
+ 1 /* Undefined */
305
+ );
306
+ var NULL_NODE = /* @__PURE__ */ createConstantNode(
307
+ 0 /* Null */
308
+ );
309
+ var NEG_ZERO_NODE = /* @__PURE__ */ createConstantNode(
310
+ 4 /* NegativeZero */
311
+ );
312
+ var INFINITY_NODE = /* @__PURE__ */ createConstantNode(
313
+ 5 /* Infinity */
314
+ );
315
+ var NEG_INFINITY_NODE = /* @__PURE__ */ createConstantNode(
316
+ 6 /* NegativeInfinity */
317
+ );
318
+ var NAN_NODE = /* @__PURE__ */ createConstantNode(7 /* NaN */);
258
319
 
259
320
  // src/core/utils/error.ts
260
321
  function getErrorConstructor(error) {
@@ -278,20 +339,24 @@ function getErrorConstructor(error) {
278
339
  }
279
340
  return 0 /* Error */;
280
341
  }
281
- function getErrorOptions(error, features) {
282
- let options;
283
- const constructor = ERROR_CONSTRUCTOR_STRING[getErrorConstructor(error)];
284
- if (error.name !== constructor) {
285
- options = { name: error.name };
286
- } else if (error.constructor.name !== constructor) {
287
- options = { name: error.constructor.name };
342
+ function getInitialErrorOptions(error) {
343
+ const construct = ERROR_CONSTRUCTOR_STRING[getErrorConstructor(error)];
344
+ if (error.name !== construct) {
345
+ return { name: error.name };
346
+ }
347
+ if (error.constructor.name !== construct) {
348
+ return { name: error.constructor.name };
288
349
  }
350
+ return {};
351
+ }
352
+ function getErrorOptions(error, features) {
353
+ let options = getInitialErrorOptions(error);
289
354
  const names = Object.getOwnPropertyNames(error);
290
355
  for (let i = 0, len = names.length, name; i < len; i++) {
291
356
  name = names[i];
292
357
  if (name !== "name" && name !== "message") {
293
358
  if (name === "stack") {
294
- if (features & 16 /* ErrorPrototypeStack */) {
359
+ if (features & 4 /* ErrorPrototypeStack */) {
295
360
  options = options || {};
296
361
  options[name] = error[name];
297
362
  }
@@ -325,31 +390,30 @@ function createNumberNode(value) {
325
390
  return INFINITY_NODE;
326
391
  case -Infinity:
327
392
  return NEG_INFINITY_NODE;
328
- default:
329
- if (value !== value) {
330
- return NAN_NODE;
331
- }
332
- if (Object.is(value, -0)) {
333
- return NEG_ZERO_NODE;
334
- }
335
- return {
336
- t: 0 /* Number */,
337
- i: void 0,
338
- s: value,
339
- l: void 0,
340
- c: void 0,
341
- m: void 0,
342
- p: void 0,
343
- e: void 0,
344
- a: void 0,
345
- f: void 0,
346
- b: void 0,
347
- o: void 0
348
- };
349
393
  }
350
- }
351
- function createStringNode(value) {
352
- return {
394
+ if (value !== value) {
395
+ return NAN_NODE;
396
+ }
397
+ if (Object.is(value, -0)) {
398
+ return NEG_ZERO_NODE;
399
+ }
400
+ return {
401
+ t: 0 /* Number */,
402
+ i: void 0,
403
+ s: value,
404
+ l: void 0,
405
+ c: void 0,
406
+ m: void 0,
407
+ p: void 0,
408
+ e: void 0,
409
+ a: void 0,
410
+ f: void 0,
411
+ b: void 0,
412
+ o: void 0
413
+ };
414
+ }
415
+ function createStringNode(value) {
416
+ return {
353
417
  t: 1 /* String */,
354
418
  i: void 0,
355
419
  s: serializeString(value),
@@ -418,7 +482,7 @@ function createRegExpNode(id, current) {
418
482
  i: id,
419
483
  s: void 0,
420
484
  l: void 0,
421
- c: current.source,
485
+ c: serializeString(current.source),
422
486
  m: current.flags,
423
487
  p: void 0,
424
488
  e: void 0,
@@ -436,7 +500,7 @@ function createArrayBufferNode(id, current) {
436
500
  values[i] = bytes[i];
437
501
  }
438
502
  return {
439
- t: 21 /* ArrayBuffer */,
503
+ t: 19 /* ArrayBuffer */,
440
504
  i: id,
441
505
  s: values,
442
506
  l: void 0,
@@ -451,7 +515,10 @@ function createArrayBufferNode(id, current) {
451
515
  };
452
516
  }
453
517
  function createWKSymbolNode(id, current) {
454
- assert(current in INV_SYMBOL_REF, new Error("Only well-known symbols are supported."));
518
+ assert(
519
+ current in INV_SYMBOL_REF,
520
+ new Error("Only well-known symbols are supported.")
521
+ );
455
522
  return {
456
523
  t: 17 /* WKSymbol */,
457
524
  i: id,
@@ -469,7 +536,7 @@ function createWKSymbolNode(id, current) {
469
536
  }
470
537
  function createReferenceNode(id, ref) {
471
538
  return {
472
- t: 20 /* Reference */,
539
+ t: 18 /* Reference */,
473
540
  i: id,
474
541
  s: serializeString(getReferenceID(ref)),
475
542
  l: void 0,
@@ -485,7 +552,7 @@ function createReferenceNode(id, ref) {
485
552
  }
486
553
  function createPluginNode(id, tag, value) {
487
554
  return {
488
- t: 40 /* Plugin */,
555
+ t: 25 /* Plugin */,
489
556
  i: id,
490
557
  s: value,
491
558
  l: void 0,
@@ -517,7 +584,7 @@ function createArrayNode(id, current, parsedItems) {
517
584
  }
518
585
  function createBoxedNode(id, boxed) {
519
586
  return {
520
- t: 27 /* Boxed */,
587
+ t: 21 /* Boxed */,
521
588
  i: id,
522
589
  s: void 0,
523
590
  l: void 0,
@@ -565,7 +632,7 @@ function createBigIntTypedArrayNode(id, current, buffer) {
565
632
  }
566
633
  function createDataViewNode(id, current, buffer) {
567
634
  return {
568
- t: 22 /* DataView */,
635
+ t: 20 /* DataView */,
569
636
  i: id,
570
637
  s: void 0,
571
638
  l: current.byteLength,
@@ -629,7 +696,7 @@ function createSetNode(id, size, items) {
629
696
  }
630
697
  function createIteratorFactoryInstanceNode(factory, items) {
631
698
  return {
632
- t: 43 /* IteratorFactoryInstance */,
699
+ t: 28 /* IteratorFactoryInstance */,
633
700
  i: void 0,
634
701
  s: void 0,
635
702
  l: void 0,
@@ -637,10 +704,7 @@ function createIteratorFactoryInstanceNode(factory, items) {
637
704
  m: void 0,
638
705
  p: void 0,
639
706
  e: void 0,
640
- a: [
641
- factory,
642
- items
643
- ],
707
+ a: [factory, items],
644
708
  f: void 0,
645
709
  b: void 0,
646
710
  o: void 0
@@ -648,7 +712,7 @@ function createIteratorFactoryInstanceNode(factory, items) {
648
712
  }
649
713
  function createAsyncIteratorFactoryInstanceNode(factory, items) {
650
714
  return {
651
- t: 45 /* AsyncIteratorFactoryInstance */,
715
+ t: 30 /* AsyncIteratorFactoryInstance */,
652
716
  i: void 0,
653
717
  s: void 0,
654
718
  l: void 0,
@@ -656,52 +720,74 @@ function createAsyncIteratorFactoryInstanceNode(factory, items) {
656
720
  m: void 0,
657
721
  p: void 0,
658
722
  e: void 0,
659
- a: [
660
- factory,
661
- items
662
- ],
723
+ a: [factory, items],
663
724
  f: void 0,
664
725
  b: void 0,
665
726
  o: void 0
666
727
  };
667
728
  }
668
-
669
- // src/core/utils/constructors.ts
670
- function createRequestOptions(current, body) {
729
+ function createStreamConstructorNode(id, factory, sequence) {
671
730
  return {
672
- body,
673
- cache: current.cache,
674
- credentials: current.credentials,
675
- headers: current.headers,
676
- integrity: current.integrity,
677
- keepalive: current.keepalive,
678
- method: current.method,
679
- mode: current.mode,
680
- redirect: current.redirect,
681
- referrer: current.referrer,
682
- referrerPolicy: current.referrerPolicy
731
+ t: 31 /* StreamConstructor */,
732
+ i: id,
733
+ s: void 0,
734
+ l: void 0,
735
+ c: void 0,
736
+ m: void 0,
737
+ p: void 0,
738
+ e: void 0,
739
+ a: sequence,
740
+ f: factory,
741
+ b: void 0,
742
+ o: void 0
683
743
  };
684
744
  }
685
- function createResponseOptions(current) {
745
+ function createStreamNextNode(id, parsed) {
686
746
  return {
687
- headers: current.headers,
688
- status: current.status,
689
- statusText: current.statusText
747
+ t: 32 /* StreamNext */,
748
+ i: id,
749
+ s: void 0,
750
+ l: void 0,
751
+ c: void 0,
752
+ m: void 0,
753
+ p: void 0,
754
+ e: void 0,
755
+ a: void 0,
756
+ f: parsed,
757
+ b: void 0,
758
+ o: void 0
690
759
  };
691
760
  }
692
- function createEventOptions(current) {
761
+ function createStreamThrowNode(id, parsed) {
693
762
  return {
694
- bubbles: current.bubbles,
695
- cancelable: current.cancelable,
696
- composed: current.composed
763
+ t: 33 /* StreamThrow */,
764
+ i: id,
765
+ s: void 0,
766
+ l: void 0,
767
+ c: void 0,
768
+ m: void 0,
769
+ p: void 0,
770
+ e: void 0,
771
+ a: void 0,
772
+ f: parsed,
773
+ b: void 0,
774
+ o: void 0
697
775
  };
698
776
  }
699
- function createCustomEventOptions(current) {
777
+ function createStreamReturnNode(id, parsed) {
700
778
  return {
701
- detail: current.detail,
702
- bubbles: current.bubbles,
703
- cancelable: current.cancelable,
704
- composed: current.composed
779
+ t: 34 /* StreamReturn */,
780
+ i: id,
781
+ s: void 0,
782
+ l: void 0,
783
+ c: void 0,
784
+ m: void 0,
785
+ p: void 0,
786
+ e: void 0,
787
+ a: void 0,
788
+ f: parsed,
789
+ b: void 0,
790
+ o: void 0
705
791
  };
706
792
  }
707
793
 
@@ -757,163 +843,16 @@ function sequenceToIterator(sequence) {
757
843
  };
758
844
  };
759
845
  }
760
- async function asyncIteratorToSequence(source) {
761
- const values = [];
762
- let throwsAt = -1;
763
- let doneAt = -1;
764
- const iterator = source[Symbol.asyncIterator]();
765
- while (true) {
766
- try {
767
- const value = await iterator.next();
768
- values.push(value.value);
769
- if (value.done) {
770
- doneAt = values.length - 1;
771
- break;
772
- }
773
- } catch (error) {
774
- throwsAt = values.length;
775
- values.push(error);
776
- }
777
- }
778
- return {
779
- v: values,
780
- t: throwsAt,
781
- d: doneAt
782
- };
783
- }
784
- function sequenceToAsyncIterator(sequence) {
785
- return () => {
786
- let index = 0;
787
- return {
788
- [Symbol.asyncIterator]() {
789
- return this;
790
- },
791
- async next() {
792
- if (index > sequence.d) {
793
- return {
794
- done: true,
795
- value: void 0
796
- };
797
- }
798
- const currentIndex = index++;
799
- const currentItem = sequence.v[currentIndex];
800
- if (currentIndex === sequence.t) {
801
- throw currentItem;
802
- }
803
- return Promise.resolve({
804
- done: currentIndex === sequence.d,
805
- value: currentItem
806
- });
807
- }
808
- };
809
- };
810
- }
811
- function asyncIteratorToReadableStream(source, parser) {
812
- return new ReadableStream({
813
- async start(controller) {
814
- const iterator = source[Symbol.asyncIterator]();
815
- while (parser.isAlive()) {
816
- try {
817
- const result = await iterator.next();
818
- controller.enqueue([result.done ? 2 : 0, result.value]);
819
- if (result.done) {
820
- controller.close();
821
- return;
822
- }
823
- } catch (error) {
824
- controller.enqueue([1, error]);
825
- }
826
- }
827
- controller.close();
828
- }
829
- });
830
- }
831
- function readableStreamToAsyncIterator(source) {
832
- let current = source;
833
- return () => {
834
- const [left, right] = current.tee();
835
- const clone = left;
836
- current = right;
837
- const reader = clone.getReader();
838
- return {
839
- [Symbol.asyncIterator]() {
840
- return this;
841
- },
842
- async next() {
843
- const result = await reader.read();
844
- if (result.done) {
845
- return {
846
- done: true,
847
- value: void 0
848
- };
849
- }
850
- const [status, value] = result.value;
851
- if (status === 1) {
852
- throw value;
853
- }
854
- return {
855
- done: status === 2,
856
- value
857
- };
858
- }
859
- };
860
- };
861
- }
862
- async function readableStreamToSequence(stream) {
863
- const values = [];
864
- let throwsAt = -1;
865
- let doneAt = -1;
866
- const iterator = stream.getReader();
867
- while (true) {
868
- try {
869
- const value = await iterator.read();
870
- values.push(value.value);
871
- if (value.done) {
872
- doneAt = values.length - 1;
873
- break;
874
- }
875
- } catch (error) {
876
- throwsAt = values.length;
877
- doneAt = throwsAt;
878
- values.push(error);
879
- break;
880
- }
881
- }
882
- return {
883
- v: values,
884
- t: throwsAt,
885
- d: doneAt
886
- };
887
- }
888
- function sequenceToReadableStream(sequence) {
889
- return new ReadableStream({
890
- start(controller) {
891
- for (let i = 0; i < sequence.d; i++) {
892
- controller.enqueue(sequence.v[i]);
893
- }
894
- if (sequence.t === -1) {
895
- controller.close();
896
- } else {
897
- controller.error(sequence.v[sequence.t]);
898
- }
899
- }
900
- });
901
- }
902
846
 
903
847
  // src/core/special-reference.ts
904
- var UNIVERSAL_SENTINEL = {};
905
848
  var ITERATOR = {};
906
849
  var ASYNC_ITERATOR = {};
907
850
  var SPECIAL_REFS = {
908
851
  [0 /* MapSentinel */]: {},
909
- [1 /* ReadableStream */]: {},
910
- [2 /* PromiseConstructor */]: {},
911
- [3 /* PromiseResolve */]: {},
912
- [4 /* PromiseReject */]: {},
913
- [5 /* ReadableStreamConstructor */]: {},
914
- [6 /* ReadableStreamEnqueue */]: {},
915
- [7 /* ReadableStreamError */]: {},
916
- [8 /* ReadableStreamClose */]: {}
852
+ [1 /* PromiseConstructor */]: {},
853
+ [2 /* PromiseResolve */]: {},
854
+ [3 /* PromiseReject */]: {},
855
+ [4 /* StreamConstructor */]: {}
917
856
  };
918
857
 
919
858
  // src/core/context/parser.ts
@@ -930,62 +869,70 @@ var BaseParserContext = class {
930
869
  isMarked(id) {
931
870
  return this.marked.has(id);
932
871
  }
933
- getReference(current) {
934
- const registeredID = this.refs.get(current);
935
- if (registeredID != null) {
936
- this.markRef(registeredID);
937
- return createIndexedValueNode(registeredID);
872
+ getIndexedValue(current) {
873
+ const registeredId = this.refs.get(current);
874
+ if (registeredId != null) {
875
+ this.markRef(registeredId);
876
+ return {
877
+ type: 1 /* Indexed */,
878
+ value: createIndexedValueNode(registeredId)
879
+ };
938
880
  }
939
881
  const id = this.refs.size;
940
882
  this.refs.set(current, id);
883
+ return {
884
+ type: 0 /* Fresh */,
885
+ value: id
886
+ };
887
+ }
888
+ getReference(current) {
889
+ const indexed = this.getIndexedValue(current);
890
+ if (indexed.type === 1 /* Indexed */) {
891
+ return indexed;
892
+ }
941
893
  if (hasReferenceID(current)) {
942
- return createReferenceNode(id, current);
894
+ return {
895
+ type: 2 /* Referenced */,
896
+ value: createReferenceNode(indexed.value, current)
897
+ };
943
898
  }
944
- return id;
899
+ return indexed;
945
900
  }
946
901
  getStrictReference(current) {
947
- const registeredID = this.refs.get(current);
948
- if (registeredID != null) {
949
- this.markRef(registeredID);
950
- return createIndexedValueNode(registeredID);
902
+ assert(
903
+ hasReferenceID(current),
904
+ new Error(
905
+ "Cannot serialize " + typeof current + " without reference ID."
906
+ )
907
+ );
908
+ const result = this.getIndexedValue(current);
909
+ if (result.type === 1 /* Indexed */) {
910
+ return result.value;
951
911
  }
952
- const id = this.refs.size;
953
- this.refs.set(current, id);
954
- return createReferenceNode(id, current);
912
+ return createReferenceNode(result.value, current);
955
913
  }
956
- // eslint-disable-next-line @typescript-eslint/ban-types
957
914
  parseFunction(current) {
958
- assert(hasReferenceID(current), new Error("Cannot serialize function without reference ID."));
959
915
  return this.getStrictReference(current);
960
916
  }
961
- parseWKSymbol(current) {
962
- assert(this.features & 1024 /* Symbol */, new UnsupportedTypeError(current));
963
- const registeredID = this.refs.get(current);
964
- if (registeredID != null) {
965
- this.markRef(registeredID);
966
- return createIndexedValueNode(registeredID);
917
+ parseWellKnownSymbol(current) {
918
+ const ref = this.getReference(current);
919
+ if (ref.type !== 0 /* Fresh */) {
920
+ return ref.value;
967
921
  }
968
- const isValid = current in INV_SYMBOL_REF;
969
- assert(current in INV_SYMBOL_REF || hasReferenceID(current), new Error("Cannot serialize symbol without reference ID."));
970
- const id = this.refs.size;
971
- this.refs.set(current, id);
972
- if (isValid) {
973
- return createWKSymbolNode(id, current);
974
- }
975
- return createReferenceNode(id, current);
922
+ assert(
923
+ current in INV_SYMBOL_REF,
924
+ new Error("Cannot serialized unsupported symbol.")
925
+ );
926
+ return createWKSymbolNode(ref.value, current);
976
927
  }
977
928
  parseSpecialReference(ref) {
978
- const specialRef = SPECIAL_REFS[ref];
979
- const registeredID = this.refs.get(specialRef);
980
- if (registeredID != null) {
981
- this.markRef(registeredID);
982
- return createIndexedValueNode(registeredID);
929
+ const result = this.getIndexedValue(SPECIAL_REFS[ref]);
930
+ if (result.type === 1 /* Indexed */) {
931
+ return result.value;
983
932
  }
984
- const id = this.refs.size;
985
- this.refs.set(specialRef, id);
986
933
  return {
987
- t: 41 /* SpecialReference */,
988
- i: id,
934
+ t: 26 /* SpecialReference */,
935
+ i: result.value,
989
936
  s: ref,
990
937
  l: void 0,
991
938
  c: void 0,
@@ -999,16 +946,13 @@ var BaseParserContext = class {
999
946
  };
1000
947
  }
1001
948
  parseIteratorFactory() {
1002
- const registeredID = this.refs.get(ITERATOR);
1003
- if (registeredID != null) {
1004
- this.markRef(registeredID);
1005
- return createIndexedValueNode(registeredID);
949
+ const result = this.getIndexedValue(ITERATOR);
950
+ if (result.type === 1 /* Indexed */) {
951
+ return result.value;
1006
952
  }
1007
- const id = this.refs.size;
1008
- this.refs.set(ITERATOR, id);
1009
953
  return {
1010
- t: 42 /* IteratorFactory */,
1011
- i: id,
954
+ t: 27 /* IteratorFactory */,
955
+ i: result.value,
1012
956
  s: void 0,
1013
957
  l: void 0,
1014
958
  c: void 0,
@@ -1016,30 +960,30 @@ var BaseParserContext = class {
1016
960
  p: void 0,
1017
961
  e: void 0,
1018
962
  a: void 0,
1019
- f: this.parseWKSymbol(Symbol.iterator),
963
+ f: this.parseWellKnownSymbol(Symbol.iterator),
1020
964
  b: void 0,
1021
965
  o: void 0
1022
966
  };
1023
967
  }
1024
- parseAsyncIteratorFactory(streaming) {
1025
- const registeredID = this.refs.get(ASYNC_ITERATOR);
1026
- if (registeredID != null) {
1027
- this.markRef(registeredID);
1028
- return createIndexedValueNode(registeredID);
968
+ parseAsyncIteratorFactory() {
969
+ const result = this.getIndexedValue(ASYNC_ITERATOR);
970
+ if (result.type === 1 /* Indexed */) {
971
+ return result.value;
1029
972
  }
1030
- const id = this.refs.size;
1031
- this.refs.set(ASYNC_ITERATOR, id);
1032
973
  return {
1033
- t: 44 /* AsyncIteratorFactory */,
1034
- i: id,
1035
- s: streaming,
974
+ t: 29 /* AsyncIteratorFactory */,
975
+ i: result.value,
976
+ s: void 0,
1036
977
  l: void 0,
1037
978
  c: void 0,
1038
979
  m: void 0,
1039
980
  p: void 0,
1040
981
  e: void 0,
1041
- a: void 0,
1042
- f: this.parseWKSymbol(Symbol.asyncIterator),
982
+ a: [
983
+ this.parseSpecialReference(1 /* PromiseConstructor */),
984
+ this.parseWellKnownSymbol(Symbol.asyncIterator)
985
+ ],
986
+ f: void 0,
1043
987
  b: void 0,
1044
988
  o: void 0
1045
989
  };
@@ -1076,6 +1020,22 @@ var BaseParserContext = class {
1076
1020
  o: void 0
1077
1021
  };
1078
1022
  }
1023
+ createPromiseConstructorNode(id) {
1024
+ return {
1025
+ t: 22 /* PromiseConstructor */,
1026
+ i: id,
1027
+ s: void 0,
1028
+ l: void 0,
1029
+ c: void 0,
1030
+ m: void 0,
1031
+ p: void 0,
1032
+ e: void 0,
1033
+ a: void 0,
1034
+ f: this.parseSpecialReference(1 /* PromiseConstructor */),
1035
+ b: void 0,
1036
+ o: void 0
1037
+ };
1038
+ }
1079
1039
  };
1080
1040
 
1081
1041
  // src/core/utils/promise-to-result.ts
@@ -1087,104 +1047,189 @@ async function promiseToResult(current) {
1087
1047
  }
1088
1048
  }
1089
1049
 
1090
- // src/core/web-api.ts
1091
- function createURLNode(id, current) {
1092
- return {
1093
- t: 18 /* URL */,
1094
- i: id,
1095
- s: serializeString(current.href),
1096
- l: void 0,
1097
- c: void 0,
1098
- m: void 0,
1099
- p: void 0,
1100
- e: void 0,
1101
- f: void 0,
1102
- a: void 0,
1103
- b: void 0,
1104
- o: void 0
1105
- };
1106
- }
1107
- function createURLSearchParamsNode(id, current) {
1050
+ // src/core/utils/deferred.ts
1051
+ function createDeferred() {
1052
+ let resolve;
1053
+ let reject;
1108
1054
  return {
1109
- t: 19 /* URLSearchParams */,
1110
- i: id,
1111
- s: serializeString(current.toString()),
1112
- l: void 0,
1113
- c: void 0,
1114
- m: void 0,
1115
- p: void 0,
1116
- e: void 0,
1117
- f: void 0,
1118
- a: void 0,
1119
- b: void 0,
1120
- o: void 0
1055
+ promise: new Promise((res, rej) => {
1056
+ resolve = res;
1057
+ reject = rej;
1058
+ }),
1059
+ resolve(value) {
1060
+ resolve(value);
1061
+ },
1062
+ reject(value) {
1063
+ reject(value);
1064
+ }
1121
1065
  };
1122
1066
  }
1123
- function createDOMExceptionNode(id, current) {
1124
- return {
1125
- t: 39 /* DOMException */,
1126
- i: id,
1127
- s: serializeString(current.message),
1128
- l: void 0,
1129
- c: serializeString(current.name),
1130
- m: void 0,
1131
- p: void 0,
1132
- e: void 0,
1133
- a: void 0,
1134
- f: void 0,
1135
- b: void 0,
1136
- o: void 0
1137
- };
1067
+
1068
+ // src/core/stream.ts
1069
+ function isStream(value) {
1070
+ return "__SEROVAL_STREAM__" in value;
1138
1071
  }
1139
- function createEventNode(id, type, options) {
1072
+ function createStream() {
1073
+ const listeners = /* @__PURE__ */ new Set();
1074
+ const buffer = [];
1075
+ let alive = true;
1076
+ let success = false;
1077
+ function flushNext(value) {
1078
+ for (const listener of listeners.keys()) {
1079
+ listener.next(value);
1080
+ }
1081
+ }
1082
+ function flushThrow(value) {
1083
+ for (const listener of listeners.keys()) {
1084
+ listener.throw(value);
1085
+ }
1086
+ }
1087
+ function flushReturn(value) {
1088
+ for (const listener of listeners.keys()) {
1089
+ listener.return(value);
1090
+ }
1091
+ }
1140
1092
  return {
1141
- t: 37 /* Event */,
1142
- i: id,
1143
- s: serializeString(type),
1144
- l: void 0,
1145
- c: void 0,
1146
- m: void 0,
1147
- p: void 0,
1148
- e: void 0,
1149
- a: void 0,
1150
- f: options,
1151
- b: void 0,
1152
- o: void 0
1093
+ __SEROVAL_STREAM__: true,
1094
+ on(listener) {
1095
+ if (alive) {
1096
+ listeners.add(listener);
1097
+ }
1098
+ for (let i = 0, len = buffer.length; i < len; i++) {
1099
+ const value = buffer[i];
1100
+ if (i === len - 1) {
1101
+ if (success) {
1102
+ listener.return(value);
1103
+ } else {
1104
+ listener.throw(value);
1105
+ }
1106
+ } else {
1107
+ listener.next(value);
1108
+ }
1109
+ }
1110
+ return () => {
1111
+ if (alive) {
1112
+ listeners.delete(listener);
1113
+ }
1114
+ };
1115
+ },
1116
+ next(value) {
1117
+ if (alive) {
1118
+ buffer.push(value);
1119
+ flushNext(value);
1120
+ }
1121
+ },
1122
+ throw(value) {
1123
+ if (alive) {
1124
+ buffer.push(value);
1125
+ flushThrow(value);
1126
+ alive = false;
1127
+ success = false;
1128
+ listeners.clear();
1129
+ }
1130
+ },
1131
+ return(value) {
1132
+ if (alive) {
1133
+ buffer.push(value);
1134
+ flushReturn(value);
1135
+ alive = false;
1136
+ success = true;
1137
+ listeners.clear();
1138
+ }
1139
+ }
1153
1140
  };
1154
1141
  }
1155
- function createCustomEventNode(id, type, options) {
1156
- return {
1157
- t: 38 /* CustomEvent */,
1158
- i: id,
1159
- s: serializeString(type),
1160
- l: void 0,
1161
- c: void 0,
1162
- m: void 0,
1163
- p: void 0,
1164
- e: void 0,
1165
- a: void 0,
1166
- f: options,
1167
- b: void 0,
1168
- o: void 0
1169
- };
1142
+ function createStreamFromAsyncIterable(iterable) {
1143
+ const stream = createStream();
1144
+ const iterator = iterable[Symbol.asyncIterator]();
1145
+ async function push() {
1146
+ try {
1147
+ const value = await iterator.next();
1148
+ if (value.done) {
1149
+ stream.return(value.value);
1150
+ } else {
1151
+ stream.next(value.value);
1152
+ await push();
1153
+ }
1154
+ } catch (error) {
1155
+ stream.throw(error);
1156
+ }
1157
+ }
1158
+ push().catch(() => {
1159
+ });
1160
+ return stream;
1170
1161
  }
1171
- function createReadableStreamNode(id, factory, items) {
1172
- return {
1173
- t: 46 /* ReadableStream */,
1174
- i: id,
1175
- s: void 0,
1176
- l: void 0,
1177
- c: void 0,
1178
- m: void 0,
1179
- p: void 0,
1180
- e: void 0,
1181
- a: [
1182
- factory,
1183
- items
1184
- ],
1185
- f: void 0,
1186
- b: void 0,
1187
- o: void 0
1162
+ function streamToAsyncIterable(stream) {
1163
+ return () => {
1164
+ const buffer = [];
1165
+ const pending = [];
1166
+ let count = 0;
1167
+ let doneAt = -1;
1168
+ let isThrow = false;
1169
+ function resolveAll() {
1170
+ for (let i = 0, len = pending.length; i < len; i++) {
1171
+ pending[i].resolve({ done: true, value: void 0 });
1172
+ }
1173
+ }
1174
+ stream.on({
1175
+ next(value) {
1176
+ const current = pending.shift();
1177
+ if (current) {
1178
+ current.resolve({ done: false, value });
1179
+ }
1180
+ buffer.push(value);
1181
+ },
1182
+ throw(value) {
1183
+ const current = pending.shift();
1184
+ if (current) {
1185
+ current.reject(value);
1186
+ }
1187
+ resolveAll();
1188
+ doneAt = buffer.length;
1189
+ buffer.push(value);
1190
+ isThrow = true;
1191
+ },
1192
+ return(value) {
1193
+ const current = pending.shift();
1194
+ if (current) {
1195
+ current.resolve({ done: true, value });
1196
+ }
1197
+ resolveAll();
1198
+ doneAt = buffer.length;
1199
+ buffer.push(value);
1200
+ }
1201
+ });
1202
+ function finalize() {
1203
+ const current = count++;
1204
+ const value = buffer[current];
1205
+ if (current !== doneAt) {
1206
+ return { done: false, value };
1207
+ }
1208
+ if (isThrow) {
1209
+ throw value;
1210
+ }
1211
+ return { done: true, value };
1212
+ }
1213
+ return {
1214
+ [Symbol.asyncIterator]() {
1215
+ return this;
1216
+ },
1217
+ async next() {
1218
+ if (doneAt === -1) {
1219
+ const current = count++;
1220
+ if (current >= buffer.length) {
1221
+ const deferred = createDeferred();
1222
+ pending.push(deferred);
1223
+ return await deferred.promise;
1224
+ }
1225
+ return { done: false, value: buffer[current] };
1226
+ }
1227
+ if (count > doneAt) {
1228
+ return { done: true, value: void 0 };
1229
+ }
1230
+ return finalize();
1231
+ }
1232
+ };
1188
1233
  };
1189
1234
  }
1190
1235
 
@@ -1200,11 +1245,7 @@ var BaseAsyncParserContext = class extends BaseParserContext {
1200
1245
  return nodes;
1201
1246
  }
1202
1247
  async parseArray(id, current) {
1203
- return createArrayNode(
1204
- id,
1205
- current,
1206
- await this.parseItems(current)
1207
- );
1248
+ return createArrayNode(id, current, await this.parseItems(current));
1208
1249
  }
1209
1250
  async parseProperties(properties) {
1210
1251
  const entries = Object.entries(properties);
@@ -1214,242 +1255,104 @@ var BaseAsyncParserContext = class extends BaseParserContext {
1214
1255
  keyNodes.push(serializeString(entries[i][0]));
1215
1256
  valueNodes.push(await this.parse(entries[i][1]));
1216
1257
  }
1217
- if (this.features & 1024 /* Symbol */) {
1218
- let symbol = Symbol.iterator;
1219
- if (symbol in properties) {
1220
- keyNodes.push(
1221
- this.parseWKSymbol(symbol)
1222
- );
1223
- valueNodes.push(
1224
- createIteratorFactoryInstanceNode(
1225
- this.parseIteratorFactory(),
1226
- await this.parse(
1227
- iteratorToSequence(properties)
1228
- )
1258
+ let symbol = Symbol.iterator;
1259
+ if (symbol in properties) {
1260
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
1261
+ valueNodes.push(
1262
+ createIteratorFactoryInstanceNode(
1263
+ this.parseIteratorFactory(),
1264
+ await this.parse(
1265
+ iteratorToSequence(properties)
1229
1266
  )
1230
- );
1231
- }
1232
- symbol = Symbol.asyncIterator;
1233
- if (symbol in properties) {
1234
- keyNodes.push(
1235
- this.parseWKSymbol(symbol)
1236
- );
1237
- valueNodes.push(
1238
- createAsyncIteratorFactoryInstanceNode(
1239
- this.parseAsyncIteratorFactory(0),
1240
- await this.parse(
1241
- await asyncIteratorToSequence(properties)
1267
+ )
1268
+ );
1269
+ }
1270
+ symbol = Symbol.asyncIterator;
1271
+ if (symbol in properties) {
1272
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
1273
+ valueNodes.push(
1274
+ createAsyncIteratorFactoryInstanceNode(
1275
+ this.parseAsyncIteratorFactory(),
1276
+ await this.parse(
1277
+ createStreamFromAsyncIterable(
1278
+ properties
1242
1279
  )
1243
1280
  )
1244
- );
1245
- }
1246
- symbol = Symbol.toStringTag;
1247
- if (symbol in properties) {
1248
- keyNodes.push(this.parseWKSymbol(symbol));
1249
- valueNodes.push(createStringNode(properties[symbol]));
1250
- }
1251
- symbol = Symbol.isConcatSpreadable;
1252
- if (symbol in properties) {
1253
- keyNodes.push(this.parseWKSymbol(symbol));
1254
- valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
1255
- }
1256
- }
1257
- return {
1258
- k: keyNodes,
1259
- v: valueNodes,
1260
- s: keyNodes.length
1261
- };
1262
- }
1263
- async parsePlainObject(id, current, empty) {
1264
- return this.createObjectNode(
1265
- id,
1266
- current,
1267
- empty,
1268
- await this.parseProperties(current)
1269
- );
1270
- }
1271
- async parseBoxed(id, current) {
1272
- return createBoxedNode(id, await this.parse(current.valueOf()));
1273
- }
1274
- async parseTypedArray(id, current) {
1275
- return createTypedArrayNode(id, current, await this.parse(current.buffer));
1276
- }
1277
- async parseBigIntTypedArray(id, current) {
1278
- return createBigIntTypedArrayNode(id, current, await this.parse(current.buffer));
1279
- }
1280
- async parseDataView(id, current) {
1281
- return createDataViewNode(id, current, await this.parse(current.buffer));
1282
- }
1283
- async parseError(id, current) {
1284
- const options = getErrorOptions(current, this.features);
1285
- return createErrorNode(
1286
- id,
1287
- current,
1288
- options ? await this.parseProperties(options) : void 0
1289
- );
1290
- }
1291
- async parseAggregateError(id, current) {
1292
- const options = getErrorOptions(current, this.features);
1293
- return createAggregateErrorNode(
1294
- id,
1295
- current,
1296
- options ? await this.parseProperties(options) : void 0
1297
- );
1298
- }
1299
- async parseMap(id, current) {
1300
- const keyNodes = [];
1301
- const valueNodes = [];
1302
- for (const [key, value] of current.entries()) {
1303
- keyNodes.push(await this.parse(key));
1304
- valueNodes.push(await this.parse(value));
1305
- }
1306
- return this.createMapNode(
1307
- id,
1308
- keyNodes,
1309
- valueNodes,
1310
- current.size
1311
- );
1312
- }
1313
- async parseSet(id, current) {
1314
- const items = [];
1315
- for (const item of current.keys()) {
1316
- items.push(await this.parse(item));
1317
- }
1318
- return createSetNode(id, current.size, items);
1319
- }
1320
- async parseBlob(id, current) {
1321
- return {
1322
- t: 23 /* Blob */,
1323
- i: id,
1324
- s: void 0,
1325
- l: void 0,
1326
- c: serializeString(current.type),
1327
- m: void 0,
1328
- p: void 0,
1329
- e: void 0,
1330
- f: await this.parse(await current.arrayBuffer()),
1331
- a: void 0,
1332
- b: void 0,
1333
- o: void 0
1334
- };
1335
- }
1336
- async parseFile(id, current) {
1337
- return {
1338
- t: 24 /* File */,
1339
- i: id,
1340
- s: void 0,
1341
- l: void 0,
1342
- c: serializeString(current.type),
1343
- m: serializeString(current.name),
1344
- p: void 0,
1345
- e: void 0,
1346
- f: await this.parse(await current.arrayBuffer()),
1347
- a: void 0,
1348
- b: current.lastModified,
1349
- o: void 0
1350
- };
1351
- }
1352
- async parsePlainProperties(entries) {
1353
- const size = entries.length;
1354
- const keyNodes = [];
1355
- const valueNodes = [];
1356
- for (let i = 0; i < size; i++) {
1357
- keyNodes.push(serializeString(entries[i][0]));
1358
- valueNodes.push(await this.parse(entries[i][1]));
1359
- }
1360
- return {
1361
- k: keyNodes,
1362
- v: valueNodes,
1363
- s: size
1364
- };
1365
- }
1366
- async parseHeaders(id, current) {
1367
- const items = [];
1368
- current.forEach((value, key) => {
1369
- items.push([key, value]);
1370
- });
1371
- return {
1372
- t: 25 /* Headers */,
1373
- i: id,
1374
- s: void 0,
1375
- l: void 0,
1376
- c: void 0,
1377
- m: void 0,
1378
- p: void 0,
1379
- e: await this.parsePlainProperties(items),
1380
- a: void 0,
1381
- f: void 0,
1382
- b: void 0,
1383
- o: void 0
1384
- };
1385
- }
1386
- async parseFormData(id, current) {
1387
- const items = [];
1388
- current.forEach((value, key) => {
1389
- items.push([key, value]);
1390
- });
1281
+ )
1282
+ );
1283
+ }
1284
+ symbol = Symbol.toStringTag;
1285
+ if (symbol in properties) {
1286
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
1287
+ valueNodes.push(createStringNode(properties[symbol]));
1288
+ }
1289
+ symbol = Symbol.isConcatSpreadable;
1290
+ if (symbol in properties) {
1291
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
1292
+ valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
1293
+ }
1391
1294
  return {
1392
- t: 26 /* FormData */,
1393
- i: id,
1394
- s: void 0,
1395
- l: void 0,
1396
- c: void 0,
1397
- m: void 0,
1398
- p: void 0,
1399
- e: await this.parsePlainProperties(items),
1400
- a: void 0,
1401
- f: void 0,
1402
- b: void 0,
1403
- o: void 0
1295
+ k: keyNodes,
1296
+ v: valueNodes,
1297
+ s: keyNodes.length
1404
1298
  };
1405
1299
  }
1406
- async parseRequest(id, current) {
1407
- return {
1408
- t: 35 /* Request */,
1409
- i: id,
1410
- s: serializeString(current.url),
1411
- l: void 0,
1412
- c: void 0,
1413
- m: void 0,
1414
- p: void 0,
1415
- e: void 0,
1416
- f: await this.parse(
1417
- createRequestOptions(current, current.body ? await current.clone().arrayBuffer() : null)
1418
- ),
1419
- a: void 0,
1420
- b: void 0,
1421
- o: void 0
1422
- };
1300
+ async parsePlainObject(id, current, empty) {
1301
+ return this.createObjectNode(
1302
+ id,
1303
+ current,
1304
+ empty,
1305
+ await this.parseProperties(current)
1306
+ );
1423
1307
  }
1424
- async parseResponse(id, current) {
1425
- return {
1426
- t: 36 /* Response */,
1427
- i: id,
1428
- s: void 0,
1429
- l: void 0,
1430
- c: void 0,
1431
- m: void 0,
1432
- p: void 0,
1433
- e: void 0,
1434
- f: void 0,
1435
- a: [
1436
- current.body ? await this.parse(await current.clone().arrayBuffer()) : NULL_NODE,
1437
- await this.parse(createResponseOptions(current))
1438
- ],
1439
- b: void 0,
1440
- o: void 0
1441
- };
1308
+ async parseBoxed(id, current) {
1309
+ return createBoxedNode(id, await this.parse(current.valueOf()));
1310
+ }
1311
+ async parseTypedArray(id, current) {
1312
+ return createTypedArrayNode(id, current, await this.parse(current.buffer));
1313
+ }
1314
+ async parseBigIntTypedArray(id, current) {
1315
+ return createBigIntTypedArrayNode(
1316
+ id,
1317
+ current,
1318
+ await this.parse(current.buffer)
1319
+ );
1320
+ }
1321
+ async parseDataView(id, current) {
1322
+ return createDataViewNode(id, current, await this.parse(current.buffer));
1442
1323
  }
1443
- async parseEvent(id, current) {
1444
- return createEventNode(id, current.type, await this.parse(createEventOptions(current)));
1324
+ async parseError(id, current) {
1325
+ const options = getErrorOptions(current, this.features);
1326
+ return createErrorNode(
1327
+ id,
1328
+ current,
1329
+ options ? await this.parseProperties(options) : void 0
1330
+ );
1445
1331
  }
1446
- async parseCustomEvent(id, current) {
1447
- return createCustomEventNode(
1332
+ async parseAggregateError(id, current) {
1333
+ const options = getErrorOptions(current, this.features);
1334
+ return createAggregateErrorNode(
1448
1335
  id,
1449
- current.type,
1450
- await this.parse(createCustomEventOptions(current))
1336
+ current,
1337
+ options ? await this.parseProperties(options) : void 0
1451
1338
  );
1452
1339
  }
1340
+ async parseMap(id, current) {
1341
+ const keyNodes = [];
1342
+ const valueNodes = [];
1343
+ for (const [key, value] of current.entries()) {
1344
+ keyNodes.push(await this.parse(key));
1345
+ valueNodes.push(await this.parse(value));
1346
+ }
1347
+ return this.createMapNode(id, keyNodes, valueNodes, current.size);
1348
+ }
1349
+ async parseSet(id, current) {
1350
+ const items = [];
1351
+ for (const item of current.keys()) {
1352
+ items.push(await this.parse(item));
1353
+ }
1354
+ return createSetNode(id, current.size, items);
1355
+ }
1453
1356
  async parsePromise(id, current) {
1454
1357
  const [status, result] = await promiseToResult(current);
1455
1358
  return {
@@ -1485,19 +1388,68 @@ var BaseAsyncParserContext = class extends BaseParserContext {
1485
1388
  }
1486
1389
  return void 0;
1487
1390
  }
1488
- async parseReadableStream(id, current) {
1489
- return createReadableStreamNode(
1391
+ async parseStream(id, current) {
1392
+ return createStreamConstructorNode(
1490
1393
  id,
1491
- this.parseSpecialReference(1 /* ReadableStream */),
1492
- await this.parse(
1493
- await readableStreamToSequence(current)
1494
- )
1394
+ this.parseSpecialReference(4 /* StreamConstructor */),
1395
+ await new Promise((resolve, reject) => {
1396
+ const sequence = [];
1397
+ const cleanup = current.on({
1398
+ next: (value) => {
1399
+ this.markRef(id);
1400
+ this.parse(value).then(
1401
+ (data) => {
1402
+ sequence.push(createStreamNextNode(id, data));
1403
+ },
1404
+ (data) => {
1405
+ reject(data);
1406
+ cleanup();
1407
+ }
1408
+ );
1409
+ },
1410
+ throw: (value) => {
1411
+ this.markRef(id);
1412
+ this.parse(value).then(
1413
+ (data) => {
1414
+ sequence.push(createStreamThrowNode(id, data));
1415
+ resolve(sequence);
1416
+ cleanup();
1417
+ },
1418
+ (data) => {
1419
+ reject(data);
1420
+ cleanup();
1421
+ }
1422
+ );
1423
+ },
1424
+ return: (value) => {
1425
+ this.markRef(id);
1426
+ this.parse(value).then(
1427
+ (data) => {
1428
+ sequence.push(createStreamReturnNode(id, data));
1429
+ resolve(sequence);
1430
+ cleanup();
1431
+ },
1432
+ (data) => {
1433
+ reject(data);
1434
+ cleanup();
1435
+ }
1436
+ );
1437
+ }
1438
+ });
1439
+ })
1495
1440
  );
1496
1441
  }
1497
1442
  async parseObject(id, current) {
1498
1443
  if (Array.isArray(current)) {
1499
1444
  return this.parseArray(id, current);
1500
1445
  }
1446
+ if (isStream(current)) {
1447
+ return this.parseStream(id, current);
1448
+ }
1449
+ const parsed = await this.parsePlugin(id, current);
1450
+ if (parsed) {
1451
+ return parsed;
1452
+ }
1501
1453
  const currentClass = current.constructor;
1502
1454
  switch (currentClass) {
1503
1455
  case Object:
@@ -1529,126 +1481,75 @@ var BaseAsyncParserContext = class extends BaseParserContext {
1529
1481
  case String:
1530
1482
  case BigInt:
1531
1483
  return this.parseBoxed(id, current);
1484
+ case ArrayBuffer:
1485
+ return createArrayBufferNode(id, current);
1486
+ case Int8Array:
1487
+ case Int16Array:
1488
+ case Int32Array:
1489
+ case Uint8Array:
1490
+ case Uint16Array:
1491
+ case Uint32Array:
1492
+ case Uint8ClampedArray:
1493
+ case Float32Array:
1494
+ case Float64Array:
1495
+ return this.parseTypedArray(id, current);
1496
+ case DataView:
1497
+ return this.parseDataView(id, current);
1498
+ case Map:
1499
+ return this.parseMap(id, current);
1500
+ case Set:
1501
+ return this.parseSet(id, current);
1532
1502
  default:
1533
1503
  break;
1534
1504
  }
1535
- const currentFeatures = this.features;
1536
- if (currentFeatures & 256 /* Promise */ && (currentClass === Promise || current instanceof Promise)) {
1505
+ if (currentClass === Promise || current instanceof Promise) {
1537
1506
  return this.parsePromise(id, current);
1538
1507
  }
1539
- if (currentFeatures & 2048 /* TypedArray */) {
1540
- switch (currentClass) {
1541
- case ArrayBuffer:
1542
- return createArrayBufferNode(id, current);
1543
- case Int8Array:
1544
- case Int16Array:
1545
- case Int32Array:
1546
- case Uint8Array:
1547
- case Uint16Array:
1548
- case Uint32Array:
1549
- case Uint8ClampedArray:
1550
- case Float32Array:
1551
- case Float64Array:
1552
- return this.parseTypedArray(id, current);
1553
- case DataView:
1554
- return this.parseDataView(id, current);
1555
- default:
1556
- break;
1557
- }
1558
- }
1559
- if ((currentFeatures & BIGINT_FLAG) === BIGINT_FLAG) {
1508
+ const currentFeatures = this.features;
1509
+ if (currentFeatures & 16 /* BigIntTypedArray */) {
1560
1510
  switch (currentClass) {
1561
1511
  case BigInt64Array:
1562
1512
  case BigUint64Array:
1563
- return this.parseBigIntTypedArray(id, current);
1564
- default:
1565
- break;
1566
- }
1567
- }
1568
- if (currentFeatures & 32 /* Map */ && currentClass === Map) {
1569
- return this.parseMap(
1570
- id,
1571
- current
1572
- );
1573
- }
1574
- if (currentFeatures & 512 /* Set */ && currentClass === Set) {
1575
- return this.parseSet(
1576
- id,
1577
- current
1578
- );
1579
- }
1580
- if (currentFeatures & 8192 /* WebAPI */) {
1581
- switch (currentClass) {
1582
- case (typeof URL !== "undefined" ? URL : UNIVERSAL_SENTINEL):
1583
- return createURLNode(id, current);
1584
- case (typeof URLSearchParams !== "undefined" ? URLSearchParams : UNIVERSAL_SENTINEL):
1585
- return createURLSearchParamsNode(id, current);
1586
- case (typeof Blob !== "undefined" ? Blob : UNIVERSAL_SENTINEL):
1587
- return this.parseBlob(id, current);
1588
- case (typeof File !== "undefined" ? File : UNIVERSAL_SENTINEL):
1589
- return this.parseFile(id, current);
1590
- case (typeof Headers !== "undefined" ? Headers : UNIVERSAL_SENTINEL):
1591
- return this.parseHeaders(id, current);
1592
- case (typeof FormData !== "undefined" ? FormData : UNIVERSAL_SENTINEL):
1593
- return this.parseFormData(id, current);
1594
- case (typeof Request !== "undefined" ? Request : UNIVERSAL_SENTINEL):
1595
- return this.parseRequest(id, current);
1596
- case (typeof Response !== "undefined" ? Response : UNIVERSAL_SENTINEL):
1597
- return this.parseResponse(id, current);
1598
- case (typeof Event !== "undefined" ? Event : UNIVERSAL_SENTINEL):
1599
- return this.parseEvent(id, current);
1600
- case (typeof CustomEvent !== "undefined" ? CustomEvent : UNIVERSAL_SENTINEL):
1601
- return this.parseCustomEvent(id, current);
1602
- case (typeof DOMException !== "undefined" ? DOMException : UNIVERSAL_SENTINEL):
1603
- return createDOMExceptionNode(id, current);
1604
- case (typeof ReadableStream !== "undefined" ? ReadableStream : UNIVERSAL_SENTINEL):
1605
- return this.parseReadableStream(id, current);
1513
+ return this.parseBigIntTypedArray(
1514
+ id,
1515
+ current
1516
+ );
1606
1517
  default:
1607
1518
  break;
1608
1519
  }
1609
1520
  }
1610
- const parsed = await this.parsePlugin(id, current);
1611
- if (parsed) {
1612
- return parsed;
1613
- }
1614
1521
  if (currentFeatures & 1 /* AggregateError */ && typeof AggregateError !== "undefined" && (currentClass === AggregateError || current instanceof AggregateError)) {
1615
1522
  return this.parseAggregateError(id, current);
1616
1523
  }
1617
1524
  if (current instanceof Error) {
1618
1525
  return this.parseError(id, current);
1619
1526
  }
1620
- if (currentFeatures & 1024 /* Symbol */ && (Symbol.iterator in current || Symbol.asyncIterator in current)) {
1527
+ if (Symbol.iterator in current || Symbol.asyncIterator in current) {
1621
1528
  return this.parsePlainObject(id, current, !!currentClass);
1622
1529
  }
1623
1530
  throw new UnsupportedTypeError(current);
1624
1531
  }
1625
1532
  async parse(current) {
1626
- switch (current) {
1627
- case true:
1628
- return TRUE_NODE;
1629
- case false:
1630
- return FALSE_NODE;
1631
- case void 0:
1632
- return UNDEFINED_NODE;
1633
- case null:
1634
- return NULL_NODE;
1635
- default:
1636
- break;
1637
- }
1638
1533
  switch (typeof current) {
1534
+ case "boolean":
1535
+ return current ? TRUE_NODE : FALSE_NODE;
1536
+ case "undefined":
1537
+ return UNDEFINED_NODE;
1639
1538
  case "string":
1640
1539
  return createStringNode(current);
1641
1540
  case "number":
1642
1541
  return createNumberNode(current);
1643
1542
  case "bigint":
1644
- assert(this.features & 8 /* BigInt */, new UnsupportedTypeError(current));
1645
1543
  return createBigIntNode(current);
1646
1544
  case "object": {
1647
- const id = this.getReference(current);
1648
- return typeof id === "number" ? this.parseObject(id, current) : id;
1545
+ if (current) {
1546
+ const ref = this.getReference(current);
1547
+ return ref.type === 0 ? await this.parseObject(ref.value, current) : ref.value;
1548
+ }
1549
+ return NULL_NODE;
1649
1550
  }
1650
1551
  case "symbol":
1651
- return this.parseWKSymbol(current);
1552
+ return this.parseWellKnownSymbol(current);
1652
1553
  case "function":
1653
1554
  return this.parseFunction(current);
1654
1555
  default:
@@ -1695,43 +1596,6 @@ function getTypedArrayConstructor(name) {
1695
1596
  }
1696
1597
  }
1697
1598
 
1698
- // src/core/utils/deferred.ts
1699
- function createDeferred() {
1700
- let resolve;
1701
- let reject;
1702
- return {
1703
- promise: new Promise((res, rej) => {
1704
- resolve = res;
1705
- reject = rej;
1706
- }),
1707
- resolve(value) {
1708
- resolve(value);
1709
- },
1710
- reject(value) {
1711
- reject(value);
1712
- }
1713
- };
1714
- }
1715
- function createDeferredStream() {
1716
- let controller;
1717
- return {
1718
- stream: new ReadableStream({
1719
- start(current) {
1720
- controller = current;
1721
- }
1722
- }),
1723
- close() {
1724
- controller.close();
1725
- },
1726
- enqueue(data) {
1727
- controller.enqueue(data);
1728
- },
1729
- error(e) {
1730
- controller.error(e);
1731
- }
1732
- };
1733
- }
1734
-
1735
1599
  // src/core/context/deserializer.ts
1736
1600
  function applyObjectFlag(obj, flag) {
1737
1601
  switch (flag) {
@@ -1751,7 +1615,10 @@ var BaseDeserializerContext = class {
1751
1615
  this.refs = options.refs || /* @__PURE__ */ new Map();
1752
1616
  }
1753
1617
  deserializeReference(node) {
1754
- return this.assignIndexedValue(node.i, getReference(deserializeString(node.s)));
1618
+ return this.assignIndexedValue(
1619
+ node.i,
1620
+ getReference(deserializeString(node.s))
1621
+ );
1755
1622
  }
1756
1623
  deserializeArray(node) {
1757
1624
  const len = node.l;
@@ -1798,7 +1665,10 @@ var BaseDeserializerContext = class {
1798
1665
  return this.assignIndexedValue(node.i, new Date(node.s));
1799
1666
  }
1800
1667
  deserializeRegExp(node) {
1801
- return this.assignIndexedValue(node.i, new RegExp(node.c, node.m));
1668
+ return this.assignIndexedValue(
1669
+ node.i,
1670
+ new RegExp(deserializeString(node.c), node.m)
1671
+ );
1802
1672
  }
1803
1673
  deserializeSet(node) {
1804
1674
  const result = this.assignIndexedValue(node.i, /* @__PURE__ */ new Set());
@@ -1809,17 +1679,11 @@ var BaseDeserializerContext = class {
1809
1679
  return result;
1810
1680
  }
1811
1681
  deserializeMap(node) {
1812
- const result = this.assignIndexedValue(
1813
- node.i,
1814
- /* @__PURE__ */ new Map()
1815
- );
1682
+ const result = this.assignIndexedValue(node.i, /* @__PURE__ */ new Map());
1816
1683
  const keys = node.e.k;
1817
1684
  const vals = node.e.v;
1818
1685
  for (let i = 0, len = node.e.s; i < len; i++) {
1819
- result.set(
1820
- this.deserialize(keys[i]),
1821
- this.deserialize(vals[i])
1822
- );
1686
+ result.set(this.deserialize(keys[i]), this.deserialize(vals[i]));
1823
1687
  }
1824
1688
  return result;
1825
1689
  }
@@ -1829,22 +1693,20 @@ var BaseDeserializerContext = class {
1829
1693
  return result;
1830
1694
  }
1831
1695
  deserializeTypedArray(node) {
1832
- const TypedArray = getTypedArrayConstructor(node.c);
1696
+ const construct = getTypedArrayConstructor(node.c);
1833
1697
  const source = this.deserialize(node.f);
1834
- const result = this.assignIndexedValue(node.i, new TypedArray(
1835
- source,
1836
- node.b,
1837
- node.l
1838
- ));
1698
+ const result = this.assignIndexedValue(
1699
+ node.i,
1700
+ new construct(source, node.b, node.l)
1701
+ );
1839
1702
  return result;
1840
1703
  }
1841
1704
  deserializeDataView(node) {
1842
1705
  const source = this.deserialize(node.f);
1843
- const result = this.assignIndexedValue(node.i, new DataView(
1844
- source,
1845
- node.b,
1846
- node.l
1847
- ));
1706
+ const result = this.assignIndexedValue(
1707
+ node.i,
1708
+ new DataView(source, node.b, node.l)
1709
+ );
1848
1710
  return result;
1849
1711
  }
1850
1712
  deserializeDictionary(node, result) {
@@ -1862,14 +1724,14 @@ var BaseDeserializerContext = class {
1862
1724
  return this.deserializeDictionary(node, result);
1863
1725
  }
1864
1726
  deserializeError(node) {
1865
- const ErrorConstructor = ERROR_CONSTRUCTOR[node.s];
1727
+ const construct = ERROR_CONSTRUCTOR[node.s];
1866
1728
  const result = this.assignIndexedValue(
1867
1729
  node.i,
1868
- new ErrorConstructor(deserializeString(node.m))
1730
+ new construct(deserializeString(node.m))
1869
1731
  );
1870
1732
  return this.deserializeDictionary(node, result);
1871
1733
  }
1872
- async deserializePromise(node) {
1734
+ deserializePromise(node) {
1873
1735
  const deferred = createDeferred();
1874
1736
  const result = this.assignIndexedValue(node.i, deferred);
1875
1737
  const deserialized = this.deserialize(node.f);
@@ -1880,107 +1742,16 @@ var BaseDeserializerContext = class {
1880
1742
  }
1881
1743
  return result.promise;
1882
1744
  }
1883
- deserializeURL(node) {
1884
- return this.assignIndexedValue(node.i, new URL(deserializeString(node.s)));
1885
- }
1886
- deserializeURLSearchParams(node) {
1887
- return this.assignIndexedValue(node.i, new URLSearchParams(deserializeString(node.s)));
1888
- }
1889
- deserializeBlob(node) {
1890
- const source = this.deserialize(node.f);
1891
- const result = this.assignIndexedValue(node.i, new Blob(
1892
- [source],
1893
- { type: deserializeString(node.c) }
1894
- ));
1895
- return result;
1896
- }
1897
- deserializeFile(node) {
1898
- const source = this.deserialize(node.f);
1899
- const result = this.assignIndexedValue(node.i, new File(
1900
- [source],
1901
- deserializeString(node.m),
1902
- { type: deserializeString(node.c), lastModified: node.b }
1903
- ));
1904
- return result;
1905
- }
1906
- deserializeHeaders(node) {
1907
- const result = this.assignIndexedValue(node.i, new Headers());
1908
- const keys = node.e.k;
1909
- const vals = node.e.v;
1910
- for (let i = 0, len = node.e.s; i < len; i++) {
1911
- result.set(
1912
- deserializeString(keys[i]),
1913
- this.deserialize(vals[i])
1914
- );
1915
- }
1916
- return result;
1917
- }
1918
- deserializeFormData(node) {
1919
- const result = this.assignIndexedValue(node.i, new FormData());
1920
- const keys = node.e.k;
1921
- const vals = node.e.v;
1922
- for (let i = 0, len = node.e.s; i < len; i++) {
1923
- result.set(
1924
- deserializeString(keys[i]),
1925
- this.deserialize(vals[i])
1926
- );
1927
- }
1928
- return result;
1929
- }
1930
1745
  deserializeBoxed(node) {
1931
- return this.assignIndexedValue(
1932
- node.i,
1933
- Object(this.deserialize(node.f))
1934
- );
1935
- }
1936
- deserializeRequest(node) {
1937
- return this.assignIndexedValue(
1938
- node.i,
1939
- new Request(deserializeString(node.s), this.deserialize(node.f))
1940
- );
1941
- }
1942
- deserializeResponse(node) {
1943
- return this.assignIndexedValue(
1944
- node.i,
1945
- new Response(
1946
- this.deserialize(node.a[0]),
1947
- this.deserialize(node.a[1])
1948
- )
1949
- );
1950
- }
1951
- deserializeEvent(node) {
1952
- return this.assignIndexedValue(
1953
- node.i,
1954
- new Event(
1955
- deserializeString(node.s),
1956
- this.deserialize(node.f)
1957
- )
1958
- );
1959
- }
1960
- deserializeCustomEvent(node) {
1961
- return this.assignIndexedValue(
1962
- node.i,
1963
- new CustomEvent(
1964
- deserializeString(node.s),
1965
- this.deserialize(node.f)
1966
- )
1967
- );
1968
- }
1969
- deserializeDOMException(node) {
1970
- return this.assignIndexedValue(
1971
- node.i,
1972
- new DOMException(
1973
- deserializeString(node.s),
1974
- deserializeString(node.c)
1975
- )
1976
- );
1746
+ return this.assignIndexedValue(node.i, Object(this.deserialize(node.f)));
1977
1747
  }
1978
1748
  deserializePlugin(node) {
1979
1749
  const currentPlugins = this.plugins;
1980
1750
  if (currentPlugins) {
1751
+ const tag = deserializeString(node.c);
1981
1752
  for (let i = 0, len = currentPlugins.length; i < len; i++) {
1982
1753
  const plugin = currentPlugins[i];
1983
- if (plugin.tag === node.c) {
1754
+ if (plugin.tag === tag) {
1984
1755
  return this.assignIndexedValue(
1985
1756
  node.i,
1986
1757
  plugin.deserialize(node.s, this, {
@@ -1993,75 +1764,65 @@ var BaseDeserializerContext = class {
1993
1764
  throw new Error('Missing plugin for tag "' + node.c + '".');
1994
1765
  }
1995
1766
  deserializePromiseConstructor(node) {
1996
- return this.assignIndexedValue(
1997
- node.i,
1998
- createDeferred()
1999
- ).promise;
1767
+ return this.assignIndexedValue(node.i, createDeferred()).promise;
2000
1768
  }
2001
1769
  deserializePromiseResolve(node) {
2002
1770
  const deferred = this.refs.get(node.i);
2003
1771
  assert(deferred, new Error("Missing Promise instance."));
2004
- deferred.resolve(
2005
- this.deserialize(node.a[1])
2006
- );
1772
+ deferred.resolve(this.deserialize(node.a[1]));
2007
1773
  return void 0;
2008
1774
  }
2009
1775
  deserializePromiseReject(node) {
2010
1776
  const deferred = this.refs.get(node.i);
2011
1777
  assert(deferred, new Error("Missing Promise instance."));
2012
- deferred.reject(
2013
- this.deserialize(node.a[1])
2014
- );
1778
+ deferred.reject(this.deserialize(node.a[1]));
2015
1779
  return void 0;
2016
1780
  }
2017
- deserializeReadableStreamConstructor(node) {
2018
- return this.assignIndexedValue(
2019
- node.i,
2020
- createDeferredStream()
2021
- ).stream;
1781
+ deserializeIteratorFactoryInstance(node) {
1782
+ this.deserialize(node.a[0]);
1783
+ const source = this.deserialize(node.a[1]);
1784
+ return sequenceToIterator(source);
1785
+ }
1786
+ deserializeAsyncIteratorFactoryInstance(node) {
1787
+ this.deserialize(node.a[0]);
1788
+ const source = this.deserialize(node.a[1]);
1789
+ return streamToAsyncIterable(source);
1790
+ }
1791
+ deserializeStreamConstructor(node) {
1792
+ const result = this.assignIndexedValue(node.i, createStream());
1793
+ const len = node.a.length;
1794
+ if (len) {
1795
+ for (let i = 0; i < len; i++) {
1796
+ this.deserialize(node.a[i]);
1797
+ }
1798
+ }
1799
+ return result;
2022
1800
  }
2023
- deserializeReadableStreamEnqueue(node) {
1801
+ deserializeStreamNext(node) {
2024
1802
  const deferred = this.refs.get(node.i);
2025
- assert(deferred, new Error("Missing ReadableStream instance."));
2026
- deferred.enqueue(
2027
- this.deserialize(node.a[1])
2028
- );
1803
+ assert(deferred, new Error("Missing Stream instance."));
1804
+ deferred.next(this.deserialize(node.f));
2029
1805
  return void 0;
2030
1806
  }
2031
- deserializeReadableStreamError(node) {
1807
+ deserializeStreamThrow(node) {
2032
1808
  const deferred = this.refs.get(node.i);
2033
- assert(deferred, new Error("Missing Promise instance."));
2034
- deferred.error(
2035
- this.deserialize(node.a[1])
2036
- );
1809
+ assert(deferred, new Error("Missing Stream instance."));
1810
+ deferred.throw(this.deserialize(node.f));
2037
1811
  return void 0;
2038
1812
  }
2039
- deserializeReadableStreamClose(node) {
1813
+ deserializeStreamReturn(node) {
2040
1814
  const deferred = this.refs.get(node.i);
2041
- assert(deferred, new Error("Missing Promise instance."));
2042
- deferred.close();
1815
+ assert(deferred, new Error("Missing Stream instance."));
1816
+ deferred.return(this.deserialize(node.f));
2043
1817
  return void 0;
2044
1818
  }
2045
- deserializeIteratorFactoryInstance(node) {
2046
- const source = this.deserialize(node.a[1]);
2047
- return sequenceToIterator(source);
2048
- }
2049
- deserializeAsyncIteratorFactoryInstance(node) {
2050
- const source = this.deserialize(node.a[1]);
2051
- if (node.s) {
2052
- return readableStreamToAsyncIterator(
2053
- source
2054
- );
2055
- }
2056
- return sequenceToAsyncIterator(source);
1819
+ deserializeIteratorFactory(node) {
1820
+ this.deserialize(node.f);
1821
+ return void 0;
2057
1822
  }
2058
- deserializeReadableStream(node) {
2059
- return this.assignIndexedValue(
2060
- node.i,
2061
- sequenceToReadableStream(
2062
- this.deserialize(node.a[1])
2063
- )
2064
- );
1823
+ deserializeAsyncIteratorFactory(node) {
1824
+ this.deserialize(node.a[1]);
1825
+ return void 0;
2065
1826
  }
2066
1827
  deserialize(node) {
2067
1828
  switch (node.t) {
@@ -2075,7 +1836,7 @@ var BaseDeserializerContext = class {
2075
1836
  return BigInt(node.s);
2076
1837
  case 4 /* IndexedValue */:
2077
1838
  return this.refs.get(node.i);
2078
- case 20 /* Reference */:
1839
+ case 18 /* Reference */:
2079
1840
  return this.deserializeReference(node);
2080
1841
  case 9 /* Array */:
2081
1842
  return this.deserializeArray(node);
@@ -2090,12 +1851,12 @@ var BaseDeserializerContext = class {
2090
1851
  return this.deserializeSet(node);
2091
1852
  case 8 /* Map */:
2092
1853
  return this.deserializeMap(node);
2093
- case 21 /* ArrayBuffer */:
1854
+ case 19 /* ArrayBuffer */:
2094
1855
  return this.deserializeArrayBuffer(node);
2095
1856
  case 16 /* BigIntTypedArray */:
2096
1857
  case 15 /* TypedArray */:
2097
1858
  return this.deserializeTypedArray(node);
2098
- case 22 /* DataView */:
1859
+ case 20 /* DataView */:
2099
1860
  return this.deserializeDataView(node);
2100
1861
  case 14 /* AggregateError */:
2101
1862
  return this.deserializeAggregateError(node);
@@ -2105,55 +1866,32 @@ var BaseDeserializerContext = class {
2105
1866
  return this.deserializePromise(node);
2106
1867
  case 17 /* WKSymbol */:
2107
1868
  return SYMBOL_REF[node.s];
2108
- case 18 /* URL */:
2109
- return this.deserializeURL(node);
2110
- case 19 /* URLSearchParams */:
2111
- return this.deserializeURLSearchParams(node);
2112
- case 23 /* Blob */:
2113
- return this.deserializeBlob(node);
2114
- case 24 /* File */:
2115
- return this.deserializeFile(node);
2116
- case 25 /* Headers */:
2117
- return this.deserializeHeaders(node);
2118
- case 26 /* FormData */:
2119
- return this.deserializeFormData(node);
2120
- case 27 /* Boxed */:
1869
+ case 21 /* Boxed */:
2121
1870
  return this.deserializeBoxed(node);
2122
- case 35 /* Request */:
2123
- return this.deserializeRequest(node);
2124
- case 36 /* Response */:
2125
- return this.deserializeResponse(node);
2126
- case 37 /* Event */:
2127
- return this.deserializeEvent(node);
2128
- case 38 /* CustomEvent */:
2129
- return this.deserializeCustomEvent(node);
2130
- case 39 /* DOMException */:
2131
- return this.deserializeDOMException(node);
2132
- case 40 /* Plugin */:
1871
+ case 25 /* Plugin */:
2133
1872
  return this.deserializePlugin(node);
2134
- case 28 /* PromiseConstructor */:
1873
+ case 22 /* PromiseConstructor */:
2135
1874
  return this.deserializePromiseConstructor(node);
2136
- case 29 /* PromiseResolve */:
1875
+ case 23 /* PromiseResolve */:
2137
1876
  return this.deserializePromiseResolve(node);
2138
- case 30 /* PromiseReject */:
1877
+ case 24 /* PromiseReject */:
2139
1878
  return this.deserializePromiseReject(node);
2140
- case 31 /* ReadableStreamConstructor */:
2141
- return this.deserializeReadableStreamConstructor(node);
2142
- case 32 /* ReadableStreamEnqueue */:
2143
- return this.deserializeReadableStreamEnqueue(node);
2144
- case 34 /* ReadableStreamError */:
2145
- return this.deserializeReadableStreamError(node);
2146
- case 33 /* ReadableStreamClose */:
2147
- return this.deserializeReadableStreamClose(node);
2148
- case 43 /* IteratorFactoryInstance */:
1879
+ case 28 /* IteratorFactoryInstance */:
2149
1880
  return this.deserializeIteratorFactoryInstance(node);
2150
- case 45 /* AsyncIteratorFactoryInstance */:
1881
+ case 30 /* AsyncIteratorFactoryInstance */:
2151
1882
  return this.deserializeAsyncIteratorFactoryInstance(node);
2152
- case 46 /* ReadableStream */:
2153
- return this.deserializeReadableStream(node);
2154
- case 41 /* SpecialReference */:
2155
- case 42 /* IteratorFactory */:
2156
- case 44 /* AsyncIteratorFactory */:
1883
+ case 31 /* StreamConstructor */:
1884
+ return this.deserializeStreamConstructor(node);
1885
+ case 32 /* StreamNext */:
1886
+ return this.deserializeStreamNext(node);
1887
+ case 33 /* StreamThrow */:
1888
+ return this.deserializeStreamThrow(node);
1889
+ case 34 /* StreamReturn */:
1890
+ return this.deserializeStreamReturn(node);
1891
+ case 27 /* IteratorFactory */:
1892
+ return this.deserializeIteratorFactory(node);
1893
+ case 29 /* AsyncIteratorFactory */:
1894
+ return this.deserializeAsyncIteratorFactory(node);
2157
1895
  default:
2158
1896
  throw new Error("invariant");
2159
1897
  }
@@ -2163,10 +1901,7 @@ var BaseDeserializerContext = class {
2163
1901
  // src/core/tree/deserializer.ts
2164
1902
  var VanillaDeserializerContext = class extends BaseDeserializerContext {
2165
1903
  constructor(options) {
2166
- super({
2167
- plugins: options.plugins,
2168
- refs: void 0
2169
- });
1904
+ super(options);
2170
1905
  this.mode = "vanilla";
2171
1906
  this.marked = new Set(options.markedRefs);
2172
1907
  }
@@ -2188,16 +1923,14 @@ function isValidIdentifier(name) {
2188
1923
  // src/core/context/serializer.ts
2189
1924
  function getAssignmentExpression(assignment) {
2190
1925
  switch (assignment.t) {
2191
- case "index":
1926
+ case 0 /* Index */:
2192
1927
  return assignment.s + "=" + assignment.v;
2193
- case "set":
1928
+ case 2 /* Set */:
2194
1929
  return assignment.s + ".set(" + assignment.k + "," + assignment.v + ")";
2195
- case "add":
1930
+ case 1 /* Add */:
2196
1931
  return assignment.s + ".add(" + assignment.v + ")";
2197
- case "delete":
1932
+ case 3 /* Delete */:
2198
1933
  return assignment.s + ".delete(" + assignment.k + ")";
2199
- default:
2200
- return "";
2201
1934
  }
2202
1935
  }
2203
1936
  function mergeAssignments(assignments) {
@@ -2205,30 +1938,30 @@ function mergeAssignments(assignments) {
2205
1938
  let current = assignments[0];
2206
1939
  for (let i = 1, len = assignments.length, item, prev = current; i < len; i++) {
2207
1940
  item = assignments[i];
2208
- if (item.t === "index" && item.v === prev.v) {
1941
+ if (item.t === 0 /* Index */ && item.v === prev.v) {
2209
1942
  current = {
2210
- t: "index",
1943
+ t: 0 /* Index */,
2211
1944
  s: item.s,
2212
1945
  k: void 0,
2213
1946
  v: getAssignmentExpression(current)
2214
1947
  };
2215
- } else if (item.t === "set" && item.s === prev.s) {
1948
+ } else if (item.t === 2 /* Set */ && item.s === prev.s) {
2216
1949
  current = {
2217
- t: "set",
1950
+ t: 2 /* Set */,
2218
1951
  s: getAssignmentExpression(current),
2219
1952
  k: item.k,
2220
1953
  v: item.v
2221
1954
  };
2222
- } else if (item.t === "add" && item.s === prev.s) {
1955
+ } else if (item.t === 1 /* Add */ && item.s === prev.s) {
2223
1956
  current = {
2224
- t: "add",
1957
+ t: 1 /* Add */,
2225
1958
  s: getAssignmentExpression(current),
2226
1959
  k: void 0,
2227
1960
  v: item.v
2228
1961
  };
2229
- } else if (item.t === "delete" && item.s === prev.s) {
1962
+ } else if (item.t === 3 /* Delete */ && item.s === prev.s) {
2230
1963
  current = {
2231
- t: "delete",
1964
+ t: 3 /* Delete */,
2232
1965
  s: getAssignmentExpression(current),
2233
1966
  k: item.k,
2234
1967
  v: void 0
@@ -2286,14 +2019,14 @@ var BaseSerializerContext = class {
2286
2019
  this.marked = new Set(options.markedRefs);
2287
2020
  }
2288
2021
  createFunction(parameters, body) {
2289
- if (this.features & 4 /* ArrowFunction */) {
2022
+ if (this.features & 2 /* ArrowFunction */) {
2290
2023
  const joined = parameters.length === 1 ? parameters[0] : "(" + parameters.join(",") + ")";
2291
2024
  return joined + "=>" + body;
2292
2025
  }
2293
2026
  return "function(" + parameters.join(",") + "){return " + body + "}";
2294
2027
  }
2295
2028
  createEffectfulFunction(parameters, body) {
2296
- if (this.features & 4 /* ArrowFunction */) {
2029
+ if (this.features & 2 /* ArrowFunction */) {
2297
2030
  const joined = parameters.length === 1 ? parameters[0] : "(" + parameters.join(",") + ")";
2298
2031
  return joined + "=>{" + body + "}";
2299
2032
  }
@@ -2346,7 +2079,7 @@ var BaseSerializerContext = class {
2346
2079
  */
2347
2080
  createAssignment(source, value) {
2348
2081
  this.assignments.push({
2349
- t: "index",
2082
+ t: 0 /* Index */,
2350
2083
  s: source,
2351
2084
  k: void 0,
2352
2085
  v: value
@@ -2354,7 +2087,7 @@ var BaseSerializerContext = class {
2354
2087
  }
2355
2088
  createAddAssignment(ref, value) {
2356
2089
  this.assignments.push({
2357
- t: "add",
2090
+ t: 1 /* Add */,
2358
2091
  s: this.getRefParam(ref),
2359
2092
  k: void 0,
2360
2093
  v: value
@@ -2362,7 +2095,7 @@ var BaseSerializerContext = class {
2362
2095
  }
2363
2096
  createSetAssignment(ref, key, value) {
2364
2097
  this.assignments.push({
2365
- t: "set",
2098
+ t: 2 /* Set */,
2366
2099
  s: this.getRefParam(ref),
2367
2100
  k: key,
2368
2101
  v: value
@@ -2370,7 +2103,7 @@ var BaseSerializerContext = class {
2370
2103
  }
2371
2104
  createDeleteAssignment(ref, key) {
2372
2105
  this.assignments.push({
2373
- t: "delete",
2106
+ t: 3 /* Delete */,
2374
2107
  s: this.getRefParam(ref),
2375
2108
  k: key,
2376
2109
  v: void 0
@@ -2390,13 +2123,20 @@ var BaseSerializerContext = class {
2390
2123
  return node.t === 4 /* IndexedValue */ && this.stack.includes(node.i);
2391
2124
  }
2392
2125
  serializeReference(node) {
2393
- return this.assignIndexedValue(node.i, REFERENCES_KEY + '.get("' + node.s + '")');
2126
+ return this.assignIndexedValue(
2127
+ node.i,
2128
+ REFERENCES_KEY + '.get("' + node.s + '")'
2129
+ );
2394
2130
  }
2395
2131
  serializeArrayItem(id, item, index) {
2396
2132
  if (item) {
2397
2133
  if (this.isIndexedValueInStack(item)) {
2398
2134
  this.markRef(id);
2399
- this.createArrayAssign(id, index, this.getRefParam(item.i));
2135
+ this.createArrayAssign(
2136
+ id,
2137
+ index,
2138
+ this.getRefParam(item.i)
2139
+ );
2400
2140
  return "";
2401
2141
  }
2402
2142
  return this.serialize(item);
@@ -2431,7 +2171,11 @@ var BaseSerializerContext = class {
2431
2171
  if (isIdentifier && check !== check) {
2432
2172
  this.createObjectAssign(source.i, key, refParam);
2433
2173
  } else {
2434
- this.createArrayAssign(source.i, isIdentifier ? key : '"' + key + '"', refParam);
2174
+ this.createArrayAssign(
2175
+ source.i,
2176
+ isIdentifier ? key : '"' + key + '"',
2177
+ refParam
2178
+ );
2435
2179
  }
2436
2180
  return "";
2437
2181
  }
@@ -2442,9 +2186,9 @@ var BaseSerializerContext = class {
2442
2186
  serializeProperties(source, record) {
2443
2187
  const len = record.s;
2444
2188
  if (len) {
2445
- this.stack.push(source.i);
2446
2189
  const keys = record.k;
2447
2190
  const values = record.v;
2191
+ this.stack.push(source.i);
2448
2192
  let result = this.serializeProperty(source, keys[0], values[0]);
2449
2193
  for (let i = 1, item = result; i < len; i++) {
2450
2194
  item = this.serializeProperty(source, keys[i], values[i]);
@@ -2457,7 +2201,10 @@ var BaseSerializerContext = class {
2457
2201
  }
2458
2202
  serializeObject(node) {
2459
2203
  this.pushObjectFlag(node.o, node.i);
2460
- return this.assignIndexedValue(node.i, this.serializeProperties(node, node.p));
2204
+ return this.assignIndexedValue(
2205
+ node.i,
2206
+ this.serializeProperties(node, node.p)
2207
+ );
2461
2208
  }
2462
2209
  serializeWithObjectAssign(source, value, serialized) {
2463
2210
  const fields = this.serializeProperties(source, value);
@@ -2466,27 +2213,38 @@ var BaseSerializerContext = class {
2466
2213
  }
2467
2214
  return serialized;
2468
2215
  }
2469
- serializeAssignment(source, mainAssignments, key, value) {
2470
- if (typeof key === "string") {
2471
- const serialized = this.serialize(value);
2472
- const check = Number(key);
2473
- const isIdentifier = check >= 0 || isValidIdentifier(key);
2474
- if (this.isIndexedValueInStack(value)) {
2475
- if (isIdentifier && check !== check) {
2476
- this.createObjectAssign(source.i, key, serialized);
2477
- } else {
2478
- this.createArrayAssign(source.i, isIdentifier ? key : '"' + key + '"', serialized);
2479
- }
2216
+ serializeStringKeyAssignment(source, mainAssignments, key, value) {
2217
+ const serialized = this.serialize(value);
2218
+ const check = Number(key);
2219
+ const isIdentifier = check >= 0 || isValidIdentifier(key);
2220
+ if (this.isIndexedValueInStack(value)) {
2221
+ if (isIdentifier && check !== check) {
2222
+ this.createObjectAssign(source.i, key, serialized);
2480
2223
  } else {
2481
- const parentAssignment = this.assignments;
2482
- this.assignments = mainAssignments;
2483
- if (isIdentifier) {
2484
- this.createObjectAssign(source.i, key, serialized);
2485
- } else {
2486
- this.createArrayAssign(source.i, isIdentifier ? key : '"' + key + '"', serialized);
2487
- }
2488
- this.assignments = parentAssignment;
2224
+ this.createArrayAssign(
2225
+ source.i,
2226
+ isIdentifier ? key : '"' + key + '"',
2227
+ serialized
2228
+ );
2229
+ }
2230
+ } else {
2231
+ const parentAssignment = this.assignments;
2232
+ this.assignments = mainAssignments;
2233
+ if (isIdentifier) {
2234
+ this.createObjectAssign(source.i, key, serialized);
2235
+ } else {
2236
+ this.createArrayAssign(
2237
+ source.i,
2238
+ isIdentifier ? key : '"' + key + '"',
2239
+ serialized
2240
+ );
2489
2241
  }
2242
+ this.assignments = parentAssignment;
2243
+ }
2244
+ }
2245
+ serializeAssignment(source, mainAssignments, key, value) {
2246
+ if (typeof key === "string") {
2247
+ this.serializeStringKeyAssignment(source, mainAssignments, key, value);
2490
2248
  } else {
2491
2249
  const parent = this.stack;
2492
2250
  this.stack = [];
@@ -2494,21 +2252,17 @@ var BaseSerializerContext = class {
2494
2252
  this.stack = parent;
2495
2253
  const parentAssignment = this.assignments;
2496
2254
  this.assignments = mainAssignments;
2497
- this.createArrayAssign(
2498
- source.i,
2499
- this.serialize(key),
2500
- serialized
2501
- );
2255
+ this.createArrayAssign(source.i, this.serialize(key), serialized);
2502
2256
  this.assignments = parentAssignment;
2503
2257
  }
2504
2258
  }
2505
2259
  serializeAssignments(source, node) {
2506
2260
  const len = node.s;
2507
2261
  if (len) {
2508
- this.stack.push(source.i);
2509
2262
  const mainAssignments = [];
2510
2263
  const keys = node.k;
2511
2264
  const values = node.v;
2265
+ this.stack.push(source.i);
2512
2266
  for (let i = 0; i < len; i++) {
2513
2267
  this.serializeAssignment(source, mainAssignments, keys[i], values[i]);
2514
2268
  }
@@ -2519,7 +2273,7 @@ var BaseSerializerContext = class {
2519
2273
  }
2520
2274
  serializeDictionary(node, init) {
2521
2275
  if (node.p) {
2522
- if (this.features & 128 /* ObjectAssign */) {
2276
+ if (this.features & 8 /* ObjectAssign */) {
2523
2277
  init = this.serializeWithObjectAssign(node, node.p, init);
2524
2278
  } else {
2525
2279
  this.markRef(node.i);
@@ -2544,7 +2298,10 @@ var BaseSerializerContext = class {
2544
2298
  serializeSetItem(id, item) {
2545
2299
  if (this.isIndexedValueInStack(item)) {
2546
2300
  this.markRef(id);
2547
- this.createAddAssignment(id, this.getRefParam(item.i));
2301
+ this.createAddAssignment(
2302
+ id,
2303
+ this.getRefParam(item.i)
2304
+ );
2548
2305
  return "";
2549
2306
  }
2550
2307
  return this.serialize(item);
@@ -2611,14 +2368,14 @@ var BaseSerializerContext = class {
2611
2368
  const size = node.e.s;
2612
2369
  const id = node.i;
2613
2370
  const sentinel = node.f;
2614
- const sentinelID = this.getRefParam(sentinel.i);
2371
+ const sentinelId = this.getRefParam(sentinel.i);
2615
2372
  if (size) {
2616
2373
  const keys = node.e.k;
2617
2374
  const vals = node.e.v;
2618
2375
  this.stack.push(id);
2619
- let result = this.serializeMapEntry(id, keys[0], vals[0], sentinelID);
2376
+ let result = this.serializeMapEntry(id, keys[0], vals[0], sentinelId);
2620
2377
  for (let i = 1, item = result; i < size; i++) {
2621
- item = this.serializeMapEntry(id, keys[i], vals[i], sentinelID);
2378
+ item = this.serializeMapEntry(id, keys[i], vals[i], sentinelId);
2622
2379
  result += (item && result && ",") + item;
2623
2380
  }
2624
2381
  this.stack.pop();
@@ -2626,7 +2383,7 @@ var BaseSerializerContext = class {
2626
2383
  serialized += "([" + result + "])";
2627
2384
  }
2628
2385
  }
2629
- if (sentinel.t === 41 /* SpecialReference */) {
2386
+ if (sentinel.t === 26 /* SpecialReference */) {
2630
2387
  this.markRef(sentinel.i);
2631
2388
  serialized = "(" + this.serialize(sentinel) + "," + serialized + ")";
2632
2389
  }
@@ -2660,113 +2417,42 @@ var BaseSerializerContext = class {
2660
2417
  serializeAggregateError(node) {
2661
2418
  const id = node.i;
2662
2419
  this.stack.push(id);
2663
- const serialized = 'new AggregateError([],"' + node.m + '")';
2420
+ const serialized = this.serializeDictionary(
2421
+ node,
2422
+ 'new AggregateError([],"' + node.m + '")'
2423
+ );
2664
2424
  this.stack.pop();
2665
- return this.serializeDictionary(node, serialized);
2425
+ return serialized;
2666
2426
  }
2667
2427
  serializeError(node) {
2668
- return this.serializeDictionary(node, "new " + ERROR_CONSTRUCTOR_STRING[node.s] + '("' + node.m + '")');
2428
+ return this.serializeDictionary(
2429
+ node,
2430
+ "new " + ERROR_CONSTRUCTOR_STRING[node.s] + '("' + node.m + '")'
2431
+ );
2669
2432
  }
2670
2433
  serializePromise(node) {
2671
2434
  let serialized;
2672
2435
  const fulfilled = node.f;
2673
2436
  const id = node.i;
2674
- const constructor = node.s ? PROMISE_RESOLVE : PROMISE_REJECT;
2437
+ const promiseConstructor = node.s ? PROMISE_RESOLVE : PROMISE_REJECT;
2675
2438
  if (this.isIndexedValueInStack(fulfilled)) {
2676
2439
  const ref = this.getRefParam(fulfilled.i);
2677
- serialized = constructor + (node.s ? "().then(" + this.createFunction([], ref) + ")" : "().catch(" + this.createEffectfulFunction([], "throw " + ref) + ")");
2440
+ serialized = promiseConstructor + (node.s ? "().then(" + this.createFunction([], ref) + ")" : "().catch(" + this.createEffectfulFunction([], "throw " + ref) + ")");
2678
2441
  } else {
2679
2442
  this.stack.push(id);
2680
2443
  const result = this.serialize(fulfilled);
2681
2444
  this.stack.pop();
2682
- serialized = constructor + "(" + result + ")";
2445
+ serialized = promiseConstructor + "(" + result + ")";
2683
2446
  }
2684
2447
  return this.assignIndexedValue(id, serialized);
2685
2448
  }
2686
- serializeWKSymbol(node) {
2449
+ serializeWellKnownSymbol(node) {
2687
2450
  return this.assignIndexedValue(node.i, SYMBOL_STRING[node.s]);
2688
2451
  }
2689
- serializeURL(node) {
2690
- return this.assignIndexedValue(node.i, 'new URL("' + node.s + '")');
2691
- }
2692
- serializeURLSearchParams(node) {
2693
- return this.assignIndexedValue(
2694
- node.i,
2695
- node.s ? 'new URLSearchParams("' + node.s + '")' : "new URLSearchParams"
2696
- );
2697
- }
2698
- serializeBlob(node) {
2699
- return this.assignIndexedValue(
2700
- node.i,
2701
- "new Blob([" + this.serialize(node.f) + '],{type:"' + node.c + '"})'
2702
- );
2703
- }
2704
- serializeFile(node) {
2705
- return this.assignIndexedValue(
2706
- node.i,
2707
- "new File([" + this.serialize(node.f) + '],"' + node.m + '",{type:"' + node.c + '",lastModified:' + node.b + "})"
2708
- );
2709
- }
2710
- serializeHeaders(node) {
2711
- return this.assignIndexedValue(
2712
- node.i,
2713
- "new Headers(" + this.serializeProperties(node, node.e) + ")"
2714
- );
2715
- }
2716
- serializeFormDataEntry(id, key, value) {
2717
- return this.getRefParam(id) + '.append("' + key + '",' + this.serialize(value) + ")";
2718
- }
2719
- serializeFormDataEntries(node, size) {
2720
- const keys = node.e.k;
2721
- const vals = node.e.v;
2722
- const id = node.i;
2723
- let result = this.serializeFormDataEntry(id, keys[0], vals[0]);
2724
- for (let i = 1; i < size; i++) {
2725
- result += "," + this.serializeFormDataEntry(id, keys[i], vals[i]);
2726
- }
2727
- return result;
2728
- }
2729
- serializeFormData(node) {
2730
- const size = node.e.s;
2731
- const id = node.i;
2732
- if (size) {
2733
- this.markRef(id);
2734
- }
2735
- const result = this.assignIndexedValue(id, "new FormData()");
2736
- if (size) {
2737
- const entries = this.serializeFormDataEntries(node, size);
2738
- return "(" + result + "," + (entries ? entries + "," : "") + this.getRefParam(id) + ")";
2739
- }
2740
- return result;
2741
- }
2742
2452
  serializeBoxed(node) {
2743
- return this.assignIndexedValue(node.i, "Object(" + this.serialize(node.f) + ")");
2744
- }
2745
- serializeRequest(node) {
2746
- return this.assignIndexedValue(node.i, 'new Request("' + node.s + '",' + this.serialize(node.f) + ")");
2747
- }
2748
- serializeResponse(node) {
2749
- return this.assignIndexedValue(
2750
- node.i,
2751
- "new Response(" + this.serialize(node.a[0]) + "," + this.serialize(node.a[1]) + ")"
2752
- );
2753
- }
2754
- serializeEvent(node) {
2755
- return this.assignIndexedValue(
2756
- node.i,
2757
- 'new Event("' + node.s + '",' + this.serialize(node.f) + ")"
2758
- );
2759
- }
2760
- serializeCustomEvent(node) {
2761
- return this.assignIndexedValue(
2762
- node.i,
2763
- 'new CustomEvent("' + node.s + '",' + this.serialize(node.f) + ")"
2764
- );
2765
- }
2766
- serializeDOMException(node) {
2767
2453
  return this.assignIndexedValue(
2768
2454
  node.i,
2769
- 'new DOMException("' + node.s + '","' + node.c + '")'
2455
+ "Object(" + this.serialize(node.f) + ")"
2770
2456
  );
2771
2457
  }
2772
2458
  serializePlugin(node) {
@@ -2787,14 +2473,11 @@ var BaseSerializerContext = class {
2787
2473
  throw new Error('Missing plugin for tag "' + node.c + '".');
2788
2474
  }
2789
2475
  getConstructor(node) {
2790
- const constructor = this.serialize(node);
2791
- return constructor === this.getRefParam(node.i) ? constructor : "(" + constructor + ")";
2476
+ const current = this.serialize(node);
2477
+ return current === this.getRefParam(node.i) ? current : "(" + current + ")";
2792
2478
  }
2793
2479
  serializePromiseConstructor(node) {
2794
- return this.assignIndexedValue(
2795
- node.i,
2796
- this.getConstructor(node.f) + "()"
2797
- );
2480
+ return this.assignIndexedValue(node.i, this.getConstructor(node.f) + "()");
2798
2481
  }
2799
2482
  serializePromiseResolve(node) {
2800
2483
  return this.getConstructor(node.a[0]) + "(" + this.getRefParam(node.i) + "," + this.serialize(node.a[1]) + ")";
@@ -2802,70 +2485,44 @@ var BaseSerializerContext = class {
2802
2485
  serializePromiseReject(node) {
2803
2486
  return this.getConstructor(node.a[0]) + "(" + this.getRefParam(node.i) + "," + this.serialize(node.a[1]) + ")";
2804
2487
  }
2805
- serializeReadableStreamConstructor(node) {
2806
- return this.assignIndexedValue(
2807
- node.i,
2808
- this.getConstructor(node.f) + "()"
2809
- );
2810
- }
2811
- serializeReadableStreamEnqueue(node) {
2812
- return this.getConstructor(node.a[0]) + "(" + this.getRefParam(node.i) + "," + this.serialize(node.a[1]) + ")";
2813
- }
2814
- serializeReadableStreamError(node) {
2815
- return this.getConstructor(node.a[0]) + "(" + this.getRefParam(node.i) + "," + this.serialize(node.a[1]) + ")";
2816
- }
2817
- serializeReadableStreamClose(node) {
2818
- return this.getConstructor(node.f) + "(" + this.getRefParam(node.i) + ")";
2819
- }
2820
2488
  serializeSpecialReferenceValue(ref) {
2821
2489
  switch (ref) {
2822
2490
  case 0 /* MapSentinel */:
2823
2491
  return "[]";
2824
- case 1 /* ReadableStream */:
2825
- return this.createFunction(
2826
- ["s"],
2827
- "new ReadableStream({start:" + this.createFunction(
2828
- ["c"],
2829
- "Promise.resolve().then(" + this.createEffectfulFunction(
2830
- ["i", "v"],
2831
- "for(i=0;i<s.d;i++)c.enqueue(s.v[i]);(s.t===-1)?c.close():c.error(s.v[i])"
2832
- ) + ")"
2833
- ) + "})"
2834
- );
2835
- case 2 /* PromiseConstructor */:
2492
+ case 1 /* PromiseConstructor */:
2836
2493
  return this.createFunction(
2837
2494
  ["s", "f", "p"],
2838
2495
  "((p=new Promise(" + this.createEffectfulFunction(["a", "b"], "s=a,f=b") + ")).s=s,p.f=f,p)"
2839
2496
  );
2840
- case 3 /* PromiseResolve */:
2497
+ case 2 /* PromiseResolve */:
2841
2498
  return this.createEffectfulFunction(
2842
2499
  ["p", "d"],
2843
2500
  'p.s(d),p.status="success",p.value=d;delete p.s;delete p.f'
2844
2501
  );
2845
- case 4 /* PromiseReject */:
2502
+ case 3 /* PromiseReject */:
2846
2503
  return this.createEffectfulFunction(
2847
2504
  ["p", "d"],
2848
2505
  'p.f(d),p.status="failure",p.value=d;delete p.s;delete p.f'
2849
2506
  );
2850
- case 5 /* ReadableStreamConstructor */:
2507
+ case 4 /* StreamConstructor */:
2851
2508
  return this.createFunction(
2852
- ["s", "c"],
2853
- "((s=new ReadableStream({start:" + this.createEffectfulFunction(["x"], "c=x") + "})).c=c,s)"
2854
- );
2855
- case 6 /* ReadableStreamEnqueue */:
2856
- return this.createEffectfulFunction(
2857
- ["s", "d"],
2858
- "s.c.enqueue(d)"
2859
- );
2860
- case 7 /* ReadableStreamError */:
2861
- return this.createEffectfulFunction(
2862
- ["s", "d"],
2863
- "s.c.error(d);delete s.c"
2864
- );
2865
- case 8 /* ReadableStreamClose */:
2866
- return this.createEffectfulFunction(
2867
- ["s"],
2868
- "s.c.close();delete s.c"
2509
+ ["b", "a", "s", "l", "p", "f", "e", "n"],
2510
+ "(b=[],a=!0,s=!1,l=[],p=0,f=" + this.createEffectfulFunction(
2511
+ ["v", "m", "x"],
2512
+ "for(x=0;x<p;x++)l[x]&&l[x][m](v)"
2513
+ ) + ",n=" + this.createEffectfulFunction(
2514
+ ["o", "x", "z", "c"],
2515
+ 'for(x=0,z=b.length;x<z;x++)(c=b[x],x===z-1?o[s?"return":"throw"](c):o.next(c))'
2516
+ ) + ",e=" + this.createFunction(
2517
+ ["o", "t"],
2518
+ "(a&&(l[t=p++]=o),n(o)," + this.createEffectfulFunction([], "a&&(l[t]=void 0)") + ")"
2519
+ ) + ",{__SEROVAL_STREAM__:!0,on:" + this.createFunction(["o"], "e(o)") + ",next:" + this.createEffectfulFunction(["v"], 'a&&(b.push(v),f(v,"next"))') + ",throw:" + this.createEffectfulFunction(
2520
+ ["v"],
2521
+ 'a&&(b.push(v),f(v,"throw"),a=s=!1,l.length=0)'
2522
+ ) + ",return:" + this.createEffectfulFunction(
2523
+ ["v"],
2524
+ 'a&&(b.push(v),f(v,"return"),a=!1,s=!0,l.length=0)'
2525
+ ) + "})"
2869
2526
  );
2870
2527
  default:
2871
2528
  return "";
@@ -2878,67 +2535,105 @@ var BaseSerializerContext = class {
2878
2535
  );
2879
2536
  }
2880
2537
  serializeIteratorFactory(node) {
2881
- return this.assignIndexedValue(
2538
+ let result = "";
2539
+ let initialized = false;
2540
+ if (node.f.t !== 4 /* IndexedValue */) {
2541
+ this.markRef(node.f.i);
2542
+ result = "(" + this.serialize(node.f) + ",";
2543
+ initialized = true;
2544
+ }
2545
+ result += this.assignIndexedValue(
2882
2546
  node.i,
2883
2547
  this.createFunction(
2884
2548
  ["s"],
2885
2549
  this.createFunction(
2886
2550
  ["i", "c", "d", "t"],
2887
- "(i=0,t={[" + this.serialize(node.f) + "]:" + this.createFunction([], "t") + ",next:" + this.createEffectfulFunction([], "if(i>s.d)return{done:!0,value:void 0};c=i++,d=s.v[c];if(c===s.t)throw d;return{done:c===s.d,value:d}") + "})"
2551
+ "(i=0,t={[" + this.getRefParam(node.f.i) + "]:" + this.createFunction([], "t") + ",next:" + this.createEffectfulFunction(
2552
+ [],
2553
+ "if(i>s.d)return{done:!0,value:void 0};if(d=s.v[c=i++],c===s.t)throw d;return{done:c===s.d,value:d}"
2554
+ ) + "})"
2888
2555
  )
2889
2556
  )
2890
2557
  );
2558
+ if (initialized) {
2559
+ result += ")";
2560
+ }
2561
+ return result;
2891
2562
  }
2892
2563
  serializeIteratorFactoryInstance(node) {
2893
2564
  return this.getConstructor(node.a[0]) + "(" + this.serialize(node.a[1]) + ")";
2894
2565
  }
2895
- getStreamingAsyncIteratorFactory(node) {
2896
- return this.createFunction(
2897
- ["s"],
2898
- this.createFunction(
2899
- ["b", "t"],
2900
- "(b=s.tee(),s=b[0],b=b[1].getReader(),t={[" + this.serialize(node.f) + "]:" + this.createFunction([], "t") + ",next:" + this.createFunction(
2901
- [],
2902
- "b.read().then(" + this.createEffectfulFunction(
2903
- ["d"],
2904
- "if(d.done)return{done:!0,value:void 0};d=d.value;if(d[0]===1)throw d[1];return{done:d[0]===2,value:d[1]}"
2905
- ) + ")"
2906
- ) + "})"
2907
- )
2908
- );
2909
- }
2910
- getBlockingAsyncIteratorFactory(node) {
2911
- return this.createFunction(
2912
- ["s"],
2913
- this.createFunction(
2914
- ["i", "t"],
2915
- "(i=0,t={[" + this.serialize(node.f) + "]:" + this.createFunction([], "t") + ",next:" + this.createFunction(
2916
- [],
2917
- "Promise.resolve().then(" + this.createEffectfulFunction(
2918
- ["c", "d"],
2919
- "if(i>s.d)return{done:!0,value:void 0};c=i++,d=s.v[c];if(c===s.t)throw d;return{done:c===s.d,value:d}"
2920
- ) + ")"
2921
- ) + "})"
2922
- )
2923
- );
2924
- }
2925
2566
  serializeAsyncIteratorFactory(node) {
2926
- return this.assignIndexedValue(
2567
+ const promise = node.a[0];
2568
+ const symbol = node.a[1];
2569
+ let result = "";
2570
+ if (promise.t !== 4 /* IndexedValue */) {
2571
+ this.markRef(promise.i);
2572
+ result += "(" + this.serialize(promise);
2573
+ }
2574
+ if (symbol.t !== 4 /* IndexedValue */) {
2575
+ this.markRef(symbol.i);
2576
+ result += (result ? "," : "(") + this.serialize(symbol);
2577
+ }
2578
+ if (result) {
2579
+ result += ",";
2580
+ }
2581
+ const iterator = this.assignIndexedValue(
2927
2582
  node.i,
2928
- node.s ? this.getStreamingAsyncIteratorFactory(node) : this.getBlockingAsyncIteratorFactory(node)
2583
+ this.createFunction(
2584
+ ["s"],
2585
+ this.createFunction(
2586
+ ["b", "c", "p", "d", "e", "t", "f"],
2587
+ "(b=[],c=0,p=[],d=-1,e=!1,f=" + this.createEffectfulFunction(
2588
+ ["i", "l"],
2589
+ "for(i=0,l=p.length;i<l;i++)p[i].s({done:!0,value:void 0})"
2590
+ ) + ",s.on({next:" + this.createEffectfulFunction(
2591
+ ["v", "t"],
2592
+ "if(t=p.shift())t.s({done:!1,value:v});b.push(v)"
2593
+ ) + ",throw:" + this.createEffectfulFunction(
2594
+ ["v", "t"],
2595
+ "if(t=p.shift())t.f(v);f(),d=b.length,e=!0,b.push(v)"
2596
+ ) + ",return:" + this.createEffectfulFunction(
2597
+ ["v", "t"],
2598
+ "if(t=p.shift())t.s({done:!0,value:v});f(),d=b.length,b.push(v)"
2599
+ ) + "}),t={[" + this.getRefParam(symbol.i) + "]:" + this.createFunction([], "t") + ",next:" + this.createEffectfulFunction(
2600
+ ["i", "t", "v"],
2601
+ "if(d===-1){return((i=c++)>=b.length)?(p.push(t=" + this.getRefParam(promise.i) + "()),t):{done:!0,value:b[i]}}if(c>d)return{done:!0,value:void 0};if(v=b[i=c++],i!==d)return{done:!1,value:v};if(e)throw v;return{done:!0,value:v}"
2602
+ ) + "})"
2603
+ )
2604
+ )
2929
2605
  );
2606
+ if (result) {
2607
+ return result + iterator + ")";
2608
+ }
2609
+ return iterator;
2930
2610
  }
2931
2611
  serializeAsyncIteratorFactoryInstance(node) {
2932
2612
  return this.getConstructor(node.a[0]) + "(" + this.serialize(node.a[1]) + ")";
2933
2613
  }
2934
- serializeReadableStream(node) {
2935
- this.stack.push(node.i);
2936
- const result = this.getConstructor(node.a[0]) + "(" + this.serialize(node.a[1]) + ")";
2937
- this.stack.pop();
2938
- return this.assignIndexedValue(
2614
+ serializeStreamConstructor(node) {
2615
+ const result = this.assignIndexedValue(
2939
2616
  node.i,
2940
- result
2617
+ this.getConstructor(node.f) + "()"
2941
2618
  );
2619
+ const len = node.a.length;
2620
+ if (len) {
2621
+ let values = this.serialize(node.a[0]);
2622
+ for (let i = 1; i < len; i++) {
2623
+ values += "," + this.serialize(node.a[i]);
2624
+ }
2625
+ return "(" + result + "," + values + "," + this.getRefParam(node.i) + ")";
2626
+ }
2627
+ return result;
2628
+ }
2629
+ serializeStreamNext(node) {
2630
+ return this.getRefParam(node.i) + ".next(" + this.serialize(node.f) + ")";
2631
+ }
2632
+ serializeStreamThrow(node) {
2633
+ return this.getRefParam(node.i) + ".throw(" + this.serialize(node.f) + ")";
2634
+ }
2635
+ serializeStreamReturn(node) {
2636
+ return this.getRefParam(node.i) + ".return(" + this.serialize(node.f) + ")";
2942
2637
  }
2943
2638
  serialize(node) {
2944
2639
  switch (node.t) {
@@ -2952,7 +2647,7 @@ var BaseSerializerContext = class {
2952
2647
  return node.s + "n";
2953
2648
  case 4 /* IndexedValue */:
2954
2649
  return this.getRefParam(node.i);
2955
- case 20 /* Reference */:
2650
+ case 18 /* Reference */:
2956
2651
  return this.serializeReference(node);
2957
2652
  case 9 /* Array */:
2958
2653
  return this.serializeArray(node);
@@ -2968,12 +2663,12 @@ var BaseSerializerContext = class {
2968
2663
  return this.serializeSet(node);
2969
2664
  case 8 /* Map */:
2970
2665
  return this.serializeMap(node);
2971
- case 21 /* ArrayBuffer */:
2666
+ case 19 /* ArrayBuffer */:
2972
2667
  return this.serializeArrayBuffer(node);
2973
2668
  case 16 /* BigIntTypedArray */:
2974
2669
  case 15 /* TypedArray */:
2975
2670
  return this.serializeTypedArray(node);
2976
- case 22 /* DataView */:
2671
+ case 20 /* DataView */:
2977
2672
  return this.serializeDataView(node);
2978
2673
  case 14 /* AggregateError */:
2979
2674
  return this.serializeAggregateError(node);
@@ -2982,59 +2677,35 @@ var BaseSerializerContext = class {
2982
2677
  case 12 /* Promise */:
2983
2678
  return this.serializePromise(node);
2984
2679
  case 17 /* WKSymbol */:
2985
- return this.serializeWKSymbol(node);
2986
- case 18 /* URL */:
2987
- return this.serializeURL(node);
2988
- case 19 /* URLSearchParams */:
2989
- return this.serializeURLSearchParams(node);
2990
- case 23 /* Blob */:
2991
- return this.serializeBlob(node);
2992
- case 24 /* File */:
2993
- return this.serializeFile(node);
2994
- case 25 /* Headers */:
2995
- return this.serializeHeaders(node);
2996
- case 26 /* FormData */:
2997
- return this.serializeFormData(node);
2998
- case 27 /* Boxed */:
2680
+ return this.serializeWellKnownSymbol(node);
2681
+ case 21 /* Boxed */:
2999
2682
  return this.serializeBoxed(node);
3000
- case 28 /* PromiseConstructor */:
2683
+ case 22 /* PromiseConstructor */:
3001
2684
  return this.serializePromiseConstructor(node);
3002
- case 29 /* PromiseResolve */:
2685
+ case 23 /* PromiseResolve */:
3003
2686
  return this.serializePromiseResolve(node);
3004
- case 30 /* PromiseReject */:
2687
+ case 24 /* PromiseReject */:
3005
2688
  return this.serializePromiseReject(node);
3006
- case 31 /* ReadableStreamConstructor */:
3007
- return this.serializeReadableStreamConstructor(node);
3008
- case 32 /* ReadableStreamEnqueue */:
3009
- return this.serializeReadableStreamEnqueue(node);
3010
- case 34 /* ReadableStreamError */:
3011
- return this.serializeReadableStreamError(node);
3012
- case 33 /* ReadableStreamClose */:
3013
- return this.serializeReadableStreamClose(node);
3014
- case 35 /* Request */:
3015
- return this.serializeRequest(node);
3016
- case 36 /* Response */:
3017
- return this.serializeResponse(node);
3018
- case 37 /* Event */:
3019
- return this.serializeEvent(node);
3020
- case 38 /* CustomEvent */:
3021
- return this.serializeCustomEvent(node);
3022
- case 39 /* DOMException */:
3023
- return this.serializeDOMException(node);
3024
- case 40 /* Plugin */:
2689
+ case 25 /* Plugin */:
3025
2690
  return this.serializePlugin(node);
3026
- case 41 /* SpecialReference */:
2691
+ case 26 /* SpecialReference */:
3027
2692
  return this.serializeSpecialReference(node);
3028
- case 42 /* IteratorFactory */:
2693
+ case 27 /* IteratorFactory */:
3029
2694
  return this.serializeIteratorFactory(node);
3030
- case 43 /* IteratorFactoryInstance */:
2695
+ case 28 /* IteratorFactoryInstance */:
3031
2696
  return this.serializeIteratorFactoryInstance(node);
3032
- case 44 /* AsyncIteratorFactory */:
2697
+ case 29 /* AsyncIteratorFactory */:
3033
2698
  return this.serializeAsyncIteratorFactory(node);
3034
- case 45 /* AsyncIteratorFactoryInstance */:
2699
+ case 30 /* AsyncIteratorFactoryInstance */:
3035
2700
  return this.serializeAsyncIteratorFactoryInstance(node);
3036
- case 46 /* ReadableStream */:
3037
- return this.serializeReadableStream(node);
2701
+ case 31 /* StreamConstructor */:
2702
+ return this.serializeStreamConstructor(node);
2703
+ case 32 /* StreamNext */:
2704
+ return this.serializeStreamNext(node);
2705
+ case 33 /* StreamThrow */:
2706
+ return this.serializeStreamThrow(node);
2707
+ case 34 /* StreamReturn */:
2708
+ return this.serializeStreamReturn(node);
3038
2709
  default:
3039
2710
  throw new Error("invariant");
3040
2711
  }
@@ -3074,12 +2745,6 @@ var VanillaSerializerContext = class extends BaseSerializerContext {
3074
2745
  */
3075
2746
  this.vars = [];
3076
2747
  }
3077
- /**
3078
- * Increments the number of references the referenced value has
3079
- */
3080
- markRef(current) {
3081
- this.marked.add(current);
3082
- }
3083
2748
  /**
3084
2749
  * Creates the reference param (identifier) from the given reference ID
3085
2750
  * Calling this function means the value has been referenced somewhere
@@ -3112,18 +2777,6 @@ var VanillaSerializerContext = class extends BaseSerializerContext {
3112
2777
  serializePromiseReject(node) {
3113
2778
  throw new Error('Unsupported node type "' + node.t + '".');
3114
2779
  }
3115
- serializeReadableStreamConstructor(node) {
3116
- throw new Error('Unsupported node type "' + node.t + '".');
3117
- }
3118
- serializeReadableStreamEnqueue(node) {
3119
- throw new Error('Unsupported node type "' + node.t + '".');
3120
- }
3121
- serializeReadableStreamError(node) {
3122
- throw new Error('Unsupported node type "' + node.t + '".');
3123
- }
3124
- serializeReadableStreamClose(node) {
3125
- throw new Error('Unsupported node type "' + node.t + '".');
3126
- }
3127
2780
  serializeTop(tree) {
3128
2781
  const result = this.serialize(tree);
3129
2782
  if (tree.i != null && this.vars.length) {
@@ -3157,11 +2810,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
3157
2810
  return nodes;
3158
2811
  }
3159
2812
  parseArray(id, current) {
3160
- return createArrayNode(
3161
- id,
3162
- current,
3163
- this.parseItems(current)
3164
- );
2813
+ return createArrayNode(id, current, this.parseItems(current));
3165
2814
  }
3166
2815
  parseProperties(properties) {
3167
2816
  const entries = Object.entries(properties);
@@ -3171,31 +2820,37 @@ var BaseSyncParserContext = class extends BaseParserContext {
3171
2820
  keyNodes.push(serializeString(entries[i][0]));
3172
2821
  valueNodes.push(this.parse(entries[i][1]));
3173
2822
  }
3174
- if (this.features & 1024 /* Symbol */) {
3175
- let symbol = Symbol.iterator;
3176
- if (symbol in properties) {
3177
- keyNodes.push(
3178
- this.parseWKSymbol(symbol)
3179
- );
3180
- valueNodes.push(
3181
- createIteratorFactoryInstanceNode(
3182
- this.parseIteratorFactory(),
3183
- this.parse(
3184
- iteratorToSequence(properties)
3185
- )
2823
+ let symbol = Symbol.iterator;
2824
+ if (symbol in properties) {
2825
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
2826
+ valueNodes.push(
2827
+ createIteratorFactoryInstanceNode(
2828
+ this.parseIteratorFactory(),
2829
+ this.parse(
2830
+ iteratorToSequence(properties)
3186
2831
  )
3187
- );
3188
- }
3189
- symbol = Symbol.toStringTag;
3190
- if (symbol in properties) {
3191
- keyNodes.push(this.parseWKSymbol(symbol));
3192
- valueNodes.push(createStringNode(properties[symbol]));
3193
- }
3194
- symbol = Symbol.isConcatSpreadable;
3195
- if (symbol in properties) {
3196
- keyNodes.push(this.parseWKSymbol(symbol));
3197
- valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
3198
- }
2832
+ )
2833
+ );
2834
+ }
2835
+ symbol = Symbol.asyncIterator;
2836
+ if (symbol in properties) {
2837
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
2838
+ valueNodes.push(
2839
+ createAsyncIteratorFactoryInstanceNode(
2840
+ this.parseAsyncIteratorFactory(),
2841
+ this.parse(createStream())
2842
+ )
2843
+ );
2844
+ }
2845
+ symbol = Symbol.toStringTag;
2846
+ if (symbol in properties) {
2847
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
2848
+ valueNodes.push(createStringNode(properties[symbol]));
2849
+ }
2850
+ symbol = Symbol.isConcatSpreadable;
2851
+ if (symbol in properties) {
2852
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
2853
+ valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
3199
2854
  }
3200
2855
  return {
3201
2856
  k: keyNodes,
@@ -3246,12 +2901,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
3246
2901
  keyNodes.push(this.parse(key));
3247
2902
  valueNodes.push(this.parse(value));
3248
2903
  }
3249
- return this.createMapNode(
3250
- id,
3251
- keyNodes,
3252
- valueNodes,
3253
- current.size
3254
- );
2904
+ return this.createMapNode(id, keyNodes, valueNodes, current.size);
3255
2905
  }
3256
2906
  parseSet(id, current) {
3257
2907
  const items = [];
@@ -3260,66 +2910,6 @@ var BaseSyncParserContext = class extends BaseParserContext {
3260
2910
  }
3261
2911
  return createSetNode(id, current.size, items);
3262
2912
  }
3263
- parsePlainProperties(entries) {
3264
- const size = entries.length;
3265
- const keyNodes = [];
3266
- const valueNodes = [];
3267
- for (let i = 0; i < size; i++) {
3268
- keyNodes.push(serializeString(entries[i][0]));
3269
- valueNodes.push(this.parse(entries[i][1]));
3270
- }
3271
- return {
3272
- k: keyNodes,
3273
- v: valueNodes,
3274
- s: size
3275
- };
3276
- }
3277
- parseHeaders(id, current) {
3278
- const items = [];
3279
- current.forEach((value, key) => {
3280
- items.push([key, value]);
3281
- });
3282
- return {
3283
- t: 25 /* Headers */,
3284
- i: id,
3285
- s: void 0,
3286
- l: void 0,
3287
- c: void 0,
3288
- m: void 0,
3289
- p: void 0,
3290
- e: this.parsePlainProperties(items),
3291
- a: void 0,
3292
- f: void 0,
3293
- b: void 0,
3294
- o: void 0
3295
- };
3296
- }
3297
- parseFormData(id, current) {
3298
- const items = [];
3299
- current.forEach((value, key) => {
3300
- items.push([key, value]);
3301
- });
3302
- return {
3303
- t: 26 /* FormData */,
3304
- i: id,
3305
- s: void 0,
3306
- l: void 0,
3307
- c: void 0,
3308
- m: void 0,
3309
- p: void 0,
3310
- e: this.parsePlainProperties(items),
3311
- a: void 0,
3312
- f: void 0,
3313
- b: void 0,
3314
- o: void 0
3315
- };
3316
- }
3317
- parseEvent(id, current) {
3318
- return createEventNode(id, current.type, this.parse(createEventOptions(current)));
3319
- }
3320
- parseCustomEvent(id, current) {
3321
- return createCustomEventNode(id, current.type, this.parse(createCustomEventOptions(current)));
3322
- }
3323
2913
  parsePlugin(id, current) {
3324
2914
  const currentPlugins = this.plugins;
3325
2915
  if (currentPlugins) {
@@ -3338,10 +2928,27 @@ var BaseSyncParserContext = class extends BaseParserContext {
3338
2928
  }
3339
2929
  return void 0;
3340
2930
  }
2931
+ parseStream(id, _current) {
2932
+ return createStreamConstructorNode(
2933
+ id,
2934
+ this.parseSpecialReference(4 /* StreamConstructor */),
2935
+ []
2936
+ );
2937
+ }
2938
+ parsePromise(id, _current) {
2939
+ return this.createPromiseConstructorNode(id);
2940
+ }
3341
2941
  parseObject(id, current) {
3342
2942
  if (Array.isArray(current)) {
3343
2943
  return this.parseArray(id, current);
3344
2944
  }
2945
+ if (isStream(current)) {
2946
+ return this.parseStream(id, current);
2947
+ }
2948
+ const parsed = this.parsePlugin(id, current);
2949
+ if (parsed) {
2950
+ return parsed;
2951
+ }
3345
2952
  const currentClass = current.constructor;
3346
2953
  switch (currentClass) {
3347
2954
  case Object:
@@ -3373,119 +2980,77 @@ var BaseSyncParserContext = class extends BaseParserContext {
3373
2980
  case String:
3374
2981
  case BigInt:
3375
2982
  return this.parseBoxed(id, current);
2983
+ case ArrayBuffer:
2984
+ return createArrayBufferNode(id, current);
2985
+ case Int8Array:
2986
+ case Int16Array:
2987
+ case Int32Array:
2988
+ case Uint8Array:
2989
+ case Uint16Array:
2990
+ case Uint32Array:
2991
+ case Uint8ClampedArray:
2992
+ case Float32Array:
2993
+ case Float64Array:
2994
+ return this.parseTypedArray(id, current);
2995
+ case DataView:
2996
+ return this.parseDataView(id, current);
2997
+ case Map:
2998
+ return this.parseMap(id, current);
2999
+ case Set:
3000
+ return this.parseSet(id, current);
3376
3001
  default:
3377
- break;
3378
- }
3379
- const currentFeatures = this.features;
3380
- if (currentFeatures & 2048 /* TypedArray */) {
3381
- switch (currentClass) {
3382
- case ArrayBuffer:
3383
- return createArrayBufferNode(id, current);
3384
- case Int8Array:
3385
- case Int16Array:
3386
- case Int32Array:
3387
- case Uint8Array:
3388
- case Uint16Array:
3389
- case Uint32Array:
3390
- case Uint8ClampedArray:
3391
- case Float32Array:
3392
- case Float64Array:
3393
- return this.parseTypedArray(id, current);
3394
- case DataView:
3395
- return this.parseDataView(id, current);
3396
- default:
3397
- break;
3398
- }
3399
- }
3400
- if ((currentFeatures & BIGINT_FLAG) === BIGINT_FLAG) {
3401
- switch (currentClass) {
3402
- case BigInt64Array:
3403
- case BigUint64Array:
3404
- return this.parseBigIntTypedArray(id, current);
3405
- default:
3406
- break;
3407
- }
3408
- }
3409
- if (currentFeatures & 32 /* Map */ && currentClass === Map) {
3410
- return this.parseMap(
3411
- id,
3412
- current
3413
- );
3002
+ break;
3414
3003
  }
3415
- if (currentFeatures & 512 /* Set */ && currentClass === Set) {
3416
- return this.parseSet(
3417
- id,
3418
- current
3419
- );
3004
+ if (currentClass === Promise || current instanceof Promise) {
3005
+ return this.parsePromise(id, current);
3420
3006
  }
3421
- if (currentFeatures & 8192 /* WebAPI */) {
3007
+ const currentFeatures = this.features;
3008
+ if (currentFeatures & 16 /* BigIntTypedArray */) {
3422
3009
  switch (currentClass) {
3423
- case (typeof URL !== "undefined" ? URL : UNIVERSAL_SENTINEL):
3424
- return createURLNode(id, current);
3425
- case (typeof URLSearchParams !== "undefined" ? URLSearchParams : UNIVERSAL_SENTINEL):
3426
- return createURLSearchParamsNode(id, current);
3427
- case (typeof Headers !== "undefined" ? Headers : UNIVERSAL_SENTINEL):
3428
- return this.parseHeaders(id, current);
3429
- case (typeof FormData !== "undefined" ? FormData : UNIVERSAL_SENTINEL):
3430
- return this.parseFormData(id, current);
3431
- case (typeof Event !== "undefined" ? Event : UNIVERSAL_SENTINEL):
3432
- return this.parseEvent(id, current);
3433
- case (typeof CustomEvent !== "undefined" ? CustomEvent : UNIVERSAL_SENTINEL):
3434
- return this.parseCustomEvent(id, current);
3435
- case (typeof DOMException !== "undefined" ? DOMException : UNIVERSAL_SENTINEL):
3436
- return createDOMExceptionNode(id, current);
3010
+ case BigInt64Array:
3011
+ case BigUint64Array:
3012
+ return this.parseBigIntTypedArray(
3013
+ id,
3014
+ current
3015
+ );
3437
3016
  default:
3438
3017
  break;
3439
3018
  }
3440
3019
  }
3441
- const parsed = this.parsePlugin(id, current);
3442
- if (parsed) {
3443
- return parsed;
3444
- }
3445
3020
  if (currentFeatures & 1 /* AggregateError */ && typeof AggregateError !== "undefined" && (currentClass === AggregateError || current instanceof AggregateError)) {
3446
3021
  return this.parseAggregateError(id, current);
3447
3022
  }
3448
3023
  if (current instanceof Error) {
3449
3024
  return this.parseError(id, current);
3450
3025
  }
3451
- if (currentFeatures & 1024 /* Symbol */ && Symbol.iterator in current) {
3026
+ if (Symbol.iterator in current || Symbol.asyncIterator in current) {
3452
3027
  return this.parsePlainObject(id, current, !!currentClass);
3453
3028
  }
3454
3029
  throw new UnsupportedTypeError(current);
3455
3030
  }
3456
3031
  parse(current) {
3457
- switch (current) {
3458
- case true:
3459
- return TRUE_NODE;
3460
- case false:
3461
- return FALSE_NODE;
3462
- case void 0:
3463
- return UNDEFINED_NODE;
3464
- case null:
3465
- return NULL_NODE;
3466
- default:
3467
- break;
3468
- }
3469
3032
  switch (typeof current) {
3033
+ case "boolean":
3034
+ return current ? TRUE_NODE : FALSE_NODE;
3035
+ case "undefined":
3036
+ return UNDEFINED_NODE;
3470
3037
  case "string":
3471
3038
  return createStringNode(current);
3472
3039
  case "number":
3473
3040
  return createNumberNode(current);
3474
3041
  case "bigint":
3475
- assert(this.features & 8 /* BigInt */, new UnsupportedTypeError(current));
3476
3042
  return createBigIntNode(current);
3477
3043
  case "object": {
3478
- const id = this.getReference(current);
3479
- return typeof id === "number" ? this.parseObject(id, current) : id;
3480
- }
3481
- case "symbol": {
3482
- assert(this.features & 1024 /* Symbol */, new UnsupportedTypeError(current));
3483
- const id = this.getReference(current);
3484
- return typeof id === "number" ? createWKSymbolNode(id, current) : id;
3044
+ if (current) {
3045
+ const ref = this.getReference(current);
3046
+ return ref.type === 0 ? this.parseObject(ref.value, current) : ref.value;
3047
+ }
3048
+ return NULL_NODE;
3485
3049
  }
3050
+ case "symbol":
3051
+ return this.parseWellKnownSymbol(current);
3486
3052
  case "function":
3487
- assert(hasReferenceID(current), new Error("Cannot serialize function without reference ID."));
3488
- return this.getStrictReference(current);
3053
+ return this.parseFunction(current);
3489
3054
  default:
3490
3055
  throw new UnsupportedTypeError(current);
3491
3056
  }
@@ -3502,26 +3067,28 @@ var SyncParserContext = class extends BaseSyncParserContext {
3502
3067
 
3503
3068
  // src/core/tree/index.ts
3504
3069
  function serialize(source, options = {}) {
3070
+ const plugins = resolvePlugins(options.plugins);
3505
3071
  const ctx = new SyncParserContext({
3506
- plugins: options.plugins,
3072
+ plugins,
3507
3073
  disabledFeatures: options.disabledFeatures
3508
3074
  });
3509
3075
  const tree = ctx.parse(source);
3510
3076
  const serial = new VanillaSerializerContext({
3511
- plugins: options.plugins,
3077
+ plugins,
3512
3078
  features: ctx.features,
3513
3079
  markedRefs: ctx.marked
3514
3080
  });
3515
3081
  return serial.serializeTop(tree);
3516
3082
  }
3517
3083
  async function serializeAsync(source, options = {}) {
3084
+ const plugins = resolvePlugins(options.plugins);
3518
3085
  const ctx = new AsyncParserContext({
3519
- plugins: options.plugins,
3086
+ plugins,
3520
3087
  disabledFeatures: options.disabledFeatures
3521
3088
  });
3522
3089
  const tree = await ctx.parse(source);
3523
3090
  const serial = new VanillaSerializerContext({
3524
- plugins: options.plugins,
3091
+ plugins,
3525
3092
  features: ctx.features,
3526
3093
  markedRefs: ctx.marked
3527
3094
  });
@@ -3531,8 +3098,9 @@ function deserialize(source) {
3531
3098
  return (0, eval)(source);
3532
3099
  }
3533
3100
  function toJSON(source, options = {}) {
3101
+ const plugins = resolvePlugins(options.plugins);
3534
3102
  const ctx = new SyncParserContext({
3535
- plugins: options.plugins,
3103
+ plugins,
3536
3104
  disabledFeatures: options.disabledFeatures
3537
3105
  });
3538
3106
  return {
@@ -3542,8 +3110,9 @@ function toJSON(source, options = {}) {
3542
3110
  };
3543
3111
  }
3544
3112
  async function toJSONAsync(source, options = {}) {
3113
+ const plugins = resolvePlugins(options.plugins);
3545
3114
  const ctx = new AsyncParserContext({
3546
- plugins: options.plugins,
3115
+ plugins,
3547
3116
  disabledFeatures: options.disabledFeatures
3548
3117
  });
3549
3118
  return {
@@ -3553,16 +3122,18 @@ async function toJSONAsync(source, options = {}) {
3553
3122
  };
3554
3123
  }
3555
3124
  function compileJSON(source, options = {}) {
3125
+ const plugins = resolvePlugins(options.plugins);
3556
3126
  const ctx = new VanillaSerializerContext({
3557
- plugins: options.plugins,
3127
+ plugins,
3558
3128
  features: source.f,
3559
3129
  markedRefs: source.m
3560
3130
  });
3561
3131
  return ctx.serializeTop(source.t);
3562
3132
  }
3563
3133
  function fromJSON(source, options = {}) {
3134
+ const plugins = resolvePlugins(options.plugins);
3564
3135
  const ctx = new VanillaDeserializerContext({
3565
- plugins: options.plugins,
3136
+ plugins,
3566
3137
  markedRefs: source.m
3567
3138
  });
3568
3139
  return ctx.deserialize(source.t);
@@ -3598,9 +3169,6 @@ var CrossSerializerContext = class extends BaseSerializerContext {
3598
3169
  this.scopeId = options.scopeId;
3599
3170
  }
3600
3171
  getRefParam(id) {
3601
- if (typeof id === "string") {
3602
- return GLOBAL_CONTEXT_REFERENCES + "." + id;
3603
- }
3604
3172
  return GLOBAL_CONTEXT_REFERENCES + "[" + id + "]";
3605
3173
  }
3606
3174
  assignIndexedValue(index, value) {
@@ -3615,12 +3183,11 @@ var CrossSerializerContext = class extends BaseSerializerContext {
3615
3183
  const patches = this.resolvePatches();
3616
3184
  const ref = this.getRefParam(id);
3617
3185
  const params = this.scopeId == null ? "" : GLOBAL_CONTEXT_REFERENCES;
3618
- const mainBody = patches ? result + "," + patches : result;
3186
+ const body = patches ? result + "," + patches + ref : result;
3619
3187
  if (params === "") {
3620
- return patches ? "(" + mainBody + ref + ")" : mainBody;
3188
+ return patches ? "(" + body + ")" : body;
3621
3189
  }
3622
3190
  const args = this.scopeId == null ? "()" : "(" + GLOBAL_CONTEXT_REFERENCES + '["' + serializeString(this.scopeId) + '"])';
3623
- const body = mainBody + (patches ? ref : "");
3624
3191
  return "(" + this.createFunction([params], body) + ")" + args;
3625
3192
  }
3626
3193
  };
@@ -3633,17 +3200,31 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
3633
3200
  this.alive = true;
3634
3201
  // Amount of pending promises/streams
3635
3202
  this.pending = 0;
3203
+ this.initial = true;
3204
+ this.buffer = [];
3636
3205
  this.onParseCallback = options.onParse;
3637
3206
  this.onErrorCallback = options.onError;
3638
3207
  this.onDoneCallback = options.onDone;
3639
3208
  }
3640
- onParse(node, initial) {
3209
+ onParseInternal(node, initial) {
3641
3210
  try {
3642
3211
  this.onParseCallback(node, initial);
3643
3212
  } catch (error) {
3644
3213
  this.onError(error);
3645
3214
  }
3646
3215
  }
3216
+ flush() {
3217
+ for (let i = 0, len = this.buffer.length; i < len; i++) {
3218
+ this.onParseInternal(this.buffer[i], false);
3219
+ }
3220
+ }
3221
+ onParse(node) {
3222
+ if (this.initial) {
3223
+ this.buffer.push(node);
3224
+ } else {
3225
+ this.onParseInternal(node, false);
3226
+ }
3227
+ }
3647
3228
  onError(error) {
3648
3229
  if (this.onErrorCallback) {
3649
3230
  this.onErrorCallback(error);
@@ -3656,12 +3237,6 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
3656
3237
  this.onDoneCallback();
3657
3238
  }
3658
3239
  }
3659
- push(value) {
3660
- this.onParse(
3661
- this.parse(value),
3662
- false
3663
- );
3664
- }
3665
3240
  pushPendingState() {
3666
3241
  this.pending++;
3667
3242
  }
@@ -3678,48 +3253,41 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
3678
3253
  keyNodes.push(serializeString(entries[i][0]));
3679
3254
  valueNodes.push(this.parse(entries[i][1]));
3680
3255
  }
3681
- if (this.features & 1024 /* Symbol */) {
3682
- let symbol = Symbol.iterator;
3683
- if (symbol in properties) {
3684
- keyNodes.push(
3685
- this.parseWKSymbol(symbol)
3686
- );
3687
- valueNodes.push(
3688
- createIteratorFactoryInstanceNode(
3689
- this.parseIteratorFactory(),
3690
- this.parse(
3691
- iteratorToSequence(properties)
3692
- )
3256
+ let symbol = Symbol.iterator;
3257
+ if (symbol in properties) {
3258
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
3259
+ valueNodes.push(
3260
+ createIteratorFactoryInstanceNode(
3261
+ this.parseIteratorFactory(),
3262
+ this.parse(
3263
+ iteratorToSequence(properties)
3693
3264
  )
3694
- );
3695
- }
3696
- symbol = Symbol.asyncIterator;
3697
- if (symbol in properties) {
3698
- keyNodes.push(
3699
- this.parseWKSymbol(symbol)
3700
- );
3701
- valueNodes.push(
3702
- createAsyncIteratorFactoryInstanceNode(
3703
- this.parseAsyncIteratorFactory(1),
3704
- this.parse(
3705
- asyncIteratorToReadableStream(
3706
- properties,
3707
- this
3708
- )
3265
+ )
3266
+ );
3267
+ }
3268
+ symbol = Symbol.asyncIterator;
3269
+ if (symbol in properties) {
3270
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
3271
+ valueNodes.push(
3272
+ createAsyncIteratorFactoryInstanceNode(
3273
+ this.parseAsyncIteratorFactory(),
3274
+ this.parse(
3275
+ createStreamFromAsyncIterable(
3276
+ properties
3709
3277
  )
3710
3278
  )
3711
- );
3712
- }
3713
- symbol = Symbol.toStringTag;
3714
- if (symbol in properties) {
3715
- keyNodes.push(this.parseWKSymbol(symbol));
3716
- valueNodes.push(createStringNode(properties[symbol]));
3717
- }
3718
- symbol = Symbol.isConcatSpreadable;
3719
- if (symbol in properties) {
3720
- keyNodes.push(this.parseWKSymbol(symbol));
3721
- valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
3722
- }
3279
+ )
3280
+ );
3281
+ }
3282
+ symbol = Symbol.toStringTag;
3283
+ if (symbol in properties) {
3284
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
3285
+ valueNodes.push(createStringNode(properties[symbol]));
3286
+ }
3287
+ symbol = Symbol.isConcatSpreadable;
3288
+ if (symbol in properties) {
3289
+ keyNodes.push(this.parseWellKnownSymbol(symbol));
3290
+ valueNodes.push(properties[symbol] ? TRUE_NODE : FALSE_NODE);
3723
3291
  }
3724
3292
  return {
3725
3293
  k: keyNodes,
@@ -3727,141 +3295,13 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
3727
3295
  s: keyNodes.length
3728
3296
  };
3729
3297
  }
3730
- pushReadableStreamReader(id, reader) {
3731
- reader.read().then(
3732
- (data) => {
3733
- if (this.alive) {
3734
- if (data.done) {
3735
- this.onParse({
3736
- t: 33 /* ReadableStreamClose */,
3737
- i: id,
3738
- s: void 0,
3739
- l: void 0,
3740
- c: void 0,
3741
- m: void 0,
3742
- p: void 0,
3743
- e: void 0,
3744
- a: void 0,
3745
- f: this.parseSpecialReference(8 /* ReadableStreamClose */),
3746
- b: void 0,
3747
- o: void 0
3748
- }, false);
3749
- this.popPendingState();
3750
- } else {
3751
- const parsed = this.parseWithError(data.value);
3752
- if (parsed) {
3753
- this.onParse({
3754
- t: 32 /* ReadableStreamEnqueue */,
3755
- i: id,
3756
- s: void 0,
3757
- l: void 0,
3758
- c: void 0,
3759
- m: void 0,
3760
- p: void 0,
3761
- e: void 0,
3762
- a: [
3763
- this.parseSpecialReference(6 /* ReadableStreamEnqueue */),
3764
- parsed
3765
- ],
3766
- f: void 0,
3767
- b: void 0,
3768
- o: void 0
3769
- }, false);
3770
- this.pushReadableStreamReader(id, reader);
3771
- }
3772
- }
3773
- }
3774
- },
3775
- (value) => {
3776
- if (this.alive) {
3777
- const parsed = this.parseWithError(value);
3778
- if (parsed) {
3779
- this.onParse({
3780
- t: 34 /* ReadableStreamError */,
3781
- i: id,
3782
- s: void 0,
3783
- l: void 0,
3784
- c: void 0,
3785
- m: void 0,
3786
- p: void 0,
3787
- e: void 0,
3788
- a: [
3789
- this.parseSpecialReference(7 /* ReadableStreamError */),
3790
- parsed
3791
- ],
3792
- f: void 0,
3793
- b: void 0,
3794
- o: void 0
3795
- }, false);
3796
- }
3797
- this.popPendingState();
3798
- }
3799
- }
3800
- );
3801
- }
3802
- parseReadableStream(id, current) {
3803
- const reader = current.getReader();
3804
- this.pushPendingState();
3805
- this.pushReadableStreamReader(id, reader);
3806
- return {
3807
- t: 31 /* ReadableStreamConstructor */,
3808
- i: id,
3809
- s: void 0,
3810
- l: void 0,
3811
- c: void 0,
3812
- m: void 0,
3813
- p: void 0,
3814
- e: void 0,
3815
- a: void 0,
3816
- f: this.parseSpecialReference(5 /* ReadableStreamConstructor */),
3817
- b: void 0,
3818
- o: void 0
3819
- };
3820
- }
3821
- parseRequest(id, current) {
3822
- return {
3823
- t: 35 /* Request */,
3824
- i: id,
3825
- s: serializeString(current.url),
3826
- l: void 0,
3827
- c: void 0,
3828
- m: void 0,
3829
- p: void 0,
3830
- e: void 0,
3831
- f: this.parse(
3832
- createRequestOptions(current, current.clone().body)
3833
- ),
3834
- a: void 0,
3835
- b: void 0,
3836
- o: void 0
3837
- };
3838
- }
3839
- parseResponse(id, current) {
3840
- return {
3841
- t: 36 /* Response */,
3842
- i: id,
3843
- s: void 0,
3844
- l: void 0,
3845
- c: void 0,
3846
- m: void 0,
3847
- p: void 0,
3848
- e: void 0,
3849
- f: void 0,
3850
- a: [
3851
- current.body ? this.parse(current.clone().body) : NULL_NODE,
3852
- this.parse(createResponseOptions(current))
3853
- ],
3854
- b: void 0,
3855
- o: void 0
3856
- };
3857
- }
3858
3298
  parsePromise(id, current) {
3859
3299
  current.then(
3860
3300
  (data) => {
3861
3301
  const parsed = this.parseWithError(data);
3862
3302
  if (parsed) {
3863
3303
  this.onParse({
3864
- t: 29 /* PromiseResolve */,
3304
+ t: 23 /* PromiseResolve */,
3865
3305
  i: id,
3866
3306
  s: void 0,
3867
3307
  l: void 0,
@@ -3870,13 +3310,13 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
3870
3310
  p: void 0,
3871
3311
  e: void 0,
3872
3312
  a: [
3873
- this.parseSpecialReference(3 /* PromiseResolve */),
3313
+ this.parseSpecialReference(2 /* PromiseResolve */),
3874
3314
  parsed
3875
3315
  ],
3876
3316
  f: void 0,
3877
3317
  b: void 0,
3878
3318
  o: void 0
3879
- }, false);
3319
+ });
3880
3320
  }
3881
3321
  this.popPendingState();
3882
3322
  },
@@ -3885,7 +3325,7 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
3885
3325
  const parsed = this.parseWithError(data);
3886
3326
  if (parsed) {
3887
3327
  this.onParse({
3888
- t: 30 /* PromiseReject */,
3328
+ t: 24 /* PromiseReject */,
3889
3329
  i: id,
3890
3330
  s: void 0,
3891
3331
  l: void 0,
@@ -3894,33 +3334,20 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
3894
3334
  p: void 0,
3895
3335
  e: void 0,
3896
3336
  a: [
3897
- this.parseSpecialReference(4 /* PromiseReject */),
3337
+ this.parseSpecialReference(3 /* PromiseReject */),
3898
3338
  parsed
3899
3339
  ],
3900
3340
  f: void 0,
3901
3341
  b: void 0,
3902
3342
  o: void 0
3903
- }, false);
3343
+ });
3904
3344
  }
3905
3345
  }
3906
3346
  this.popPendingState();
3907
3347
  }
3908
3348
  );
3909
3349
  this.pushPendingState();
3910
- return {
3911
- t: 28 /* PromiseConstructor */,
3912
- i: id,
3913
- s: void 0,
3914
- l: void 0,
3915
- c: void 0,
3916
- m: void 0,
3917
- p: void 0,
3918
- e: void 0,
3919
- a: void 0,
3920
- f: this.parseSpecialReference(2 /* PromiseConstructor */),
3921
- b: void 0,
3922
- o: void 0
3923
- };
3350
+ return this.createPromiseConstructorNode(id);
3924
3351
  }
3925
3352
  parsePlugin(id, current) {
3926
3353
  const currentPlugins = this.plugins;
@@ -3940,129 +3367,42 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
3940
3367
  }
3941
3368
  return void 0;
3942
3369
  }
3943
- parseObject(id, current) {
3944
- if (Array.isArray(current)) {
3945
- return this.parseArray(id, current);
3946
- }
3947
- const currentClass = current.constructor;
3948
- switch (currentClass) {
3949
- case Object:
3950
- return this.parsePlainObject(
3951
- id,
3952
- current,
3953
- false
3954
- );
3955
- case void 0:
3956
- return this.parsePlainObject(
3957
- id,
3958
- current,
3959
- true
3960
- );
3961
- case Date:
3962
- return createDateNode(id, current);
3963
- case RegExp:
3964
- return createRegExpNode(id, current);
3965
- case Error:
3966
- case EvalError:
3967
- case RangeError:
3968
- case ReferenceError:
3969
- case SyntaxError:
3970
- case TypeError:
3971
- case URIError:
3972
- return this.parseError(id, current);
3973
- case Number:
3974
- case Boolean:
3975
- case String:
3976
- case BigInt:
3977
- return this.parseBoxed(id, current);
3978
- default:
3979
- break;
3980
- }
3981
- const currentFeatures = this.features;
3982
- if (currentFeatures & 256 /* Promise */ && (currentClass === Promise || current instanceof Promise)) {
3983
- return this.parsePromise(id, current);
3984
- }
3985
- if (currentFeatures & 2048 /* TypedArray */) {
3986
- switch (currentClass) {
3987
- case ArrayBuffer:
3988
- return createArrayBufferNode(id, current);
3989
- case Int8Array:
3990
- case Int16Array:
3991
- case Int32Array:
3992
- case Uint8Array:
3993
- case Uint16Array:
3994
- case Uint32Array:
3995
- case Uint8ClampedArray:
3996
- case Float32Array:
3997
- case Float64Array:
3998
- return this.parseTypedArray(id, current);
3999
- case DataView:
4000
- return this.parseDataView(id, current);
4001
- default:
4002
- break;
4003
- }
4004
- }
4005
- if ((currentFeatures & BIGINT_FLAG) === BIGINT_FLAG) {
4006
- switch (currentClass) {
4007
- case BigInt64Array:
4008
- case BigUint64Array:
4009
- return this.parseBigIntTypedArray(id, current);
4010
- default:
4011
- break;
4012
- }
4013
- }
4014
- if (currentFeatures & 32 /* Map */ && currentClass === Map) {
4015
- return this.parseMap(
4016
- id,
4017
- current
4018
- );
4019
- }
4020
- if (currentFeatures & 512 /* Set */ && currentClass === Set) {
4021
- return this.parseSet(
4022
- id,
4023
- current
4024
- );
4025
- }
4026
- if (currentFeatures & 8192 /* WebAPI */) {
4027
- switch (currentClass) {
4028
- case (typeof URL !== "undefined" ? URL : UNIVERSAL_SENTINEL):
4029
- return createURLNode(id, current);
4030
- case (typeof URLSearchParams !== "undefined" ? URLSearchParams : UNIVERSAL_SENTINEL):
4031
- return createURLSearchParamsNode(id, current);
4032
- case (typeof Headers !== "undefined" ? Headers : UNIVERSAL_SENTINEL):
4033
- return this.parseHeaders(id, current);
4034
- case (typeof FormData !== "undefined" ? FormData : UNIVERSAL_SENTINEL):
4035
- return this.parseFormData(id, current);
4036
- case (typeof ReadableStream !== "undefined" ? ReadableStream : UNIVERSAL_SENTINEL):
4037
- return this.parseReadableStream(id, current);
4038
- case (typeof Request !== "undefined" ? Request : UNIVERSAL_SENTINEL):
4039
- return this.parseRequest(id, current);
4040
- case (typeof Response !== "undefined" ? Response : UNIVERSAL_SENTINEL):
4041
- return this.parseResponse(id, current);
4042
- case (typeof Event !== "undefined" ? Event : UNIVERSAL_SENTINEL):
4043
- return this.parseEvent(id, current);
4044
- case (typeof CustomEvent !== "undefined" ? CustomEvent : UNIVERSAL_SENTINEL):
4045
- return this.parseCustomEvent(id, current);
4046
- case (typeof DOMException !== "undefined" ? DOMException : UNIVERSAL_SENTINEL):
4047
- return createDOMExceptionNode(id, current);
4048
- default:
4049
- break;
3370
+ parseStream(id, current) {
3371
+ const result = createStreamConstructorNode(
3372
+ id,
3373
+ this.parseSpecialReference(4 /* StreamConstructor */),
3374
+ []
3375
+ );
3376
+ this.pushPendingState();
3377
+ current.on({
3378
+ next: (value) => {
3379
+ if (this.alive) {
3380
+ const parsed = this.parseWithError(value);
3381
+ if (parsed) {
3382
+ this.onParse(createStreamNextNode(id, parsed));
3383
+ }
3384
+ }
3385
+ },
3386
+ throw: (value) => {
3387
+ if (this.alive) {
3388
+ const parsed = this.parseWithError(value);
3389
+ if (parsed) {
3390
+ this.onParse(createStreamThrowNode(id, parsed));
3391
+ }
3392
+ }
3393
+ this.popPendingState();
3394
+ },
3395
+ return: (value) => {
3396
+ if (this.alive) {
3397
+ const parsed = this.parseWithError(value);
3398
+ if (parsed) {
3399
+ this.onParse(createStreamReturnNode(id, parsed));
3400
+ }
3401
+ }
3402
+ this.popPendingState();
4050
3403
  }
4051
- }
4052
- const parsed = this.parsePlugin(id, current);
4053
- if (parsed) {
4054
- return parsed;
4055
- }
4056
- if (currentFeatures & 1 /* AggregateError */ && typeof AggregateError !== "undefined" && (currentClass === AggregateError || current instanceof AggregateError)) {
4057
- return this.parseAggregateError(id, current);
4058
- }
4059
- if (current instanceof Error) {
4060
- return this.parseError(id, current);
4061
- }
4062
- if (currentFeatures & 1024 /* Symbol */ && (Symbol.iterator in current || Symbol.asyncIterator in current)) {
4063
- return this.parsePlainObject(id, current, !!currentClass);
4064
- }
4065
- throw new UnsupportedTypeError(current);
3404
+ });
3405
+ return result;
4066
3406
  }
4067
3407
  parseWithError(current) {
4068
3408
  try {
@@ -4078,7 +3418,9 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
4078
3418
  start(current) {
4079
3419
  const parsed = this.parseWithError(current);
4080
3420
  if (parsed) {
4081
- this.onParse(parsed, true);
3421
+ this.onParseInternal(parsed, true);
3422
+ this.initial = false;
3423
+ this.flush();
4082
3424
  if (this.pending <= 0) {
4083
3425
  this.destroy();
4084
3426
  }
@@ -4116,14 +3458,15 @@ var CrossSyncParserContext = class extends BaseSyncParserContext {
4116
3458
 
4117
3459
  // src/core/cross/index.ts
4118
3460
  function crossSerialize(source, options = {}) {
3461
+ const plugins = resolvePlugins(options.plugins);
4119
3462
  const ctx = new CrossSyncParserContext({
4120
- plugins: options.plugins,
3463
+ plugins,
4121
3464
  disabledFeatures: options.disabledFeatures,
4122
3465
  refs: options.refs
4123
3466
  });
4124
3467
  const tree = ctx.parse(source);
4125
3468
  const serial = new CrossSerializerContext({
4126
- plugins: options.plugins,
3469
+ plugins,
4127
3470
  features: ctx.features,
4128
3471
  scopeId: options.scopeId,
4129
3472
  markedRefs: ctx.marked
@@ -4131,14 +3474,15 @@ function crossSerialize(source, options = {}) {
4131
3474
  return serial.serializeTop(tree);
4132
3475
  }
4133
3476
  async function crossSerializeAsync(source, options = {}) {
3477
+ const plugins = resolvePlugins(options.plugins);
4134
3478
  const ctx = new CrossAsyncParserContext({
4135
- plugins: options.plugins,
3479
+ plugins,
4136
3480
  disabledFeatures: options.disabledFeatures,
4137
3481
  refs: options.refs
4138
3482
  });
4139
3483
  const tree = await ctx.parse(source);
4140
3484
  const serial = new CrossSerializerContext({
4141
- plugins: options.plugins,
3485
+ plugins,
4142
3486
  features: ctx.features,
4143
3487
  scopeId: options.scopeId,
4144
3488
  markedRefs: ctx.marked
@@ -4146,29 +3490,32 @@ async function crossSerializeAsync(source, options = {}) {
4146
3490
  return serial.serializeTop(tree);
4147
3491
  }
4148
3492
  function toCrossJSON(source, options = {}) {
3493
+ const plugins = resolvePlugins(options.plugins);
4149
3494
  const ctx = new CrossSyncParserContext({
4150
- plugins: options.plugins,
3495
+ plugins,
4151
3496
  disabledFeatures: options.disabledFeatures,
4152
3497
  refs: options.refs
4153
3498
  });
4154
3499
  return ctx.parse(source);
4155
3500
  }
4156
3501
  async function toCrossJSONAsync(source, options = {}) {
3502
+ const plugins = resolvePlugins(options.plugins);
4157
3503
  const ctx = new CrossAsyncParserContext({
4158
- plugins: options.plugins,
3504
+ plugins,
4159
3505
  disabledFeatures: options.disabledFeatures,
4160
3506
  refs: options.refs
4161
3507
  });
4162
- return ctx.parse(source);
3508
+ return await ctx.parse(source);
4163
3509
  }
4164
3510
  function crossSerializeStream(source, options) {
3511
+ const plugins = resolvePlugins(options.plugins);
4165
3512
  const ctx = new CrossStreamParserContext({
4166
- plugins: options.plugins,
3513
+ plugins,
4167
3514
  refs: options.refs,
4168
3515
  disabledFeatures: options.disabledFeatures,
4169
3516
  onParse(node, initial) {
4170
3517
  const serial = new CrossSerializerContext({
4171
- plugins: options.plugins,
3518
+ plugins,
4172
3519
  features: ctx.features,
4173
3520
  scopeId: options.scopeId,
4174
3521
  markedRefs: ctx.marked
@@ -4182,10 +3529,7 @@ function crossSerializeStream(source, options) {
4182
3529
  }
4183
3530
  return;
4184
3531
  }
4185
- options.onSerialize(
4186
- serialized,
4187
- initial
4188
- );
3532
+ options.onSerialize(serialized, initial);
4189
3533
  },
4190
3534
  onError: options.onError,
4191
3535
  onDone: options.onDone
@@ -4196,8 +3540,9 @@ function crossSerializeStream(source, options) {
4196
3540
  };
4197
3541
  }
4198
3542
  function toCrossJSONStream(source, options) {
3543
+ const plugins = resolvePlugins(options.plugins);
4199
3544
  const ctx = new CrossStreamParserContext({
4200
- plugins: options.plugins,
3545
+ plugins,
4201
3546
  refs: options.refs,
4202
3547
  disabledFeatures: options.disabledFeatures,
4203
3548
  onParse: options.onParse,
@@ -4210,8 +3555,9 @@ function toCrossJSONStream(source, options) {
4210
3555
  };
4211
3556
  }
4212
3557
  function fromCrossJSON(source, options) {
3558
+ const plugins = resolvePlugins(options.plugins);
4213
3559
  const ctx = new CrossDeserializerContext({
4214
- plugins: options.plugins,
3560
+ plugins,
4215
3561
  refs: options.refs
4216
3562
  });
4217
3563
  return ctx.deserialize(source);
@@ -4229,34 +3575,37 @@ var Serializer = class {
4229
3575
  this.refs = /* @__PURE__ */ new Map();
4230
3576
  this.keys = /* @__PURE__ */ new Set();
4231
3577
  this.ids = 0;
3578
+ this.plugins = resolvePlugins(options.plugins);
4232
3579
  }
4233
3580
  write(key, value) {
4234
3581
  if (this.alive && !this.flushed) {
4235
3582
  this.pending++;
4236
3583
  this.keys.add(key);
4237
- this.cleanups.push(crossSerializeStream(value, {
4238
- plugins: this.options.plugins,
4239
- scopeId: this.options.scopeId,
4240
- refs: this.refs,
4241
- disabledFeatures: this.options.disabledFeatures,
4242
- onError: this.options.onError,
4243
- onSerialize: (data, initial) => {
4244
- if (this.alive) {
4245
- this.options.onData(
4246
- initial ? this.options.globalIdentifier + '["' + serializeString(key) + '"]=' + data : data
4247
- );
4248
- }
4249
- },
4250
- onDone: () => {
4251
- if (this.alive) {
4252
- this.pending--;
4253
- if (this.pending <= 0 && this.flushed && !this.done && this.options.onDone) {
4254
- this.options.onDone();
4255
- this.done = true;
3584
+ this.cleanups.push(
3585
+ crossSerializeStream(value, {
3586
+ plugins: this.plugins,
3587
+ scopeId: this.options.scopeId,
3588
+ refs: this.refs,
3589
+ disabledFeatures: this.options.disabledFeatures,
3590
+ onError: this.options.onError,
3591
+ onSerialize: (data, initial) => {
3592
+ if (this.alive) {
3593
+ this.options.onData(
3594
+ initial ? this.options.globalIdentifier + '["' + serializeString(key) + '"]=' + data : data
3595
+ );
3596
+ }
3597
+ },
3598
+ onDone: () => {
3599
+ if (this.alive) {
3600
+ this.pending--;
3601
+ if (this.pending <= 0 && this.flushed && !this.done && this.options.onDone) {
3602
+ this.options.onDone();
3603
+ this.done = true;
3604
+ }
4256
3605
  }
4257
3606
  }
4258
- }
4259
- }));
3607
+ })
3608
+ );
4260
3609
  }
4261
3610
  }
4262
3611
  getNextID() {
@@ -4292,28 +3641,21 @@ var Serializer = class {
4292
3641
  }
4293
3642
  }
4294
3643
  };
4295
-
4296
- // src/core/plugin.ts
4297
- function createPlugin(plugin) {
4298
- return plugin;
4299
- }
4300
-
4301
- // src/index.ts
4302
- var src_default = serialize;
4303
3644
  export {
4304
3645
  Feature,
4305
3646
  Serializer,
4306
3647
  compileJSON,
4307
3648
  createPlugin,
4308
3649
  createReference,
3650
+ createStream,
4309
3651
  crossSerialize,
4310
3652
  crossSerializeAsync,
4311
3653
  crossSerializeStream,
4312
- src_default as default,
4313
3654
  deserialize,
4314
3655
  fromCrossJSON,
4315
3656
  fromJSON,
4316
3657
  getCrossReferenceHeader,
3658
+ resolvePlugins,
4317
3659
  serialize,
4318
3660
  serializeAsync,
4319
3661
  toCrossJSON,