{"action":"created","issue":{"url":"https://api.github.com/repos/babel/babel/issues/1351","labels_url":"https://api.github.com/repos/babel/babel/issues/1351/labels{/name}","comments_url":"https://api.github.com/repos/babel/babel/issues/1351/comments","events_url":"https://api.github.com/repos/babel/babel/issues/1351/events","html_url":"https://github.com/babel/babel/issues/1351","id":71113787,"number":1351,"title":"Parser plugins","user":{"login":"natew","id":12100,"avatar_url":"https://avatars.githubusercontent.com/u/12100?v=3","gravatar_id":"","url":"https://api.github.com/users/natew","html_url":"https://github.com/natew","followers_url":"https://api.github.com/users/natew/followers","following_url":"https://api.github.com/users/natew/following{/other_user}","gists_url":"https://api.github.com/users/natew/gists{/gist_id}","starred_url":"https://api.github.com/users/natew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natew/subscriptions","organizations_url":"https://api.github.com/users/natew/orgs","repos_url":"https://api.github.com/users/natew/repos","events_url":"https://api.github.com/users/natew/events{/privacy}","received_events_url":"https://api.github.com/users/natew/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/babel/babel/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/babel/babel/labels/generation","name":"generation","color":"eb6420"},{"url":"https://api.github.com/repos/babel/babel/labels/medium%20priority","name":"medium priority","color":"009800"},{"url":"https://api.github.com/repos/babel/babel/labels/parser","name":"parser","color":"207de5"},{"url":"https://api.github.com/repos/babel/babel/labels/umbrella","name":"umbrella","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-04-26T20:12:14Z","updated_at":"2015-05-17T21:03:02Z","closed_at":null,"body":"I'm enjoying playing with Babel plugins so far and have been looking at sweet.js as well. Unfortunately using the two together (as I've seen talked in threads here before) isn't great.\r\n\r\nHow could one implement a similar macro system for JS but using Babel/Acorn rather than Sweet/Esprima? Are there plans for custom syntax support, I would imaging this issue really falls more on the AST generation side, but then I realize Babel already has custom syntax like decorators and JSX.\r\n\r\nI guess I'm a little green on how it all works, but curious on plans for this or ways to implement this today. As a minimal example I'd like to do some of the following transformations:\r\n\r\n```\r\n#x = 1\r\n```\r\n\r\nto:\r\n```\r\nState.set('x', 1)\r\n```\r\n\r\nAnd also\r\n```\r\ncomponent XYZ {\r\n  <sortaJSX></sortaJSX>\r\n}\r\n```\r\n\r\ninto:\r\n```\r\nclass XYZ extends Some.Component {\r\n  render() {\r\n    return { name: 'sortaJSX' };\r\n  }\r\n}\r\n```\r\n\r\nJust throwing out a couple examples of things that would be really awesome and enabled by macro support. For now I'm hacking together stuff with webpack loaders with regex replace, checking into PEG, and also reading through Babel, but would like to see if there's any interest in this, and would appreciate pointers in the right direction."},"comment":{"url":"https://api.github.com/repos/babel/babel/issues/comments/102858001","html_url":"https://github.com/babel/babel/issues/1351#issuecomment-102858001","issue_url":"https://api.github.com/repos/babel/babel/issues/1351","id":102858001,"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-05-17T21:03:02Z","updated_at":"2015-05-17T21:03:02Z","body":"I agree with @RnbWd that JSX is a great example of the value of macros. I find it difficult not to include all of the babel plugins and transformers under the label of 'macro'. Making it easy for people to prototype and share potential future javascript syntax improvements seems like part of [the core goal of babel](http://babeljs.io/blog/2015/02/15/not-born-to-die/).\r\n\r\nAcorn in theory supports plugins already, although the author has been pretty open about not intending to spend any time improving plugin support in the forseeable future. @natew the espree team might be worth keeping an eye on too, looking at the code they seem to be slowly progressing towards better parser modularity. \r\n\r\nWhatever happens it'll be important to learn from sweet.js experience. It's still a great project but I can't imagine anyone wishing that babel was written as sweet macros - and in the end the goal should be, IMHO, that \"everything that babel does should probably be built as a macro\" with babel being a framework for running a pipeline of macros to generate an ast, transforming that ast, and generate code for a js target."}}