seroval 1.0.2 → 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.
- package/dist/cjs/development/index.cjs +11 -3
- package/dist/cjs/development/index.cjs.map +2 -2
- package/dist/cjs/production/index.cjs +1 -1
- package/dist/esm/development/index.mjs +11 -3
- package/dist/esm/development/index.mjs.map +2 -2
- package/dist/esm/production/index.mjs +1 -1
- package/dist/types/core/context/serializer.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/core/context/serializer.ts +31 -7
|
@@ -2210,7 +2210,11 @@ var BaseSerializerContext = class {
|
|
|
2210
2210
|
serializeProperty(source, key, val) {
|
|
2211
2211
|
if (typeof key === "string") {
|
|
2212
2212
|
const check = Number(key);
|
|
2213
|
-
const isIdentifier =
|
|
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
|
+
);
|
|
2214
2218
|
if (this.isIndexedValueInStack(val)) {
|
|
2215
2219
|
const refParam = this.getRefParam(val.i);
|
|
2216
2220
|
this.markRef(source.i);
|
|
@@ -2262,7 +2266,11 @@ var BaseSerializerContext = class {
|
|
|
2262
2266
|
serializeStringKeyAssignment(source, mainAssignments, key, value) {
|
|
2263
2267
|
const serialized = this.serialize(value);
|
|
2264
2268
|
const check = Number(key);
|
|
2265
|
-
const isIdentifier =
|
|
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
|
+
);
|
|
2266
2274
|
if (this.isIndexedValueInStack(value)) {
|
|
2267
2275
|
if (isIdentifier && check !== check) {
|
|
2268
2276
|
this.createObjectAssign(source.i, key, serialized);
|
|
@@ -2276,7 +2284,7 @@ var BaseSerializerContext = class {
|
|
|
2276
2284
|
} else {
|
|
2277
2285
|
const parentAssignment = this.assignments;
|
|
2278
2286
|
this.assignments = mainAssignments;
|
|
2279
|
-
if (isIdentifier) {
|
|
2287
|
+
if (isIdentifier && check !== check) {
|
|
2280
2288
|
this.createObjectAssign(source.i, key, serialized);
|
|
2281
2289
|
} else {
|
|
2282
2290
|
this.createArrayAssign(
|