added version
This commit is contained in:
+13
-1
@@ -5,6 +5,7 @@ import {
|
||||
NEGATIVE_INFINITY,
|
||||
NEGATIVE_ZERO,
|
||||
POSITIVE_INFINITY,
|
||||
SPARSE,
|
||||
UNDEFINED
|
||||
} from './constants.js';
|
||||
|
||||
@@ -201,6 +202,17 @@ export function unflatten(parsed, revivers) {
|
||||
default:
|
||||
throw new Error(`Unknown type ${type}`);
|
||||
}
|
||||
} else if (value[0] === SPARSE) {
|
||||
// Sparse array encoding: [SPARSE, length, idx, val, idx, val, ...]
|
||||
const len = value[1];
|
||||
|
||||
const array = new Array(len);
|
||||
hydrated[index] = array;
|
||||
|
||||
for (let i = 2; i < value.length; i += 2) {
|
||||
const idx = value[i];
|
||||
array[idx] = hydrate(value[i + 1]);
|
||||
}
|
||||
} else {
|
||||
const array = new Array(value.length);
|
||||
hydrated[index] = array;
|
||||
@@ -217,7 +229,7 @@ export function unflatten(parsed, revivers) {
|
||||
const object = {};
|
||||
hydrated[index] = object;
|
||||
|
||||
for (const key in value) {
|
||||
for (const key of Object.keys(value)) {
|
||||
if (key === '__proto__') {
|
||||
throw new Error('Cannot parse an object with a `__proto__` property');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user