Smarter implicit then: only before command keywords — 341/831 (41%)
Fixed then insertion to only trigger before known HS command keywords (set, put, add, remove, toggle, etc.) via lookahead regex, instead of on all multi-space sequences. Prevents breaking single-command expressions with wide spacing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1377,7 +1377,7 @@
|
||||
(deftest "hide element then show element retains original display"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click 1 hide then on click 2 show")
|
||||
(dom-set-attr _el-div "_" "on click 1 hide on click 2 show")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1581,7 +1581,7 @@
|
||||
(deftest "basic else if branch works with end"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click if false then else if true put \"foo\" into me.innerHTML end")
|
||||
(dom-set-attr _el-div "_" "on click if false else if true put \"foo\" into me.innerHTML end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1608,7 +1608,7 @@
|
||||
(deftest "triple else if branch works with end"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click if false then else if false then else put \"foo\" into me.innerHTML end")
|
||||
(dom-set-attr _el-div "_" "on click if false else if false else put \"foo\" into me.innerHTML end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1617,7 +1617,7 @@
|
||||
(deftest "basic else branch works with multiple commands"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click if false put \"bar\" into me.innerHTML then else log me then put \"foo\" into me.innerHTML")
|
||||
(dom-set-attr _el-div "_" "on click if false put \"bar\" into me.innerHTML else log me then put \"foo\" into me.innerHTML")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1653,7 +1653,7 @@
|
||||
(deftest "if properly supports nested if statements and end block"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click n then if window.tmp thenn then put \"foo\" into men then else if not window.tmp thenn then // do nothingn then endn then catch en then // just here for the parsing...n")
|
||||
(dom-set-attr _el-div "_" "on click n then if window.tmp thenn then put \"foo\" into men else if not window.tmp thenn // do nothingn endn catch en // just here for the parsing...n")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1663,7 +1663,7 @@
|
||||
(deftest "if on new line does not join w/ else"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click n then if window.tmp thenn then elsen then if window.tmp then endn then put \"foo\" into men then endn then")
|
||||
(dom-set-attr _el-div "_" "on click n then if window.tmp thenn elsen then if window.tmp then endn then put \"foo\" into men endn")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1679,7 +1679,7 @@
|
||||
(deftest "basic for loop works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click repeat for x in [1, 2, 3] then put x at end of me then end")
|
||||
(dom-set-attr _el-div "_" "on click repeat for x in [1, 2, 3] then put x at end of me end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1688,7 +1688,7 @@
|
||||
(deftest "basic for loop with null works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click repeat for x in null then put x at end of me then end")
|
||||
(dom-set-attr _el-div "_" "on click repeat for x in null then put x at end of me end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1697,7 +1697,7 @@
|
||||
(deftest "waiting in for loop works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click repeat for x in [1, 2, 3]n then log me then put x at end of men then wait 1msn then end")
|
||||
(dom-set-attr _el-div "_" "on click repeat for x in [1, 2, 3]n then log me then put x at end of men then wait 1msn end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1706,7 +1706,7 @@
|
||||
(deftest "basic raw for loop works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click for x in [1, 2, 3] then put x at end of me then end")
|
||||
(dom-set-attr _el-div "_" "on click for x in [1, 2, 3] then put x at end of me end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1715,7 +1715,7 @@
|
||||
(deftest "basic raw for loop works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click for x in null then put x at end of me then end")
|
||||
(dom-set-attr _el-div "_" "on click for x in null then put x at end of me end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1724,7 +1724,7 @@
|
||||
(deftest "waiting in raw for loop works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click for x in [1, 2, 3]n then put x at end of men then wait 1msn then end")
|
||||
(dom-set-attr _el-div "_" "on click for x in [1, 2, 3]n then put x at end of men then wait 1msn end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1757,7 +1757,7 @@
|
||||
(deftest "basic in loop works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click repeat in [1, 2, 3] then put it at end of me then end")
|
||||
(dom-set-attr _el-div "_" "on click repeat in [1, 2, 3] then put it at end of me end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1766,7 +1766,7 @@
|
||||
(deftest "index syntax works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click repeat for x in [\"a\", \"ab\", \"abc\"] index i then put x + i at end of me then end")
|
||||
(dom-set-attr _el-div "_" "on click repeat for x in [\"a\", \"ab\", \"abc\"] index i then put x + i at end of me end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1775,7 +1775,7 @@
|
||||
(deftest "indexed by syntax works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click repeat for x in [\"a\", \"ab\", \"abc\"] indexed by i then put x + i at end of me then end")
|
||||
(dom-set-attr _el-div "_" "on click repeat for x in [\"a\", \"ab\", \"abc\"] indexed by i then put x + i at end of me end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1843,7 +1843,7 @@
|
||||
(deftest "basic times loop works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click repeat 3 times then put \"a\" at end of me then end")
|
||||
(dom-set-attr _el-div "_" "on click repeat 3 times then put \"a\" at end of me end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1852,7 +1852,7 @@
|
||||
(deftest "times loop with expression works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click repeat 3 + 3 times then put \"a\" at end of me then end")
|
||||
(dom-set-attr _el-div "_" "on click repeat 3 + 3 times then put \"a\" at end of me end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1861,7 +1861,7 @@
|
||||
(deftest "loop continue works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click then repeat 2 times then for x in ['A', 'B', 'C', 'D'] then if (x != 'D') then put 'success ' + x then + '. ' at end of me then continue then put 'FAIL!!. ' at end of me then end then put 'expected D. ' at end of me then end then end then")
|
||||
(dom-set-attr _el-div "_" "on click then repeat 2 times then for x in ['A', 'B', 'C', 'D'] then if (x != 'D') then put 'success ' + x + '. ' at end of me then continue then put 'FAIL!!. ' at end of me then end then put 'expected D. ' at end of me then end then end then")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1879,7 +1879,7 @@
|
||||
(deftest "basic raw for loop with null works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click for x in null then put x at end of me then end")
|
||||
(dom-set-attr _el-div "_" "on click for x in null then put x at end of me end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1888,7 +1888,7 @@
|
||||
(deftest "basic property for loop works"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click set x to {foo:1, bar:2, baz:3} then for prop in x then put x[prop] at end of me then end")
|
||||
(dom-set-attr _el-div "_" "on click set x to {foo:1, bar:2, baz:3} then for prop in x then put x[prop] at end of me end")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1897,7 +1897,7 @@
|
||||
(deftest "bottom-tested repeat until"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click set x to 0 then repeat then set x to then until x is 3 end then put x into me")
|
||||
(dom-set-attr _el-div "_" "on click set x to 0 then repeat then set x to until x is 3 end then put x into me")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1906,7 +1906,7 @@
|
||||
(deftest "bottom-tested repeat while"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click set x to 0 then repeat then set x to then while x < 3 end then put x into me")
|
||||
(dom-set-attr _el-div "_" "on click set x to 0 then repeat then set x to while x < 3 end then put x into me")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -1915,7 +1915,7 @@
|
||||
(deftest "bottom-tested loop always runs at least once"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click set x to 0 then repeat then set x to then until true end then put x into me")
|
||||
(dom-set-attr _el-div "_" "on click set x to 0 then repeat then set x to until true end then put x into me")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -2396,7 +2396,7 @@
|
||||
(deftest "can transition with parameterized values"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click then set startWidth to 0 then set endWidth to 100 then transition width from (startWidth)px to (endWidth)px")
|
||||
(dom-set-attr _el-div "_" "on click then set startWidth to 0 then set endWidth to 100 transition width from (startWidth)px to (endWidth)px")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -2465,7 +2465,7 @@
|
||||
(deftest "can transition on another element no element prefix with it"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")) (_el-foo (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click get then #foo then transition its width from 0px to 100px")
|
||||
(dom-set-attr _el-div "_" "on click get #foo then transition its width from 0px to 100px")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-set-attr _el-foo "id" "foo")
|
||||
@@ -2524,7 +2524,7 @@
|
||||
(deftest "can use initial to transition to original value"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click 1 transition my *width to 100px then on click 2 transition my *width to initial")
|
||||
(dom-set-attr _el-div "_" "on click 1 transition my *width to 100px on click 2 transition my *width to initial")
|
||||
(dom-set-attr _el-div "style" "width: 10px")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
@@ -3294,7 +3294,7 @@
|
||||
(hs-cleanup!)
|
||||
(let ((_el-d1 (dom-create-element "div")) (_el-d2 (dom-create-element "div")))
|
||||
(dom-set-attr _el-d1 "id" "d1")
|
||||
(dom-set-attr _el-d1 "_" "on click then tell #d2 then add .bar then end then add .foo")
|
||||
(dom-set-attr _el-d1 "_" "on click then tell #d2 then add .bar end then add .foo")
|
||||
(dom-append (dom-body) _el-d1)
|
||||
(hs-activate! _el-d1)
|
||||
(dom-set-attr _el-d2 "id" "d2")
|
||||
@@ -3309,7 +3309,7 @@
|
||||
(hs-cleanup!)
|
||||
(let ((_el-d1 (dom-create-element "div")) (_el-d2 (dom-create-element "div")))
|
||||
(dom-set-attr _el-d1 "id" "d1")
|
||||
(dom-set-attr _el-d1 "_" "on click then tell null then add .bar then end then add .foo")
|
||||
(dom-set-attr _el-d1 "_" "on click then tell null then add .bar end then add .foo")
|
||||
(dom-append (dom-body) _el-d1)
|
||||
(hs-activate! _el-d1)
|
||||
(dom-set-attr _el-d2 "id" "d2")
|
||||
@@ -3590,7 +3590,7 @@
|
||||
(deftest "can have multiple event handlers"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on foo put increment() into my.innerHTML end then on bar put increment() into my.innerHTML")
|
||||
(dom-set-attr _el-div "_" "on foo put increment() into my.innerHTML end on bar put increment() into my.innerHTML")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "foo" nil)
|
||||
@@ -3603,7 +3603,7 @@
|
||||
(deftest "can have multiple event handlers, no end"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on foo put increment() into my.innerHTML then on bar put increment() into my.innerHTML")
|
||||
(dom-set-attr _el-div "_" "on foo put increment() into my.innerHTML on bar put increment() into my.innerHTML")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "foo" nil)
|
||||
@@ -3747,7 +3747,7 @@
|
||||
(deftest "can mix ranges"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "on click 1 put \"one\" into my.innerHTML then on click 3 put \"three\" into my.innerHTML then on click 2 put \"two\" into my.innerHTML")
|
||||
(dom-set-attr _el-div "_" "on click 1 put \"one\" into my.innerHTML on click 3 put \"three\" into my.innerHTML on click 2 put \"two\" into my.innerHTML")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -3910,7 +3910,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 then increment :x then if :x is 1 then wait 1ms then throw \"bar\" then otherwise then put \"success\" into me then end then catch e then put e into me")
|
||||
(dom-set-attr _el-button "_" "on click then 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-append (dom-body) _el-button)
|
||||
(hs-activate! _el-button)
|
||||
(dom-dispatch _el-button "click" nil)
|
||||
@@ -3920,7 +3920,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 then increment :x then if :x is 1 then throw \"bar\" then otherwise then put \"success\" into me then end then catch e then put e into me then throw e")
|
||||
(dom-set-attr _el-button "_" "on click then 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-append (dom-body) _el-button)
|
||||
(hs-activate! _el-button)
|
||||
(dom-dispatch _el-button "click" nil)
|
||||
@@ -3930,7 +3930,7 @@
|
||||
(deftest "uncaught exceptions trigger 'exception' event"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-button (dom-create-element "button")))
|
||||
(dom-set-attr _el-button "_" "on click put \"foo\" into me then throw \"bar\" then on exception(error) put error into me")
|
||||
(dom-set-attr _el-button "_" "on click put \"foo\" into me then throw \"bar\" on exception(error) put error into me")
|
||||
(dom-append (dom-body) _el-button)
|
||||
(hs-activate! _el-button)
|
||||
(dom-dispatch _el-button "click" nil)
|
||||
@@ -3939,7 +3939,7 @@
|
||||
(deftest "caught exceptions do not trigger 'exception' event"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-button (dom-create-element "button")))
|
||||
(dom-set-attr _el-button "_" "on click put \"foo\" into me then throw \"bar\" then catch e log e then on exception(error) put error into me")
|
||||
(dom-set-attr _el-button "_" "on click put \"foo\" into me then throw \"bar\" catch e log e on exception(error) put error into me")
|
||||
(dom-append (dom-body) _el-button)
|
||||
(hs-activate! _el-button)
|
||||
(dom-dispatch _el-button "click" nil)
|
||||
@@ -3948,7 +3948,7 @@
|
||||
(deftest "rethrown exceptions trigger 'exception' event"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-button (dom-create-element "button")))
|
||||
(dom-set-attr _el-button "_" "on click put \"foo\" into me then throw \"bar\" then catch e throw e then on exception(error) put error into me")
|
||||
(dom-set-attr _el-button "_" "on click put \"foo\" into me then throw \"bar\" catch e throw e on exception(error) put error into me")
|
||||
(dom-append (dom-body) _el-button)
|
||||
(hs-activate! _el-button)
|
||||
(dom-dispatch _el-button "click" nil)
|
||||
@@ -3957,7 +3957,7 @@
|
||||
(deftest "basic finally blocks work"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-button (dom-create-element "button")))
|
||||
(dom-set-attr _el-button "_" "on click throw \"bar\" then finally put \"bar\" into me")
|
||||
(dom-set-attr _el-button "_" "on click throw \"bar\" finally put \"bar\" into me")
|
||||
(dom-append (dom-body) _el-button)
|
||||
(hs-activate! _el-button)
|
||||
(dom-dispatch _el-button "click" nil)
|
||||
@@ -3966,7 +3966,7 @@
|
||||
(deftest "finally blocks work when exception thrown in catch"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-button (dom-create-element "button")))
|
||||
(dom-set-attr _el-button "_" "on click throw \"bar\" then catch e throw e then finally put \"bar\" into me")
|
||||
(dom-set-attr _el-button "_" "on click throw \"bar\" catch e throw e finally put \"bar\" into me")
|
||||
(dom-append (dom-body) _el-button)
|
||||
(hs-activate! _el-button)
|
||||
(dom-dispatch _el-button "click" nil)
|
||||
@@ -3975,7 +3975,7 @@
|
||||
(deftest "async basic finally blocks work"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-button (dom-create-element "button")))
|
||||
(dom-set-attr _el-button "_" "on click wait a tick then throw \"bar\" then finally put \"bar\" into me")
|
||||
(dom-set-attr _el-button "_" "on click wait a tick then throw \"bar\" finally put \"bar\" into me")
|
||||
(dom-append (dom-body) _el-button)
|
||||
(hs-activate! _el-button)
|
||||
(dom-dispatch _el-button "click" nil)
|
||||
@@ -3984,7 +3984,7 @@
|
||||
(deftest "async finally blocks work when exception thrown in catch"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-button (dom-create-element "button")))
|
||||
(dom-set-attr _el-button "_" "on click wait a tick then throw \"bar\" then catch e set :foo to \"foo\" then throw e then finally put :foo + \"bar\" into me")
|
||||
(dom-set-attr _el-button "_" "on click wait a tick then throw \"bar\" catch e set :foo to \"foo\" then throw e finally put :foo + \"bar\" into me")
|
||||
(dom-append (dom-body) _el-button)
|
||||
(hs-activate! _el-button)
|
||||
(dom-dispatch _el-button "click" nil)
|
||||
@@ -3993,7 +3993,7 @@
|
||||
(deftest "async exceptions in finally block don't kill the event queue"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-button (dom-create-element "button")))
|
||||
(dom-set-attr _el-button "_" "on click then increment :x then finally then if :x is 1 then wait 1ms then throw \"bar\" then otherwise then put \"success\" into me then end then")
|
||||
(dom-set-attr _el-button "_" "on click then increment :x finally then if :x is 1 then wait 1ms then throw \"bar\" otherwise then put \"success\" into me end")
|
||||
(dom-append (dom-body) _el-button)
|
||||
(hs-activate! _el-button)
|
||||
(dom-dispatch _el-button "click" nil)
|
||||
@@ -4003,7 +4003,7 @@
|
||||
(deftest "exceptions in finally block don't kill the event queue"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-button (dom-create-element "button")))
|
||||
(dom-set-attr _el-button "_" "on click then increment :x then finally then if :x is 1 then throw \"bar\" then otherwise then put \"success\" into me then end then")
|
||||
(dom-set-attr _el-button "_" "on click then increment :x finally then if :x is 1 then throw \"bar\" otherwise then put \"success\" into me end")
|
||||
(dom-append (dom-body) _el-button)
|
||||
(hs-activate! _el-button)
|
||||
(dom-dispatch _el-button "click" nil)
|
||||
@@ -4014,7 +4014,7 @@
|
||||
(hs-cleanup!)
|
||||
(let ((_el-#d1 (dom-create-element "div")))
|
||||
(dom-set-attr _el-#d1 "id" "#d1")
|
||||
(dom-set-attr _el-#d1 "_" "then on click from #doesntExist then throw \"bar\" then on click then put \"clicked\" into me")
|
||||
(dom-set-attr _el-#d1 "_" "on click from #doesntExist then throw \"bar\" on click then put \"clicked\" into me")
|
||||
(dom-append (dom-body) _el-#d1)
|
||||
(hs-activate! _el-#d1)
|
||||
(dom-dispatch _el-#d1 "click" nil)
|
||||
@@ -4027,7 +4027,7 @@
|
||||
(dom-append (dom-body) _el-d1)
|
||||
(dom-set-attr _el-d2 "id" "d2")
|
||||
(dom-append (dom-body) _el-d2)
|
||||
(dom-set-attr _el-div "_" "then on click from #d1 or click from #d2 then increment @count then put @count into me")
|
||||
(dom-set-attr _el-div "_" "on click from #d1 or click from #d2 then increment @count then put @count into me")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-d1 "click" nil)
|
||||
@@ -4056,7 +4056,7 @@
|
||||
(deftest "caught exceptions do not trigger 'exception' event"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-button (dom-create-element "button")))
|
||||
(dom-set-attr _el-button "_" "on click put \"foo\" into me then throw \"bar\" then catch e log e then on exception(error) put error into me")
|
||||
(dom-set-attr _el-button "_" "on click put \"foo\" into me then throw \"bar\" catch e log e on exception(error) put error into me")
|
||||
(dom-append (dom-body) _el-button)
|
||||
(hs-activate! _el-button)
|
||||
(dom-dispatch _el-button "click" nil)
|
||||
@@ -4065,7 +4065,7 @@
|
||||
(deftest "rethrown exceptions trigger 'exception' event"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-button (dom-create-element "button")))
|
||||
(dom-set-attr _el-button "_" "on click put \"foo\" into me then throw \"bar\" then catch e throw e then on exception(error) put error into me")
|
||||
(dom-set-attr _el-button "_" "on click put \"foo\" into me then throw \"bar\" catch e throw e on exception(error) put error into me")
|
||||
(dom-append (dom-body) _el-button)
|
||||
(hs-activate! _el-button)
|
||||
(dom-dispatch _el-button "click" nil)
|
||||
@@ -4074,7 +4074,7 @@
|
||||
(deftest "can ignore when target doesn\'t exist"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "then on click from #doesntExist then throw \"bar\" then on click then put \"clicked\" into me")
|
||||
(dom-set-attr _el-div "_" "on click from #doesntExist then throw \"bar\" on click then put \"clicked\" into me")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -4087,7 +4087,7 @@
|
||||
(deftest "can define an init block inline"
|
||||
(hs-cleanup!)
|
||||
(let ((_el-div (dom-create-element "div")))
|
||||
(dom-set-attr _el-div "_" "init then set my.foo to 42 then end then on click put my.foo into my.innerHTML")
|
||||
(dom-set-attr _el-div "_" "init then set my.foo to 42 end on click put my.foo into my.innerHTML")
|
||||
(dom-append (dom-body) _el-div)
|
||||
(hs-activate! _el-div)
|
||||
(dom-dispatch _el-div "click" nil)
|
||||
@@ -7366,7 +7366,7 @@
|
||||
(hs-cleanup!)
|
||||
(let ((_el-d1 (dom-create-element "div")))
|
||||
(dom-set-attr _el-d1 "id" "d1")
|
||||
(dom-set-attr _el-d1 "_" "on click 1 set :x to 10 then on click 2 set @out to :x")
|
||||
(dom-set-attr _el-d1 "_" "on click 1 set :x to 10 on click 2 set @out to :x")
|
||||
(dom-append (dom-body) _el-d1)
|
||||
(hs-activate! _el-d1)
|
||||
(dom-dispatch (dom-query-by-id "d1") "click" nil)
|
||||
|
||||
@@ -432,11 +432,16 @@ def emit_element_setup(lines, elements, var_names):
|
||||
if el['hs']:
|
||||
hs_val = el['hs']
|
||||
hs_val = hs_val.replace('\\', '')
|
||||
# Newlines in _hyperscript act as implicit 'then' separators
|
||||
hs_val = re.sub(r'\s*\n\s*', ' then ', hs_val)
|
||||
# Collapse multiple spaces (from HTML formatting)
|
||||
hs_val = re.sub(r'\s{2,}', ' then ', hs_val)
|
||||
hs_val = re.sub(r'(then\s*)+then', 'then', hs_val) # dedupe
|
||||
# Newlines/tabs in _hyperscript act as implicit 'then' separators.
|
||||
# Only insert 'then' before command keywords, not within expressions.
|
||||
cmd_kws = r'(?:set|put|get|add|remove|toggle|hide|show|if|repeat|for|wait|send|trigger|log|call|take|throw|return|append|tell|go|halt|settle|increment|decrement|fetch|make|install|measure|empty|reset|swap|default|morph|render|scroll|focus|select|pick|beep!)'
|
||||
# Replace multi-whitespace before a command keyword with ' then '
|
||||
hs_val = re.sub(r'\s{2,}(?=' + cmd_kws + r'\b)', ' then ', hs_val)
|
||||
# Also handle actual newlines
|
||||
hs_val = re.sub(r'\s*[\n\r]\s*', ' then ', hs_val)
|
||||
# Clean up: collapse spaces, dedupe then
|
||||
hs_val = re.sub(r'\s+', ' ', hs_val)
|
||||
hs_val = re.sub(r'(then\s*)+then', 'then', hs_val)
|
||||
hs_val = hs_val.strip()
|
||||
if not hs_val:
|
||||
lines.append(f' (dom-append (dom-body) {var})')
|
||||
|
||||
Reference in New Issue
Block a user