Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 13, 2022
1 parent d014318 commit c605dd2
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/config/normalize/lib/wild_wild_path/iterate/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,37 @@ export const expandTokens = function (entries, index, opts) {
}

// Use the token to list entries against a target value.
const expandToken = function (
{ queryArray, value, path },
index,
{ missing: includeMissing, classes, inherited },
) {
const expandToken = function ({ queryArray, value, path }, index, opts) {
const token = queryArray[index]
const {
tokenType,
missing: missingParent,
value: valueA,
} = handleMissingValue(value, token, classes)

if (missingParent && !includeMissing) {
return []
}

const childEntries = tokenType.iterate(valueA, token, inherited)
const childEntriesA = includeMissing
? childEntries
: childEntries.filter(isNotMissing)
const missingReturn = handleMissingValue(value, token, opts.classes)
const childEntriesA = iterateToken(token, missingReturn, opts)
return childEntriesA.map(
({ value: childValue, prop, missing: missingEntry }) => ({
queryArray,
value: childValue,
path: [...path, prop],
missing: missingParent || missingEntry,
missing: missingReturn.missing || missingEntry,
}),
)
}

const iterateToken = function (
token,
{ tokenType, missing: missingParent, value },
{ inherited, missing: includeMissing },
) {
if (includeMissing) {
return tokenType.iterate(value, token, inherited)
}

if (missingParent) {
return []
}

const childEntries = tokenType.iterate(value, token, inherited)
return childEntries.filter(isNotMissing)
}

const isNotMissing = function ({ missing }) {
return !missing
}

0 comments on commit c605dd2

Please sign in to comment.