Skip to content

Commit

Permalink
[lang] fix unsited (java.nio.Path/of ..) and (into-array String []) c…
Browse files Browse the repository at this point in the history
…ljs output
  • Loading branch information
xificurC committed Dec 11, 2024
1 parent 07d93dc commit c4ed77a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/hyperfiddle/electric/impl/cljs_analyzer2.clj
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,8 @@
(def implicit-nses '#{goog goog.object goog.string goog.array Math String})

(defn imported? [a sym ns$]
(let [imports (into implicit-nses (-> a ::nses (get ns$) ::imports))
dot-access (-> sym str (str/replace #"\.[^.]+$" "") symbol)]
(or (get imports dot-access)
(and (qualified-symbol? sym) (get imports (-> sym namespace symbol))))))
(let [imports (into implicit-nses (-> a ::nses (get ns$) ::imports))]
(cond (qualified-symbol? sym) (get imports (-> sym namespace symbol))
(str/includes? sym ".") (get imports (-> sym str (str/replace #"\.[^.]+$" "") symbol)))))

(defn referred? [a sym ns$] (-> a ::nses (get ns$) ::refers (get sym)))
12 changes: 7 additions & 5 deletions src/hyperfiddle/electric/impl/lang3.clj
Original file line number Diff line number Diff line change
Expand Up @@ -684,12 +684,12 @@

(and (symbol? (second form)) (class? (resolve env (second form))))
(if (seq? (nth form 2)) ; (. java.time.Instant (ofEpochMilli 1))
(if me?
(if (= :clj (->env-type env))
(let [[_ clazz [method & method-args]] form]
(->class-method-call clazz method method-args pe env form ts))
(recur `[~@(next (nth form 2))] pe env ts))
(let [[_ clazz x & xs] form] ; (. java.time.instant opEpochMilli 1)
(if me?
(if (= :clj (->env-type env))
(->class-method-call clazz x xs pe env form ts)
(recur `[~@xs] pe env ts))))

Expand Down Expand Up @@ -1584,9 +1584,11 @@
(defn ->ts [] (ts/->ts {::->id (->->id), ::->uid (->->id)}))

(defn compile [nm form env]
(compile* nm env
(analyze (expand-all env `(::ctor ~form))
'_ env (->ts))))
(let [expanded (expand-all env `(::ctor ~form))]
(when (::print-expansion env) (fipp.edn/pprint expanded))
(compile* nm env
(analyze expanded
'_ env (->ts)))))

(defn ->source [env root-key efn]
(let [expanded (expand-all env efn)
Expand Down
16 changes: 13 additions & 3 deletions test/hyperfiddle/electric/impl/compiler_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,19 @@
(fn [~'frame]
(r/ap '{} (r/pure r/cannot-resolve)
(r/lookup ~'frame :hyperfiddle.electric3/Count
(r/pure (r/resolve ~'frame :hyperfiddle.electric3/Count))))))]))
(r/pure (r/resolve ~'frame :hyperfiddle.electric3/Count))))))])

(match (l/test-compile ::Main (lang/->cljs-env) (java.nio.file.Path/of "./src"))
`[(r/cdef 0 [] [] nil
(fn [~'frame]
(r/pure (vector "./src"))))])

(match (l/test-compile ::Main (merge e/web-config (lang/normalize-env {}) {:js-globals {}})
String)
`[(r/cdef 0 [] [] :server
(fn [~'frame]
(r/pure r/cannot-resolve)))])
)

(tests "::lang/tag"
(match (l/test-compile ::Main [(::lang/tag)
Expand Down Expand Up @@ -680,8 +692,6 @@
(foreign-js '(fn ([x] 1) ([x y] 2))) := '(fn* ([x] 1) ([x y] 2))
(foreign-js '(letfn [(foo [x] 1) (bar [y] 2)] 3)) := '(letfn* [foo (fn* foo ([x] 1)) bar (fn* bar ([y] 2))] 3)
(foreign-js '(Math/abs -1)) := '(Math/abs -1)
(foreign-js '(. Math abs -1)) := '(Math/abs -1)
(foreign-js '(. Math (abs -1))) := '(Math/abs -1)
(foreign-js '(binding [x 1 y 2] 3)) := '(binding [x 1 y 2] 3)
(foreign-js '(def foo 1)) := '(def foo 1)
(foreign-js '(do (def foo 1) 2)) := '(do (def foo 1) 2)
Expand Down

0 comments on commit c4ed77a

Please sign in to comment.