jashkenas/coffee-script — Issue #2115: Object literal syntax: Implicit keys undocumented(?) and inconsistent
Author: joliss
Created: 2012-02-12 02:21:06+00:00
State: open

On CoffeeScript 1.2.0,

{a}

compiles to

({
a: a
});

I read about this feature before, but I cannot for the life of me find it in the docs. Perhaps it is actually undocumented?

Also, it seems inconsistent in its implementation, unless I'm missing something:

o:
x: x
a

yields

Error: Parse error on line 3: Unexpected 'TERMINATOR'
at Object.parseError (/usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/parser.js:470:11)
at Object.parse (/usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/parser.js:546:22)
at Object.compile (/usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/coffee-script.js:40:22)
at /usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/command.js:140:33
at ReadStream. (/usr/local/lib/nodejs/.npm/coffee-script/1.2.0/package/lib/coffee-script/command.js:167:14)
at ReadStream.emit (events.js:61:17)
at ReadStream._onReadable (net.js:658:51)
at IOWatcher.onReadable [as callback] (net.js:177:10)

I wonder if this inconsistency can be meaningfully fixed. If not, I'm thinking perhaps this feature could also be removed in version 2.0. If it's not documented, few people are bound to be using it, and I find that it doesn't make my code more readable. (Not arguing it *should* be removed, just throwing it out there.)