Skip to content

Commit

Permalink
Fix **.**
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 13, 2022
1 parent 8b7c0a8 commit d053c1e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/config/normalize/lib/wild_wild_path/tokens/any_deep.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { getTokenType as getTokenTypeName } from '../../wild_wild_path_parser/main.js'

// Handle ** recursion.
// It matches 0, 1 or more levels.
// - It can match 0 levels, i.e. the current object
// It is the same as the union of . * *.* *.*.* and so on.
// Using both * and ** can express minimum depth, e.g. *.** or *.*.**
const recurse = function (queryArray, index) {
const parentQuery = queryArray.slice(0, index)
const childQuery = queryArray.slice(index)
return [parentQuery, [...parentQuery, { type: 'any' }, ...childQuery]]
const lastIndex = getLastIndex(queryArray, index)
return [
[...parentQuery, ...queryArray.slice(lastIndex + 1)],
[...parentQuery, { type: 'any' }, ...queryArray.slice(lastIndex)],
]
}

// Squash consecutive ** into a single one
const getLastIndex = function (queryArray, index) {
return index <= queryArray.length - 1 &&
getTokenTypeName(queryArray[index]) === 'anyDeep'
? getLastIndex(queryArray, index + 1)
: index - 1
}

export const ANY_DEEP_TOKEN = {
Expand Down

0 comments on commit d053c1e

Please sign in to comment.