* Stringify a condition value reference for display purposes.
(value: ConditionValue)
| 1169 | * Stringify a condition value reference for display purposes. |
| 1170 | */ |
| 1171 | function stringifyConditionValueRef(value: ConditionValue): string { |
| 1172 | if (value === null) return "null"; |
| 1173 | if (value === undefined) return "undefined"; |
| 1174 | if (typeof value !== "object") return JSON.stringify(value); |
| 1175 | |
| 1176 | switch (value.type) { |
| 1177 | case "variableRef": |
| 1178 | return value.variable; |
| 1179 | case "pathRef": |
| 1180 | return value.variable; |
| 1181 | case "propertyRef": |
| 1182 | return `${value.variable}.${value.property}`; |
| 1183 | case "parameterRef": |
| 1184 | return `$${value.name}`; |
| 1185 | case "arithmeticExpression": |
| 1186 | return `(${stringifyConditionValueRef(value.left)} ${value.operator} ${stringifyConditionValueRef(value.right)})`; |
| 1187 | case "unaryExpression": |
| 1188 | return `${value.operator}${stringifyConditionValueRef(value.operand)}`; |
| 1189 | case "booleanExpression": |
| 1190 | if (value.operator === "NOT") { |
| 1191 | return `NOT ${stringifyConditionValueRef((value as { operand: ConditionValue }).operand)}`; |
| 1192 | } |
| 1193 | return `(${stringifyConditionValueRef(value.left)} ${value.operator} ${stringifyConditionValueRef(value.right)})`; |
| 1194 | case "comparisonExpression": |
| 1195 | if (value.operator === "IS NULL" || value.operator === "IS NOT NULL") { |
| 1196 | return `${stringifyConditionValueRef(value.left)} ${value.operator}`; |
| 1197 | } |
| 1198 | return `(${stringifyConditionValueRef(value.left)} ${value.operator} ${stringifyConditionValueRef((value as { right: ConditionValue }).right)})`; |
| 1199 | case "functionCall": |
| 1200 | return `${value.name}(${value.args.map(stringifyConditionValueRef).join(", ")})`; |
| 1201 | case "listLiteral": |
| 1202 | return `[${value.values.map(stringifyConditionValueRef).join(", ")}]`; |
| 1203 | case "mapLiteral": |
| 1204 | return `{${value.entries.map((e) => `${e.key}: ${stringifyConditionValueRef(e.value)}`).join(", ")}}`; |
| 1205 | case "null": |
| 1206 | return "null"; |
| 1207 | default: |
| 1208 | return JSON.stringify(value); |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | /** |
| 1213 | * Resolve a condition value - either return the literal value or resolve a reference from the path. |