Uploaded image for project: 'ClojureScript'
  1. CLJS-1059

Simple interface wanted to convert cljs forms to js

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects versions: 0.0-3211
    • Fix versions: None
    • Labels:

      Description

      In our project (a clojurescript debugger) we want to convert cljs forms or a sequence of forms into javascript so that they can be executed in the javascript console.

      We would like something similar to closure/compile-form-seq (https://github.com/clojure/clojurescript/blob/master/src/clj/cljs/closure.clj#L308)

      However, we need to supply, the namespace requires and locals in an env like this

      {:ns {:name "test.core" :requires {(quote gstring) (quote goog.string)}} :locals {}}
      

      This code seems to do what we want.

      (defn compile-form-seq
          \"Compile a sequence of forms to a JavaScript source string.\"
          [forms env]
          (env/ensure
          (compiler/with-core-cljs nil
            (fn []
              (with-out-str
                  (doseq [form forms]
                    (compiler/emit (analyzer/analyze env form))))))))
      

      I am not sure why I need env/ensure.

      Would you be able to patch compile-form-seq to provide the needed interface, or suggest what we should be doing.

      Thanks
      Stu

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              stumitchell Stuart Mitchell
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: