seroval 0.15.1 → 1.0.0

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