gkz / LiveScript

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.
http://livescript.net
MIT License
2.31k stars 155 forks source link

The 'CoffeeScript to LiveScript Conversion Guide' should have a point about string ranges #351

Open Haspaker opened 11 years ago

Haspaker commented 11 years ago

I don't know if this is the right forum for this, so forgive me in advance if I should have brought it up somewhere else.

Anyway, ranges on strings do not behave the same in CoffeScript and LiveScript.

In CoffeeScript, 'sample'[0..2] compiles to 'sample'.slice(0, 3) and returns the string 'sam'.

In LiveScript, 'sample'[0 to 2] compiles to ['sample'[0], 'sample'[1], 'sample'[2]] and returns the array ['s','a','m'].

This could break things when moving from CoffeScript to LiveScript, so it would be helpful if it was brought to attention in the 'CoffeeScript to LiveScript Conversion Guide'.

(this happened to me a few minutes ago when converting a server I had written)

ethanresnick commented 10 years ago

I'm happy to submit a PR documenting this, but maybe livescript should just compile to slice like Coffeescript does, as being able to use the range to get a substring is useful.

vendethiel commented 10 years ago

see #168