diff --git a/lib/hyperscript/compiler.sx b/lib/hyperscript/compiler.sx index f00d6fef..e34fa5e0 100644 --- a/lib/hyperscript/compiler.sx +++ b/lib/hyperscript/compiler.sx @@ -1426,6 +1426,20 @@ (quote hs-toggle-class!) (hs-to-sx (nth ast 2)) (nth ast 1)))) + ((= head (quote toggle-class-until)) + (let + ((cls (nth ast 1)) + (tgt (hs-to-sx (nth ast 2))) + (event-name (nth ast 3)) + (source (nth ast 4))) + (list + (quote do) + (list (quote hs-toggle-class!) tgt cls) + (list + (quote hs-wait-for) + (if source (hs-to-sx source) (quote me)) + event-name) + (list (quote hs-toggle-class!) tgt cls)))) ((= head (quote set-on)) (list (quote hs-set-on!) diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index 233eb9b7..aba0bf5d 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -1132,14 +1132,45 @@ ((= (tp-type) "class") (let ((cls (do (let ((v (tp-val))) (adv!) v)))) + (define + collect-classes + (fn + (acc) + (if + (= (tp-type) "class") + (let + ((v (tp-val))) + (adv!) + (collect-classes (append acc (list v)))) + acc))) (let - ((tgt (parse-tgt-kw "on" (list (quote me))))) - (if - (match-kw "for") - (let - ((dur (parse-expr))) - (list (quote toggle-class-for) cls tgt dur)) - (list (quote toggle-class) cls tgt))))) + ((extra-classes (collect-classes (list)))) + (let + ((tgt (parse-tgt-kw "on" (list (quote me))))) + (cond + ((> (len extra-classes) 0) + (list + (quote toggle-between) + cls + (first extra-classes) + tgt)) + ((match-kw "for") + (let + ((dur (parse-expr))) + (list (quote toggle-class-for) cls tgt dur))) + ((match-kw "until") + (let + ((event-name (tp-val))) + (adv!) + (let + ((source (if (match-kw "from") (parse-expr) nil))) + (list + (quote toggle-class-until) + cls + tgt + event-name + source)))) + (true (list (quote toggle-class) cls tgt))))))) ((= (tp-type) "style") (let ((prop (get (adv!) "value"))) diff --git a/shared/static/wasm/sx/hs-compiler.sx b/shared/static/wasm/sx/hs-compiler.sx index f00d6fef..e34fa5e0 100644 --- a/shared/static/wasm/sx/hs-compiler.sx +++ b/shared/static/wasm/sx/hs-compiler.sx @@ -1426,6 +1426,20 @@ (quote hs-toggle-class!) (hs-to-sx (nth ast 2)) (nth ast 1)))) + ((= head (quote toggle-class-until)) + (let + ((cls (nth ast 1)) + (tgt (hs-to-sx (nth ast 2))) + (event-name (nth ast 3)) + (source (nth ast 4))) + (list + (quote do) + (list (quote hs-toggle-class!) tgt cls) + (list + (quote hs-wait-for) + (if source (hs-to-sx source) (quote me)) + event-name) + (list (quote hs-toggle-class!) tgt cls)))) ((= head (quote set-on)) (list (quote hs-set-on!) diff --git a/shared/static/wasm/sx/hs-parser.sx b/shared/static/wasm/sx/hs-parser.sx index 30523f26..aba0bf5d 100644 --- a/shared/static/wasm/sx/hs-parser.sx +++ b/shared/static/wasm/sx/hs-parser.sx @@ -1132,14 +1132,45 @@ ((= (tp-type) "class") (let ((cls (do (let ((v (tp-val))) (adv!) v)))) + (define + collect-classes + (fn + (acc) + (if + (= (tp-type) "class") + (let + ((v (tp-val))) + (adv!) + (collect-classes (append acc (list v)))) + acc))) (let - ((tgt (parse-tgt-kw "on" (list (quote me))))) - (if - (match-kw "for") - (let - ((dur (parse-expr))) - (list (quote toggle-class-for) cls tgt dur)) - (list (quote toggle-class) cls tgt))))) + ((extra-classes (collect-classes (list)))) + (let + ((tgt (parse-tgt-kw "on" (list (quote me))))) + (cond + ((> (len extra-classes) 0) + (list + (quote toggle-between) + cls + (first extra-classes) + tgt)) + ((match-kw "for") + (let + ((dur (parse-expr))) + (list (quote toggle-class-for) cls tgt dur))) + ((match-kw "until") + (let + ((event-name (tp-val))) + (adv!) + (let + ((source (if (match-kw "from") (parse-expr) nil))) + (list + (quote toggle-class-until) + cls + tgt + event-name + source)))) + (true (list (quote toggle-class) cls tgt))))))) ((= (tp-type) "style") (let ((prop (get (adv!) "value"))) @@ -2472,14 +2503,6 @@ (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__))))) ((and (not (at-end?)) (= (tp-type) "keyword") (cmd-kw? (tp-val)))