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.32k stars 155 forks source link

for of loop assigned to object field issue #878

Open normalser opened 8 years ago

normalser commented 8 years ago

Hi,

Sorry if duplicate (couldn't find one):

a: for x,y of {} => x => Fails with Unexpected '}' a: for x of {} => x => Works fine a= for x,y of {} => x => Works fine a: for x,y in [] => x => Works fine

summivox commented 8 years ago

The problem occurs at lexer rewrite pass. Specifically regarding implicit object. The comma after x is interpreted as field separator of the implicit object (my mistake, not the real reason) rather than a part of the loophead.

IMHO this is (yet again) a problem with current (hacky) lexer design. It has something to do with how for loop is handled right now, which I planned to fix (but couldn't find time as it's a big change).

Tokens after rewrite:

{ ID:a : FOR: ID:x }: , ID:y OF { } INDENT:0 ID:x DEDENT:0 NEWLINE:\n