Skip to content

Commit

Permalink
Exclude overriden keys from dynamic map
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed May 24, 2024
1 parent 75893fc commit 6bcfef4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
67 changes: 36 additions & 31 deletions src/squint/compiler_common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1049,37 +1049,42 @@ break;}" body)
(when v
(emit v (dissoc env :jsx)))
(if (seq v)
(str
" "
(str/join " "
(map
(fn [[k v]]
(let [str? (string? v)]
(if (= :& k)
(if html?
(do
(when-let [dyn (:has-dynamic-expr env)]
(reset! dyn true))
(format "${squint_html.attrs(%s)}" (emit v (dissoc env :jsx))))
(str "{..." (emit v (dissoc env :jsx)) "}"))
(str (name k) "="
(let [env env]
(cond
(and html? (map? v))
(emit-css v env)
#_#_(and html? (vector? v))
(-> (str/join " " (map #(emit % env) v))
(wrap-double-quotes))
:else
(cond-> (emit v (assoc env :jsx false))
(not str?)
;; since we escape here, we
;; can probably remove
;; escaping elsewhere?
(escape-jsx env)
(and html? (not str?))
(wrap-double-quotes))))))))
v)))
(let [v* v]
(str
" "
(str/join " "
(map
(fn [[k v]]
(let [str? (string? v)]
(if (= :& k)
(if html?
(do
(when-let [dyn (:has-dynamic-expr env)]
(reset! dyn true))
(format "${squint_html.attrs(%s,%s)}" (emit v (dissoc env :jsx))
(format "new Set([%s])" (str/join "," (map (comp wrap-double-quotes
#(subs % 1)
str)
(disj (set (keys v*)) :&))))))
(str "{..." (emit v (dissoc env :jsx)) "}"))
(str (name k) "="
(let [env env]
(cond
(and html? (map? v))
(emit-css v env)
#_#_(and html? (vector? v))
(-> (str/join " " (map #(emit % env) v))
(wrap-double-quotes))
:else
(cond-> (emit v (assoc env :jsx false))
(not str?)
;; since we escape here, we
;; can probably remove
;; escaping elsewhere?
(escape-jsx env)
(and html? (not str?))
(wrap-double-quotes))))))))
v))))
""))))

(defmethod emit-special 'squint.defclass/defclass* [_ env form]
Expand Down
4 changes: 3 additions & 1 deletion src/squint/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ function css(v) {
return ret;
}

export function attrs(v) {
export function attrs(v, exclude) {
let ret = "";
if (v == null) return ret;
let first = true;
for (const kv of Object.entries(v)) {
if (!first) {
ret += ' ';
}
const k = kv[0];
if (exclude.has(k)) continue;
ret += kv[0];
ret += "=";
ret += '"';
Expand Down

0 comments on commit 6bcfef4

Please sign in to comment.