Skip to content

Commit 7b4ae36

Browse files
Metadata handling fixes in analyzer for #488 and #489 (#491)
* Be resilient in face of unrecognized type tags closes #488 * Strip metadata from forms before printing them to hash closes #489
1 parent 8b21c48 commit 7b4ae36

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/nextjournal/clerk/analyzer.clj

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
[clojure.tools.analyzer.ast :as ana-ast]
1313
[clojure.tools.analyzer.jvm :as ana-jvm]
1414
[clojure.tools.analyzer.utils :as ana-utils]
15+
[clojure.walk :as walk]
1516
[multiformats.base.b58 :as b58]
1617
[multiformats.hash :as hash]
1718
[nextjournal.clerk.parser :as parser]
@@ -113,8 +114,12 @@
113114
(defn unresolvable-symbol-handler [ns sym ast-node]
114115
ast-node)
115116

117+
(defn wrong-tag-handler [tag ast-node]
118+
ast-node)
119+
116120
(def analyzer-passes-opts
117121
(assoc ana-jvm/default-passes-opts
122+
:validate/wrong-tag-handler wrong-tag-handler
118123
:validate/unresolvable-symbol-handler unresolvable-symbol-handler))
119124

120125
(defn form->ex-data
@@ -544,12 +549,21 @@
544549
#_(dep/immediate-dependencies (:graph (build-graph "src/nextjournal/clerk/analyzer.clj")) #'nextjournal.clerk.analyzer/long-thing)
545550
#_(dep/transitive-dependencies (:graph (build-graph "src/nextjournal/clerk/analyzer.clj")) #'nextjournal.clerk.analyzer/long-thing)
546551

552+
(defn strip-form-meta [form]
553+
(clojure.walk/postwalk
554+
(fn [v]
555+
(if (or (instance? clojure.lang.IObj v)
556+
(instance? clojure.lang.IMeta v))
557+
(vary-meta v (constantly nil))
558+
v))
559+
form))
560+
547561
(defn hash-codeblock [->hash {:as codeblock :keys [hash form id deps vars]}]
548562
(when (and (seq deps) (not (ifn? ->hash)))
549563
(throw (ex-info "`->hash` must be `ifn?`" {:->hash ->hash :codeblock codeblock})))
550564
(let [hashed-deps (into #{} (map ->hash) deps)]
551565
(sha1-base58 (binding [*print-length* nil]
552-
(pr-str (set/union (conj hashed-deps (if form form hash))
566+
(pr-str (set/union (conj hashed-deps (if form (strip-form-meta form) hash))
553567
vars))))))
554568

555569
(defn hash

0 commit comments

Comments
 (0)