diff --git a/lib/hyperscript/compiler.sx b/lib/hyperscript/compiler.sx index 73daa348..efc4a8cb 100644 --- a/lib/hyperscript/compiler.sx +++ b/lib/hyperscript/compiler.sx @@ -1107,13 +1107,21 @@ (hs-to-sx (nth ast 1)) (nth ast 2))) ((= head (quote coll-where)) - (list - (quote filter) + (let + ((raw-coll (hs-to-sx (nth ast 1)))) (list - (quote fn) - (list (quote it)) - (hs-to-sx (nth ast 2))) - (hs-to-sx (nth ast 1)))) + (quote filter) + (list + (quote fn) + (list (quote it)) + (hs-to-sx (nth ast 2))) + (if + (symbol? raw-coll) + (list + (quote cek-try) + (list (quote fn) (list) raw-coll) + (list (quote fn) (list (quote _e)) nil)) + raw-coll)))) ((= head (quote coll-sorted)) (list (quote hs-sorted-by) diff --git a/lib/hyperscript/integration.sx b/lib/hyperscript/integration.sx index 823a899d..03b6f3b7 100644 --- a/lib/hyperscript/integration.sx +++ b/lib/hyperscript/integration.sx @@ -115,7 +115,15 @@ (dom-set-data el "hs-script" src) (dom-set-data el "hs-active" true) (dom-set-attr el "data-hyperscript-powered" "true") - (let ((handler (hs-handler src))) (handler el)) + (let + ((handler (hs-handler src))) + (let + ((el-type (dom-get-attr el "type")) + (comp-name (dom-get-attr el "component"))) + (if + (= el-type "text/hyperscript-template") + (for-each handler (hs-query-all (or comp-name ""))) + (handler el)))) (dom-dispatch el "hyperscript:after:init" nil))))))) ;; ── Boot subtree: for dynamic content ─────────────────────────── diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index 1a263ece..09d3ace0 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -2783,6 +2783,8 @@ ((body (parse-cmd-list))) (match-kw "end") (list (quote view-transition!) using body))))) + ((and (= typ "keyword") (or (= val "on") (= val "init") (= val "def") (= val "behavior") (= val "live"))) + nil) (true (parse-expr)))))) (define parse-cmd-list diff --git a/shared/static/wasm/sx/hs-compiler.sx b/shared/static/wasm/sx/hs-compiler.sx index 05504731..efc4a8cb 100644 --- a/shared/static/wasm/sx/hs-compiler.sx +++ b/shared/static/wasm/sx/hs-compiler.sx @@ -32,10 +32,9 @@ (let ((th (first target))) (cond - ((= th dot-sym) + ((or (= th dot-sym) (= th (make-symbol "poss"))) (let - ((base-ast (nth target 1)) - (prop (nth target 2))) + ((base-ast (nth target 1)) (prop (nth target 2))) (cond ((and (list? base-ast) (= (first base-ast) (quote query)) (let ((s (nth base-ast 1))) (and (string? s) (> (len s) 0) (= (substring s 0 1) ".")))) (list @@ -69,16 +68,56 @@ (list (quote hs-query-all) (nth inner 1))))) (true (list - (quote dom-set-prop) - (hs-to-sx base-ast) - prop - value))))) + (quote let) + (list + (list + (quote __hs-obj) + (if + (or + (symbol? base-ast) + (and + (list? base-ast) + (= (str (first base-ast)) "ref"))) + (let + ((sel (if (symbol? base-ast) (str base-ast) (nth base-ast 1)))) + (list + (quote do) + (list + (quote host-set!) + (list (quote host-global) "window") + "_hs_last_query_sel" + sel) + (hs-to-sx base-ast))) + (hs-to-sx base-ast)))) + (list + (quote do) + (list (quote hs-null-raise!) (quote __hs-obj)) + (list + (quote dom-set-prop) + (quote __hs-obj) + prop + value))))))) ((= th (quote attr)) - (list - (quote hs-set-attr!) - (hs-to-sx (nth target 2)) - (nth target 1) - value)) + (let + ((base-ast (nth target 2))) + (if + (and (list? base-ast) (= (str (first base-ast)) "ref")) + (list + (quote do) + (list + (quote set!) + (quote _hs-last-query-sel) + (nth base-ast 1)) + (list + (quote hs-set-attr!) + (hs-to-sx base-ast) + (nth target 1) + value)) + (list + (quote hs-set-attr!) + (hs-to-sx base-ast) + (nth target 1) + value)))) ((= th (quote style)) (list (quote dom-set-style) @@ -86,10 +125,7 @@ (nth target 1) value)) ((= th (quote ref)) - (list - (quote set!) - (make-symbol (nth target 1)) - value)) + (list (quote set!) (make-symbol (nth target 1)) value)) ((= th (quote local)) (list (quote hs-scoped-set!) @@ -117,8 +153,7 @@ (list (quote hs-set-inner-html!) (hs-to-sx target) value)) ((= th (quote of)) (let - ((prop-ast (nth target 1)) - (obj-ast (nth target 2))) + ((prop-ast (nth target 1)) (obj-ast (nth target 2))) (if (and (list? prop-ast) (= (first prop-ast) dot-sym)) (let @@ -370,13 +405,13 @@ (cond ((and (= (len ast) 4) (list? (nth ast 2)) (= (first (nth ast 2)) (quote dict))) (list - (quote dom-dispatch) + (quote hs-dispatch!) (hs-to-sx (nth ast 3)) name (hs-to-sx (nth ast 2)))) ((= (len ast) 3) (list - (quote dom-dispatch) + (quote hs-dispatch!) (hs-to-sx (nth ast 2)) name (list (quote dict) "sender" (quote me)))) @@ -391,8 +426,7 @@ (fn (ast) (let - ((mode (nth ast 1)) - (body (hs-to-sx (nth ast 2)))) + ((mode (nth ast 1)) (body (hs-to-sx (nth ast 2)))) (cond ((and (list? mode) (= (first mode) (quote forever))) (list @@ -480,9 +514,7 @@ (quote map-indexed) (list (quote fn) - (list - (make-symbol (nth ast 5)) - (make-symbol safe-param)) + (list (make-symbol (nth ast 5)) (make-symbol safe-param)) body) collection) (list @@ -495,15 +527,13 @@ (ast) (let ((event-name (nth ast 1)) - (has-from - (and (> (len ast) 2) (= (nth ast 2) :from))) + (has-from (and (> (len ast) 2) (= (nth ast 2) :from))) (has-from-or (and (> (len ast) 4) (= (nth ast 2) :from) (= (nth ast 4) :or))) - (has-or - (and (> (len ast) 2) (= (nth ast 2) :or)))) + (has-or (and (> (len ast) 2) (= (nth ast 2) :or)))) (cond (has-from-or (list @@ -512,10 +542,7 @@ event-name (nth ast 5))) (has-from - (list - (quote hs-wait-for) - (hs-to-sx (nth ast 3)) - event-name)) + (list (quote hs-wait-for) (hs-to-sx (nth ast 3)) event-name)) (has-or (list (quote hs-wait-for-or) @@ -544,14 +571,9 @@ (ast) (let ((type-name (nth ast 1)) - (called - (if (>= (len ast) 3) (nth ast 2) nil)) + (called (if (>= (len ast) 3) (nth ast 2) nil)) (args (if (>= (len ast) 4) (nth ast 3) nil)) - (kind - (if - (>= (len ast) 5) - (nth ast 4) - (quote auto)))) + (kind (if (>= (len ast) 5) (nth ast 4) (quote auto)))) (let ((make-call (cond ((nil? args) (list (quote hs-make) type-name)) (true (cons (quote hs-make) (cons type-name (map hs-to-sx args))))))) (cond @@ -606,25 +628,34 @@ (quote do) (list (quote dom-set-attr) el attr-name (quote __hs-new)) (list (quote set!) (quote it) (quote __hs-new)))))) - ((and (list? expr) (= (first expr) dot-sym)) + ((and (list? expr) (or (= (first expr) dot-sym) (= (first expr) (make-symbol "poss")))) (let - ((obj (hs-to-sx (nth expr 1))) - (prop (nth expr 2))) + ((obj (hs-to-sx (nth expr 1))) (prop (nth expr 2))) (list (quote let) - (list - (list - (quote __hs-new) - (list - (quote +) - (list - (quote hs-to-number) - (list (quote host-get) obj prop)) - amount))) + (list (list (quote __hs-obj) obj)) (list (quote do) - (list (quote host-set!) obj prop (quote __hs-new)) - (list (quote set!) (quote it) (quote __hs-new)))))) + (list (quote hs-null-raise!) (quote __hs-obj)) + (list + (quote let) + (list + (list + (quote __hs-new) + (list + (quote +) + (list + (quote hs-to-number) + (list (quote host-get) (quote __hs-obj) prop)) + amount))) + (list + (quote do) + (list + (quote host-set!) + (quote __hs-obj) + prop + (quote __hs-new)) + (list (quote set!) (quote it) (quote __hs-new)))))))) ((and (list? expr) (= (first expr) (quote style))) (let ((el (if tgt-override (hs-to-sx tgt-override) (quote me))) @@ -646,8 +677,7 @@ (list (quote set!) (quote it) (quote __hs-new)))))) ((and (list? expr) (= (first expr) (quote dom-ref))) (let - ((el (hs-to-sx (nth expr 2))) - (name (nth expr 1))) + ((el (hs-to-sx (nth expr 2))) (name (nth expr 1))) (list (quote let) (list @@ -724,25 +754,34 @@ (quote do) (list (quote dom-set-attr) el attr-name (quote __hs-new)) (list (quote set!) (quote it) (quote __hs-new)))))) - ((and (list? expr) (= (first expr) dot-sym)) + ((and (list? expr) (or (= (first expr) dot-sym) (= (first expr) (make-symbol "poss")))) (let - ((obj (hs-to-sx (nth expr 1))) - (prop (nth expr 2))) + ((obj (hs-to-sx (nth expr 1))) (prop (nth expr 2))) (list (quote let) - (list - (list - (quote __hs-new) - (list - (quote -) - (list - (quote hs-to-number) - (list (quote host-get) obj prop)) - amount))) + (list (list (quote __hs-obj) obj)) (list (quote do) - (list (quote host-set!) obj prop (quote __hs-new)) - (list (quote set!) (quote it) (quote __hs-new)))))) + (list (quote hs-null-raise!) (quote __hs-obj)) + (list + (quote let) + (list + (list + (quote __hs-new) + (list + (quote -) + (list + (quote hs-to-number) + (list (quote host-get) (quote __hs-obj) prop)) + amount))) + (list + (quote do) + (list + (quote host-set!) + (quote __hs-obj) + prop + (quote __hs-new)) + (list (quote set!) (quote it) (quote __hs-new)))))))) ((and (list? expr) (= (first expr) (quote style))) (let ((el (if tgt-override (hs-to-sx tgt-override) (quote me))) @@ -764,8 +803,7 @@ (list (quote set!) (quote it) (quote __hs-new)))))) ((and (list? expr) (= (first expr) (quote dom-ref))) (let - ((el (hs-to-sx (nth expr 2))) - (name (nth expr 1))) + ((el (hs-to-sx (nth expr 2))) (name (nth expr 1))) (list (quote let) (list @@ -823,9 +861,7 @@ (fn (ast) (let - ((name (nth ast 1)) - (params (nth ast 2)) - (body (nth ast 3))) + ((name (nth ast 1)) (params (nth ast 2)) (body (nth ast 3))) (list (quote define) (make-symbol name) @@ -836,10 +872,7 @@ (map (fn (p) - (if - (list? p) - (make-symbol (nth p 1)) - (make-symbol p))) + (if (list? p) (make-symbol (nth p 1)) (make-symbol p))) params)) (list (quote let) @@ -901,10 +934,7 @@ (let ((raw (nth ast 1))) (let - ((parts (list)) - (buf "") - (i 0) - (n (len raw))) + ((parts (list)) (buf "") (i 0) (n (len raw))) (define tpl-flush (fn @@ -942,14 +972,10 @@ (if (= depth 1) j - (tpl-find-close - (+ j 1) - (- depth 1))) + (tpl-find-close (+ j 1) (- depth 1))) (if (= (nth raw j) "{") - (tpl-find-close - (+ j 1) - (+ depth 1)) + (tpl-find-close (+ j 1) (+ depth 1)) (tpl-find-close (+ j 1) depth)))))) (define tpl-collect @@ -1049,10 +1075,7 @@ (list (quote hs-pick-random) (hs-to-sx (nth ast 1)) - (if - (nil? (nth ast 2)) - nil - (hs-to-sx (nth ast 2)))))) + (if (nil? (nth ast 2)) nil (hs-to-sx (nth ast 2)))))) ((= head (quote pick-items)) (list (quote set!) @@ -1084,13 +1107,21 @@ (hs-to-sx (nth ast 1)) (nth ast 2))) ((= head (quote coll-where)) - (list - (quote filter) + (let + ((raw-coll (hs-to-sx (nth ast 1)))) (list - (quote fn) - (list (quote it)) - (hs-to-sx (nth ast 2))) - (hs-to-sx (nth ast 1)))) + (quote filter) + (list + (quote fn) + (list (quote it)) + (hs-to-sx (nth ast 2))) + (if + (symbol? raw-coll) + (list + (quote cek-try) + (list (quote fn) (list) raw-coll) + (list (quote fn) (list (quote _e)) nil)) + raw-coll)))) ((= head (quote coll-sorted)) (list (quote hs-sorted-by) @@ -1132,13 +1163,29 @@ (if (and (list? dot-node) - (= (first dot-node) (make-symbol "."))) + (or + (= (str (first dot-node)) ".") + (= (str (first dot-node)) "poss"))) (let - ((obj (hs-to-sx (nth dot-node 1))) - (method (nth dot-node 2))) - (cons - (quote hs-method-call) - (cons obj (cons method args)))) + ((receiver-ast (nth dot-node 1)) + (method (nth dot-node 2)) + (sel + (hs-receiver-selector (nth dot-node 1) "poss"))) + (list + (quote let) + (list + (list (quote __hs-recv) (hs-to-sx receiver-ast))) + (list + (quote do) + (list + (quote host-set!) + (list (quote host-global) "window") + "_hs_last_query_sel" + sel) + (list (quote hs-null-raise!) (quote __hs-recv)) + (cons + (quote hs-method-call) + (cons (quote __hs-recv) (cons method args)))))) (if (and (list? dot-node) @@ -1151,10 +1198,7 @@ (quote hs-method-call) (cons (hs-to-sx dot-node) args)))))) ((= head (quote string-postfix)) - (list - (quote str) - (hs-to-sx (nth ast 1)) - (nth ast 2))) + (list (quote str) (hs-to-sx (nth ast 1)) (nth ast 2))) ((= head (quote block-literal)) (let ((params (map make-symbol (nth ast 1))) @@ -1172,6 +1216,10 @@ ((= prop "first") (list (quote hs-first) target)) ((= prop "last") (list (quote hs-last) target)) (true (list (quote host-get) target prop))))) + ((= head (make-symbol "poss")) + (let + ((target (hs-to-sx (nth ast 1))) (prop (nth ast 2))) + (list (quote host-get) target prop))) ((= head (quote ref)) (cond ((= (nth ast 1) "selection") @@ -1206,10 +1254,7 @@ (hs-to-sx (nth ast 1)) (nth ast 2))) ((= head (quote local)) - (list - (quote hs-scoped-get) - (quote me) - (nth ast 1))) + (list (quote hs-scoped-get) (quote me) (nth ast 1))) ((= head (quote array)) (cons (quote list) (map hs-to-sx (rest ast)))) ((= head (quote not)) @@ -1272,8 +1317,7 @@ (list (quote nil?) (hs-to-sx (nth ast 1))))) ((= head (quote matches?)) (let - ((left (nth ast 1)) - (right (nth ast 2))) + ((left (nth ast 1)) (right (nth ast 2))) (if (and (list? right) (= (first right) (quote query))) (list @@ -1393,10 +1437,7 @@ "parentElement") (nth ast 1))) ((= head (quote next)) - (list - (quote hs-next) - (hs-to-sx (nth ast 2)) - (nth ast 1))) + (list (quote hs-next) (hs-to-sx (nth ast 2)) (nth ast 1))) ((= head (quote previous)) (list (quote hs-previous) @@ -1434,7 +1475,7 @@ (quote dom-add-class) (quote _el) (nth ast 1))) - (list (quote hs-query-all) (nth raw-tgt 1))) + (list (quote hs-query-all-checked) (nth raw-tgt 1))) (list (quote dom-add-class) (hs-to-sx raw-tgt) @@ -1447,19 +1488,23 @@ (nth ast 2))) ((= head (quote set-styles)) (let - ((pairs (nth ast 1)) - (tgt (hs-to-sx (nth ast 2)))) - (cons - (quote do) - (map - (fn - (p) - (list - (quote dom-set-style) - tgt - (first p) - (nth p 1))) - pairs)))) + ((pairs (nth ast 1)) (tgt (hs-to-sx (nth ast 2)))) + (list + (quote let) + (list (list (quote __hs-tgt) tgt)) + (cons + (quote do) + (cons + (list (quote hs-null-raise!) (quote __hs-tgt)) + (map + (fn + (p) + (list + (quote dom-set-style) + (quote __hs-tgt) + (first p) + (nth p 1))) + pairs)))))) ((= head (quote multi-add-class)) (let ((target (hs-to-sx (nth ast 1))) @@ -1575,7 +1620,7 @@ (quote dom-remove-class) (quote _el) (nth ast 1))) - (list (quote hs-query-all) (nth raw-tgt 1))) + (list (quote hs-query-all-checked) (nth raw-tgt 1))) (list (quote dom-remove-class) (if (nil? raw-tgt) (quote me) (hs-to-sx raw-tgt)) @@ -1586,10 +1631,7 @@ (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))))) + ((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 @@ -1622,8 +1664,7 @@ (list (quote hs-splice-at!) (hs-to-sx coll) idx)))) ((and (list? tgt) (= (first tgt) dot-sym)) (let - ((obj (nth tgt 1)) - (prop (nth tgt 2))) + ((obj (nth tgt 1)) (prop (nth tgt 2))) (emit-set obj (list @@ -1632,8 +1673,7 @@ prop)))) ((and (list? tgt) (= (first tgt) (quote of))) (let - ((prop-ast (nth tgt 1)) - (obj-ast (nth tgt 2))) + ((prop-ast (nth tgt 1)) (obj-ast (nth tgt 2))) (let ((prop (cond ((string? prop-ast) prop-ast) ((and (list? prop-ast) (= (first prop-ast) (quote ref))) (nth prop-ast 1)) (true (hs-to-sx prop-ast))))) (emit-set @@ -1642,11 +1682,19 @@ (quote hs-dict-without) (hs-to-sx obj-ast) prop))))) - (true (list (quote dom-remove) (hs-to-sx tgt)))))) + (true + (let + ((tgt (hs-to-sx tgt))) + (list + (quote let) + (list (list (quote __hs-tgt) tgt)) + (list + (quote do) + (list (quote hs-null-raise!) (quote __hs-tgt)) + (list (quote dom-remove) (quote __hs-tgt))))))))) ((= head (quote add-value)) (let - ((val (hs-to-sx (nth ast 1))) - (tgt (nth ast 2))) + ((val (hs-to-sx (nth ast 1))) (tgt (nth ast 2))) (emit-set tgt (list (quote hs-add-to!) val (hs-to-sx tgt))))) @@ -1660,8 +1708,7 @@ (hs-to-sx (nth ast 2))))) ((= head (quote remove-value)) (let - ((val (hs-to-sx (nth ast 1))) - (tgt (nth ast 2))) + ((val (hs-to-sx (nth ast 1))) (tgt (nth ast 2))) (emit-set tgt (list (quote hs-remove-from!) val (hs-to-sx tgt))))) @@ -1704,7 +1751,16 @@ ((= head (quote remove-attr)) (let ((tgt (if (nil? (nth ast 2)) (quote me) (hs-to-sx (nth ast 2))))) - (list (quote dom-remove-attr) tgt (nth ast 1)))) + (list + (quote let) + (list (list (quote __hs-tgt) tgt)) + (list + (quote do) + (list (quote hs-null-raise!) (quote __hs-tgt)) + (list + (quote dom-remove-attr) + (quote __hs-tgt) + (nth ast 1)))))) ((= head (quote remove-css)) (let ((tgt (if (nil? (nth ast 2)) (quote me) (hs-to-sx (nth ast 2)))) @@ -1827,14 +1883,19 @@ (nth ast 3) (hs-to-sx (nth ast 4)))) ((= head (quote set!)) - (emit-set - (nth ast 1) - (hs-to-sx (nth ast 2)))) + (emit-set (nth ast 1) (hs-to-sx (nth ast 2)))) ((= head (quote set-el!)) - (list (quote hs-set-element!) (hs-to-sx (nth ast 1)) (hs-to-sx (nth ast 2)))) + (list + (quote hs-set-element!) + (hs-to-sx (nth ast 1)) + (hs-to-sx (nth ast 2)))) ((= head (quote view-transition!)) - (let ((body (nth ast 2))) - (list (quote hs-view-transition!) (hs-to-sx (nth ast 1)) (if (nil? body) (quote nil) (hs-to-sx body))))) + (let + ((body (nth ast 2))) + (list + (quote hs-view-transition!) + (hs-to-sx (nth ast 1)) + (if (nil? body) (quote nil) (hs-to-sx body))))) ((= head (quote put!)) (let ((val (hs-to-sx (nth ast 1))) @@ -1924,8 +1985,7 @@ (= (first c) (quote define))))) compiled))) (cons (quote do) (append defs non-defs))))))) - ((= head (quote wait)) - (list (quote hs-wait) (nth ast 1))) + ((= head (quote wait)) (list (quote hs-wait) (nth ast 1))) ((= head (quote wait-for)) (emit-wait-for ast)) ((= head (quote log)) (list (quote console-log) (hs-to-sx (nth ast 1)))) @@ -1938,34 +1998,18 @@ (= (len ast) 4) (list? (nth ast 2)) (= (first (nth ast 2)) (quote dict)))) - (tgt - (if - (= (len ast) 4) - (nth ast 3) - (nth ast 2))) - (detail - (if - (= (len ast) 4) - (nth ast 2) - nil))) + (tgt (if (= (len ast) 4) (nth ast 3) (nth ast 2))) + (detail (if (= (len ast) 4) (nth ast 2) nil))) (list - (quote dom-dispatch) + (quote hs-dispatch!) (hs-to-sx tgt) name (if has-detail (hs-to-sx detail) nil)))) ((= head (quote hide)) (let ((tgt (let ((raw-tgt (nth ast 1))) (if (and (list? raw-tgt) (= (first raw-tgt) (quote query))) (list (quote hs-query-all) (nth raw-tgt 1)) (hs-to-sx raw-tgt)))) - (strategy - (if - (> (len ast) 2) - (nth ast 2) - "display")) - (when-cond - (if - (> (len ast) 3) - (nth ast 3) - nil))) + (strategy (if (> (len ast) 2) (nth ast 2) "display")) + (when-cond (if (> (len ast) 3) (nth ast 3) nil))) (if (nil? when-cond) (list (quote hs-hide!) tgt strategy) @@ -1980,16 +2024,8 @@ ((= head (quote show)) (let ((tgt (let ((raw-tgt (nth ast 1))) (if (and (list? raw-tgt) (= (first raw-tgt) (quote query))) (list (quote hs-query-all) (nth raw-tgt 1)) (hs-to-sx raw-tgt)))) - (strategy - (if - (> (len ast) 2) - (nth ast 2) - "display")) - (when-cond - (if - (> (len ast) 3) - (nth ast 3) - nil))) + (strategy (if (> (len ast) 2) (nth ast 2) "display")) + (when-cond (if (> (len ast) 3) (nth ast 3) nil))) (if (nil? when-cond) (list (quote hs-show!) tgt strategy) @@ -2033,25 +2069,13 @@ ((= head (quote repeat-until)) (list (quote hs-repeat-until) - (list - (quote fn) - (list) - (hs-to-sx (nth ast 1))) - (list - (quote fn) - (list) - (hs-to-sx (nth ast 2))))) + (list (quote fn) (list) (hs-to-sx (nth ast 1))) + (list (quote fn) (list) (hs-to-sx (nth ast 2))))) ((= head (quote repeat-while)) (list (quote hs-repeat-while) - (list - (quote fn) - (list) - (hs-to-sx (nth ast 1))) - (list - (quote fn) - (list) - (hs-to-sx (nth ast 2))))) + (list (quote fn) (list) (hs-to-sx (nth ast 1))) + (list (quote fn) (list) (hs-to-sx (nth ast 2))))) ((= head (quote fetch)) (list (if @@ -2064,10 +2088,7 @@ (list (quote hs-fetch-gql) (nth ast 1) - (if - (nth ast 2) - (hs-to-sx (nth ast 2)) - nil))) + (if (nth ast 2) (hs-to-sx (nth ast 2)) nil))) ((= head (quote call)) (let ((raw-fn (nth ast 1)) @@ -2077,9 +2098,42 @@ (make-symbol raw-fn) (hs-to-sx raw-fn))) (args (map hs-to-sx (rest (rest ast))))) - (let - ((call-expr (if (and (list? raw-fn) (= (first raw-fn) (quote ref))) (list (quote hs-win-call) (nth raw-fn 1) (cons (quote list) args)) (cons fn-expr args)))) - (emit-set (quote the-result) call-expr)))) + (cond + ((and (list? raw-fn) (= (first raw-fn) (quote ref))) + (emit-set + (quote the-result) + (list + (quote hs-win-call) + (nth raw-fn 1) + (cons (quote list) args)))) + ((and (list? raw-fn) (= (str (first raw-fn)) ".")) + (let + ((receiver-ast (nth raw-fn 1)) + (prop-name (nth raw-fn 2)) + (sel (hs-receiver-selector (nth raw-fn 1) "dot"))) + (list + (quote let) + (list + (list + (quote __hs-recv) + (hs-to-sx receiver-ast))) + (list + (quote do) + (list + (quote set!) + (quote _hs-last-query-sel) + sel) + (list (quote hs-null-raise!) (quote __hs-recv)) + (emit-set + (quote the-result) + (cons + (list + (quote host-get) + (quote __hs-recv) + prop-name) + args)))))) + (true + (emit-set (quote the-result) (cons fn-expr args)))))) ((= head (quote return)) (let ((val (nth ast 1))) @@ -2094,11 +2148,13 @@ ((= head (quote throw)) (list (quote raise) (hs-to-sx (nth ast 1)))) ((= head (quote settle)) - (list (quote hs-settle) (quote me))) + (let + ((raw-tgt (if (> (len ast) 1) (nth ast 1) nil))) + (list + (quote hs-settle) + (if (nil? raw-tgt) (quote me) (hs-to-sx raw-tgt))))) ((= head (quote go)) - (list - (quote hs-navigate!) - (hs-to-sx (nth ast 1)))) + (list (quote hs-navigate!) (hs-to-sx (nth ast 1)))) ((= head (quote ask)) (let ((val (list (quote hs-ask) (hs-to-sx (nth ast 1))))) @@ -2184,35 +2240,17 @@ (let ((kind (nth ast 1)) (name (nth ast 2)) - (from-sel - (if - (> (len ast) 3) - (nth ast 3) - nil)) - (for-tgt - (if - (> (len ast) 4) - (nth ast 4) - nil)) - (attr-val - (if - (> (len ast) 5) - (nth ast 5) - nil)) - (with-val - (if - (> (len ast) 6) - (nth ast 6) - nil))) + (from-sel (if (> (len ast) 3) (nth ast 3) nil)) + (for-tgt (if (> (len ast) 4) (nth ast 4) nil)) + (attr-val (if (> (len ast) 5) (nth ast 5) nil)) + (with-val (if (> (len ast) 6) (nth ast 6) nil))) (let ((target (if for-tgt (hs-to-sx for-tgt) (quote me))) (scope (cond ((nil? from-sel) nil) ((and (list? from-sel) (= (first from-sel) (quote query))) - (list - (quote hs-query-all) - (nth from-sel 1))) + (list (quote hs-query-all) (nth from-sel 1))) (true (hs-to-sx from-sel)))) (with-sx (if @@ -2265,10 +2303,7 @@ ((= head (quote increment!)) (if (= (len ast) 3) - (emit-inc - (nth ast 1) - 1 - (nth ast 2)) + (emit-inc (nth ast 1) 1 (nth ast 2)) (emit-inc (nth ast 1) (nth ast 2) @@ -2276,10 +2311,7 @@ ((= head (quote decrement!)) (if (= (len ast) 3) - (emit-dec - (nth ast 1) - 1 - (nth ast 2)) + (emit-dec (nth ast 1) 1 (nth ast 2)) (emit-dec (nth ast 1) (nth ast 2) @@ -2293,8 +2325,7 @@ ((= head (quote on)) (emit-on ast)) ((= head (quote when-changes)) (let - ((expr (nth ast 1)) - (body (nth ast 2))) + ((expr (nth ast 1)) (body (nth ast 2))) (if (and (list? expr) (= (first expr) (quote dom-ref))) (list @@ -2306,10 +2337,7 @@ ((= head (quote init)) (list (quote hs-init) - (list - (quote fn) - (list) - (hs-to-sx (nth ast 1))))) + (list (quote fn) (list) (hs-to-sx (nth ast 1))))) ((= head (quote def)) (let ((body (hs-to-sx (nth ast 3))) @@ -2348,10 +2376,7 @@ (quote =) (list (quote first) (quote _e)) "hs-return")) - (list - (quote nth) - (quote _e) - 1) + (list (quote nth) (quote _e) 1) (list (quote raise) (quote _e))))) body)))) (list @@ -2370,22 +2395,14 @@ (string? src) (first (sx-parse src)) (list (quote cek-eval) (hs-to-sx src))))) - ((= head (quote component)) - (make-symbol (nth ast 1))) + ((= head (quote component)) (make-symbol (nth ast 1))) ((= head (quote render)) (let ((comp-raw (nth ast 1)) (kwargs (nth ast 2)) - (pos - (if - (> (len ast) 3) - (nth ast 3) - nil)) + (pos (if (> (len ast) 3) (nth ast 3) nil)) (target - (if - (> (len ast) 4) - (hs-to-sx (nth ast 4)) - nil))) + (if (> (len ast) 4) (hs-to-sx (nth ast 4)) nil))) (let ((comp (if (string? comp-raw) (make-symbol comp-raw) (hs-to-sx comp-raw)))) (define @@ -2482,9 +2499,7 @@ ((and (list? raw-tgt) (= (first raw-tgt) (quote query))) (list (quote hs-reset!) - (list - (quote hs-query-all) - (nth raw-tgt 1)))) + (list (quote hs-query-all) (nth raw-tgt 1)))) (true (list (quote hs-reset!) (hs-to-sx raw-tgt)))))) ((= head (quote default!)) (let @@ -2510,8 +2525,7 @@ (list (quote dom-focus) (hs-to-sx (nth ast 1)))) ((= head (quote js-block)) (let - ((params (nth ast 1)) - (js-src (nth ast 2))) + ((params (nth ast 1)) (js-src (nth ast 2))) (let ((bound-syms (map (fn (p) (make-symbol p)) params))) (list @@ -2531,4 +2545,16 @@ (true ast))))))))) ;; ── Convenience: source → SX ───────────────────────────────── +(define + hs-receiver-selector + (fn + (ast notation) + (cond + ((and (list? ast) (= (str (first ast)) "ref")) (nth ast 1)) + ((and (list? ast) (= (str (first ast)) ".")) + (str (hs-receiver-selector (nth ast 1) notation) "." (nth ast 2))) + ((and (list? ast) (= (str (first ast)) "poss")) + (str (hs-receiver-selector (nth ast 1) "poss") "'s " (nth ast 2))) + (true "?")))) + (define hs-to-sx-from-source (fn (src) (hs-to-sx (hs-compile src)))) \ No newline at end of file diff --git a/shared/static/wasm/sx/hs-integration.sx b/shared/static/wasm/sx/hs-integration.sx index 823a899d..03b6f3b7 100644 --- a/shared/static/wasm/sx/hs-integration.sx +++ b/shared/static/wasm/sx/hs-integration.sx @@ -115,7 +115,15 @@ (dom-set-data el "hs-script" src) (dom-set-data el "hs-active" true) (dom-set-attr el "data-hyperscript-powered" "true") - (let ((handler (hs-handler src))) (handler el)) + (let + ((handler (hs-handler src))) + (let + ((el-type (dom-get-attr el "type")) + (comp-name (dom-get-attr el "component"))) + (if + (= el-type "text/hyperscript-template") + (for-each handler (hs-query-all (or comp-name ""))) + (handler el)))) (dom-dispatch el "hyperscript:after:init" nil))))))) ;; ── Boot subtree: for dynamic content ─────────────────────────── diff --git a/shared/static/wasm/sx/hs-parser.sx b/shared/static/wasm/sx/hs-parser.sx index 1a263ece..09d3ace0 100644 --- a/shared/static/wasm/sx/hs-parser.sx +++ b/shared/static/wasm/sx/hs-parser.sx @@ -2783,6 +2783,8 @@ ((body (parse-cmd-list))) (match-kw "end") (list (quote view-transition!) using body))))) + ((and (= typ "keyword") (or (= val "on") (= val "init") (= val "def") (= val "behavior") (= val "live"))) + nil) (true (parse-expr)))))) (define parse-cmd-list