* Convert a SetValue AST node to a SetAssignmentValue.
(value: SetValue)
| 1013 | * Convert a SetValue AST node to a SetAssignmentValue. |
| 1014 | */ |
| 1015 | function convertSetValue(value: SetValue): SetAssignmentValue { |
| 1016 | // Handle literal values (primitives) |
| 1017 | if ( |
| 1018 | typeof value === "string" || |
| 1019 | typeof value === "number" || |
| 1020 | typeof value === "boolean" || |
| 1021 | value === null |
| 1022 | ) { |
| 1023 | return { type: "literal", value }; |
| 1024 | } |
| 1025 | |
| 1026 | // Handle PropertyAccess |
| 1027 | if (value.type === "PropertyAccess") { |
| 1028 | return { |
| 1029 | type: "property", |
| 1030 | variable: value.variable, |
| 1031 | property: value.property, |
| 1032 | }; |
| 1033 | } |
| 1034 | |
| 1035 | // Handle VariableRef |
| 1036 | if (value.type === "VariableRef") { |
| 1037 | return { type: "variable", variable: value.variable }; |
| 1038 | } |
| 1039 | |
| 1040 | // Handle ParameterRef |
| 1041 | if (value.type === "ParameterRef") { |
| 1042 | return { type: "parameter", name: value.name }; |
| 1043 | } |
| 1044 | |
| 1045 | // Handle ListLiteral |
| 1046 | if (value.type === "ListLiteral") { |
| 1047 | return { type: "list", values: value.values as unknown[] }; |
| 1048 | } |
| 1049 | |
| 1050 | // Handle NestedMap (JSON object value) |
| 1051 | if (value.type === "NestedMap") { |
| 1052 | return { |
| 1053 | type: "literal", |
| 1054 | value: convertPropertyMap(value.value as Record<string, unknown>), |
| 1055 | }; |
| 1056 | } |
| 1057 | |
| 1058 | // This should never happen given the SetValue type definition |
| 1059 | // If it does, it's a parser bug or type mismatch |
| 1060 | throw new Error(`Unexpected SetValue type: ${JSON.stringify(value)}`); |
| 1061 | } |
| 1062 | |
| 1063 | /** |
| 1064 | * Convert a FOREACH clause into a ForeachStep. |
no test coverage detected