From 922e7a7892ba0f6e8ea1ad9d4e06b850d9739974 Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 21 Apr 2026 05:44:08 +0000 Subject: [PATCH] HS: halt command modes, mock event methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parser: - halt default/bubbling: match ident type (not just keyword) - halt the event's: consume possessive marker Runtime: - hs-halt! dispatches: default→preventDefault, bubbling→stopPropagation, event→both Mock DOM: - Add event method dispatch: preventDefault, stopPropagation, stopImmediatePropagation set correct flags on event dict Co-Authored-By: Claude Opus 4.6 (1M context) --- hosts/ocaml/bin/run_tests.ml | 9 +++++++++ lib/hyperscript/parser.sx | 4 ++-- lib/hyperscript/runtime.sx | 9 +++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/hosts/ocaml/bin/run_tests.ml b/hosts/ocaml/bin/run_tests.ml index a63da8c6..21e01599 100644 --- a/hosts/ocaml/bin/run_tests.ml +++ b/hosts/ocaml/bin/run_tests.ml @@ -1807,6 +1807,15 @@ let run_spec_tests env test_files = | _ -> Bool false) | _ -> Nil) + else if mt = "event" then + (match m with + | "preventDefault" -> Hashtbl.replace d "defaultPrevented" (Bool true); Nil + | "stopPropagation" -> Hashtbl.replace d "_stopped" (Bool true); Nil + | "stopImmediatePropagation" -> + Hashtbl.replace d "_stopped" (Bool true); + Hashtbl.replace d "_stopImmediate" (Bool true); Nil + | _ -> Nil) + else if mt = "style" then (match m with | "setProperty" -> diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index 1137e7fc..8e5dada7 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -1657,8 +1657,8 @@ (fn () (let - ((the-event (and (match-kw "the") (or (match-kw "event") (match-kw "default"))))) - (list (quote halt!) (if the-event "event" "default"))))) + ((mode (cond ((match-kw "the") (do (match-kw "event") (match-kw "'s") "event")) ((or (match-kw "default") (and (= (tp-val) "default") (do (adv!) true))) "default") ((or (match-kw "bubbling") (and (= (tp-val) "bubbling") (do (adv!) true))) "bubbling") (true "event")))) + (list (quote halt!) mode)))) (define parse-param-list (fn () (if (= (tp-type) "paren-open") (parse-call-args) (list)))) diff --git a/lib/hyperscript/runtime.sx b/lib/hyperscript/runtime.sx index 1aa21151..1c1cb627 100644 --- a/lib/hyperscript/runtime.sx +++ b/lib/hyperscript/runtime.sx @@ -222,8 +222,13 @@ (mode) (when event - (host-call event "preventDefault" (list)) - (when (= mode "event") (host-call event "stopPropagation" (list)))))) + (cond + ((= mode "default") (host-call event "preventDefault")) + ((= mode "bubbling") (host-call event "stopPropagation")) + (true + (do + (host-call event "preventDefault") + (host-call event "stopPropagation"))))))) ;; ── Type coercion ───────────────────────────────────────────────