Skip to content

Commit

Permalink
[Refactor] use an internal null options object instead of an `immutab…
Browse files Browse the repository at this point in the history
…le` boolean
  • Loading branch information
ljharb committed Mar 12, 2024
1 parent 165f954 commit 0f1e6f1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,14 @@ function copy(src) {
return src;
}

function walk(root, cb, immutable) {
var emptyNull = { __proto__: null };

function walk(root, cb) {
var path = [];
var parents = [];
var alive = true;
var options = arguments.length > 2 ? arguments[2] : emptyNull;
var immutable = !!options.immutable;

return (function walker(node_) {
var node = immutable ? copy(node_) : node_;
Expand Down Expand Up @@ -255,12 +259,14 @@ Traverse.prototype.set = function (ps, value) {
return value;
};

var immutableOpts = { __proto__: null, immutable: true };

Traverse.prototype.map = function (cb) {
return walk(this.value, cb, true);
return walk(this.value, cb, immutableOpts);
};

Traverse.prototype.forEach = function (cb) {
this.value = walk(this.value, cb, false);
this.value = walk(this.value, cb);
return this.value;
};

Expand Down

0 comments on commit 0f1e6f1

Please sign in to comment.