diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index 9bba0878..abccc04e 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -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 diff --git a/shared/static/wasm/sx/hs-parser.sx b/shared/static/wasm/sx/hs-parser.sx index 9bba0878..abccc04e 100644 --- a/shared/static/wasm/sx/hs-parser.sx +++ b/shared/static/wasm/sx/hs-parser.sx @@ -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 diff --git a/spec/tests/test-hyperscript-behavioral.sx b/spec/tests/test-hyperscript-behavioral.sx index 2075fbe4..0e77d941 100644 --- a/spec/tests/test-hyperscript-behavioral.sx +++ b/spec/tests/test-hyperscript-behavioral.sx @@ -1396,8 +1396,10 @@ (hs-activate! _el-div) (dom-dispatch _el-div "click" nil) (assert (dom-has-class? _el-div "foo")) - (assert (not (dom-has-class? _el-div "foo"))) - )) + (hs-deactivate! _el-div) + (dom-remove-class _el-div "foo") + (dom-dispatch _el-div "click" nil) + (assert (not (dom-has-class? _el-div "foo"))))) (deftest "cleanup tracks listeners in elt._hyperscript" (hs-cleanup!) (let ((_el-div (dom-create-element "div"))) @@ -1478,9 +1480,10 @@ (hs-activate! _el-div) (dom-dispatch _el-div "click" nil) (assert (dom-has-class? _el-div "foo")) + (dom-set-attr _el-div "_" "on click add .bar") + (hs-activate! _el-div) (dom-dispatch _el-div "click" nil) - (assert (dom-has-class? _el-div "bar")) - )) + (assert (dom-has-class? _el-div "bar")))) (deftest "sets data-hyperscript-powered on initialized elements" (hs-cleanup!) (let ((_el-div (dom-create-element "div")))