Skip to content

Commit a5f40db

Browse files
committed
fixes
1 parent 1e661a4 commit a5f40db

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/parse.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,24 @@ export function parse(serialized) {
7878
}
7979
} else {
8080
const array = new Array(value.length);
81+
hydrated[index] = array;
8182

8283
for (let i = 0; i < value.length; i += 1) {
8384
const n = value[i];
8485
if (n === HOLE) continue;
8586

8687
array[i] = hydrate(n);
8788
}
88-
89-
hydrated[index] = array;
9089
}
9190
} else {
9291
/** @type {Record<string, any>} */
9392
const object = {};
93+
hydrated[index] = object;
9494

9595
for (const key in value) {
9696
const n = value[key];
9797
object[key] = hydrate(n);
9898
}
99-
100-
hydrated[index] = object;
10199
}
102100

103101
return hydrated[index];

test/test.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,11 @@ const fixtures = {
242242
name: 'Array (cyclical)',
243243
value: arr,
244244
js: '(function(a){a[0]=a;return a}(Array(1)))',
245-
json: '[[0]]'
245+
json: '[[0]]',
246+
validate: (value) => {
247+
assert.equal(value.length, 1);
248+
assert.equal(value[0], value);
249+
}
246250
};
247251
})([]),
248252

@@ -252,7 +256,10 @@ const fixtures = {
252256
name: 'Object (cyclical)',
253257
value: obj,
254258
js: '(function(a){a.self=a;return a}({}))',
255-
json: '[{"self":0}]'
259+
json: '[{"self":0}]',
260+
validate: (value) => {
261+
assert.equal(value.self, value);
262+
}
256263
};
257264
})({}),
258265

@@ -277,7 +284,11 @@ const fixtures = {
277284
name: 'Object (cyclical)',
278285
value: [first, second],
279286
js: '(function(a,b){a.second=b;b.first=a;return [a,b]}({},{}))',
280-
json: '[[1,2],{"second":2},{"first":1}]'
287+
json: '[[1,2],{"second":2},{"first":1}]',
288+
validate: (value) => {
289+
assert.equal(value[0].second, value[1]);
290+
assert.equal(value[1].first, value[0]);
291+
}
281292
};
282293
})({}, {})
283294
],

0 commit comments

Comments
 (0)