{"action":"created","issue":{"url":"https://api.github.com/repos/batiste/CokeScript/issues/2","labels_url":"https://api.github.com/repos/batiste/CokeScript/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/batiste/CokeScript/issues/2/comments","events_url":"https://api.github.com/repos/batiste/CokeScript/issues/2/events","html_url":"https://github.com/batiste/CokeScript/issues/2","id":64607249,"number":2,"title":"Feature request: Arrow instead of def keyword, Babel by default, IIFE creation in loops","user":{"login":"m1sta","id":721667,"avatar_url":"https://avatars.githubusercontent.com/u/721667?v=3","gravatar_id":"","url":"https://api.github.com/users/m1sta","html_url":"https://github.com/m1sta","followers_url":"https://api.github.com/users/m1sta/followers","following_url":"https://api.github.com/users/m1sta/following{/other_user}","gists_url":"https://api.github.com/users/m1sta/gists{/gist_id}","starred_url":"https://api.github.com/users/m1sta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m1sta/subscriptions","organizations_url":"https://api.github.com/users/m1sta/orgs","repos_url":"https://api.github.com/users/m1sta/repos","events_url":"https://api.github.com/users/m1sta/events{/privacy}","received_events_url":"https://api.github.com/users/m1sta/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-26T18:55:05Z","updated_at":"2015-03-27T10:13:02Z","closed_at":null,"body":"Just throwing this all out there for discussion. \r\n\r\nI'd love to see CokeScript evolve to be a wrapper above Babel so that we basically got ES7 (or whatever Babel is able to support) but with more terse and more easy to read syntax.\r\n\r\nBeing able to conciously grab one compliation package would be great. Especially if the result is that any normal javascript would work fine, plus there are a few little shortcuts that can be included too. \r\n\r\nThe things that jump out in my mind..\r\n - optional curly brackets when indentation is used.\r\n - shorthand skinny-arrow function definition (with optional '=' character where function definition can be directly linked to use of the 'let' keyword)\r\n - multipurpose for-in syntax with automatic inclusion of 'let' keyword\r\n - inline try/catch\r\n - automatic inclusion of 'let' for 'catch variables' in the 'finally' part of try/catch/finally blocks\r\n - optional curly brackes for object literals, and square bracks for array declaration where bracket location can be confidently inferred\r\n - automatic generation of IIFE to help with the loop/closure ugliness (see use of `#i` in example2 below)\r\n - support for typescript and/or flow style type definition, standard javascript, and JSX passthrough (ie. transform what you can and leave everything else free to progress through the pipeline)\r\n - automatic inclusion of 'async' function prefix where await is used\r\n - automatic wrapping of functions such that they return a promise when resolve and reject keywords are used\r\n - automatic marking of functions as generators where yield is used\r\n - sourcemaps\r\n\r\n```javascript\r\n    let example1 (callback) ->\r\n        try \r\n            let dataToStore = JSON.stringify(hello:'world')\r\n            await db.put(id: 123, data: dataToStore)\r\n            let resultString = await db.get(id: 123)\r\n            let resultJSON = try JSON.parse(resultString) catch resultString\r\n        catch (err)\r\n            if (err.status !== 409) throw err;\r\n       finally\r\n            callback(err, resultJSON)\r\n    \r\n    let example2 ->\r\n        let funcs = {}\r\n        for (i in 1,2,3) funcs[i] = (msg, #i) -> msg + i\r\n        for (key, value in funcs) \r\n            let expected = \"Value should be \" + key\r\n            let actual = value(\"Actual value is \")\r\n            console.log(expected, actual)\r\n```\r\n\r\n I'm personally not a fan of automatic variable declaration outside of for loops and try/catch/finally combinations, makes picking up typos more difficult, and classes and array destrucuring are part of the new JS spec. I left these out deliberatley. "},"comment":{"url":"https://api.github.com/repos/batiste/CokeScript/issues/comments/86888974","html_url":"https://github.com/batiste/CokeScript/issues/2#issuecomment-86888974","issue_url":"https://api.github.com/repos/batiste/CokeScript/issues/2","id":86888974,"user":{"login":"m1sta","id":721667,"avatar_url":"https://avatars.githubusercontent.com/u/721667?v=3","gravatar_id":"","url":"https://api.github.com/users/m1sta","html_url":"https://github.com/m1sta","followers_url":"https://api.github.com/users/m1sta/followers","following_url":"https://api.github.com/users/m1sta/following{/other_user}","gists_url":"https://api.github.com/users/m1sta/gists{/gist_id}","starred_url":"https://api.github.com/users/m1sta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m1sta/subscriptions","organizations_url":"https://api.github.com/users/m1sta/orgs","repos_url":"https://api.github.com/users/m1sta/repos","events_url":"https://api.github.com/users/m1sta/events{/privacy}","received_events_url":"https://api.github.com/users/m1sta/received_events","type":"User","site_admin":false},"created_at":"2015-03-27T10:13:02Z","updated_at":"2015-03-27T10:13:02Z","body":"Thanks Bastiste for replying.\r\n\r\n - optional curly brackets: the only reason you'd allow them is so that you can optional include inline javascript unmodified\r\n - skinny arrow func def: I just personally prefer how the arrow looks vs the def keyword. I'm used to it from C# and coffescript. Can't comment on the dom keyword.\r\n - multipurpose for-in: the current implementation is perfect. Not looking for this to be changed, just listing it because I see it as an important feature.\r\n - automatic inclusion of 'let' for catch var: this is so that if you have `catch(err)` you can use the variable `err` in the finally statement, if one exists. Basically just generating `let err = undefined` before the try statement when a catch and finally are being used.\r\n - optional curly bracket for object literals: I think it should only be allowed in a direct variable assignment or where the delimited list is surrounded by parens\r\n - types, async etc: these are largely pass-through type things related to either es7 or other compliers which I'd imagine would be used in the same build pipeline as CokeScript.\r\n - I totally understand what you mean about it being too much of a change from the original intent. I'd love to take epeg.js and have a stab myself but it'd take me a very long time given my current capacity and skill level when it comes to parsers.\r\n- IIFE: it's not a CokeScript problem. It's a javascript problem, but I think CokeScript can help. \r\n\r\nReferring to this: http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example I'd imagine that this...\r\n\r\n```javascript\r\nvar funcs = []\r\nfor (var index = 0; index < 3; index++)\r\n   funcs[index] = (#index) -> console.log(\"My value: \" + index)\r\n\r\n```\r\nwould complie to this...\r\n```\r\nvar funcs = [];\r\nfor (var index = 0; index < 3; index++) {\r\n    funcs[index] = (function(index) {\r\n        return function() {\r\n            console.log(\"My value: \" + index);\r\n        };\r\n    }(index));\r\n}\r\n\r\n```\r\n\r\nThe hash symbol indicates a parameter that should pushed into an IIFE to ensure that it the required closure is created. "}}