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 156 forks source link

String keys for objects in short syntax #1020

Open nazar-pc opened 6 years ago

nazar-pc commented 6 years ago

I'm working with Google Closure Compiler lately and sometimes need to return objects for external consumption. In order to prevent Closure Compiler from mangling object keys I need to use strings like {'key': value} instead of {key: value}.

Would be nice if LiveScript supported compiling this:

{'whatever'}

To this:

{'whatever': whatever}

Otherwise some parts of the code become verbose very quickly.

Currently it would compile to:

{'whatever': 'whatever'}

Which makes sense, but is not so useful.

Non-obscure syntax alternatives that don't break BC would be nice too.

rhendric commented 6 years ago

Need to think about this one a bit. In the meantime, here's a question: what should {'foo-bar'} compile to?

nazar-pc commented 6 years ago

I'd say it should literally expand to {'foo-bar': foo-bar} and compile to {'foo-bar': fooBar}. I you need camelCase key you can write it explicitly using the same syntax and the first option doesn't follow current syntax in LiveScript regarding hyphens.

pepkin88 commented 6 years ago

Possible outcomes that I see:

I know there are more features, other than this one, which would be nice to modernize, but wouldn't be backward compatible. Maybe we should list them and discuss what to do with them?

nazar-pc commented 6 years ago

I'd vote to a major version bump just to make sure everyone reads a changelog. There is really nothing to be afraid in a major version change, especially if breaking changes are not groundbreaking, but just some nice improvements.

pepkin88 commented 6 years ago

In that case I would like to add some modernization proposals, to include in such version. I'll pitch them soon.