Skip to content

Commit

Permalink
Fix issue with cljs not running because of the mock analyzer file
Browse files Browse the repository at this point in the history
Background - I made this change so that uers can exclude clojurescript
as a dependency if they are only using it for clojure but that caused a
lot of problems. I guess the only way to get it to work is to have them
as separate jars
  • Loading branch information
AbhinavOmprakash committed Jan 11, 2025
1 parent d742465 commit fdae1df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 36 deletions.
17 changes: 0 additions & 17 deletions src/snitch/analyzer.cljc

This file was deleted.

30 changes: 15 additions & 15 deletions src/snitch/core.cljc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns snitch.core
(:refer-clojure :exclude [#?(:cljs macroexpand)])
(:require
[clojure.string :as s]
[snitch.analyzer :as ana])
[cljs.analyzer :as ana]
[clojure.string :as s])
#?(:cljs
(:require-macros
[snitch.core])))
Expand Down Expand Up @@ -116,7 +116,7 @@


(defn cc-destructure
"A slightly modified version of clj and cljs' destructure to
"A slightly modified version of clj and cljs' destructure to
work with clj and cljs."
[bindings]
(let [bents (partition 2 bindings)
Expand Down Expand Up @@ -244,8 +244,8 @@
(defn insert-into-let
([bindings]
(reduce (fn [acc [var* value]]
;; if the var is introduced by
;; clojure's destructuring it makes
;; if the var is introduced by
;; clojure's destructuring it makes
;; no sense to globally define it, since no one
;; will know about it, and its wasteful.
(if (autogensym? var*)
Expand All @@ -263,7 +263,7 @@


(defn define-let-bindings
"injects inline defs inside let bindings, and adds metadata indicating
"injects inline defs inside let bindings, and adds metadata indicating
that the form contains inline defs.
This is to prevent let forms from repeatedly being passed to `insert-into-let`.
"
Expand Down Expand Up @@ -312,11 +312,11 @@
(defn namespaced-destructuring
"namespaced maps can be destructured in two ways.
[{:keys [a/b]}] #:a{:b 1}
or
or
[{:a/keys [b]}] #:a{:b 1}
This function handles the 2nd case.
Converts the 2nd case to the first case
This function handles the 2nd case.
Converts the 2nd case to the first case
"
[k v]
(let [v* (mapv (fn [sym]
Expand All @@ -327,9 +327,9 @@

(def preserve-symbol?
"Certain values will get printed in a way that's not readable.
for e.g functions when evaluated return function Objects
like this -
identity
for e.g functions when evaluated return function Objects
like this -
identity
;=> #function[clojure.core/identity]
These can't be evaluated, so we preserve the symbol as it is.
"
Expand Down Expand Up @@ -406,7 +406,7 @@
;; There is some hairy quoting going on here so let me explain
;; let's say we have a function (defn* foo [x] x)
;; and I call it (foo 1)
;; what I want from `replay-function` is to define a
;; what I want from `replay-function` is to define a
;; var such that when I evaluate it, it returns me a list (foo 1)
;; that I can evaluate.
;; notice that here foo is a symbol but 1 is the value of the symbol x
Expand Down Expand Up @@ -437,7 +437,7 @@
(or (vector? (:pre (first forms)))
(vector? (:post (first forms))))
;; test for (rest form)
;; because the map shouldn't be treated
;; because the map shouldn't be treated
;; as a prep-post map IFF there is no body
;; since a fn can't exist without a body
(seq (rest forms))))
Expand Down Expand Up @@ -491,7 +491,7 @@


(defmacro defn*
"Like the defn macro but injects inline defs for the arguments
"Like the defn macro but injects inline defs for the arguments
and any let bindings, or lambdas inside it."
[name & forms]

Expand Down
9 changes: 5 additions & 4 deletions test/snitch/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@

(testing "prep-post map identification works correctly for variadic args"
;; This exists because define-in-variadic-forms
;; treated any map in the body as a prepost-map?
;; treated any map in the body as a prepost-map?
;; instead of checking whether there was a body or not
(let [_ (defn* foo7
([a] {:a a})
Expand All @@ -185,10 +185,11 @@
(let [_ (defn* foo9 ([b]
{:pre [(even? b)]}
b))]
;; AssertionError is thrown when
;; prep-post maps are correctly recognised
;; AssertionError is thrown when
;; prep-post maps are correctly recognised
;; because 1 is odd
(is (thrown? AssertionError (foo9 1)))
#?(:clj (is (thrown? AssertionError (foo9 1)))
:cljs (is (thrown? js/Error (foo9 1))))
(is (= 2 (foo9 2)))))

;; FIXME commenting out the history feature because it doesn't work in cljs yet.
Expand Down

0 comments on commit fdae1df

Please sign in to comment.