js-on-sx: optional chaining ?.
Parser: jp-parse-postfix handles op "?." followed by ident / [ / ( emitting (js-optchain-member obj name), (js-optchain-index obj k), or (js-optchain-call callee args). Transpile: each emits (js-optchain-get obj key) or (js-optchain-call fn args). Runtime: js-optchain-get and js-optchain-call short-circuit to js-undefined when receiver is null/undefined. 423/425 unit (+5), 148/148 slice unchanged.
This commit is contained in:
@@ -1750,6 +1750,24 @@
|
||||
|
||||
(define Object {:entries js-object-entries :values js-object-values :freeze js-object-freeze :assign js-object-assign :keys js-object-keys})
|
||||
|
||||
(define
|
||||
js-optchain-get
|
||||
(fn
|
||||
(obj key)
|
||||
(if
|
||||
(or (= obj nil) (js-undefined? obj))
|
||||
js-undefined
|
||||
(js-get-prop obj key))))
|
||||
|
||||
(define
|
||||
js-optchain-call
|
||||
(fn
|
||||
(fn-val args)
|
||||
(if
|
||||
(or (= fn-val nil) (js-undefined? fn-val))
|
||||
js-undefined
|
||||
(js-call-plain fn-val args))))
|
||||
|
||||
(define
|
||||
js-array-spread-build
|
||||
(fn
|
||||
|
||||
Reference in New Issue
Block a user