diff --git a/lib/hyperscript/compiler.sx b/lib/hyperscript/compiler.sx index 850b222a..093633af 100644 --- a/lib/hyperscript/compiler.sx +++ b/lib/hyperscript/compiler.sx @@ -1571,6 +1571,35 @@ (quote dom-remove-class) (if (nil? raw-tgt) (quote me) (hs-to-sx raw-tgt)) (nth ast 1))))) + ((= head (quote remove-class-when)) + (let + ((cls (nth ast 1)) + (raw-tgt (nth ast 2)) + (when-cond (nth ast 3))) + (let + ((tgt-expr (cond + ((and (list? raw-tgt) (= (first raw-tgt) (quote query))) + (list (quote hs-query-all) (nth raw-tgt 1))) + (true (hs-to-sx raw-tgt))))) + (list + (quote let) + (list + (list + (quote __hs-matched) + (list + (quote filter) + (list + (quote fn) + (list (quote it)) + (hs-to-sx when-cond)) + tgt-expr))) + (list + (quote for-each) + (list + (quote fn) + (list (quote it)) + (list (quote dom-remove-class) (quote it) cls)) + (quote __hs-matched)))))) ((= head (quote remove-element)) (let ((tgt (nth ast 1))) diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index 44ae5698..eb8270cf 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -1133,12 +1133,17 @@ (collect-classes!) (let ((tgt (if (match-kw "from") (parse-expr) (list (quote beingTold))))) - (if - (empty? extra-classes) - (list (quote remove-class) cls tgt) - (cons - (quote multi-remove-class) - (cons tgt (cons cls extra-classes))))))) + (let + ((when-clause (if (match-kw "when") (parse-expr) nil))) + (if + (empty? extra-classes) + (if + when-clause + (list (quote remove-class-when) cls tgt when-clause) + (list (quote remove-class) cls tgt)) + (cons + (quote multi-remove-class) + (cons tgt (cons cls extra-classes)))))))) ((= (tp-type) "attr") (let ((attr-name (get (adv!) "value"))) diff --git a/shared/static/wasm/sx/hs-compiler.sx b/shared/static/wasm/sx/hs-compiler.sx index 850b222a..093633af 100644 --- a/shared/static/wasm/sx/hs-compiler.sx +++ b/shared/static/wasm/sx/hs-compiler.sx @@ -1571,6 +1571,35 @@ (quote dom-remove-class) (if (nil? raw-tgt) (quote me) (hs-to-sx raw-tgt)) (nth ast 1))))) + ((= head (quote remove-class-when)) + (let + ((cls (nth ast 1)) + (raw-tgt (nth ast 2)) + (when-cond (nth ast 3))) + (let + ((tgt-expr (cond + ((and (list? raw-tgt) (= (first raw-tgt) (quote query))) + (list (quote hs-query-all) (nth raw-tgt 1))) + (true (hs-to-sx raw-tgt))))) + (list + (quote let) + (list + (list + (quote __hs-matched) + (list + (quote filter) + (list + (quote fn) + (list (quote it)) + (hs-to-sx when-cond)) + tgt-expr))) + (list + (quote for-each) + (list + (quote fn) + (list (quote it)) + (list (quote dom-remove-class) (quote it) cls)) + (quote __hs-matched)))))) ((= head (quote remove-element)) (let ((tgt (nth ast 1))) diff --git a/shared/static/wasm/sx/hs-parser.sx b/shared/static/wasm/sx/hs-parser.sx index 44ae5698..eb8270cf 100644 --- a/shared/static/wasm/sx/hs-parser.sx +++ b/shared/static/wasm/sx/hs-parser.sx @@ -1133,12 +1133,17 @@ (collect-classes!) (let ((tgt (if (match-kw "from") (parse-expr) (list (quote beingTold))))) - (if - (empty? extra-classes) - (list (quote remove-class) cls tgt) - (cons - (quote multi-remove-class) - (cons tgt (cons cls extra-classes))))))) + (let + ((when-clause (if (match-kw "when") (parse-expr) nil))) + (if + (empty? extra-classes) + (if + when-clause + (list (quote remove-class-when) cls tgt when-clause) + (list (quote remove-class) cls tgt)) + (cons + (quote multi-remove-class) + (cons tgt (cons cls extra-classes)))))))) ((= (tp-type) "attr") (let ((attr-name (get (adv!) "value")))