HS: fix parser then-skip + bootstrap test fixes (+3)

Parser: parse-cmd-list now skips a leading 'then' token so that
'on click from #bar then add .clicked' compiles correctly instead
of producing nil as the body.

Bootstrap tests: fix two broken tests whose assertions were
incomplete or contradictory:
- "cleanup removes event listeners" — deactivate + re-click to
  verify listener is gone
- "reinitializes if script attribute changes" — actually change
  the _ attribute before re-activating and re-clicking

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 21:26:16 +00:00
parent 8b972483ae
commit 87072e61c1
3 changed files with 73 additions and 88 deletions

View File

@@ -10,8 +10,10 @@
(tokens src)
(let
((tokens (filter (fn (t) (not (= (get t "type") "whitespace"))) tokens))
(p 0)
(tok-len (len (filter (fn (t) (not (= (get t "type") "whitespace"))) tokens))))
(p 0)
(tok-len
(len
(filter (fn (t) (not (= (get t "type") "whitespace"))) tokens))))
(define tp (fn () (if (< p tok-len) (nth tokens p) nil)))
(define
tp-type
@@ -1801,25 +1803,7 @@
(let
((fmt (or fmt-before fmt-after "text")))
(let
((do-not-throw
(cond
((and (or (= (tp-type) "keyword") (= (tp-type) "ident")) (= (tp-val) "do"))
(do
(adv!)
(if (and (or (= (tp-type) "keyword") (= (tp-type) "ident")) (= (tp-val) "not"))
(do
(adv!)
(if (and (or (= (tp-type) "keyword") (= (tp-type) "ident")) (= (tp-val) "throw"))
(do (adv!) true)
false))
false)))
((and (= (tp-type) "ident") (= (tp-val) "don't"))
(do
(adv!)
(if (and (or (= (tp-type) "keyword") (= (tp-type) "ident")) (= (tp-val) "throw"))
(do (adv!) true)
false)))
(true false))))
((do-not-throw (cond ((and (or (= (tp-type) "keyword") (= (tp-type) "ident")) (= (tp-val) "do")) (do (adv!) (if (and (or (= (tp-type) "keyword") (= (tp-type) "ident")) (= (tp-val) "not")) (do (adv!) (if (and (or (= (tp-type) "keyword") (= (tp-type) "ident")) (= (tp-val) "throw")) (do (adv!) true) false)) false))) ((and (= (tp-type) "ident") (= (tp-val) "don't")) (do (adv!) (if (and (or (= (tp-type) "keyword") (= (tp-type) "ident")) (= (tp-val) "throw")) (do (adv!) true) false))) (true false))))
(list (quote fetch) url fmt do-not-throw))))))))))
(define
parse-call-args
@@ -2768,27 +2752,34 @@
cl-collect
(fn
(acc)
(let
((cmd (parse-cmd)))
(if
(nil? cmd)
acc
(let
((acc2 (append acc (list cmd))))
(cond
((match-kw "unless")
(let
((cnd (parse-expr)))
(cl-collect
(append
acc
(list
(list (quote if) (list (quote no) cnd) cmd))))))
((match-kw "then")
(cl-collect (append acc2 (list (quote __then__)))))
((or (and (not (at-end?)) (= (tp-type) "keyword") (cmd-kw? (tp-val))) (= (tp-type) "paren-open"))
(cl-collect acc2))
(true acc2)))))))
(do
(when
(and (= (tp-type) "keyword") (= (tp-val) "then"))
(adv!))
(let
((cmd (parse-cmd)))
(if
(nil? cmd)
acc
(let
((acc2 (append acc (list cmd))))
(cond
((match-kw "unless")
(let
((cnd (parse-expr)))
(cl-collect
(append
acc
(list
(list
(quote if)
(list (quote no) cnd)
cmd))))))
((match-kw "then")
(cl-collect (append acc2 (list (quote __then__)))))
((or (and (not (at-end?)) (= (tp-type) "keyword") (cmd-kw? (tp-val))) (= (tp-type) "paren-open"))
(cl-collect acc2))
(true acc2))))))))
(let
((cmds (cl-collect (list))))
(define