An observation found while testing collection lite...
# javascript
e
An observation found while testing collection literals. Not sure if it's JS-specific or not.
b
You are right, this is due to
[]
translating to an
inline
function call. Generally, each new level of inlining causes the creation of a temporary variable. This is done for better stepping experience when debugging. Bu here we indeed could treat an inline function transparently.
e
Yup for the debugging part I agree that it's expected. I guess I could rephrase to: is there anything that the JS pipeline can do about this, or should the collection literal implementation itself be "smarter"?
b
No, this has nothing to do with collection literals, it's the general behavior.
gratitude thank you 1
e
I'm wondering mostly because inlining the usage is not always possible from a minification perspective. It's very rare.
So basically my idea of
Why not instead map
[]
directly to
emptyList()
?
Is going down the wrong path. Understood.
b
The right solution would be to annotate the parameterless
of()
method (which the empty collection literal is translated into) with something like
@InlineOnly
for it to be transparent wrt debug info. It should work this way in Kotlin/JVM, I'm not sure about Kotlin/JS though.
gratitude thank you 1
e
Thanks! In the meantime I'll keep using
empty*
functions directly. It probably communicates the intent in a clearer way too.