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