* Convert an UNWIND expression AST node to a StepUnwindExpression.
(expr: ASTUnwindExpression)
| 916 | * Convert an UNWIND expression AST node to a StepUnwindExpression. |
| 917 | */ |
| 918 | function convertUnwindExpression(expr: ASTUnwindExpression): StepUnwindExpression { |
| 919 | if (expr.type === "ListLiteral") { |
| 920 | // ListLiteral from UNWIND grammar - values may be complex AST nodes |
| 921 | // Check if all values are simple primitives or if we need runtime evaluation |
| 922 | const isPrimitive = (v: unknown): boolean => { |
| 923 | return typeof v === "string" || typeof v === "number" || typeof v === "boolean" || v === null; |
| 924 | }; |
| 925 | |
| 926 | const allPrimitives = expr.values.every(isPrimitive); |
| 927 | |
| 928 | if (allPrimitives) { |
| 929 | // Simple case: all values are primitives |
| 930 | return { |
| 931 | type: "literal", |
| 932 | values: expr.values, |
| 933 | }; |
| 934 | } |
| 935 | |
| 936 | // Complex case: values contain AST nodes that need runtime evaluation |
| 937 | // Convert the entire ListLiteral to an expression for runtime evaluation |
| 938 | return { |
| 939 | type: "expression", |
| 940 | value: convertConditionValue(expr), |
| 941 | }; |
| 942 | } |
| 943 | |
| 944 | if (expr.type === "NullLiteral") { |
| 945 | return { type: "null" }; |
| 946 | } |
| 947 | |
| 948 | if (expr.type === "PropertyAccess") { |
| 949 | return { |
| 950 | type: "property", |
| 951 | variable: expr.variable, |
| 952 | property: expr.property, |
| 953 | }; |
| 954 | } |
| 955 | |
| 956 | if (expr.type === "VariableRef") { |
| 957 | return { |
| 958 | type: "variable", |
| 959 | variable: expr.variable, |
| 960 | }; |
| 961 | } |
| 962 | |
| 963 | if (expr.type === "ParameterRef") { |
| 964 | return { |
| 965 | type: "parameter", |
| 966 | name: expr.name, |
| 967 | }; |
| 968 | } |
| 969 | |
| 970 | if (expr.type === "FunctionCall") { |
| 971 | // Convert function call arguments to ConditionValue |
| 972 | const args = expr.args.map((arg) => convertConditionValue(arg)); |
| 973 | return { |
| 974 | type: "function", |
| 975 | name: expr.name, |
no test coverage detected