js-on-sx: logical assignment &&= ||= ??=
js-compound-update gains logical-assign operators: - &&= → (if (js-to-boolean lhs) rhs lhs) - ||= → (if (js-to-boolean lhs) lhs rhs) - ??= → (if nullish? rhs lhs) 427/429 unit (+4), 148/148 slice unchanged.
This commit is contained in:
@@ -1093,6 +1093,16 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 2704)
|
||||
(eval "(js-eval \"var o = {a:null}; var r = o?.a?.b; r === undefined\")")
|
||||
|
||||
;; ── Phase 11.logassign: &&= ||= ??= ─────────────────────────────
|
||||
(epoch 2800)
|
||||
(eval "(js-eval \"var q=0; q||=5; q\")")
|
||||
(epoch 2801)
|
||||
(eval "(js-eval \"var q=1; q&&=7; q\")")
|
||||
(epoch 2802)
|
||||
(eval "(js-eval \"var q=null; q??=99; q\")")
|
||||
(epoch 2803)
|
||||
(eval "(js-eval \"var q=42; q??=99; q\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
|
||||
@@ -1683,6 +1693,12 @@ check 2702 "?. obj undef" 'undefined'
|
||||
check 2703 "?. chained" '7'
|
||||
check 2704 "?. null-chain" 'true'
|
||||
|
||||
# ── Phase 11.logassign ────────────────────────────────────────
|
||||
check 2800 "||= falsy" '5'
|
||||
check 2801 "&&= truthy" '7'
|
||||
check 2802 "??= null" '99'
|
||||
check 2803 "??= has value" '42'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "✓ $PASS/$TOTAL JS-on-SX tests passed"
|
||||
|
||||
@@ -506,6 +506,27 @@
|
||||
((= op "/=") (list (js-sym "js-div") lhs-expr rhs-expr))
|
||||
((= op "%=") (list (js-sym "js-mod") lhs-expr rhs-expr))
|
||||
((= op "**=") (list (js-sym "js-pow") lhs-expr rhs-expr))
|
||||
((= op "&&=")
|
||||
(list
|
||||
(js-sym "if")
|
||||
(list (js-sym "js-to-boolean") lhs-expr)
|
||||
rhs-expr
|
||||
lhs-expr))
|
||||
((= op "||=")
|
||||
(list
|
||||
(js-sym "if")
|
||||
(list (js-sym "js-to-boolean") lhs-expr)
|
||||
lhs-expr
|
||||
rhs-expr))
|
||||
((= op "??=")
|
||||
(list
|
||||
(js-sym "if")
|
||||
(list
|
||||
(js-sym "or")
|
||||
(list (js-sym "=") lhs-expr nil)
|
||||
(list (js-sym "js-undefined?") lhs-expr))
|
||||
rhs-expr
|
||||
lhs-expr))
|
||||
(else (error (str "js-compound-update: unsupported op: " op))))))
|
||||
|
||||
(define
|
||||
|
||||
Reference in New Issue
Block a user