Skip to content

Commit efba36a

Browse files
committed
More fixes for #987
1 parent bd3555c commit efba36a

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/sci/impl/analyzer.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@
957957
(subs method-name 1)
958958
method-name)
959959
meth-name* meth-name
960-
meth-name (munge meth-name)
960+
meth-name (#?(:clj munge :cljs utils/munge-str) meth-name)
961961
stack (assoc (meta expr)
962962
:ns @utils/current-ns
963963
:file @utils/current-file)]

src/sci/impl/utils.cljc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
{:no-doc true}
33
(:refer-clojure :exclude [eval demunge var? macroexpand macroexpand-1])
44
(:require [clojure.string :as str]
5+
#?(:cljs [goog.object :as gobject])
56
[sci.impl.macros :as macros]
67
[sci.impl.types :as t]
78
[sci.impl.vars :as vars]
89
[sci.lang :as lang])
10+
#?(:cljs (:import [goog.string StringBuffer]))
911
#?(:cljs (:require-macros [sci.impl.utils :refer [kw-identical? dotimes+]])))
1012

1113
#?(:clj (set! *warn-on-reflection* true))
@@ -307,3 +309,16 @@
307309
'*unchecked-math* clojure.core/*unchecked-math*
308310
{:ns clojure-core-ns
309311
:doc "While bound to true, compilations of +, -, *, inc, dec and the\n coercions will be done without overflow checks. While bound\n to :warn-on-boxed, same behavior as true, and a warning is emitted\n when compilation uses boxed math. Default: false."})))
312+
313+
#?(:cljs
314+
(defn ^string munge-str [name]
315+
(let [sb (StringBuffer.)]
316+
(loop [i 0]
317+
(when (< i (. name -length))
318+
(let [c (.charAt name i)
319+
sub (gobject/get CHAR_MAP c)]
320+
(if-not (nil? sub)
321+
(.append sb sub)
322+
(.append sb c))
323+
(recur (inc i)))))
324+
(.toString sb))))

test/sci/interop_test.cljc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@
397397
(deftest issue-987-munged-property-name-test
398398
(is (= 1 (sci/eval-string "(def x #js {:foo_bar 1}) (.-foo-bar x)" {:classes {:allow :all}})))
399399
(is (= 1 (sci/eval-string "(def x #js {:foo_bar (fn [] 1)}) (.foo-bar x)" {:classes {:allow :all}})))
400+
(testing "reserved keyword mungined is bypassed"
401+
(is (= 1 (sci/eval-string "(def x #js {:catch (fn [] 1)}) (.catch x)" {:classes {:allow :all}}))))
400402
(is (= {:foo_bar 1} (sci/eval-string "(js->clj (doto #js {} (set! -foo-bar 1)) :keywordize-keys true)" {:classes {:allow :all}})))))
401403

402404
#?(:clj

0 commit comments

Comments
 (0)