From b90aa54dd08bd62204ad64a0d37fd71d045b3ee4 Mon Sep 17 00:00:00 2001 From: giles Date: Thu, 23 Apr 2026 12:01:53 +0000 Subject: [PATCH] HS test generator: drop bogus `then` after `else` and `catch X` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit process_hs_val replaces newlines with `then` to give the HS parser a statement separator, but `else then` and `catch foo then` are syntax errors — `else` and `catch ` already open new blocks. Strip the inserted `then` after them so multi-line if/try parses cleanly. No net pass-count delta on smoke-tested suites (the if-with-window-state tests fail for a separate reason: window setups all run before any click rather than being interleaved with state changes), but the source now parses correctly and matches what upstream HS sees. Co-Authored-By: Claude Opus 4.7 (1M context) --- spec/tests/test-hyperscript-behavioral.sx | 12 ++++++------ tests/playwright/generate-sx-tests.py | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/spec/tests/test-hyperscript-behavioral.sx b/spec/tests/test-hyperscript-behavioral.sx index fffc03d1..e2dd83d5 100644 --- a/spec/tests/test-hyperscript-behavioral.sx +++ b/spec/tests/test-hyperscript-behavioral.sx @@ -1223,7 +1223,7 @@ (deftest "rejected promise triggers catch block" (hs-cleanup!) (let ((_el-button (dom-create-element "button")) (_el-out (dom-create-element "div"))) - (dom-set-attr _el-button "_" "on click call failAsync() then put 'unreachable' into #out then catch e then put e.message into #out then") + (dom-set-attr _el-button "_" "on click call failAsync() then put 'unreachable' into #out then catch e put e.message into #out then") (dom-set-inner-html _el-button "Go") (dom-set-attr _el-out "id" "out") (dom-append (dom-body) _el-button) @@ -4066,7 +4066,7 @@ (dom-set-attr _el-input9 "type" "checkbox") (dom-set-attr _el-input9 "checked" "") (dom-set-attr _el-master "id" "master") - (dom-set-attr _el-master "_" "set :checkboxes to in the closest where it is not me then on change set checked of the :checkboxes to my checked then on change from the closest
then if no :checkboxes where it is checked then set my indeterminate to false then set my checked to false then else if no :checkboxes where it is not checked then set my indeterminate to false then set my checked to true then else then set my indeterminate to true then end") + (dom-set-attr _el-master "_" "set :checkboxes to in the closest
where it is not me then on change set checked of the :checkboxes to my checked then on change from the closest
then if no :checkboxes where it is checked then set my indeterminate to false then set my checked to false then else if no :checkboxes where it is not checked then set my indeterminate to false then set my checked to true then else set my indeterminate to true then end") (dom-set-attr _el-master "type" "checkbox") (dom-append (dom-body) _el-table) (dom-append _el-table _el-tr) @@ -7723,7 +7723,7 @@ (host-set! (host-global "window") "tmp" false) (host-set! (host-global "window") "tmp" true) (let ((_el-div (dom-create-element "div"))) - (dom-set-attr _el-div "_" "on click if window.tmp then else then if window.tmp then end put \"foo\" into me then end") + (dom-set-attr _el-div "_" "on click if window.tmp then else if window.tmp then end put \"foo\" into me then end") (dom-append (dom-body) _el-div) (hs-activate! _el-div) (dom-dispatch _el-div "click" nil) @@ -7745,7 +7745,7 @@ (host-set! (host-global "window") "tmp" false) (host-set! (host-global "window") "tmp" true) (let ((_el-div (dom-create-element "div"))) - (dom-set-attr _el-div "_" "on click if window.tmp then put \"foo\" into me then else if not window.tmp then // do nothing then end catch e then // just here for the parsing... then") + (dom-set-attr _el-div "_" "on click if window.tmp then put \"foo\" into me then else if not window.tmp then // do nothing then end catch e // just here for the parsing... then") (dom-append (dom-body) _el-div) (hs-activate! _el-div) (dom-dispatch _el-div "click" nil) @@ -8754,7 +8754,7 @@ (deftest "async exceptions don't kill the event queue" (hs-cleanup!) (let ((_el-button (dom-create-element "button"))) - (dom-set-attr _el-button "_" "on click increment :x then if :x is 1 then wait 1ms then throw \"bar\" otherwise then put \"success\" into me end catch e then put e into me") + (dom-set-attr _el-button "_" "on click increment :x then if :x is 1 then wait 1ms then throw \"bar\" otherwise then put \"success\" into me end catch e put e into me") (dom-append (dom-body) _el-button) (hs-activate! _el-button) (dom-dispatch _el-button "click" nil) @@ -9035,7 +9035,7 @@ (deftest "exceptions in catch block don't kill the event queue" (hs-cleanup!) (let ((_el-button (dom-create-element "button"))) - (dom-set-attr _el-button "_" "on click increment :x then if :x is 1 then throw \"bar\" otherwise then put \"success\" into me end catch e then put e into me then throw e") + (dom-set-attr _el-button "_" "on click increment :x then if :x is 1 then throw \"bar\" otherwise then put \"success\" into me end catch e put e into me then throw e") (dom-append (dom-body) _el-button) (hs-activate! _el-button) (dom-dispatch _el-button "click" nil) diff --git a/tests/playwright/generate-sx-tests.py b/tests/playwright/generate-sx-tests.py index 92868c30..216fccee 100644 --- a/tests/playwright/generate-sx-tests.py +++ b/tests/playwright/generate-sx-tests.py @@ -813,6 +813,10 @@ def process_hs_val(hs_val): hs_val = re.sub(r'(\bin (?:\[.*?\]|\S+)) then\b', r'\1 ', hs_val) hs_val = re.sub(r'\btimes then\b', 'times ', hs_val) hs_val = re.sub(r'\bend then\b', 'end ', hs_val) + # `else then` is invalid HS — `else` already opens a new block. + hs_val = re.sub(r'\belse then\b', 'else ', hs_val) + # Same for `catch then` (try/catch syntax). + hs_val = re.sub(r'\bcatch (\w+) then\b', r'catch \1 ', hs_val) return hs_val.strip()