Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 6, 2022
1 parent 4fbfa9d commit 36cacd5
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/config/normalize/lib/star_dot_path/parsing/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,28 @@ const safeParseQuery = function (query) {

// Use imperative logic for performance
/* eslint-disable complexity, max-depth, max-statements, fp/no-loops,
fp/no-mutation, fp/no-let */
fp/no-mutation */
const parseQuery = function (query) {
if (query === '') {
return []
}

const path = []
const state = { hasAny: false, hasMinus: false, hasRegExp: false, chars: '' }
let index = query[0] === SEPARATOR ? 1 : 0
const index = query[0] === SEPARATOR ? 1 : 0
const state = {
chars: '',
index,
hasAny: false,
hasMinus: false,
hasRegExp: false,
}

for (; index <= query.length; index += 1) {
const char = query[index]
for (; state.index <= query.length; state.index += 1) {
const char = query[state.index]

if (char === ESCAPE) {
index = addEscapedChar(query, index, state)
} else if (char === SEPARATOR || index === query.length) {
addEscapedChar(query, state)
} else if (char === SEPARATOR || state.index === query.length) {
addToken(path, state)
} else {
addChar(char, state)
Expand All @@ -91,12 +97,11 @@ const parseQuery = function (query) {
return path
}
/* eslint-enable complexity, max-depth, max-statements, fp/no-loops,
fp/no-mutation, fp/no-let */
fp/no-mutation */

const addEscapedChar = function (query, index, state) {
const indexA = index + 1
state.chars += parseEscapedChar(query[indexA])
return indexA
const addEscapedChar = function (query, state) {
state.index += 1
state.chars += parseEscapedChar(query[state.index])
}

const addToken = function (path, state) {
Expand Down

0 comments on commit 36cacd5

Please sign in to comment.