seroval 0.4.0-alpha.0 → 0.4.0-alpha.1

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.
@@ -48,65 +48,6 @@ function isIterable(obj) {
48
48
  return !!obj && typeof obj === "object" && !isIterableBuiltin(obj) && Symbol.iterator in obj && typeof obj[Symbol.iterator] === "function";
49
49
  }
50
50
 
51
- // src/quote.ts
52
- function quote(str) {
53
- let result = "";
54
- let lastPos = 0;
55
- for (let i = 0, len = str.length; i < len; i++) {
56
- let replacement;
57
- switch (str[i]) {
58
- case '"':
59
- replacement = '\\"';
60
- break;
61
- case "\\":
62
- replacement = "\\\\";
63
- break;
64
- case "<":
65
- replacement = "\\x3C";
66
- break;
67
- case "\n":
68
- replacement = "\\n";
69
- break;
70
- case "\r":
71
- replacement = "\\r";
72
- break;
73
- case "\u2028":
74
- replacement = "\\u2028";
75
- break;
76
- case "\u2029":
77
- replacement = "\\u2029";
78
- break;
79
- default:
80
- continue;
81
- }
82
- result += str.slice(lastPos, i) + replacement;
83
- lastPos = i + 1;
84
- }
85
- if (lastPos === 0) {
86
- result = str;
87
- } else {
88
- result += str.slice(lastPos);
89
- }
90
- return `"${result}"`;
91
- }
92
-
93
- // src/get-identifier.ts
94
- var REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_";
95
- var REF_START_CHARS_LEN = REF_START_CHARS.length;
96
- var REF_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_";
97
- var REF_CHARS_LEN = REF_CHARS.length;
98
- function getIdentifier(index) {
99
- let mod = index % REF_START_CHARS_LEN;
100
- let ref = REF_START_CHARS[mod];
101
- index = (index - mod) / REF_START_CHARS_LEN;
102
- while (index > 0) {
103
- mod = index % REF_CHARS_LEN;
104
- ref += REF_CHARS[mod];
105
- index = (index - mod) / REF_CHARS_LEN;
106
- }
107
- return ref;
108
- }
109
-
110
51
  // src/assert.ts
111
52
  function assert(cond, error) {
112
53
  if (!cond) {
@@ -127,7 +68,7 @@ function compareVersion(left, right) {
127
68
  }
128
69
  var VERSION_TABLE = {
129
70
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError#browser_compatibility
130
- "aggregate-error": {
71
+ [0 /* AggregateError */]: {
131
72
  es: [2021, 0, 0],
132
73
  chrome: [85, 0, 0],
133
74
  edge: [85, 0, 0],
@@ -140,7 +81,7 @@ var VERSION_TABLE = {
140
81
  node: [15, 0, 0]
141
82
  },
142
83
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values#browser_compatibility
143
- "array-values": {
84
+ [1 /* ArrayPrototypeValues */]: {
144
85
  es: [6, 0, 0],
145
86
  chrome: [66, 0, 0],
146
87
  edge: [14, 0, 0],
@@ -153,7 +94,7 @@ var VERSION_TABLE = {
153
94
  node: [10, 9, 0]
154
95
  },
155
96
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#browser_compatibility
156
- "arrow-function": {
97
+ [2 /* ArrowFunction */]: {
157
98
  es: [6, 0, 0],
158
99
  chrome: [45, 0, 0],
159
100
  edge: [12, 0, 0],
@@ -166,7 +107,7 @@ var VERSION_TABLE = {
166
107
  node: [4, 0, 0]
167
108
  },
168
109
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#browser_compatibility
169
- bigint: {
110
+ [3 /* BigInt */]: {
170
111
  es: [2020, 0, 0],
171
112
  chrome: [67, 0, 0],
172
113
  edge: [79, 0, 0],
@@ -179,7 +120,7 @@ var VERSION_TABLE = {
179
120
  node: [10, 4, 0]
180
121
  },
181
122
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#browser_compatibility
182
- map: {
123
+ [4 /* Map */]: {
183
124
  es: [6, 0, 0],
184
125
  chrome: [38, 0, 0],
185
126
  edge: [12, 0, 0],
@@ -192,7 +133,7 @@ var VERSION_TABLE = {
192
133
  node: [0, 12, 0]
193
134
  },
194
135
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions#browser_compatibility
195
- "method-shorthand": {
136
+ [5 /* MethodShorthand */]: {
196
137
  es: [6, 0, 0],
197
138
  chrome: [39, 0, 0],
198
139
  edge: [12, 0, 0],
@@ -205,7 +146,7 @@ var VERSION_TABLE = {
205
146
  node: [4, 0, 0]
206
147
  },
207
148
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#browser_compatibility
208
- "object-assign": {
149
+ [6 /* ObjectAssign */]: {
209
150
  es: [6, 0, 0],
210
151
  chrome: [45, 0, 0],
211
152
  edge: [12, 0, 0],
@@ -218,7 +159,7 @@ var VERSION_TABLE = {
218
159
  node: [4, 0, 0]
219
160
  },
220
161
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#browser_compatibility
221
- promise: {
162
+ [7 /* Promise */]: {
222
163
  es: [6, 0, 0],
223
164
  chrome: [32, 0, 0],
224
165
  edge: [12, 0, 0],
@@ -231,7 +172,7 @@ var VERSION_TABLE = {
231
172
  node: [0, 12, 0]
232
173
  },
233
174
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#browser_compatibility
234
- set: {
175
+ [8 /* Set */]: {
235
176
  es: [6, 0, 0],
236
177
  chrome: [38, 0, 0],
237
178
  edge: [12, 0, 0],
@@ -244,7 +185,7 @@ var VERSION_TABLE = {
244
185
  node: [0, 12, 0]
245
186
  },
246
187
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator#browser_compatibility
247
- "symbol-iterator": {
188
+ [9 /* SymbolIterator */]: {
248
189
  es: [6, 0, 0],
249
190
  chrome: [43, 0, 0],
250
191
  edge: [12, 0, 0],
@@ -257,7 +198,7 @@ var VERSION_TABLE = {
257
198
  node: [0, 12, 0]
258
199
  },
259
200
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#browser_compatibility
260
- "typed-arrays": {
201
+ [10 /* TypedArray */]: {
261
202
  es: [6, 0, 0],
262
203
  chrome: [7, 0, 0],
263
204
  edge: [12, 0, 0],
@@ -288,26 +229,82 @@ function getTargetVersions(targets) {
288
229
  }
289
230
  return [parseTarget(targets)];
290
231
  }
291
- function isFeatureSupported(key, targets) {
292
- const base = VERSION_TABLE[key];
293
- let flag = true;
294
- for (const [platform, version] of targets) {
295
- const baseVersion = base[platform];
296
- flag = flag && !!baseVersion && compareVersion(baseVersion, version) <= 0;
297
- }
298
- return flag;
299
- }
300
232
  function parseTargets(targets) {
301
233
  const parsed = getTargetVersions(targets);
302
234
  const flags = /* @__PURE__ */ new Set();
303
235
  for (const key in VERSION_TABLE) {
304
- if (isFeatureSupported(key, parsed)) {
305
- flags.add(key);
236
+ const base = VERSION_TABLE[key];
237
+ let flag = true;
238
+ for (const [platform, version] of parsed) {
239
+ const baseVersion = base[platform];
240
+ flag = flag && !!baseVersion && compareVersion(baseVersion, version) <= 0;
241
+ }
242
+ if (flag) {
243
+ flags.add(Number(key));
306
244
  }
307
245
  }
308
246
  return flags;
309
247
  }
310
248
 
249
+ // src/quote.ts
250
+ function quote(str) {
251
+ let result = "";
252
+ let lastPos = 0;
253
+ for (let i = 0, len = str.length; i < len; i++) {
254
+ let replacement;
255
+ switch (str[i]) {
256
+ case '"':
257
+ replacement = '\\"';
258
+ break;
259
+ case "\\":
260
+ replacement = "\\\\";
261
+ break;
262
+ case "<":
263
+ replacement = "\\x3C";
264
+ break;
265
+ case "\n":
266
+ replacement = "\\n";
267
+ break;
268
+ case "\r":
269
+ replacement = "\\r";
270
+ break;
271
+ case "\u2028":
272
+ replacement = "\\u2028";
273
+ break;
274
+ case "\u2029":
275
+ replacement = "\\u2029";
276
+ break;
277
+ default:
278
+ continue;
279
+ }
280
+ result += str.slice(lastPos, i) + replacement;
281
+ lastPos = i + 1;
282
+ }
283
+ if (lastPos === 0) {
284
+ result = str;
285
+ } else {
286
+ result += str.slice(lastPos);
287
+ }
288
+ return `"${result}"`;
289
+ }
290
+
291
+ // src/get-identifier.ts
292
+ var REF_START_CHARS = "hjkmoquxzABCDEFGHIJKLNPQRTUVWXYZ$_";
293
+ var REF_START_CHARS_LEN = REF_START_CHARS.length;
294
+ var REF_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$_";
295
+ var REF_CHARS_LEN = REF_CHARS.length;
296
+ function getIdentifier(index) {
297
+ let mod = index % REF_START_CHARS_LEN;
298
+ let ref = REF_START_CHARS[mod];
299
+ index = (index - mod) / REF_START_CHARS_LEN;
300
+ while (index > 0) {
301
+ mod = index % REF_CHARS_LEN;
302
+ ref += REF_CHARS[mod];
303
+ index = (index - mod) / REF_CHARS_LEN;
304
+ }
305
+ return ref;
306
+ }
307
+
311
308
  // src/tree.ts
312
309
  var DEFAULT_OPTIONS = {
313
310
  target: "es2023"
@@ -532,51 +529,51 @@ function generateSemiPrimitiveValue(ctx, current, id) {
532
529
  return [3 /* RegExp */, current, id];
533
530
  }
534
531
  if (constructorCheck(current, Int8Array)) {
535
- assert(ctx.features.has("typed-arrays"), 'Unsupported value type "Int8Array"');
532
+ assert(ctx.features.has(10 /* TypedArray */), 'Unsupported value type "Int8Array"');
536
533
  return [13 /* TypedArray */, ["Int8Array", current], id];
537
534
  }
538
535
  if (constructorCheck(current, Int16Array)) {
539
- assert(ctx.features.has("typed-arrays"), 'Unsupported value type "Int16Array"');
536
+ assert(ctx.features.has(10 /* TypedArray */), 'Unsupported value type "Int16Array"');
540
537
  return [13 /* TypedArray */, ["Int16Array", current], id];
541
538
  }
542
539
  if (constructorCheck(current, Int32Array)) {
543
- assert(ctx.features.has("typed-arrays"), 'Unsupported value type "Int32Array"');
540
+ assert(ctx.features.has(10 /* TypedArray */), 'Unsupported value type "Int32Array"');
544
541
  return [13 /* TypedArray */, ["Int32Array", current], id];
545
542
  }
546
543
  if (constructorCheck(current, Uint8Array)) {
547
- assert(ctx.features.has("typed-arrays"), 'Unsupported value type "Uint8Array"');
544
+ assert(ctx.features.has(10 /* TypedArray */), 'Unsupported value type "Uint8Array"');
548
545
  return [13 /* TypedArray */, ["Uint8Array", current], id];
549
546
  }
550
547
  if (constructorCheck(current, Uint16Array)) {
551
- assert(ctx.features.has("typed-arrays"), 'Unsupported value type "Uint16Array"');
548
+ assert(ctx.features.has(10 /* TypedArray */), 'Unsupported value type "Uint16Array"');
552
549
  return [13 /* TypedArray */, ["Uint16Array", current], id];
553
550
  }
554
551
  if (constructorCheck(current, Uint32Array)) {
555
- assert(ctx.features.has("typed-arrays"), 'Unsupported value type "Uint32Array"');
552
+ assert(ctx.features.has(10 /* TypedArray */), 'Unsupported value type "Uint32Array"');
556
553
  return [13 /* TypedArray */, ["Uint32Array", current], id];
557
554
  }
558
555
  if (constructorCheck(current, Uint8ClampedArray)) {
559
- assert(ctx.features.has("typed-arrays"), 'Unsupported value type "Uint8ClampedArray"');
556
+ assert(ctx.features.has(10 /* TypedArray */), 'Unsupported value type "Uint8ClampedArray"');
560
557
  return [13 /* TypedArray */, ["Uint8ClampedArray", current], id];
561
558
  }
562
559
  if (constructorCheck(current, Float32Array)) {
563
- assert(ctx.features.has("typed-arrays"), 'Unsupported value type "Float32Array"');
560
+ assert(ctx.features.has(10 /* TypedArray */), 'Unsupported value type "Float32Array"');
564
561
  return [13 /* TypedArray */, ["Float32Array", current], id];
565
562
  }
566
563
  if (constructorCheck(current, Float64Array)) {
567
- assert(ctx.features.has("typed-arrays"), 'Unsupported value type "Float64Array"');
564
+ assert(ctx.features.has(10 /* TypedArray */), 'Unsupported value type "Float64Array"');
568
565
  return [13 /* TypedArray */, ["Float64Array", current], id];
569
566
  }
570
567
  if (constructorCheck(current, BigInt64Array)) {
571
568
  assert(
572
- ctx.features.has("typed-arrays") && ctx.features.has("bigint"),
569
+ ctx.features.has(10 /* TypedArray */) && ctx.features.has(3 /* BigInt */),
573
570
  'Unsupported value type "BigInt64Array"'
574
571
  );
575
572
  return [13 /* TypedArray */, ["BigInt64Array", current], id];
576
573
  }
577
574
  if (constructorCheck(current, BigUint64Array)) {
578
575
  assert(
579
- ctx.features.has("typed-arrays") && ctx.features.has("bigint"),
576
+ ctx.features.has(10 /* TypedArray */) && ctx.features.has(3 /* BigInt */),
580
577
  'Unsupported value type "BigUint64Array"'
581
578
  );
582
579
  return [13 /* TypedArray */, ["BigUint64Array", current], id];
@@ -619,7 +616,7 @@ function generateTreeSync(ctx, current) {
619
616
  return semiPrimitive;
620
617
  }
621
618
  if (constructorCheck(current, Set)) {
622
- assert(ctx.features.has("set"), 'Unsupported type "Set"');
619
+ assert(ctx.features.has(8 /* Set */), 'Unsupported type "Set"');
623
620
  const nodes = [];
624
621
  const deferred = [];
625
622
  for (const item of current.keys()) {
@@ -635,7 +632,7 @@ function generateTreeSync(ctx, current) {
635
632
  return [4 /* Set */, nodes, id];
636
633
  }
637
634
  if (constructorCheck(current, Map)) {
638
- assert(ctx.features.has("map"), 'Unsupported type "Map"');
635
+ assert(ctx.features.has(4 /* Map */), 'Unsupported type "Map"');
639
636
  const keyNodes = [];
640
637
  const valueNodes = [];
641
638
  const deferredKey = [];
@@ -677,7 +674,7 @@ function generateTreeSync(ctx, current) {
677
674
  }
678
675
  return [6 /* Array */, nodes, id];
679
676
  }
680
- if (current instanceof AggregateError && ctx.features.has("aggregate-error")) {
677
+ if (current instanceof AggregateError && ctx.features.has(0 /* AggregateError */)) {
681
678
  const options = getErrorOptions(current);
682
679
  const optionsNode = options ? serializeProperties(options) : void 0;
683
680
  const errorsNode = generateTreeSync(ctx, current.errors);
@@ -693,7 +690,7 @@ function generateTreeSync(ctx, current) {
693
690
  ];
694
691
  }
695
692
  if (isIterable(current)) {
696
- assert(ctx.features.has("symbol-iterator"), 'Unsupported type "Iterable"');
693
+ assert(ctx.features.has(9 /* SymbolIterator */), 'Unsupported type "Iterable"');
697
694
  const options = getIterableOptions(current);
698
695
  return [12 /* Iterable */, [
699
696
  // Parse options first before the items
@@ -747,7 +744,7 @@ async function generateTreeAsync(ctx, current) {
747
744
  return semiPrimitive;
748
745
  }
749
746
  if (isPromise(current)) {
750
- assert(ctx.features.has("promise"), 'Unsupported type "Promise"');
747
+ assert(ctx.features.has(7 /* Promise */), 'Unsupported type "Promise"');
751
748
  return current.then(async (value) => [
752
749
  9 /* Promise */,
753
750
  await generateTreeAsync(ctx, value),
@@ -755,7 +752,7 @@ async function generateTreeAsync(ctx, current) {
755
752
  ]);
756
753
  }
757
754
  if (constructorCheck(current, Set)) {
758
- assert(ctx.features.has("set"), 'Unsupported type "Set"');
755
+ assert(ctx.features.has(8 /* Set */), 'Unsupported type "Set"');
759
756
  const nodes = [];
760
757
  const deferred = [];
761
758
  for (const item of current.keys()) {
@@ -771,7 +768,7 @@ async function generateTreeAsync(ctx, current) {
771
768
  return [4 /* Set */, nodes, id];
772
769
  }
773
770
  if (constructorCheck(current, Map)) {
774
- assert(ctx.features.has("map"), 'Unsupported type "Map"');
771
+ assert(ctx.features.has(4 /* Map */), 'Unsupported type "Map"');
775
772
  const keyNodes = [];
776
773
  const valueNodes = [];
777
774
  const deferredKey = [];
@@ -830,7 +827,7 @@ async function generateTreeAsync(ctx, current) {
830
827
  ];
831
828
  }
832
829
  if (isIterable(current)) {
833
- assert(ctx.features.has("symbol-iterator"), 'Unsupported type "Iterable"');
830
+ assert(ctx.features.has(9 /* SymbolIterator */), 'Unsupported type "Iterable"');
834
831
  const options = getIterableOptions(current);
835
832
  return [12 /* Iterable */, [
836
833
  options ? await serializeProperties(options) : void 0,
@@ -861,7 +858,7 @@ function serializePrimitive(ctx, value) {
861
858
  return "null";
862
859
  }
863
860
  if (typeof value === "bigint") {
864
- assert(ctx.features.has("bigint"), 'Unsupported type "BigInt"');
861
+ assert(ctx.features.has(3 /* BigInt */), 'Unsupported type "BigInt"');
865
862
  return `${value}n`;
866
863
  }
867
864
  if (typeof value === "string") {
@@ -1051,7 +1048,7 @@ function serializeTree(ctx, [type, value, id]) {
1051
1048
  let serialized = `new AggregateError(${serializeTree(ctx, value[2])},${quote(value[0])})`;
1052
1049
  ctx.stack.pop();
1053
1050
  if (value[1]) {
1054
- if (ctx.features.has("object-assign")) {
1051
+ if (ctx.features.has(6 /* ObjectAssign */)) {
1055
1052
  const options = serializeObject(id, value[1]);
1056
1053
  serialized = `Object.assign(${serialized},${options})`;
1057
1054
  } else {
@@ -1068,7 +1065,7 @@ function serializeTree(ctx, [type, value, id]) {
1068
1065
  case 10 /* Error */: {
1069
1066
  let serialized = `new ${value[0]}(${quote(value[1])})`;
1070
1067
  if (value[2]) {
1071
- if (ctx.features.has("object-assign")) {
1068
+ if (ctx.features.has(6 /* ObjectAssign */)) {
1072
1069
  const options = serializeObject(id, value[2]);
1073
1070
  serialized = `Object.assign(${serialized},${options})`;
1074
1071
  } else {
@@ -1088,20 +1085,20 @@ function serializeTree(ctx, [type, value, id]) {
1088
1085
  const values = serializeTree(ctx, value[1]);
1089
1086
  ctx.stack = parent;
1090
1087
  let serialized;
1091
- if (ctx.features.has("array-values")) {
1088
+ if (ctx.features.has(1 /* ArrayPrototypeValues */)) {
1092
1089
  serialized = `${values}.values()`;
1093
1090
  } else {
1094
1091
  serialized = `${values}[Symbol.iterator]()`;
1095
1092
  }
1096
- if (ctx.features.has("arrow-function")) {
1093
+ if (ctx.features.has(2 /* ArrowFunction */)) {
1097
1094
  serialized = `{[Symbol.iterator]:()=>${serialized}}`;
1098
- } else if (ctx.features.has("method-shorthand")) {
1095
+ } else if (ctx.features.has(5 /* MethodShorthand */)) {
1099
1096
  serialized = `{[Symbol.iterator](){return ${serialized}}}`;
1100
1097
  } else {
1101
1098
  serialized = `{[Symbol.iterator]:function(){return ${serialized}}}`;
1102
1099
  }
1103
1100
  if (value[0]) {
1104
- if (ctx.features.has("object-assign")) {
1101
+ if (ctx.features.has(6 /* ObjectAssign */)) {
1105
1102
  const options = serializeObject(id, value[0]);
1106
1103
  serialized = `Object.assign(${serialized},${options})`;
1107
1104
  } else {
@@ -1117,7 +1114,7 @@ function serializeTree(ctx, [type, value, id]) {
1117
1114
  }
1118
1115
  case 8 /* NullConstructor */: {
1119
1116
  let serialized = "Object.create(null)";
1120
- if (ctx.features.has("object-assign")) {
1117
+ if (ctx.features.has(6 /* ObjectAssign */)) {
1121
1118
  const fields = serializeObject(id, value);
1122
1119
  if (fields !== "{}") {
1123
1120
  serialized = `Object.assign(${serialized},${fields})`;
@@ -1153,7 +1150,7 @@ function finalize(ctx, source, result) {
1153
1150
  }
1154
1151
  }
1155
1152
  let params = ctx.vars.length > 1 ? ctx.vars.join(",") : ctx.vars[0];
1156
- if (ctx.features.has("arrow-function")) {
1153
+ if (ctx.features.has(2 /* ArrowFunction */)) {
1157
1154
  params = ctx.vars.length > 1 || ctx.vars.length === 0 ? `(${params})` : params;
1158
1155
  return `(${params}=>(${body}))()`;
1159
1156
  }