seroval 1.5.4 → 1.5.5
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 +52 -29
- package/dist/cjs/development/index.cjs.map +3 -3
- package/dist/cjs/production/index.cjs +3 -3
- package/dist/esm/development/index.mjs +52 -29
- package/dist/esm/development/index.mjs.map +3 -3
- package/dist/esm/production/index.mjs +3 -3
- package/dist/types/core/context/deserializer.d.ts.map +1 -1
- package/dist/types/core/context/serializer.d.ts +9 -2
- package/dist/types/core/context/serializer.d.ts.map +1 -1
- package/dist/types/core/context/sync-parser.d.ts +2 -0
- package/dist/types/core/context/sync-parser.d.ts.map +1 -1
- package/dist/types/core/utils/valid-properties.d.ts +3 -0
- package/dist/types/core/utils/valid-properties.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/core/base-primitives.ts +1 -1
- package/src/core/context/deserializer.ts +1 -34
- package/src/core/context/serializer.ts +44 -4
- package/src/core/context/sync-parser.ts +11 -0
- package/src/core/utils/valid-properties.ts +34 -0
|
@@ -663,7 +663,7 @@ function createBigIntTypedArrayNode(id, current, buffer) {
|
|
|
663
663
|
buffer,
|
|
664
664
|
current.byteOffset,
|
|
665
665
|
NIL,
|
|
666
|
-
current.
|
|
666
|
+
current.length
|
|
667
667
|
);
|
|
668
668
|
}
|
|
669
669
|
function createDataViewNode(id, current, buffer) {
|
|
@@ -1949,6 +1949,33 @@ function getTypedArrayConstructor(name) {
|
|
|
1949
1949
|
}
|
|
1950
1950
|
}
|
|
1951
1951
|
|
|
1952
|
+
// src/core/utils/valid-properties.ts
|
|
1953
|
+
function isValidKey(key) {
|
|
1954
|
+
switch (key) {
|
|
1955
|
+
case "constructor":
|
|
1956
|
+
case "__proto__":
|
|
1957
|
+
case "prototype":
|
|
1958
|
+
case "__defineGetter__":
|
|
1959
|
+
case "__defineSetter__":
|
|
1960
|
+
case "__lookupGetter__":
|
|
1961
|
+
case "__lookupSetter__":
|
|
1962
|
+
return false;
|
|
1963
|
+
default:
|
|
1964
|
+
return true;
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
function isValidSymbol(symbol) {
|
|
1968
|
+
switch (symbol) {
|
|
1969
|
+
case SYM_ASYNC_ITERATOR:
|
|
1970
|
+
case SYM_IS_CONCAT_SPREADABLE:
|
|
1971
|
+
case SYM_TO_STRING_TAG:
|
|
1972
|
+
case SYM_ITERATOR:
|
|
1973
|
+
return true;
|
|
1974
|
+
default:
|
|
1975
|
+
return false;
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1952
1979
|
// src/core/context/deserializer.ts
|
|
1953
1980
|
var MAX_BASE64_LENGTH = 1e6;
|
|
1954
1981
|
var MAX_BIGINT_LENGTH = 1e4;
|
|
@@ -2064,31 +2091,6 @@ function deserializeArray(ctx, depth, node) {
|
|
|
2064
2091
|
applyObjectFlag(result, node.o);
|
|
2065
2092
|
return result;
|
|
2066
2093
|
}
|
|
2067
|
-
function isValidKey(key) {
|
|
2068
|
-
switch (key) {
|
|
2069
|
-
case "constructor":
|
|
2070
|
-
case "__proto__":
|
|
2071
|
-
case "prototype":
|
|
2072
|
-
case "__defineGetter__":
|
|
2073
|
-
case "__defineSetter__":
|
|
2074
|
-
case "__lookupGetter__":
|
|
2075
|
-
case "__lookupSetter__":
|
|
2076
|
-
return false;
|
|
2077
|
-
default:
|
|
2078
|
-
return true;
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
function isValidSymbol(symbol) {
|
|
2082
|
-
switch (symbol) {
|
|
2083
|
-
case SYM_ASYNC_ITERATOR:
|
|
2084
|
-
case SYM_IS_CONCAT_SPREADABLE:
|
|
2085
|
-
case SYM_TO_STRING_TAG:
|
|
2086
|
-
case SYM_ITERATOR:
|
|
2087
|
-
return true;
|
|
2088
|
-
default:
|
|
2089
|
-
return false;
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
2094
|
function assignStringProperty(object, key, value) {
|
|
2093
2095
|
if (isValidKey(key)) {
|
|
2094
2096
|
object[key] = value;
|
|
@@ -2523,6 +2525,8 @@ function getAssignmentExpression(assignment) {
|
|
|
2523
2525
|
return assignment.s + ".add(" + assignment.v + ")";
|
|
2524
2526
|
case 3 /* Delete */:
|
|
2525
2527
|
return assignment.s + ".delete(" + assignment.k + ")";
|
|
2528
|
+
case 4 /* Define */:
|
|
2529
|
+
return "Object.defineProperty(" + assignment.s + ',"__proto__",{value:' + assignment.k + ",configurable:!0,enumerable:!0,writable:!0})";
|
|
2526
2530
|
}
|
|
2527
2531
|
}
|
|
2528
2532
|
function mergeAssignments(assignments) {
|
|
@@ -2719,6 +2723,15 @@ function createArrayAssign(ctx, ref, index, value) {
|
|
|
2719
2723
|
createAssignment(ctx.base, getRefParam(ctx, ref) + "[" + index + "]", value);
|
|
2720
2724
|
}
|
|
2721
2725
|
function createObjectAssign(ctx, ref, key, value) {
|
|
2726
|
+
if (!isValidKey(key)) {
|
|
2727
|
+
ctx.base.assignments.push({
|
|
2728
|
+
t: 4 /* Define */,
|
|
2729
|
+
s: getRefParam(ctx, ref),
|
|
2730
|
+
k: value,
|
|
2731
|
+
v: NIL
|
|
2732
|
+
});
|
|
2733
|
+
return;
|
|
2734
|
+
}
|
|
2722
2735
|
createAssignment(ctx.base, getRefParam(ctx, ref) + "." + key, value);
|
|
2723
2736
|
}
|
|
2724
2737
|
function createSequenceAssign(ctx, ref, index, value) {
|
|
@@ -2805,7 +2818,10 @@ function serializeProperty(ctx, source, key, val) {
|
|
|
2805
2818
|
}
|
|
2806
2819
|
return "";
|
|
2807
2820
|
}
|
|
2808
|
-
|
|
2821
|
+
if (isValidKey(key)) {
|
|
2822
|
+
return (isIdentifier ? key : '"' + key + '"') + ":" + serialize(ctx, val);
|
|
2823
|
+
}
|
|
2824
|
+
return '["' + key + '"]:' + serialize(ctx, val);
|
|
2809
2825
|
}
|
|
2810
2826
|
return "[" + serialize(ctx, key) + "]:" + serialize(ctx, val);
|
|
2811
2827
|
}
|
|
@@ -2933,7 +2949,7 @@ function serializeDate(node) {
|
|
|
2933
2949
|
}
|
|
2934
2950
|
function serializeRegExp(ctx, node) {
|
|
2935
2951
|
if (ctx.base.features & 32 /* RegExp */) {
|
|
2936
|
-
return "/" + node.c + "/" + node.m;
|
|
2952
|
+
return "/" + deserializeString(node.c) + "/" + node.m;
|
|
2937
2953
|
}
|
|
2938
2954
|
throw new SerovalUnsupportedNodeError(node);
|
|
2939
2955
|
}
|
|
@@ -3400,6 +3416,9 @@ var StreamParsePluginContext = class {
|
|
|
3400
3416
|
onError(error) {
|
|
3401
3417
|
onError(this._p, error);
|
|
3402
3418
|
}
|
|
3419
|
+
addCleanup(callback) {
|
|
3420
|
+
this._p.state.cleanups.push(callback);
|
|
3421
|
+
}
|
|
3403
3422
|
};
|
|
3404
3423
|
function createStreamParserState(options) {
|
|
3405
3424
|
return {
|
|
@@ -3409,7 +3428,8 @@ function createStreamParserState(options) {
|
|
|
3409
3428
|
buffer: [],
|
|
3410
3429
|
onParse: options.onParse,
|
|
3411
3430
|
onError: options.onError,
|
|
3412
|
-
onDone: options.onDone
|
|
3431
|
+
onDone: options.onDone,
|
|
3432
|
+
cleanups: []
|
|
3413
3433
|
};
|
|
3414
3434
|
}
|
|
3415
3435
|
function createStreamParserContext(options) {
|
|
@@ -3893,6 +3913,9 @@ function onDone(ctx) {
|
|
|
3893
3913
|
if (ctx.state.onDone) {
|
|
3894
3914
|
ctx.state.onDone();
|
|
3895
3915
|
}
|
|
3916
|
+
for (let i = 0, len = ctx.state.cleanups.length; i < len; i++) {
|
|
3917
|
+
ctx.state.cleanups[i]();
|
|
3918
|
+
}
|
|
3896
3919
|
}
|
|
3897
3920
|
function onParseInternal(ctx, node, initial) {
|
|
3898
3921
|
try {
|