mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-05 23:50:08 +00:00
fix bad re.lastIndex usage
This commit is contained in:
@@ -10,14 +10,19 @@ import { reactive } from 'vue'
|
||||
*/
|
||||
function tokenize(expr: string): { t: string }[] {
|
||||
const tokens: { t: string }[] = []
|
||||
let pos = 0
|
||||
const re =
|
||||
/\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|==|!=|&&|\|\||[A-Za-z0-9_.]+|!|\(|\))\s*/g
|
||||
let m: RegExpExecArray | null
|
||||
while ((m = re.exec(expr))) {
|
||||
if (m.index !== pos) {
|
||||
throw new Error(`Invalid character in expression at pos ${pos}`)
|
||||
}
|
||||
tokens.push({ t: m[1] })
|
||||
pos = re.lastIndex
|
||||
}
|
||||
if (re.lastIndex !== expr.length) {
|
||||
throw new Error(`Invalid character in expression at pos ${re.lastIndex}`)
|
||||
if (pos !== expr.length) {
|
||||
throw new Error(`Invalid character in expression at pos ${pos}`)
|
||||
}
|
||||
return tokens
|
||||
}
|
||||
|
||||
@@ -11,6 +11,13 @@ describe('evalAst via evaluateCondition', () => {
|
||||
store = useContextKeyStore()
|
||||
})
|
||||
|
||||
it('evaluates logical OR correctly', () => {
|
||||
store.setContextKey('a', true)
|
||||
store.setContextKey('b', false)
|
||||
const result = store.evaluateCondition('a || b')
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it('evaluates logical AND and NOT correctly', () => {
|
||||
store.setContextKey('a', true)
|
||||
store.setContextKey('b', false)
|
||||
|
||||
Reference in New Issue
Block a user