Skip to content

Commit

Permalink
Split file
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 20, 2022
1 parent d671bbe commit e1b0377
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
27 changes: 27 additions & 0 deletions src/config/normalize/lib/wild_wild_parser/parse/escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
ESCAPE,
ARRAY_SEPARATOR_NAME,
TOKEN_SEPARATOR,
SPECIAL_CHARS,
} from '../tokens/escape.js'
import { throwQueryError } from '../validate/throw.js'

// Parse escape character in a query string
export const parseEscape = function (state, queryString) {
const nextChar = queryString[state.index + 1]

if (SPECIAL_CHARS.has(nextChar)) {
state.index += 1
state.chars += nextChar
return
}

if (state.chars.length !== 0) {
throwQueryError(
queryString,
`Character "${ESCAPE}" must either be at the start of a token, or be followed by ${ARRAY_SEPARATOR_NAME} or ${TOKEN_SEPARATOR} or ${ESCAPE}`,
)
}

state.isProp = true
}
30 changes: 3 additions & 27 deletions src/config/normalize/lib/wild_wild_parser/parse/main.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import {
ESCAPE,
ARRAY_SEPARATOR,
ARRAY_SEPARATOR_NAME,
TOKEN_SEPARATOR,
SPECIAL_CHARS,
} from '../tokens/escape.js'
import { ESCAPE, ARRAY_SEPARATOR, TOKEN_SEPARATOR } from '../tokens/escape.js'
import { getStringTokenType } from '../tokens/main.js'
import { normalizeArraysPath } from '../validate/path.js'
import { validateEmptyQuery, validateQueryString } from '../validate/string.js'
import { throwQueryError } from '../validate/throw.js'

import { parseEscape } from './escape.js'

// Parse a query string into an array of tokens.
// Also validate and normalize it.
Expand Down Expand Up @@ -56,25 +51,6 @@ const getInitialState = function () {
return state
}

const parseEscape = function (state, queryString) {
const nextChar = queryString[state.index + 1]

if (SPECIAL_CHARS.has(nextChar)) {
state.index += 1
state.chars += nextChar
return
}

if (state.chars.length !== 0) {
throwQueryError(
queryString,
`Character "${ESCAPE}" must either be at the start of a token, or be followed by ${ARRAY_SEPARATOR_NAME} or ${TOKEN_SEPARATOR} or ${ESCAPE}`,
)
}

state.isProp = true
}

const addQueryArray = function (state) {
if (hasNoQueryArray(state)) {
return
Expand Down

0 comments on commit e1b0377

Please sign in to comment.