| 1133 | SetNode(const Location & loc, const std::string & ns, const std::vector<std::string> & vns, std::shared_ptr<Expression> && v) |
| 1134 | : TemplateNode(loc), ns(ns), var_names(vns), value(std::move(v)) {} |
| 1135 | void do_render(std::ostringstream &, const std::shared_ptr<Context> & context) const override { |
| 1136 | if (!value) throw std::runtime_error("SetNode.value is null"); |
| 1137 | if (!ns.empty()) { |
| 1138 | if (var_names.size() != 1) { |
| 1139 | throw std::runtime_error("Namespaced set only supports a single variable name"); |
| 1140 | } |
| 1141 | auto & name = var_names[0]; |
| 1142 | auto ns_value = context->get(ns); |
| 1143 | if (!ns_value.is_object()) throw std::runtime_error("Namespace '" + ns + "' is not an object"); |
| 1144 | ns_value.set(name, this->value->evaluate(context)); |
| 1145 | } else { |
| 1146 | auto val = value->evaluate(context); |
| 1147 | destructuring_assign(var_names, context, val); |
| 1148 | } |
| 1149 | } |
| 1150 | }; |
| 1151 | |
| 1152 | class SetTemplateNode : public TemplateNode { |