seroval 1.0.0 → 1.0.3

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.
@@ -920,25 +920,25 @@ var BaseParserContext = class {
920
920
  if (registeredId != null) {
921
921
  this.markRef(registeredId);
922
922
  return {
923
- type: 1,
923
+ type: 1 /* Indexed */,
924
924
  value: createIndexedValueNode(registeredId)
925
925
  };
926
926
  }
927
927
  const id = this.refs.size;
928
928
  this.refs.set(current, id);
929
929
  return {
930
- type: 0,
930
+ type: 0 /* Fresh */,
931
931
  value: id
932
932
  };
933
933
  }
934
934
  getReference(current) {
935
935
  const indexed = this.getIndexedValue(current);
936
- if (indexed.type === 1) {
936
+ if (indexed.type === 1 /* Indexed */) {
937
937
  return indexed;
938
938
  }
939
939
  if (hasReferenceID(current)) {
940
940
  return {
941
- type: 2,
941
+ type: 2 /* Referenced */,
942
942
  value: createReferenceNode(indexed.value, current)
943
943
  };
944
944
  }
@@ -952,7 +952,7 @@ var BaseParserContext = class {
952
952
  )
953
953
  );
954
954
  const result = this.getIndexedValue(current);
955
- if (result.type === 1) {
955
+ if (result.type === 1 /* Indexed */) {
956
956
  return result.value;
957
957
  }
958
958
  return createReferenceNode(result.value, current);
@@ -962,7 +962,7 @@ var BaseParserContext = class {
962
962
  }
963
963
  parseWellKnownSymbol(current) {
964
964
  const ref = this.getReference(current);
965
- if (ref.type !== 0) {
965
+ if (ref.type !== 0 /* Fresh */) {
966
966
  return ref.value;
967
967
  }
968
968
  assert(
@@ -973,7 +973,7 @@ var BaseParserContext = class {
973
973
  }
974
974
  parseSpecialReference(ref) {
975
975
  const result = this.getIndexedValue(SPECIAL_REFS[ref]);
976
- if (result.type === 1) {
976
+ if (result.type === 1 /* Indexed */) {
977
977
  return result.value;
978
978
  }
979
979
  return {
@@ -993,7 +993,7 @@ var BaseParserContext = class {
993
993
  }
994
994
  parseIteratorFactory() {
995
995
  const result = this.getIndexedValue(ITERATOR);
996
- if (result.type === 1) {
996
+ if (result.type === 1 /* Indexed */) {
997
997
  return result.value;
998
998
  }
999
999
  return {
@@ -1013,7 +1013,7 @@ var BaseParserContext = class {
1013
1013
  }
1014
1014
  parseAsyncIteratorFactory() {
1015
1015
  const result = this.getIndexedValue(ASYNC_ITERATOR);
1016
- if (result.type === 1) {
1016
+ if (result.type === 1 /* Indexed */) {
1017
1017
  return result.value;
1018
1018
  }
1019
1019
  return {
@@ -1066,6 +1066,22 @@ var BaseParserContext = class {
1066
1066
  o: void 0
1067
1067
  };
1068
1068
  }
1069
+ createPromiseConstructorNode(id) {
1070
+ return {
1071
+ t: 22 /* PromiseConstructor */,
1072
+ i: id,
1073
+ s: void 0,
1074
+ l: void 0,
1075
+ c: void 0,
1076
+ m: void 0,
1077
+ p: void 0,
1078
+ e: void 0,
1079
+ a: void 0,
1080
+ f: this.parseSpecialReference(1 /* PromiseConstructor */),
1081
+ b: void 0,
1082
+ o: void 0
1083
+ };
1084
+ }
1069
1085
  };
1070
1086
 
1071
1087
  // src/core/utils/promise-to-result.ts
@@ -1953,16 +1969,14 @@ function isValidIdentifier(name) {
1953
1969
  // src/core/context/serializer.ts
1954
1970
  function getAssignmentExpression(assignment) {
1955
1971
  switch (assignment.t) {
1956
- case "index":
1972
+ case 0 /* Index */:
1957
1973
  return assignment.s + "=" + assignment.v;
1958
- case "set":
1974
+ case 2 /* Set */:
1959
1975
  return assignment.s + ".set(" + assignment.k + "," + assignment.v + ")";
1960
- case "add":
1976
+ case 1 /* Add */:
1961
1977
  return assignment.s + ".add(" + assignment.v + ")";
1962
- case "delete":
1978
+ case 3 /* Delete */:
1963
1979
  return assignment.s + ".delete(" + assignment.k + ")";
1964
- default:
1965
- return "";
1966
1980
  }
1967
1981
  }
1968
1982
  function mergeAssignments(assignments) {
@@ -1970,30 +1984,30 @@ function mergeAssignments(assignments) {
1970
1984
  let current = assignments[0];
1971
1985
  for (let i = 1, len = assignments.length, item, prev = current; i < len; i++) {
1972
1986
  item = assignments[i];
1973
- if (item.t === "index" && item.v === prev.v) {
1987
+ if (item.t === 0 /* Index */ && item.v === prev.v) {
1974
1988
  current = {
1975
- t: "index",
1989
+ t: 0 /* Index */,
1976
1990
  s: item.s,
1977
1991
  k: void 0,
1978
1992
  v: getAssignmentExpression(current)
1979
1993
  };
1980
- } else if (item.t === "set" && item.s === prev.s) {
1994
+ } else if (item.t === 2 /* Set */ && item.s === prev.s) {
1981
1995
  current = {
1982
- t: "set",
1996
+ t: 2 /* Set */,
1983
1997
  s: getAssignmentExpression(current),
1984
1998
  k: item.k,
1985
1999
  v: item.v
1986
2000
  };
1987
- } else if (item.t === "add" && item.s === prev.s) {
2001
+ } else if (item.t === 1 /* Add */ && item.s === prev.s) {
1988
2002
  current = {
1989
- t: "add",
2003
+ t: 1 /* Add */,
1990
2004
  s: getAssignmentExpression(current),
1991
2005
  k: void 0,
1992
2006
  v: item.v
1993
2007
  };
1994
- } else if (item.t === "delete" && item.s === prev.s) {
2008
+ } else if (item.t === 3 /* Delete */ && item.s === prev.s) {
1995
2009
  current = {
1996
- t: "delete",
2010
+ t: 3 /* Delete */,
1997
2011
  s: getAssignmentExpression(current),
1998
2012
  k: item.k,
1999
2013
  v: void 0
@@ -2111,7 +2125,7 @@ var BaseSerializerContext = class {
2111
2125
  */
2112
2126
  createAssignment(source, value) {
2113
2127
  this.assignments.push({
2114
- t: "index",
2128
+ t: 0 /* Index */,
2115
2129
  s: source,
2116
2130
  k: void 0,
2117
2131
  v: value
@@ -2119,7 +2133,7 @@ var BaseSerializerContext = class {
2119
2133
  }
2120
2134
  createAddAssignment(ref, value) {
2121
2135
  this.assignments.push({
2122
- t: "add",
2136
+ t: 1 /* Add */,
2123
2137
  s: this.getRefParam(ref),
2124
2138
  k: void 0,
2125
2139
  v: value
@@ -2127,7 +2141,7 @@ var BaseSerializerContext = class {
2127
2141
  }
2128
2142
  createSetAssignment(ref, key, value) {
2129
2143
  this.assignments.push({
2130
- t: "set",
2144
+ t: 2 /* Set */,
2131
2145
  s: this.getRefParam(ref),
2132
2146
  k: key,
2133
2147
  v: value
@@ -2135,7 +2149,7 @@ var BaseSerializerContext = class {
2135
2149
  }
2136
2150
  createDeleteAssignment(ref, key) {
2137
2151
  this.assignments.push({
2138
- t: "delete",
2152
+ t: 3 /* Delete */,
2139
2153
  s: this.getRefParam(ref),
2140
2154
  k: key,
2141
2155
  v: void 0
@@ -2196,7 +2210,11 @@ var BaseSerializerContext = class {
2196
2210
  serializeProperty(source, key, val) {
2197
2211
  if (typeof key === "string") {
2198
2212
  const check = Number(key);
2199
- const isIdentifier = check >= 0 || isValidIdentifier(key);
2213
+ const isIdentifier = (
2214
+ // Test if key is a valid positive number or JS identifier
2215
+ // so that we don't have to serialize the key and wrap with brackets
2216
+ check >= 0 && check.toString() === key || isValidIdentifier(key)
2217
+ );
2200
2218
  if (this.isIndexedValueInStack(val)) {
2201
2219
  const refParam = this.getRefParam(val.i);
2202
2220
  this.markRef(source.i);
@@ -2218,9 +2236,9 @@ var BaseSerializerContext = class {
2218
2236
  serializeProperties(source, record) {
2219
2237
  const len = record.s;
2220
2238
  if (len) {
2221
- this.stack.push(source.i);
2222
2239
  const keys = record.k;
2223
2240
  const values = record.v;
2241
+ this.stack.push(source.i);
2224
2242
  let result = this.serializeProperty(source, keys[0], values[0]);
2225
2243
  for (let i = 1, item = result; i < len; i++) {
2226
2244
  item = this.serializeProperty(source, keys[i], values[i]);
@@ -2248,7 +2266,11 @@ var BaseSerializerContext = class {
2248
2266
  serializeStringKeyAssignment(source, mainAssignments, key, value) {
2249
2267
  const serialized = this.serialize(value);
2250
2268
  const check = Number(key);
2251
- const isIdentifier = check >= 0 || isValidIdentifier(key);
2269
+ const isIdentifier = (
2270
+ // Test if key is a valid positive number or JS identifier
2271
+ // so that we don't have to serialize the key and wrap with brackets
2272
+ check >= 0 && check.toString() === key || isValidIdentifier(key)
2273
+ );
2252
2274
  if (this.isIndexedValueInStack(value)) {
2253
2275
  if (isIdentifier && check !== check) {
2254
2276
  this.createObjectAssign(source.i, key, serialized);
@@ -2262,7 +2284,7 @@ var BaseSerializerContext = class {
2262
2284
  } else {
2263
2285
  const parentAssignment = this.assignments;
2264
2286
  this.assignments = mainAssignments;
2265
- if (isIdentifier) {
2287
+ if (isIdentifier && check !== check) {
2266
2288
  this.createObjectAssign(source.i, key, serialized);
2267
2289
  } else {
2268
2290
  this.createArrayAssign(
@@ -2291,10 +2313,10 @@ var BaseSerializerContext = class {
2291
2313
  serializeAssignments(source, node) {
2292
2314
  const len = node.s;
2293
2315
  if (len) {
2294
- this.stack.push(source.i);
2295
2316
  const mainAssignments = [];
2296
2317
  const keys = node.k;
2297
2318
  const values = node.v;
2319
+ this.stack.push(source.i);
2298
2320
  for (let i = 0; i < len; i++) {
2299
2321
  this.serializeAssignment(source, mainAssignments, keys[i], values[i]);
2300
2322
  }
@@ -2449,9 +2471,12 @@ var BaseSerializerContext = class {
2449
2471
  serializeAggregateError(node) {
2450
2472
  const id = node.i;
2451
2473
  this.stack.push(id);
2452
- const serialized = 'new AggregateError([],"' + node.m + '")';
2474
+ const serialized = this.serializeDictionary(
2475
+ node,
2476
+ 'new AggregateError([],"' + node.m + '")'
2477
+ );
2453
2478
  this.stack.pop();
2454
- return this.serializeDictionary(node, serialized);
2479
+ return serialized;
2455
2480
  }
2456
2481
  serializeError(node) {
2457
2482
  return this.serializeDictionary(
@@ -2478,9 +2503,6 @@ var BaseSerializerContext = class {
2478
2503
  serializeWellKnownSymbol(node) {
2479
2504
  return this.assignIndexedValue(node.i, SYMBOL_STRING[node.s]);
2480
2505
  }
2481
- serializeFormDataEntry(id, key, value) {
2482
- return this.getRefParam(id) + '.append("' + key + '",' + this.serialize(value) + ")";
2483
- }
2484
2506
  serializeBoxed(node) {
2485
2507
  return this.assignIndexedValue(
2486
2508
  node.i,
@@ -2539,9 +2561,9 @@ var BaseSerializerContext = class {
2539
2561
  case 4 /* StreamConstructor */:
2540
2562
  return this.createFunction(
2541
2563
  ["b", "a", "s", "l", "p", "f", "e", "n"],
2542
- "(b=[],a=!0,s=!1,l=[],s=0,f=" + this.createEffectfulFunction(
2564
+ "(b=[],a=!0,s=!1,l=[],p=0,f=" + this.createEffectfulFunction(
2543
2565
  ["v", "m", "x"],
2544
- "for(x=0;x<s;x++)l[x]&&l[x][m](v)"
2566
+ "for(x=0;x<p;x++)l[x]&&l[x][m](v)"
2545
2567
  ) + ",n=" + this.createEffectfulFunction(
2546
2568
  ["o", "x", "z", "c"],
2547
2569
  'for(x=0,z=b.length;x<z;x++)(c=b[x],x===z-1?o[s?"return":"throw"](c):o.next(c))'
@@ -2968,20 +2990,7 @@ var BaseSyncParserContext = class extends BaseParserContext {
2968
2990
  );
2969
2991
  }
2970
2992
  parsePromise(id, _current) {
2971
- return {
2972
- t: 22 /* PromiseConstructor */,
2973
- i: id,
2974
- s: void 0,
2975
- l: void 0,
2976
- c: void 0,
2977
- m: void 0,
2978
- p: void 0,
2979
- e: void 0,
2980
- a: void 0,
2981
- f: this.parseSpecialReference(1 /* PromiseConstructor */),
2982
- b: void 0,
2983
- o: void 0
2984
- };
2993
+ return this.createPromiseConstructorNode(id);
2985
2994
  }
2986
2995
  parseObject(id, current) {
2987
2996
  if (Array.isArray(current)) {
@@ -3392,20 +3401,7 @@ var BaseStreamParserContext = class extends BaseSyncParserContext {
3392
3401
  }
3393
3402
  );
3394
3403
  this.pushPendingState();
3395
- return {
3396
- t: 22 /* PromiseConstructor */,
3397
- i: id,
3398
- s: void 0,
3399
- l: void 0,
3400
- c: void 0,
3401
- m: void 0,
3402
- p: void 0,
3403
- e: void 0,
3404
- a: void 0,
3405
- f: this.parseSpecialReference(1 /* PromiseConstructor */),
3406
- b: void 0,
3407
- o: void 0
3408
- };
3404
+ return this.createPromiseConstructorNode(id);
3409
3405
  }
3410
3406
  parsePlugin(id, current) {
3411
3407
  const currentPlugins = this.plugins;