Skip to content

Instantly share code, notes, and snippets.

@chrisdickinson
Created December 21, 2012 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdickinson/4350051 to your computer and use it in GitHub Desktop.
Save chrisdickinson/4350051 to your computer and use it in GitHub Desktop.
highlight words in vim, then do `:'<,'>!rewrite-js platoon-to-tape.js`
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