Closed pepkin88 closed 5 years ago
In my opinion, the most straightforward reading of the docs implies that you're correct. However, every tagged version of LiveScript that I tested, as well as Coco, all do the same thing with that expression.
A fix would be relatively simple—swapping the order of add-implicit-braces
and expand-literals
in the lexer seems to do the trick—and testing that fix shows that no test and no code in the compiler relies on the current behavior. But it's possible someone out there does (a slightly less silly example would be something like [text, name: \node type]
).
I'm on the fence about changing this. Anyone else have any opinions?
i thought about [{a: [1 2 3]}]
.. it's unclear syntax imo
The more I think about this, the more I agree with you, @pepkin88. This seems like a bug. Property shorthand should not work outside of braces. The cases in your postscript make that clear: v = a: 1, 2, 3
is a parse error, so it's very odd that v = a: 1 2 3
compiles to anything. Adding array brackets or a function being called shouldn't change how object expressions are parsed; braces should be the only thing that unlocks new property shorthands.
The code:
compiles to this:
and not to this:
like
[a: 1, 2, 3]
would.Are my expectations correct? Should
[a: 1 2 3]
be equivalent to[a: 1, 2, 3]
?Edit: Same with
fn a: 1 2 3
,v = a: 1 2 3
, etc.