From 0f1e6f126a3d847864d3a80fc8227a2bb1f97c78 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 11 Mar 2024 21:13:28 -0700 Subject: [PATCH] [Refactor] use an internal null options object instead of an `immutable` boolean --- index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 23d0766..797c3b1 100644 --- a/index.js +++ b/index.js @@ -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_; @@ -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; };