* Convert an AST condition value to Step condition value format. * Handles literal values, property references, variable references, and arithmetic expressions.
(
value: import("./AST.js").ConditionValue,
)
| 2035 | * Handles literal values, property references, variable references, and arithmetic expressions. |
| 2036 | */ |
| 2037 | function convertConditionValue( |
| 2038 | value: import("./AST.js").ConditionValue, |
| 2039 | ): import("./Steps.js").ConditionValue { |
| 2040 | // Literal values (string, number, boolean, null) are passed through as-is |
| 2041 | if (value === null || typeof value !== "object") { |
| 2042 | return value; |
| 2043 | } |
| 2044 | |
| 2045 | // Object values are references or expressions |
| 2046 | if (value.type === "PropertyAccess") { |
| 2047 | return { |
| 2048 | type: "propertyRef", |
| 2049 | variable: value.variable, |
| 2050 | property: value.property, |
| 2051 | }; |
| 2052 | } |
| 2053 | |
| 2054 | if (value.type === "VariableRef") { |
| 2055 | return { |
| 2056 | type: "variableRef", |
| 2057 | variable: value.variable, |
| 2058 | }; |
| 2059 | } |
| 2060 | |
| 2061 | if (value.type === "ParameterRef") { |
| 2062 | return { |
| 2063 | type: "parameterRef", |
| 2064 | name: value.name, |
| 2065 | }; |
| 2066 | } |
| 2067 | |
| 2068 | if (value.type === "ArithmeticExpression") { |
| 2069 | return { |
| 2070 | type: "arithmeticExpression", |
| 2071 | operator: value.operator, |
| 2072 | left: convertConditionValue(value.left), |
| 2073 | right: convertConditionValue(value.right), |
| 2074 | }; |
| 2075 | } |
| 2076 | |
| 2077 | if (value.type === "BooleanExpression") { |
| 2078 | // Handle boolean operators: AND, OR, XOR, NOT |
| 2079 | if (value.operator === "NOT") { |
| 2080 | return { |
| 2081 | type: "booleanExpression", |
| 2082 | operator: "NOT", |
| 2083 | operand: convertConditionValue( |
| 2084 | (value as { operand: import("./AST.js").ConditionValue }).operand, |
| 2085 | ), |
| 2086 | }; |
| 2087 | } |
| 2088 | // For binary operators (AND, OR, XOR), left and right are always present |
| 2089 | return { |
| 2090 | type: "booleanExpression", |
| 2091 | operator: value.operator, |
| 2092 | left: convertConditionValue(value.left!), |
| 2093 | right: convertConditionValue(value.right!), |
| 2094 | }; |
no test coverage detected