Skip to content

Commit 4228ee3

Browse files
committed
CLJS-109: Compiler errors/warnings should be displayed when cljs namespace 'package' names start with an unacceptable javascript symbol
throw on invalid ns names
1 parent 7c62704 commit 4228ee3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/clj/cljs/analyzer.clj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,11 @@
14361436
(warning :single-segment-namespace env {:name name}))
14371437
(when (some js-reserved segments)
14381438
(warning :munged-namespace env {:name name}))
1439-
(find-def-clash env name segments))
1439+
(find-def-clash env name segments)
1440+
(when (some (complement util/valid-js-id-start?) segments)
1441+
(throw (AssertionError.
1442+
(str "Namespace " name " has a segment starting with an invaild "
1443+
"JavaScript identifier")))))
14401444
(let [docstring (if (string? (first args)) (first args))
14411445
mdocstr (-> name meta :doc)
14421446
args (if docstring (next args) args)

src/clj/cljs/util.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@
126126
(when (= depth 0)
127127
(distinct (apply concat (vals @state)))))))
128128

129+
(defn valid-js-id-start? [s]
130+
(re-find #"(?U)^[\p{Alpha}_$]" s))
131+
129132
(defn debug-prn
130133
[& args]
131134
(binding [*out* *err*]

0 commit comments

Comments
 (0)