hello, I was doing some testing with JS codegen an...
# javascript
w
hello, I was doing some testing with JS codegen and found something interesting. For example if we have an expression
foo?.bar?.baz
the code generated is
(tmp$ = foo != null ? foo.bar : null) != null ? tmp$.baz : null
. This feels unnecessary as there are multiple
null
checks. Couldnt an alternative be
foo == null ? null : (foo.bar == null ? null : foo.bar.baz)
? this removes all the extra
!= null
checks. If there is some reason for this that I am unaware, please let me know. Thanks in advance for the clarification
e
custom properties mean that the temporary variable is needed
w
right i understand that...but would it still not be beneficial to do
== null
? and early exit with a null value?
as opposed to the current solution
something like
(tmp$ = foo) == null ? null : ((tmp$ = tmp$.bar) == null ? null : tmp$.baz)
?
a
Couldn't we use optional chaining ? It's pretty much the same syntax as Kotlin and present in all browser/runtimes since years now, so totally safe to use
e
Kotlin/JS targets ES5, not ES6, so no optional chaining
a
Ah yes you're right, as JS IR is said stable in 1.8.0-RC, is the ES6 target being worked on now ?