LiveScript is a language which compiles to JavaScript. It has a straightforward mapping to JavaScript and allows you to write expressive code devoid of repetitive boilerplate. While LiveScript adds many features to assist in functional style programming, it also has many improvements for object oriented and imperative programming.
We stumbled upon a problem in livescript compiling (haven't found it in the issues, if it already exists, let me know!)
In our code, we sometimes use for in loops to only use the index since this produces quite elegant code. E.g:
array = ["a", "a", "a"]
for ,i in array
console.log(i)
Independently, we sometimes use the ? operator to default to something in case a variable doesn't exist. E.g:
for el, i in (array ? [])
console.log(el, i)
These things work fine. What doesn't work is the following:
array = ["a", "a", "a"]
for ,i in (array ? [])
console.log(i)
It works when I write for el, i, but with for ,i this fails. This seems to be an issue with the compile:
var array, i$, len$, i, results$ = [];
array = ["a", "a", "a"];
for (i$ = 0, len$ = array != null
? array
: [].length; i$ < len$; ++i$) {
i = i$;
results$.push(console.log(i));
}
In our opinion, since it doesn't use parentheses, it len$ always refers to [].length instead of array.length.
Can you fix this or is our way of writing for-in loops with the iterated element ommited (for ,i in array) generally not supported? (We've used it quite often and in other situations didn't come across problems)
We stumbled upon a problem in livescript compiling (haven't found it in the issues, if it already exists, let me know!)
In our code, we sometimes use for in loops to only use the index since this produces quite elegant code. E.g:
Independently, we sometimes use the
?
operator to default to something in case a variable doesn't exist. E.g:These things work fine. What doesn't work is the following:
It works when I write
for el, i
, but withfor ,i
this fails. This seems to be an issue with the compile:In our opinion, since it doesn't use parentheses, it
len$
always refers to[].length
instead ofarray.length
.Can you fix this or is our way of writing for-in loops with the iterated element ommited (
for ,i in array
) generally not supported? (We've used it quite often and in other situations didn't come across problems)Thanks in advance,
Jonathan