                    (map (fn [[k v]]
                           [(if (symbol? k) (str (comp/munge k)) k) v])
                      (:closure-defines opts)))))
-        {:keys [libs foreign-libs externs]} (get-upstream-deps)]
+        {:keys [libs foreign-libs externs]} (get-upstream-deps)
+        emit-constants (or (and (= optimizations :advanced)
+                                (not (false? (:optimize-constants opts))))
+                           (:optimize-constants opts))]
     (cond->
       (-> opts
         (assoc

  ([source opts compiler-env]
     (env/with-compiler-env compiler-env
       (let [compiler-stats (:compiler-stats opts)
             all-opts (add-implicit-options opts)
             emit-constants (or (and (= (:optimizations opts) :advanced)
                                     (not (false? (:optimize-constants opts))))
                                (:optimize-constants opts))]
         (check-output-to opts)
         (check-output-dir opts)
         (check-source-map opts)

                                        [(-compile (io/resource "cljs/nodejs.cljs") all-opts)])))
                                  (when (= :nodejs (:target all-opts))
                                    [(-compile (io/resource "cljs/nodejscli.cljs") all-opts)]))))
                 _ (when (:emit-constants all-opts)
                     (comp/emit-constants-table-to-file
                       (::ana/constant-table @env/*compiler*)
                       (str (util/output-directory all-opts) "/constants_table.js")))
