js-on-sx: delete operator

js-transpile-unop intercepts 'delete' before transpiling the
operand. Maps to (js-delete-prop obj key) for members and indexed
access. Runtime js-delete-prop sets the dict value to js-undefined
and returns true.

444/446 unit (+2), 148/148 slice unchanged.
This commit is contained in:
2026-04-23 23:34:05 +00:00
parent 27bd25843e
commit 6293a0fe70
3 changed files with 44 additions and 10 deletions

View File

@@ -165,16 +165,31 @@
js-transpile-unop
(fn
(op arg)
(let
((a (js-transpile arg)))
(cond
((= op "-") (list (js-sym "js-neg") a))
((= op "+") (list (js-sym "js-pos") a))
((= op "!") (list (js-sym "js-not") a))
((= op "~") (list (js-sym "js-bitnot") a))
((= op "typeof") (list (js-sym "js-typeof") a))
((= op "void") (list (js-sym "quote") :js-undefined))
(else (error (str "js-transpile-unop: unsupported op: " op)))))))
(cond
((= op "delete")
(cond
((js-tag? arg "js-member")
(list
(js-sym "js-delete-prop")
(js-transpile (nth arg 1))
(nth arg 2)))
((js-tag? arg "js-index")
(list
(js-sym "js-delete-prop")
(js-transpile (nth arg 1))
(js-transpile (nth arg 2))))
(else true)))
(else
(let
((a (js-transpile arg)))
(cond
((= op "-") (list (js-sym "js-neg") a))
((= op "+") (list (js-sym "js-pos") a))
((= op "!") (list (js-sym "js-not") a))
((= op "~") (list (js-sym "js-bitnot") a))
((= op "typeof") (list (js-sym "js-typeof") a))
((= op "void") (list (js-sym "quote") :js-undefined))
(else (error (str "js-transpile-unop: unsupported op: " op)))))))))
;; ── Binary ops ────────────────────────────────────────────────────