-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/config/normalize/lib/wild_wild_path/iterate/recurse.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { getTokenType } from '../../wild_wild_path_parser/main.js' | ||
|
||
// Some tokens are recursive. Those are expanded iteratively at each level. | ||
export const expandRecursiveTokens = function (entries, index) { | ||
return entries.flatMap((entry) => expandRecursiveToken(entry, index)) | ||
} | ||
|
||
const expandRecursiveToken = function (entry, index) { | ||
const { queryArray } = entry | ||
const token = queryArray[index] | ||
const tokenTypeName = getTokenType(token) | ||
const recursor = RECURSORS[tokenTypeName] | ||
|
||
if (recursor === undefined) { | ||
return entry | ||
} | ||
|
||
const queryArrays = recursor(queryArray, index) | ||
return queryArrays.map((queryArrayA) => ({ | ||
...entry, | ||
queryArray: queryArrayA, | ||
})) | ||
} | ||
|
||
// Handle ** recursion | ||
const recurseAnyDeep = function (queryArray, index) { | ||
const parentQuery = queryArray.slice(0, index) | ||
const childQuery = queryArray.slice(index) | ||
return [parentQuery, [...parentQuery, { type: 'any' }, ...childQuery]] | ||
} | ||
|
||
const RECURSORS = { | ||
anyDeep: recurseAnyDeep, | ||
} |