{"action":"created","issue":{"url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4046","labels_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4046/labels{/name}","comments_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4046/comments","events_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4046/events","html_url":"https://github.com/jashkenas/coffeescript/issues/4046","id":96861386,"number":4046,"title":"Interior objects in array require extra braces","user":{"login":"jessaustin","id":295056,"avatar_url":"https://avatars.githubusercontent.com/u/295056?v=3","gravatar_id":"","url":"https://api.github.com/users/jessaustin","html_url":"https://github.com/jessaustin","followers_url":"https://api.github.com/users/jessaustin/followers","following_url":"https://api.github.com/users/jessaustin/following{/other_user}","gists_url":"https://api.github.com/users/jessaustin/gists{/gist_id}","starred_url":"https://api.github.com/users/jessaustin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jessaustin/subscriptions","organizations_url":"https://api.github.com/users/jessaustin/orgs","repos_url":"https://api.github.com/users/jessaustin/repos","events_url":"https://api.github.com/users/jessaustin/events{/privacy}","received_events_url":"https://api.github.com/users/jessaustin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-23T17:18:23Z","updated_at":"2015-07-24T07:14:01Z","closed_at":null,"body":"I suspect that many people already know about these behaviors, but they surprise me occasionally so I wanted to document them clearly. In the simple case, a leading comma indicates a new object in an array:\r\n```coffeescript\r\n[\r\n  a: 'first'\r\n, a: 'second'\r\n]\r\n```\r\n...is transpiled to...\r\n```javascript\r\n[\r\n  {\r\n    a: 'first'\r\n  }, {\r\n    a: 'second'\r\n  }\r\n];\r\n```\r\nThis seems reasonable. However that understanding doesn't work for three objects in an array:\r\n```coffeescript\r\n[\r\n  a: 'first'\r\n, a: 'second'\r\n, a: 'third'\r\n]\r\n```\r\n...becomes...\r\n```javascript\r\n[\r\n  {\r\n    a: 'first'\r\n  }, {\r\n    a: 'second',\r\n    a: 'third'\r\n  }\r\n];\r\n```\r\nThat's not what we want! We can get that with some extra braces:\r\n```coffeescript\r\n[\r\n  a: 'first'\r\n, a: 'second'\r\n, {a: 'third'}\r\n]\r\n```\r\n...transpiles to...\r\n```javascript\r\n[\r\n  {\r\n    a: 'first'\r\n  }, {\r\n    a: 'second'\r\n  }, {\r\n    a: 'third'\r\n  }\r\n];\r\n```\r\n...which is what we want, but doesn't seem *right*.\r\n\r\nAdding another object to the array...\r\n```coffeescript\r\n[\r\n  a: 'first'\r\n, a: 'second'\r\n, {a: 'third'}\r\n, a: 'fourth'\r\n]\r\n```\r\n...still works...\r\n```javascript\r\n[\r\n  {\r\n    a: 'first'\r\n  }, {\r\n    a: 'second'\r\n  }, {\r\n    a: 'third'\r\n  }, {\r\n    a: 'fourth'\r\n  }\r\n];\r\n```\r\nBut adding yet another...\r\n```coffeescript\r\n[\r\n  a: 'first'\r\n, a: 'second'\r\n, {a: 'third'}\r\n, a: 'fourth'\r\n, a: 'fifth'\r\n]\r\n```\r\n...does not...\r\n```javascript\r\n[\r\n  {\r\n    a: 'first'\r\n  }, {\r\n    a: 'second'\r\n  }, {\r\n    a: 'third'\r\n  }, {\r\n    a: 'fourth',\r\n    a: 'fifth'\r\n  }\r\n];\r\n```\r\nIn general, the first two and last one of the objects in the array *don't* need to be (but may be) wrapped in braces, and all other objects *do* need to be wrapped in braces. [Except when there are only three objects in the array, in which case either the second or third (or both or all three) need to be wrapped in braces.] For example:\r\n```coffeescript\r\n[\r\n  a: 'first'\r\n, a: 'second'\r\n, {a: 'third'}\r\n, {a: 'fourth'}\r\n, {a: 'fifth'}\r\n, {a: 'sixth'}\r\n, a: 'seventh'\r\n]\r\n```\r\n...transpiles to...\r\n```javascript\r\n[\r\n  {\r\n    a: 'first'\r\n  }, {\r\n    a: 'second'\r\n  }, {\r\n    a: 'third'\r\n  }, {\r\n    a: 'fourth'\r\n  }, {\r\n    a: 'fifth'\r\n  }, {\r\n    a: 'sixth'\r\n  }, {\r\n    a: 'seventh'\r\n  }\r\n];\r\n```\r\nThis seems kind of arbitrary! That's OK, coffeescript doesn't have many complications, but this is one. I totally understand if this isn't something that maintainers want to \"fix\". It just seems that the leading comma works about half-way. To look at it from another perspective, it makes total sense that with no leading commas to dedent out of the object back into the array...\r\n```coffeescript\r\n[\r\n  a: 'first'\r\n  a: 'second'\r\n  a: 'third'\r\n  a: 'fourth'\r\n]\r\n```\r\n...only one object is created...\r\n```javascript\r\n[\r\n  {\r\n    a: 'first',\r\n    a: 'second',\r\n    a: 'third',\r\n    a: 'fourth'\r\n  }\r\n];\r\n```"},"comment":{"url":"https://api.github.com/repos/jashkenas/coffeescript/issues/comments/124381615","html_url":"https://github.com/jashkenas/coffeescript/issues/4046#issuecomment-124381615","issue_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4046","id":124381615,"user":{"login":"netlovers","id":1451148,"avatar_url":"https://avatars.githubusercontent.com/u/1451148?v=3","gravatar_id":"","url":"https://api.github.com/users/netlovers","html_url":"https://github.com/netlovers","followers_url":"https://api.github.com/users/netlovers/followers","following_url":"https://api.github.com/users/netlovers/following{/other_user}","gists_url":"https://api.github.com/users/netlovers/gists{/gist_id}","starred_url":"https://api.github.com/users/netlovers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netlovers/subscriptions","organizations_url":"https://api.github.com/users/netlovers/orgs","repos_url":"https://api.github.com/users/netlovers/repos","events_url":"https://api.github.com/users/netlovers/events{/privacy}","received_events_url":"https://api.github.com/users/netlovers/received_events","type":"User","site_admin":false},"created_at":"2015-07-24T07:14:01Z","updated_at":"2015-07-24T07:14:01Z","body":"I always use it like this:\r\n```coffee\r\n[\r\n  a: 'first'\r\n,\r\n  a: 'second'\r\n,\r\n  a: 'third'\r\n]\r\n```\r\nGenerates:\r\n```js\r\n[\r\n  {\r\n    a: 'first'\r\n  }, {\r\n    a: 'second'\r\n  }, {\r\n    a: 'third'\r\n  }\r\n];\r\n```"}}