|
55 | 55 | (some #{(str name)} (ns-first-segments)) (inc d)
|
56 | 56 | :else d))))
|
57 | 57 |
|
| 58 | +(declare munge) |
| 59 | + |
| 60 | +(defn fn-self-name [{:keys [name info] :as name-var}] |
| 61 | + (let [{:keys [ns fn-scope]} info |
| 62 | + scoped-name (apply str |
| 63 | + (interpose "_$_" |
| 64 | + (concat (map (comp str :name) fn-scope) [name])))] |
| 65 | + (symbol |
| 66 | + (munge |
| 67 | + (str (string/replace (str ns) "." "$") |
| 68 | + "_SLASH_" scoped-name))))) |
| 69 | + |
58 | 70 | (defn munge
|
59 | 71 | ([s] (munge s js-reserved))
|
60 | 72 | ([s reserved]
|
61 |
| - (if (map? s) |
62 |
| - ; Unshadowing |
63 |
| - (let [{:keys [name field] :as info} s |
64 |
| - depth (shadow-depth s) |
65 |
| - renamed (*lexical-renames* (System/identityHashCode s)) |
66 |
| - munged-name (munge (cond field (str "self__." name) |
67 |
| - renamed renamed |
68 |
| - :else name) |
69 |
| - reserved)] |
70 |
| - (if (or field (zero? depth)) |
71 |
| - munged-name |
72 |
| - (symbol (str munged-name "__$" depth)))) |
73 |
| - ; String munging |
74 |
| - (let [ss (string/replace (str s) #"\/(.)" ".$1") ; Division is special |
75 |
| - ss (apply str (map #(if (reserved %) (str % "$") %) |
76 |
| - (string/split ss #"(?<=\.)|(?=\.)"))) |
77 |
| - ms (clojure.lang.Compiler/munge ss)] |
78 |
| - (if (symbol? s) |
79 |
| - (symbol ms) |
80 |
| - ms))))) |
| 73 | + (if (map? s) |
| 74 | + (let [{:keys [name field info] :as name-var} s] |
| 75 | + (if (:fn-self-name info) |
| 76 | + (fn-self-name s) |
| 77 | + ;; Unshadowing |
| 78 | + (let [depth (shadow-depth s) |
| 79 | + renamed (*lexical-renames* (System/identityHashCode s)) |
| 80 | + munged-name (munge |
| 81 | + (cond field (str "self__." name) |
| 82 | + renamed renamed |
| 83 | + :else name) |
| 84 | + reserved)] |
| 85 | + (if (or field (zero? depth)) |
| 86 | + munged-name |
| 87 | + (symbol (str munged-name "__$" depth)))))) |
| 88 | + ;; String munging |
| 89 | + (let [ss (string/replace (str s) #"\/(.)" ".$1") ; Division is special |
| 90 | + ss (apply str |
| 91 | + (map #(if (reserved %) (str % "$") %) |
| 92 | + (string/split ss #"(?<=\.)|(?=\.)"))) |
| 93 | + ms (clojure.lang.Compiler/munge ss)] |
| 94 | + (if (symbol? s) |
| 95 | + (symbol ms) |
| 96 | + ms))))) |
81 | 97 |
|
82 | 98 | (defn- comma-sep [xs]
|
83 | 99 | (interpose "," xs))
|
|
772 | 788 |
|
773 | 789 | ;; direct dispatch to variadic case
|
774 | 790 | (and variadic? (> arity mfa))
|
775 |
| - [(update-in f [:info :name] |
776 |
| - (fn [name] (symbol (str (munge info) ".cljs$core$IFn$_invoke$arity$variadic")))) |
| 791 | + [(update-in f [:info] |
| 792 | + (fn [info] |
| 793 | + (-> info |
| 794 | + (assoc :name (symbol (str (munge info) ".cljs$core$IFn$_invoke$arity$variadic"))) |
| 795 | + ;; bypass local fn-self-name munging, we're emitting direct |
| 796 | + (update-in [:info] dissoc :fn-self-name)))) |
777 | 797 | {:max-fixed-arity mfa}]
|
778 | 798 |
|
779 | 799 | ;; direct dispatch to specific arity case
|
780 | 800 | :else
|
781 | 801 | (let [arities (map count mps)]
|
782 | 802 | (if (some #{arity} arities)
|
783 |
| - [(update-in f [:info :name] |
784 |
| - (fn [name] (symbol (str (munge info) ".cljs$core$IFn$_invoke$arity$" arity)))) nil] |
| 803 | + [(update-in f [:info] |
| 804 | + (fn [info] |
| 805 | + (-> info |
| 806 | + (assoc :name (symbol (str (munge info) ".cljs$core$IFn$_invoke$arity$" arity))) |
| 807 | + ;; bypass local fn-self-name munging, we're emitting direct |
| 808 | + (update-in [:info] dissoc :fn-self-name)))) nil] |
785 | 809 | [f nil]))))
|
786 | 810 | [f nil])]
|
787 | 811 | (emit-wrap env
|
|
808 | 832 |
|
809 | 833 | :else
|
810 | 834 | (if (and ana/*cljs-static-fns* (= (:op f) :var))
|
| 835 | + ;; higher order case, static information missing |
811 | 836 | (let [fprop (str ".cljs$core$IFn$_invoke$arity$" (count args))]
|
812 | 837 | (emits "(" f fprop " ? " f fprop "(" (comma-sep args) ") : " f ".call(" (comma-sep (cons "null" args)) "))"))
|
813 | 838 | (emits f ".call(" (comma-sep (cons "null" args)) ")"))))))
|
|
1072 | 1097 | (if (.exists src-file)
|
1073 | 1098 | (try
|
1074 | 1099 | (let [{ns :ns :as ns-info} (ana/parse-ns src-file dest-file opts)
|
1075 |
| - opts (if (= ns 'cljs.core) (assoc opts :static-fns true) opts)] |
| 1100 | + opts (if (and (= ns 'cljs.core) |
| 1101 | + (not (false? (:static-fns opts)))) |
| 1102 | + (assoc opts :static-fns true) |
| 1103 | + opts)] |
1076 | 1104 | (if (requires-compilation? src-file dest-file opts)
|
1077 | 1105 | (do
|
1078 | 1106 | (util/mkdirs dest-file)
|
|
0 commit comments