Created
December 21, 2012 01:18
-
-
Save chrisdickinson/4350051 to your computer and use it in GitHub Desktop.
highlight words in vim, then do `:'<,'>!rewrite-js platoon-to-tape.js`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
':root > expr > assign > lookup + call:contains(platoon) > function > block > expr:first-child': annotate_name | |
, ':root > expr > assign > lookup + call:contains(platoon) > function:last-child': rewrite_exports | |
, 'call:contains(async) > function:last-child': rewrite_async | |
} | |
function annotate_name(node) { | |
node.update('') | |
} | |
function rewrite_exports(node) { | |
var assign = node.parent.parent | |
, platoon = assign.right.arguments.slice(1) | |
node.parent.parent.parent.update( | |
platoon.map(function(subnode) { | |
var body = subnode.body.body | |
, val = JSON.stringify(body[0].expression.value) | |
subnode.body.body = subnode.body.body.slice(1) | |
return 'test('+val+', '+subnode.source()+'\n)' | |
}).join('\n\n') | |
) | |
return false | |
} | |
function rewrite_async(node) { | |
node.parent.update(node.source()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment