anmonteiro / lumo

Fast, cross-platform, standalone ClojureScript environment
Eclipse Public License 1.0
1.89k stars 84 forks source link

cljs.js/compile-str doesn't require cljs.core #172

Open raoofha opened 7 years ago

raoofha commented 7 years ago

I'm working on a toy tool and found this bug

cljs.user=> (cljs.js/compile-str (cljs.js/empty-state) "(print \"yes\")" #(println (:value %)))
WARNING: Use of undeclared Var cljs.user/print at line 1 
cljs.user.print.call(null,"yes");

it should be cljs.core.print.call(null,"yes");

anmonteiro commented 7 years ago

To make startup faster we lazy-load the core analysis caches in Lumo, which means that cljs.js/empty-state won't know about cljs.core. I see 2 ways of solving your problem:

I'll leave the issue open in any case because we could either document this better or provide easier hooks for people doing stuff with cljs.js in Lumo.

mfikes commented 7 years ago

FWIW, Planck has a solution for this that Lumo could consider:

cljs.user=> (require 'cljs.js '[planck.core :refer [init-empty-state]])
nil
cljs.user=> (cljs.js/compile-str (cljs.js/empty-state init-empty-state) "(print \"yes\")" #(println (:value %)))
cljs.core.print.call(null,"yes");

nil
cljs.user=> (doc init-empty-state)
-------------------------
planck.core/init-empty-state
([state])
  An init function for use with cljs.js/empty-state which initializes the
  empty state with cljs.core analysis metadata.

  This is useful because Planck is built with :dump-core set to false.

  Usage: (cljs.js/empty-state init-empty-state)
Spec
 args: (cat :state map?)
 ret: map?
nil