HS: when :count changes — scoped watch + parse-cmd feature boundary fix
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 47s

Three-part fix for element-scoped reactive expressions:

1. Parser: add when/bind to parse-cmd's feature-keyword nil set so
   `... then when X changes ...` is parsed as a new feature, not absorbed
   into the preceding on-handler body as a (ref "when") expression.

2. Parser: parse-when-feat now recognises local (:var) token type so
   `when :count changes ...` dispatches to the when-changes branch.

3. Runtime + compiler: hs-scoped-set! now fires hs-scoped-fire-watchers!
   on change; new hs-scoped-watch! / hs-scoped-fire-watchers! registry;
   compiler emits (hs-scoped-watch! me name (fn (it) body)) for local
   expressions in when-changes AST nodes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-05 02:59:15 +00:00
parent abbb1fe5c6
commit e7169af985
6 changed files with 144 additions and 42 deletions

View File

@@ -2356,14 +2356,26 @@
((= head (quote when-changes))
(let
((expr (nth ast 1)) (body (nth ast 2)))
(if
(and (list? expr) (= (first expr) (quote dom-ref)))
(list
(quote hs-dom-watch!)
(hs-to-sx (nth expr 2))
(nth expr 1)
(list (quote fn) (list (quote it)) (hs-to-sx body)))
nil)))
(cond
((and (list? expr) (= (first expr) (quote dom-ref)))
(list
(quote hs-dom-watch!)
(hs-to-sx (nth expr 2))
(nth expr 1)
(list
(quote fn)
(list (quote it))
(hs-to-sx body))))
((and (list? expr) (= (first expr) (quote local)))
(list
(quote hs-scoped-watch!)
(quote me)
(nth expr 1)
(list
(quote fn)
(list (quote it))
(hs-to-sx body))))
(true nil))))
((= head (quote init))
(list
(quote hs-init)