HS: take attr semantics fix, +6 tests (509→515/831)

- 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) <noreply@anthropic.com>
This commit is contained in:
2026-04-16 14:11:18 +00:00
parent 6bd45daed6
commit fc76a42403
4 changed files with 36 additions and 24 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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)