Skip to content

Commit

Permalink
Fix #950: interop on local in CLJS (#951)
Browse files Browse the repository at this point in the history
* Fix #950: interop on local in CLJS

* fix shadow dep
  • Loading branch information
borkdude authored Dec 9, 2024
1 parent ba8518a commit 1e15f0f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SCI is used in [babashka](https://github.com/babashka/babashka),

- Fix [#942](https://github.com/babashka/sci/issues/942): improve error location of invalid destructuring
- Add `volatile?` to core vars
- Fix [#950](https://github.com/babashka/sci/issues/950): interop on local in CLJS

## 0.9.44 (2024-10-17)

Expand Down
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
org.clojure/clojurescript {:mvn/version "1.11.132"}
clj-commons/conch {:mvn/version "0.9.2"}
funcool/promesa {:mvn/version "8.0.450"}}}
:shadow {:extra-deps {thheller/shadow-cljs {:mvn/version "2.28b.16"}}}
:shadow {:extra-deps {thheller/shadow-cljs {:mvn/version "2.28.16"}}}
:cljs {:extra-deps {org.clojure/clojurescript {:mvn/version "1.11.54"}}}
:clj-test-runner
{:extra-deps {com.cognitect/test-runner
Expand Down
24 changes: 15 additions & 9 deletions src/sci/impl/analyzer.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1563,23 +1563,29 @@
(sci.impl.types/->Node
(interop/invoke-js-constructor* ctx bindings ctor children)
nil))
(let [method (unchecked-get class method-name)]
(if (instance? t/NodeR class)
(sci.impl.types/->Node
(interop/invoke-static-method ctx bindings class method children)
nil)))
(let [class (t/eval class ctx bindings)
method (unchecked-get class method-name)]
(interop/invoke-static-method ctx bindings class method children))
nil)
(let [method (unchecked-get class method-name)]
(sci.impl.types/->Node
(interop/invoke-static-method ctx bindings class method children)
nil))))
(if ctor?
(sci.impl.types/->Node
(let [arr (lookup-fn)
ctor (aget arr 0)]
(interop/invoke-js-constructor* ctx bindings ctor children))
nil)
(sci.impl.types/->Node
(let [arr (lookup-fn)
class (aget arr 0)
method-name (aget arr 1)
method (unchecked-get class method-name)]
(interop/invoke-static-method ctx bindings class method children))
nil)))))
(let [arr (lookup-fn)
class (aget arr 0)
method-name (aget arr 1)
method (unchecked-get class method-name)]
(interop/invoke-static-method ctx bindings class method children))
nil)))))
#?@(:clj [(and f-meta (:sci.impl.analyzer/interop f-meta))
(let [[obj & children] (analyze-children ctx (rest expr))
meth (-> (second f)
Expand Down
2 changes: 1 addition & 1 deletion src/sci/impl/resolve.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,5 @@
#?(:cljs (let [resolved (resolve-dotted-access ctx sym call? tag)]
resolved))
(throw-error-with-location
(str "Could not resolve symbol: " (str sym))
(str "Could not resolve symbol: " sym)
sym)))))
3 changes: 3 additions & 0 deletions test/sci/interop_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,6 @@
(is (true? (tu/eval* "(when js/document js/document.getElementById) true"
{:classes
{'js goog/global :allow :all}})))))

#?(:cljs (deftest local-interop-test
(is (= 1 (tu/eval* "(def j #js {:a (fn [] 2)}) (let [j #js {:a (fn [] 1)}] (j.a))" nil)))))

0 comments on commit 1e15f0f

Please sign in to comment.