Skip to content

Commit

Permalink
passing circular ref update forEach test but failing for likewise wit…
Browse files Browse the repository at this point in the history
…h map
  • Loading branch information
James Halliday committed Feb 18, 2011
1 parent 42b6b84 commit d411695
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function walk (root, cb) {
var path = [];
var parents = [];

return (function walker (node) {
(function walker (node) {
var modifiers = {};

var state = {
Expand Down
18 changes: 14 additions & 4 deletions test/circular.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,26 @@ exports.doubleCirc = function () {
assert.eql(circs.length, 2);
};

exports.circDubUp = function () {
exports.circDubUpForEach = function () {
var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] };
obj.y[2] = obj;
obj.x.push(obj.y);

var c = Traverse(obj).map(function (x) {
Traverse(obj).forEach(function (x) {
if (this.circular) this.update('...');
});

console.dir(c);
assert.eql(obj, { x : [ 1, 2, 3, [ 4, 5, '...' ] ], y : [ 4, 5, '...' ] });
};

exports.circDubUpMap = function () {
var obj = { x : [ 1, 2, 3 ], y : [ 4, 5 ] };
obj.y[2] = obj;
obj.x.push(obj.y);

var c = Traverse(obj).map(function (x) {
if (this.circular) this.update('...');
});

assert.eql(c, { x : [ 1, 2, 3, '...' ], y : [ 4, 5, '...' ] });
assert.eql(c, { x : [ 1, 2, 3, [ 4, 5, '...' ] ], y : [ 4, 5, '...' ] });
};

0 comments on commit d411695

Please sign in to comment.