From 1e15f0f6a129ef7512351efc65f7475209d8cc4c Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Mon, 9 Dec 2024 14:56:49 +0100 Subject: [PATCH] Fix #950: interop on local in CLJS (#951) * Fix #950: interop on local in CLJS * fix shadow dep --- CHANGELOG.md | 1 + deps.edn | 2 +- src/sci/impl/analyzer.cljc | 24 +++++++++++++++--------- src/sci/impl/resolve.cljc | 2 +- test/sci/interop_test.cljc | 3 +++ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b8da179..a6cbbb22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/deps.edn b/deps.edn index 507b9b14..d7775d32 100644 --- a/deps.edn +++ b/deps.edn @@ -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 diff --git a/src/sci/impl/analyzer.cljc b/src/sci/impl/analyzer.cljc index 7b7b6f66..1a4ab2c7 100644 --- a/src/sci/impl/analyzer.cljc +++ b/src/sci/impl/analyzer.cljc @@ -1563,10 +1563,16 @@ (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) @@ -1574,12 +1580,12 @@ (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) diff --git a/src/sci/impl/resolve.cljc b/src/sci/impl/resolve.cljc index 73355020..4d8039ac 100644 --- a/src/sci/impl/resolve.cljc +++ b/src/sci/impl/resolve.cljc @@ -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))))) diff --git a/test/sci/interop_test.cljc b/test/sci/interop_test.cljc index b452911a..af46a456 100644 --- a/test/sci/interop_test.cljc +++ b/test/sci/interop_test.cljc @@ -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)))))