HS trigger: compound event names + detail, event-refs via host-get

- parse-trigger-cmd: use parse-compound-event-name so 'trigger foo:bar' and
  'trigger foo.bar' preserve the full event name. Also parse an optional
  detail dict '(x:42)' like parse-send-cmd.
- compiler: 3-arg (trigger NAME DETAIL TGT) emits dom-dispatch with the
  detail dict. 2-arg (trigger NAME TGT) unchanged.
- emit-on event-ref bindings now use (host-get event 'detail') → the event
  carries detail as a JS object, so the SX 'get' primitive returned nil
  and tests checking 'on foo(x) … x' saw empty values.

Net: trigger 2→6 (100%).
This commit is contained in:
2026-04-23 17:22:25 +00:00
parent d6137f0d6f
commit 7ecdd59335
4 changed files with 46 additions and 18 deletions

View File

@@ -162,7 +162,7 @@
(let
((raw-compiled (hs-to-sx stripped-body)))
(let
((compiled-body (if (> (len event-refs) 0) (let ((bindings (map (fn (r) (let ((name (nth r 1))) (list (make-symbol name) (list (quote get) (list (quote get) (quote event) "detail") name)))) event-refs))) (list (quote let) bindings raw-compiled)) raw-compiled)))
((compiled-body (if (> (len event-refs) 0) (let ((bindings (map (fn (r) (let ((name (nth r 1))) (list (make-symbol name) (list (quote host-get) (list (quote host-get) (quote event) "detail") name)))) event-refs))) (list (quote let) bindings raw-compiled)) raw-compiled)))
(let
((wrapped-body (if catch-info (let ((var (make-symbol (nth catch-info 0))) (catch-body (hs-to-sx (nth catch-info 1)))) (if finally-info (list (quote do) (list (quote guard) (list var (list true catch-body)) compiled-body) (hs-to-sx finally-info)) (list (quote guard) (list var (list true catch-body)) compiled-body))) (if finally-info (list (quote do) compiled-body (hs-to-sx finally-info)) compiled-body)))
(handler
@@ -1468,11 +1468,20 @@
(list (quote console-log) (hs-to-sx (nth ast 1))))
((= head (quote send)) (emit-send ast))
((= head (quote trigger))
(list
(quote dom-dispatch)
(hs-to-sx (nth ast 2))
(nth ast 1)
nil))
(let
((name (nth ast 1))
(has-detail
(and
(= (len ast) 4)
(list? (nth ast 2))
(= (first (nth ast 2)) (quote dict))))
(tgt (if (= (len ast) 4) (nth ast 3) (nth ast 2)))
(detail (if (= (len ast) 4) (nth ast 2) nil)))
(list
(quote dom-dispatch)
(hs-to-sx tgt)
name
(if has-detail (hs-to-sx detail) nil))))
((= head (quote hide))
(let
((tgt (let ((raw-tgt (nth ast 1))) (if (and (list? raw-tgt) (= (first raw-tgt) (quote query))) (list (quote hs-query-all) (nth raw-tgt 1)) (hs-to-sx raw-tgt))))

View File

@@ -1438,10 +1438,15 @@
(fn
()
(let
((name (get (adv!) "value")))
((name (parse-compound-event-name)))
(let
((tgt (parse-tgt-kw "on" (list (quote me)))))
(list (quote trigger) name tgt)))))
((dtl (if (= (tp-type) "paren-open") (parse-detail-dict) nil)))
(let
((tgt (parse-tgt-kw "on" (list (quote me)))))
(if
dtl
(list (quote trigger) name dtl tgt)
(list (quote trigger) name tgt)))))))
(define parse-log-cmd (fn () (list (quote log) (parse-expr))))
(define
parse-inc-cmd

View File

@@ -162,7 +162,7 @@
(let
((raw-compiled (hs-to-sx stripped-body)))
(let
((compiled-body (if (> (len event-refs) 0) (let ((bindings (map (fn (r) (let ((name (nth r 1))) (list (make-symbol name) (list (quote get) (list (quote get) (quote event) "detail") name)))) event-refs))) (list (quote let) bindings raw-compiled)) raw-compiled)))
((compiled-body (if (> (len event-refs) 0) (let ((bindings (map (fn (r) (let ((name (nth r 1))) (list (make-symbol name) (list (quote host-get) (list (quote host-get) (quote event) "detail") name)))) event-refs))) (list (quote let) bindings raw-compiled)) raw-compiled)))
(let
((wrapped-body (if catch-info (let ((var (make-symbol (nth catch-info 0))) (catch-body (hs-to-sx (nth catch-info 1)))) (if finally-info (list (quote do) (list (quote guard) (list var (list true catch-body)) compiled-body) (hs-to-sx finally-info)) (list (quote guard) (list var (list true catch-body)) compiled-body))) (if finally-info (list (quote do) compiled-body (hs-to-sx finally-info)) compiled-body)))
(handler
@@ -1468,11 +1468,20 @@
(list (quote console-log) (hs-to-sx (nth ast 1))))
((= head (quote send)) (emit-send ast))
((= head (quote trigger))
(list
(quote dom-dispatch)
(hs-to-sx (nth ast 2))
(nth ast 1)
nil))
(let
((name (nth ast 1))
(has-detail
(and
(= (len ast) 4)
(list? (nth ast 2))
(= (first (nth ast 2)) (quote dict))))
(tgt (if (= (len ast) 4) (nth ast 3) (nth ast 2)))
(detail (if (= (len ast) 4) (nth ast 2) nil)))
(list
(quote dom-dispatch)
(hs-to-sx tgt)
name
(if has-detail (hs-to-sx detail) nil))))
((= head (quote hide))
(let
((tgt (let ((raw-tgt (nth ast 1))) (if (and (list? raw-tgt) (= (first raw-tgt) (quote query))) (list (quote hs-query-all) (nth raw-tgt 1)) (hs-to-sx raw-tgt))))

View File

@@ -1438,10 +1438,15 @@
(fn
()
(let
((name (get (adv!) "value")))
((name (parse-compound-event-name)))
(let
((tgt (parse-tgt-kw "on" (list (quote me)))))
(list (quote trigger) name tgt)))))
((dtl (if (= (tp-type) "paren-open") (parse-detail-dict) nil)))
(let
((tgt (parse-tgt-kw "on" (list (quote me)))))
(if
dtl
(list (quote trigger) name dtl tgt)
(list (quote trigger) name tgt)))))))
(define parse-log-cmd (fn () (list (quote log) (parse-expr))))
(define
parse-inc-cmd