From d8ee2b236c45f97b2c7aa0a39ed94219ec83b07c Mon Sep 17 00:00:00 2001 From: ehmicky Date: Sun, 3 Apr 2022 13:52:07 +0200 Subject: [PATCH] Refactoring --- src/iterate/path.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/iterate/path.js b/src/iterate/path.js index 08e0a5d..49469ac 100644 --- a/src/iterate/path.js +++ b/src/iterate/path.js @@ -2,16 +2,27 @@ import { isAllowedProp } from './expand.js' import { MISSING_HANDLERS } from './missing.js' // Performance-optimized `iterate()` logic when the query is a path -export const iteratePath = function* ( +export const iteratePath = function* (target, pathArray, opts) { + const { entry, matches } = getPathValue(target, pathArray, opts) + + if (matches) { + yield entry + } +} + +const getPathValue = function ( target, pathArray, { missing: missingOpt, entries }, ) { const { value, missing } = getDeepValue(target, pathArray) - if (!missing || missingOpt) { - yield entries ? { value, path: pathArray, missing } : value + if (missing && !missingOpt) { + return { matches: false } } + + const entry = entries ? { value, path: pathArray, missing } : value + return { entry, matches: true } } const getDeepValue = function (value, pathArray) {