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

Semiautovivification with a concat assignment produces an erroneous code #1028

Closed pepkin88 closed 6 years ago

pepkin88 commented 6 years ago

Example:

a[]b ++= [1 2]

Result:

a.b || (a.b = []) = (a.b = []).concat([1, 2]);

Expected result:

a.b = (a.b || (a.b = [])).concat([1, 2]);

The current behavior produces a code, which gives a runtime error ReferenceError: Invalid left-hand side in assignment.


The "expected result" block is a result of compiling: (after merging #1026)

a.b = a[]b ++ [1 2]

which is a simplification of (currently uncompilable):

a[]b = a[]b ++ [1 2]

because the effects of semiautovivification are canceled by an assign.

pepkin88 commented 6 years ago

The issue also applies to other assignments, but this one has a practical use case.

determin1st commented 6 years ago

that's the craziest syntax i've ever seen 8)