From 7cb1c7a603abcedc9cc021dc700a3d14b4791c80 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 11 Sep 2017 13:05:30 +0200 Subject: [PATCH] fix: _get and _has internal args handling. Fixes #88 --- lib/configure-map.js | 8 ++++++-- test/lib/configure-map.js | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/configure-map.js b/lib/configure-map.js index 086a2a9..9a7b280 100644 --- a/lib/configure-map.js +++ b/lib/configure-map.js @@ -162,14 +162,18 @@ module.exports = function (original, length, options) { } extGet = defineLength(function () { var id, args = arguments; + if (length === 0) return cache.data; if (resolve) args = resolve(args); - id = get(args); + if (get) id = get(args); + else id = String(args[0]); return cache[id]; }); extHas = defineLength(function () { var id, args = arguments; + if (length === 0) return conf.has("data"); if (resolve) args = resolve(args); - id = get(args); + if (get) id = get(args); + else id = String(args[0]); if (id === null) return false; return conf.has(id); }); diff --git a/test/lib/configure-map.js b/test/lib/configure-map.js index 689816e..cb4d1db 100644 --- a/test/lib/configure-map.js +++ b/test/lib/configure-map.js @@ -24,6 +24,25 @@ module.exports = function () { a(mfn("foo"), y, "#2"); a(i, 1, "Called once"); }, + "No args": function (a) { + var i = 0 + , fn = function () { + ++i; + return "foo"; + } + , mfn + , y = { + toString: function () { + return "foo"; + } + }; + mfn = memoize(fn); + a(mfn._has(), false); + a(mfn(), "foo", "#1"); + a(mfn._has(), true); + mfn(); + a(i, 1, "Called once"); + }, "Clear cache": function (a) { var i = 0 , fn = function (x, y, z) {