diff --git a/lib/hyperscript/compiler.sx b/lib/hyperscript/compiler.sx index f11c2678..e25a60f3 100644 --- a/lib/hyperscript/compiler.sx +++ b/lib/hyperscript/compiler.sx @@ -413,11 +413,14 @@ (hs-to-sx mode) (list (quote fn) (list) body))))))) (define + hs-reserved-var? + (fn (name) (or (= name "meta") (= name "event") (= name "it") (= name "result"))) emit-for (fn (ast) (let ((var-name (nth ast 1)) + (safe-param (if (hs-reserved-var? var-name) (str "_hs_lv_" var-name) var-name)) (raw-coll-ast (nth ast 2)) (where-cond (if @@ -452,12 +455,12 @@ (quote map-indexed) (list (quote fn) - (list (make-symbol (nth ast 5)) (make-symbol var-name)) + (list (make-symbol (nth ast 5)) (make-symbol safe-param)) body) collection) (list (quote hs-for-each) - (list (quote fn) (list (make-symbol var-name)) body) + (list (quote fn) (list (make-symbol safe-param)) body) collection))))) (define emit-wait-for @@ -1556,6 +1559,11 @@ (emit-set tgt (list (quote hs-empty-like) (hs-to-sx tgt)))) + ((and (list? tgt) (= (first tgt) (quote query))) + (list + (quote for-each) + (list (quote fn) (list (quote _el)) (list (quote hs-empty-target!) (quote _el))) + (list (quote hs-query-all) (nth tgt 1)))) (true (list (quote hs-empty-target!) (hs-to-sx tgt)))))) ((= head (quote open-element)) (list (quote hs-open!) (hs-to-sx (nth ast 1)))) diff --git a/shared/static/wasm/sx/hs-compiler.sx b/shared/static/wasm/sx/hs-compiler.sx index f11c2678..e25a60f3 100644 --- a/shared/static/wasm/sx/hs-compiler.sx +++ b/shared/static/wasm/sx/hs-compiler.sx @@ -413,11 +413,14 @@ (hs-to-sx mode) (list (quote fn) (list) body))))))) (define + hs-reserved-var? + (fn (name) (or (= name "meta") (= name "event") (= name "it") (= name "result"))) emit-for (fn (ast) (let ((var-name (nth ast 1)) + (safe-param (if (hs-reserved-var? var-name) (str "_hs_lv_" var-name) var-name)) (raw-coll-ast (nth ast 2)) (where-cond (if @@ -452,12 +455,12 @@ (quote map-indexed) (list (quote fn) - (list (make-symbol (nth ast 5)) (make-symbol var-name)) + (list (make-symbol (nth ast 5)) (make-symbol safe-param)) body) collection) (list (quote hs-for-each) - (list (quote fn) (list (make-symbol var-name)) body) + (list (quote fn) (list (make-symbol safe-param)) body) collection))))) (define emit-wait-for @@ -1556,6 +1559,11 @@ (emit-set tgt (list (quote hs-empty-like) (hs-to-sx tgt)))) + ((and (list? tgt) (= (first tgt) (quote query))) + (list + (quote for-each) + (list (quote fn) (list (quote _el)) (list (quote hs-empty-target!) (quote _el))) + (list (quote hs-query-all) (nth tgt 1)))) (true (list (quote hs-empty-target!) (hs-to-sx tgt)))))) ((= head (quote open-element)) (list (quote hs-open!) (hs-to-sx (nth ast 1))))