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:
@@ -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 ────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user