Skip to content

Commit 6e7541b

Browse files
michaelballantynednolen
authored andcommitted
CLJS-1422: cljs.js/eval-str fails for ns form on node.js with simple optimizations
The special case of find-ns-obj for node.js under optimizations now guards the eval of the initial path segment, catching ReferenceError. This fixes eval-str of ns forms.
1 parent e8330a2 commit 6e7541b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10135,7 +10135,16 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."
1013510135
segs (.split munged-ns ".")]
1013610136
(case *target*
1013710137
"nodejs" (if ^boolean js/COMPILED
10138-
(js/eval munged-ns)
10138+
; Under simple optimizations on nodejs, namespaces will be in module
10139+
; rather than global scope and must be accessed by a direct call to eval.
10140+
; The first segment may refer to an undefined variable, so its evaluation
10141+
; may throw ReferenceError.
10142+
(find-ns-obj*
10143+
(try
10144+
(js/eval (first segs))
10145+
(catch js/ReferenceError e
10146+
nil))
10147+
(next segs))
1013910148
(find-ns-obj* js/global segs))
1014010149
"default" (find-ns-obj* goog/global segs)
1014110150
(throw (js/Error. (str "find-ns-obj not supported for target " *target*))))))

src/test/self/self_host/test.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
(is (nil? error))
125125
(is (== 3 value))
126126
(inc! l)))
127-
#_(cljs/eval-str st "(ns foo.bar)" nil
127+
(cljs/eval-str st "(ns foo.bar)" nil
128128
{:eval node-eval
129129
:context :expr
130130
:def-emits-var true}

0 commit comments

Comments
 (0)