Skip to content

Commit 20a6e1f

Browse files
anmonteirodnolen
authored andcommitted
CLJS-2312: Miss-compile: Uncaught SyntaxError: Unexpected token default
1 parent 8e4f49d commit 20a6e1f

File tree

5 files changed

+28
-24
lines changed

5 files changed

+28
-24
lines changed

src/main/cljs/cljs/pprint.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,7 @@ of parameters as well."
25372537

25382538
(merge ; create the result map
25392539
(into (array-map) ; start with the default values, make sure the order is right
2540-
(reverse (for [[name [default-def]] (:params def)] [name [default-def offset]])))
2540+
(reverse (for [[name [default]] (:params def)] [name [default offset]])))
25412541
(reduce #(apply assoc %1 %2) {} (filter #(first (nth % 1)) (zipmap (keys (:params def)) params))) ; add the specified parameters, filtering out nils
25422542
flags)); and finally add the flags
25432543

src/main/cljs/cljs/stacktrace.cljc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,11 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
576576
(second (first columns)))))
577577
(adjust [mapped]
578578
(vec (map #(%1 %2) [inc inc identity] mapped)))]
579-
(let [default-ret [line column nil]]
579+
(let [default [line column nil]]
580580
;; source maps are 0 indexed for lines
581581
(if-let [columns (get source-map (dec line))]
582582
(adjust (map (get-best-column columns column) [:line :col :name]))
583-
default-ret)))))
583+
default)))))
584584

585585
(defn mapped-frame
586586
"Given opts and a canonicalized JavaScript stacktrace frame, return the
@@ -689,4 +689,4 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
689689
:line 6
690690
:column 0}]
691691
sms {:output-dir "samples/hello/out"})
692-
)
692+
)

src/main/cljs/cljs/test.cljs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@
386386
first)))
387387

388388
(defn mapped-line-and-column [filename line column]
389-
(let [default-ret [filename line column]]
389+
(let [default [filename line column]]
390390
(if-let [source-map (:source-map (get-current-env))]
391391
;; source maps are 0 indexed for lines
392392
(if-let [columns (get-in source-map [filename (dec line)])]
@@ -400,8 +400,8 @@
400400
mapping
401401
(second (first columns))))
402402
[:source :line :col]))
403-
default-ret)
404-
default-ret)))
403+
default)
404+
default)))
405405

406406
(defn file-and-line [exception depth]
407407
;; TODO: flesh out
@@ -439,7 +439,7 @@
439439
(defn run-block
440440
"Invoke all functions in fns with no arguments. A fn can optionally
441441
return
442-
442+
443443
an async test - is invoked with a continuation running left fns
444444
445445
a seq of fns tagged per block - are invoked immediately after fn"

src/main/clojure/cljs/analyzer.cljc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,14 +1359,14 @@
13591359
:children [test-expr then-expr else-expr]}))
13601360

13611361
(defmethod parse 'case*
1362-
[op env [_ sym tests thens default-clause :as form] name _]
1362+
[op env [_ sym tests thens default :as form] name _]
13631363
(assert (symbol? sym) "case* must switch on symbol")
13641364
(assert (every? vector? tests) "case* tests must be grouped in vectors")
13651365
(let [expr-env (assoc env :context :expr)
13661366
v (disallowing-recur (analyze expr-env sym))
13671367
tests (mapv #(mapv (fn [t] (analyze expr-env t)) %) tests)
13681368
thens (mapv #(analyze env %) thens)
1369-
default-clause (analyze env default-clause)]
1369+
default (analyze env default)]
13701370
(assert (every? (fn [t]
13711371
(or
13721372
(-> t :info :const)
@@ -1375,8 +1375,8 @@
13751375
(apply concat tests))
13761376
"case* tests must be numbers, strings, or constants")
13771377
{:env env :op :case* :form form
1378-
:v v :tests tests :thens thens :default default-clause
1379-
:children (vec (concat [v] tests thens (if default-clause [default-clause])))}))
1378+
:v v :tests tests :thens thens :default default
1379+
:children (vec (concat [v] tests thens (if default [default])))}))
13801380

13811381
(defmethod parse 'throw
13821382
[op env [_ throw :as form] name _]
@@ -1415,9 +1415,9 @@
14151415
finally (when (seq fblock)
14161416
(analyze (assoc env :context :statement) `(do ~@(rest fblock))))
14171417
e (when (or (seq cblocks) dblock) (gensym "e"))
1418-
default-block (if-let [[_ _ name & cb] dblock]
1419-
`(cljs.core/let [~name ~e] ~@cb)
1420-
`(throw ~e))
1418+
default (if-let [[_ _ name & cb] dblock]
1419+
`(cljs.core/let [~name ~e] ~@cb)
1420+
`(throw ~e))
14211421
cblock (if (seq cblocks)
14221422
`(cljs.core/cond
14231423
~@(mapcat
@@ -1426,8 +1426,8 @@
14261426
`[(cljs.core/instance? ~type ~e)
14271427
(cljs.core/let [~name ~e] ~@cb)])
14281428
cblocks)
1429-
:else ~default-block)
1430-
default-block)
1429+
:else ~default)
1430+
default)
14311431
locals (:locals catchenv)
14321432
locals (if e
14331433
(assoc locals e

src/main/clojure/cljs/compiler.cljc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,20 @@
349349
(let [js-module-name (get-in cenv [:js-module-index (name var-name) :name])]
350350
(or js-module-name (name var-name)))
351351
info)]
352-
; We need a way to write bindings out to source maps and javascript
353-
; without getting wrapped in an emit-wrap calls, otherwise we get
354-
; e.g. (function greet(return x, return y) {}).
352+
;; We need a way to write bindings out to source maps and javascript
353+
;; without getting wrapped in an emit-wrap calls, otherwise we get
354+
;; e.g. (function greet(return x, return y) {}).
355355
(if (:binding-form? ast)
356-
; Emit the arg map so shadowing is properly handled when munging
357-
; (prevents duplicate fn-param-names)
356+
;; Emit the arg map so shadowing is properly handled when munging
357+
;; (prevents duplicate fn-param-names)
358358
(emits (munge ast))
359359
(when-not (= :statement (:context env))
360360
(let [reserved (cond-> js-reserved
361-
(es5>= (:language-out options))
361+
(and (es5>= (:language-out options))
362+
;; we can skip munging things like `my.ns.default`
363+
;; but not standalone `default` variable names
364+
;; as they're not valid ES5 - Antonio
365+
(some? (namespace var-name)))
362366
(set/difference ana/es5-allowed))]
363367
(emit-wrap env
364368
(emits
@@ -1045,7 +1049,7 @@
10451049

10461050
keyword?
10471051
(emits f ".cljs$core$IFn$_invoke$arity$" (count args) "(" (comma-sep args) ")")
1048-
1052+
10491053
variadic-invoke
10501054
(let [mfa (:max-fixed-arity variadic-invoke)]
10511055
(emits f "(" (comma-sep (take mfa args))

0 commit comments

Comments
 (0)