This commit is contained in:
@@ -10,14 +10,14 @@ export type TemplateVariable = {
|
||||
const IF_RE = /<@(?:if|elseif)\((.+?)\)>/g
|
||||
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\.(.+)$/
|
||||
|
||||
function extractCondition(expr: string | undefined, vars: TemplateVariable[]) {
|
||||
if (!expr) throw new Error("Missing condition expression")
|
||||
const eqMatch = expr.match(EQ_RE)
|
||||
if (eqMatch) {
|
||||
vars.push({ path: eqMatch[1]!, type: "string" })
|
||||
const stringCompareMatch = expr.match(STRING_COMPARE_RE)
|
||||
if (stringCompareMatch) {
|
||||
vars.push({ path: stringCompareMatch[1]!, type: "string" })
|
||||
return
|
||||
}
|
||||
const pathMatch = expr.match(PATH_RE)
|
||||
|
||||
Reference in New Issue
Block a user