Creating a simple babel compiler command line
As a continuation of the previous post, we can create a npm executable to compile our script which makes more sense. :) You can clone the code from here . Please follow the installation instruction. For this task, we will be creating a custom babel plug-in. The main code resides in bin/hsc.js which uses node to open a file and pass to babel for further transformation. At line 11, we have a plugin keyword and we pass in our helloscript. This is how we tell babel to use our newly created plugin. If you look at helloscript.js it uses babel specification to traverse and locate a variable called 'a' and then attempt to convert it to ''total''. For our purpose, it resides in 'path,parent.id.name'. This is basically discovered via trial and error as I traced through the AST output. If you have problem zooming down on an expression, try to do a console.log(path), and slowly narrow down your PATH by adding more element to the constraint for ex