Skip to content

Commit f042734

Browse files
committed
Only restore references to object types
1 parent f53ff44 commit f042734

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

javascript-stringify.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,23 +283,25 @@
283283
*/
284284
var recurse = references ?
285285
function (value, stringify) {
286-
var exists = encountered.indexOf(value);
287-
288-
// Track nodes to restore later.
289-
if (exists > -1) {
290-
restore.push(path.slice(), paths[exists]);
291-
return;
286+
if (value && (typeof value === 'object' || typeof value === 'function')) {
287+
var exists = encountered.indexOf(value);
288+
289+
// Track nodes to restore later.
290+
if (exists > -1) {
291+
restore.push(path.slice(), paths[exists]);
292+
return;
293+
}
294+
295+
// Track encountered nodes.
296+
encountered.push(value);
297+
paths.push(path.slice());
292298
}
293299

294300
// Stop when we hit the max depth.
295301
if (path.length > maxDepth) {
296302
return;
297303
}
298304

299-
// Track encountered nodes.
300-
encountered.push(value);
301-
paths.push(path.slice());
302-
303305
// Stringify the value and fallback to
304306
return stringify(value, space, next);
305307
} :

0 commit comments

Comments
 (0)