<commit_before>(ns daiquiri.compiler
  (:require [daiquiri.normalize :as normalize]
            [daiquiri.util :refer :all]
            [clojure.set :as set]
            [cljs.analyzer :as ana]))

(def warn-on-interpretation (atom false))

(defn maybe-warn-on-interpret
  ([env expr]
   (maybe-warn-on-interpret env expr nil))
  ([env expr tag]
   (when @warn-on-interpretation
     (binding [*out* *err*]
       (let [column (:column env)
             line (:line env)]
         (println (str "WARNING: interpreting by default at " ana/*cljs-file* ":" line ":" column))
         (prn expr)
         (when tag
           (println "Inferred tag was:" tag)))))))

(def ^:private primitive-types
  "The set of primitive types that can be handled by React."
  #{'js 'clj-nil 'js/React.Element
    'number 'string 'boolean 'symbol
    'array 'function})

(defn- primitive-type?
  "Return true if `tag` is a primitive type that can be handled by
  React, otherwise false. "
  [tags]
  (and (not (empty? tags))
       (set/subset? tags primitive-types)))

(defn- normalize-tags [tags]
  (if (set? tags) tags (set [tags])))

(defn infer-tag
  "Infer the tag of `form` using `env`."
  [env form]
  (when env
    (let [e (ana/no-warn (ana/analyze env form))
          ;; Roman. Propagating Rum's component return tag
          ;; via :rum/tag meta field, because a component
          ;; is generated as a `def` instead of `defn`
          rum-tag (when (= :invoke (:op e))
                    (-> e :fn :info :meta :rum/tag second))]
      (if rum-tag
        (normalize-tags rum-tag)
        (when-let [tags (ana/infer-tag env e)]
          (normalize-tags tags))))))<commit_msg>defer requiring cljs.analyzer, resolves #222<commit_after>(ns daiquiri.compiler
  (:require [daiquiri.normalize :as normalize]
            [daiquiri.util :refer :all]
            [clojure.set :as set]))

(def warn-on-interpretation (atom false))

(defn- requiring-resolve [sym]
  (or (resolve sym)
      (do (require (-> sym namespace symbol))
          (resolve sym))))

(defn maybe-warn-on-interpret
  ([env expr]
   (maybe-warn-on-interpret env expr nil))
  ([env expr tag]
   (when @warn-on-interpretation
     (binding [*out* *err*]
       (let [column (:column env)
             line (:line env)]
         (require 'cljs.analyzer)
         (println (str "WARNING: interpreting by default at " (requiring-resolve 'cljs.analyzer/*cljs-file*) ":" line ":" column))
         (prn expr)
         (when tag
           (println "Inferred tag was:" tag)))))))

(def ^:private primitive-types
  "The set of primitive types that can be handled by React."
  #{'js 'clj-nil 'js/React.Element
    'number 'string 'boolean 'symbol
    'array 'function})

(defn- primitive-type?
  "Return true if `tag` is a primitive type that can be handled by
  React, otherwise false. "
  [tags]
  (and (not (empty? tags))
       (set/subset? tags primitive-types)))

(defn- normalize-tags [tags]
  (if (set? tags) tags (set [tags])))

(defn infer-tag
  "Infer the tag of `form` using `env`."
  [env form]
  (when env
    (let [e (with-bindings* {(requiring-resolve 'cljs.analyzer/*cljs-warnings*) {}}
              (fn []
                ((requiring-resolve 'cljs.analyzer/analyze) env form)))
          ;; Roman. Propagating Rum's component return tag
          ;; via :rum/tag meta field, because a component
          ;; is generated as a `def` instead of `defn`
          rum-tag (when (= :invoke (:op e))
                    (-> e :fn :info :meta :rum/tag second))]
      (if rum-tag
        (normalize-tags rum-tag)
        (when-let [tags ((requiring-resolve 'cljs.analyzer/infer-tag) env e)]
          (normalize-tags tags))))))
{'fraction_non_alphanumeric': 0.14514378730330982, 'fraction_numerical': 0.0008138903960933261, 'mean_word_length': 2.5080875356803043, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4707420', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1187, 'n_words': 383}