(defn emit-let
[{:keys [bindings expr env]} is-loop]
(let [context (:context env)]
(when (= :expr context) (emits "(function (){"))
(binding [*lexical-renames*
(into *lexical-renames*
(when (= :statement context)
(map
(fn [binding]
(let [name (:name binding)]
(vector (hash-scope binding)
(gensym (str name "-")))))
bindings)))]
(doseq [{:keys [init] :as binding} bindings]
(emits "var ")
(emit binding) ; Binding will be treated as a var
(emitln " = " init ";"))
(when is-loop (emitln "while(true){"))
(emits expr)
(when is-loop
(emitln "break;")
(emitln "}")))
(when (= :expr context) (emits "})()"))))