Skip to content

Commit b2df2c2

Browse files
jonaseswannodette
authored andcommitted
Warn on invalid js forms. refs #455
1 parent ea95d83 commit b2df2c2

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

samples/twitterbuzz/src/twitterbuzz/anneal.cljs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
(ns twitterbuzz.anneal)
1010

1111
(defn exp [x]
12-
(js/Math.exp x))
12+
(.exp js/Math x))
1313

1414
(defn abs [x]
15-
(js/Math.abs x))
15+
(.abs js/Math x))
1616

1717
(defn random []
18-
(js/Math.random))
18+
(.random js/Math))
1919

2020
(defn standard-prob [e e1 temp]
2121
(if (< e1 e)

samples/twitterbuzz/src/twitterbuzz/layout.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
(* x x))
1919

2020
(defn sqrt [x]
21-
(js/Math.sqrt x))
21+
(.sqrt js/Math x))
2222

2323
(defn dist [{x1 :x y1 :y} {x2 :x y2 :y}]
2424
(sqrt (+ (sqr (- x2 x1)) (sqr (- y2 y1)))))

samples/twitterbuzz/src/twitterbuzz/showgraph.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
(+ (* unit-arg (- canvas-size avatar-size)) (/ avatar-size 2)))
4646

4747
(defn log [& args]
48-
(js/console.log (apply pr-str args)))
48+
(.log js/console (apply pr-str args)))
4949

5050
(def avatar-hover
5151
(doto

src/clj/cljs/analyzer.clj

+3-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@
151151
([env sym] (resolve-var env sym nil))
152152
([env sym confirm]
153153
(if (= (namespace sym) "js")
154-
{:name sym :ns 'js}
154+
(do (when (some #{\.} (-> sym name str))
155+
(warning env (str "Invalid js form " sym)))
156+
{:name sym :ns 'js})
155157
(let [s (str sym)
156158
lb (-> env :locals sym)]
157159
(cond

src/cljs/cljs/core.cljs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,7 @@ reduces them without incurring seq initialization"
18001800
([this coll not-found]
18011801
(get coll (.toString this) not-found))))
18021802

1803-
(set! js/String.prototype.apply
1803+
(set! (.-apply (.-prototype js/String))
18041804
(fn
18051805
[s args]
18061806
(if (< (count args) 2)
@@ -6025,7 +6025,7 @@ reduces them without incurring seq initialization"
60256025
(-count [rng]
60266026
(if-not (-seq rng)
60276027
0
6028-
(js/Math.ceil (/ (- end start) step))))
6028+
(.ceil js/Math (/ (- end start) step))))
60296029

60306030
IIndexed
60316031
(-nth [rng n]
@@ -6049,7 +6049,7 @@ reduces them without incurring seq initialization"
60496049
"Returns a lazy seq of nums from start (inclusive) to end
60506050
(exclusive), by step, where start defaults to 0, step to 1,
60516051
and end to infinity."
6052-
([] (range 0 js/Number.MAX_VALUE 1))
6052+
([] (range 0 (.-MAX_VALUE js/Number) 1))
60536053
([end] (range 0 end 1))
60546054
([start end] (range start end 1))
60556055
([start end step] (Range. nil start end step nil)))

0 commit comments

Comments
 (0)