Skip to content

Commit 2271a6e

Browse files
committed
chore: make passing precedenceLevel optional
1 parent e097e1c commit 2271a6e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/parse.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function parse(query: string, options?: JSONQueryParseOptions): JSONQuery
3737
customOperators.filter((op) => op.leftAssociative).map((op) => op.op)
3838
)
3939

40-
const parseOperator = (precedenceLevel: number) => {
40+
const parseOperator = (precedenceLevel = allOperators.length - 1) => {
4141
const currentOperators = allOperators[precedenceLevel]
4242
if (!currentOperators) {
4343
return parseParenthesis()
@@ -96,7 +96,7 @@ export function parse(query: string, options?: JSONQueryParseOptions): JSONQuery
9696

9797
if (query[i] === '(') {
9898
i++
99-
const inner = parseOperator(allOperators.length - 1)
99+
const inner = parseOperator()
100100
eatChar(')')
101101
return inner
102102
}
@@ -141,11 +141,11 @@ export function parse(query: string, options?: JSONQueryParseOptions): JSONQuery
141141

142142
skipWhitespace()
143143

144-
const args = query[i] !== ')' ? [parseOperator(allOperators.length - 1)] : []
144+
const args = query[i] !== ')' ? [parseOperator()] : []
145145
while (i < query.length && query[i] !== ')') {
146146
skipWhitespace()
147147
eatChar(',')
148-
args.push(parseOperator(allOperators.length - 1))
148+
args.push(parseOperator())
149149
}
150150

151151
eatChar(')')
@@ -174,7 +174,7 @@ export function parse(query: string, options?: JSONQueryParseOptions): JSONQuery
174174
skipWhitespace()
175175
eatChar(':')
176176

177-
object[key] = parseOperator(allOperators.length - 1)
177+
object[key] = parseOperator()
178178
}
179179

180180
eatChar('}')
@@ -201,7 +201,7 @@ export function parse(query: string, options?: JSONQueryParseOptions): JSONQuery
201201
skipWhitespace()
202202
}
203203

204-
array.push(parseOperator(allOperators.length - 1))
204+
array.push(parseOperator())
205205
}
206206

207207
eatChar(']')
@@ -260,7 +260,7 @@ export function parse(query: string, options?: JSONQueryParseOptions): JSONQuery
260260
}
261261

262262
let i = 0
263-
const output = parseOperator(allOperators.length - 1)
263+
const output = parseOperator()
264264
parseEnd()
265265

266266
return output

0 commit comments

Comments
 (0)