This commit is contained in:
@@ -14,7 +14,7 @@ import { TextDecoder } from "node:util"
|
||||
const IF_PATH_RE = /^<@if\((.+?)\)>(.*)$/
|
||||
const VAR_RE = /<@var\(context\.(.+?)(?::(\w+))?\)>/g
|
||||
const DIRECTIVE_RE = /<@(if|elseif|else|endif)(?:\((.+?)\))?>/g
|
||||
const EQ_RE = /^eq\(context\.(.+?),\s*"(.*)"\)$/
|
||||
const STRING_COMPARE_RE = /^(eq|neq)\(context\.(.+?),\s*"(.*)"\)$/
|
||||
const PATH_RE = /^context\.(.+)$/
|
||||
|
||||
export type ReverseMapToken = {
|
||||
@@ -68,9 +68,10 @@ type RenderState = {
|
||||
|
||||
function evalCondition(expr: string | undefined, context: Record<string, unknown>): boolean {
|
||||
if (!expr) throw new Error("Missing condition expression")
|
||||
const eqMatch = expr.match(EQ_RE)
|
||||
if (eqMatch) {
|
||||
return resolveContext(context, eqMatch[1]!) === eqMatch[2]
|
||||
const stringCompareMatch = expr.match(STRING_COMPARE_RE)
|
||||
if (stringCompareMatch) {
|
||||
const result = resolveContext(context, stringCompareMatch[2]!) === stringCompareMatch[3]
|
||||
return stringCompareMatch[1] === "eq" ? result : !result
|
||||
}
|
||||
const pathMatch = expr.match(PATH_RE)
|
||||
if (pathMatch) {
|
||||
|
||||
Reference in New Issue
Block a user