Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c26c700

Browse files
committed
Correctly stringify non-cyclic shared references
1 parent f70d444 commit c26c700

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

‎index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ module.exports = function (obj, opts) {
6464
;
6565
out.push(indent + space + keyValue);
6666
}
67+
seen.splice(seen.indexOf(node), 1);
6768
return '{' + out.join(',') + indent + '}';
6869
}
6970
})({ '': obj }, '', obj, 0);

‎test/nested.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ test('cyclic (specifically allowed)', function (t) {
2626
one.two = two;
2727
t.equal(stringify(one, {cycles:true}), '{"a":1,"two":{"a":2,"one":"__cycle__"}}');
2828
});
29+
30+
test('repeated non-cyclic value', function(t) {
31+
t.plan(1);
32+
var one = { x: 1 };
33+
var two = { a: one, b: one };
34+
t.equal(stringify(two), '{"a":{"x":1},"b":{"x":1}}');
35+
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /