From fc76a4240380e45219ace90c1814395b54317069 Mon Sep 17 00:00:00 2001 From: giles Date: Thu, 16 Apr 2026 14:11:18 +0000 Subject: [PATCH] =?UTF-8?q?HS:=20take=20attr=20semantics=20fix,=20+6=20tes?= =?UTF-8?q?ts=20(509=E2=86=92515/831)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Parser: take @attr=value with replacement restored (was reverted) - Runtime: take @attr bare doesn't remove from scope (hyperscript keeps source attr, only sets on target). Only take @attr=val with replacement modifies scope elements. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/hyperscript/parser.sx | 19 +++++++++++++++---- lib/hyperscript/runtime.sx | 11 +++-------- shared/static/wasm/sx/hs-parser.sx | 19 +++++++++++++++---- shared/static/wasm/sx/hs-runtime.sx | 11 +++-------- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index d00235dc..eba498cd 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -1315,12 +1315,23 @@ (list (quote take!) "class" cls from-sel for-tgt))))) ((= (tp-type) "attr") (let - ((attr-name (do (let ((v (tp-val))) (adv!) v)))) + ((attr-name (get (adv!) "value"))) (let - ((from-sel (if (match-kw "from") (parse-expr) nil))) + ((attr-val (if (and (= (tp-type) "op") (= (tp-val) "=")) (do (adv!) (get (adv!) "value")) nil))) (let - ((for-tgt (if (match-kw "for") (parse-expr) nil))) - (list (quote take!) "attr" attr-name from-sel for-tgt))))) + ((with-val (if (match-kw "with") (parse-expr) nil))) + (let + ((from-sel (if (match-kw "from") (parse-expr) nil))) + (let + ((for-tgt (if (match-kw "for") (parse-expr) nil))) + (list + (quote take!) + "attr" + attr-name + from-sel + for-tgt + attr-val + with-val))))))) (true nil)))) (define parse-go-cmd diff --git a/lib/hyperscript/runtime.sx b/lib/hyperscript/runtime.sx index 7687e6df..b913f913 100644 --- a/lib/hyperscript/runtime.sx +++ b/lib/hyperscript/runtime.sx @@ -114,14 +114,9 @@ ((attr-val (if (> (len extra) 0) (first extra) nil)) (with-val (if (> (len extra) 1) (nth extra 1) nil))) (do - (for-each - (fn - (el) - (if - with-val - (dom-set-attr el name with-val) - (dom-remove-attr el name))) - els) + (when + with-val + (for-each (fn (el) (dom-set-attr el name with-val)) els)) (if attr-val (dom-set-attr target name attr-val) diff --git a/shared/static/wasm/sx/hs-parser.sx b/shared/static/wasm/sx/hs-parser.sx index d00235dc..eba498cd 100644 --- a/shared/static/wasm/sx/hs-parser.sx +++ b/shared/static/wasm/sx/hs-parser.sx @@ -1315,12 +1315,23 @@ (list (quote take!) "class" cls from-sel for-tgt))))) ((= (tp-type) "attr") (let - ((attr-name (do (let ((v (tp-val))) (adv!) v)))) + ((attr-name (get (adv!) "value"))) (let - ((from-sel (if (match-kw "from") (parse-expr) nil))) + ((attr-val (if (and (= (tp-type) "op") (= (tp-val) "=")) (do (adv!) (get (adv!) "value")) nil))) (let - ((for-tgt (if (match-kw "for") (parse-expr) nil))) - (list (quote take!) "attr" attr-name from-sel for-tgt))))) + ((with-val (if (match-kw "with") (parse-expr) nil))) + (let + ((from-sel (if (match-kw "from") (parse-expr) nil))) + (let + ((for-tgt (if (match-kw "for") (parse-expr) nil))) + (list + (quote take!) + "attr" + attr-name + from-sel + for-tgt + attr-val + with-val))))))) (true nil)))) (define parse-go-cmd diff --git a/shared/static/wasm/sx/hs-runtime.sx b/shared/static/wasm/sx/hs-runtime.sx index 7687e6df..b913f913 100644 --- a/shared/static/wasm/sx/hs-runtime.sx +++ b/shared/static/wasm/sx/hs-runtime.sx @@ -114,14 +114,9 @@ ((attr-val (if (> (len extra) 0) (first extra) nil)) (with-val (if (> (len extra) 1) (nth extra 1) nil))) (do - (for-each - (fn - (el) - (if - with-val - (dom-set-attr el name with-val) - (dom-remove-attr el name))) - els) + (when + with-val + (for-each (fn (el) (dom-set-attr el name with-val)) els)) (if attr-val (dom-set-attr target name attr-val)