Skip to content

Instantly share code, notes, and snippets.

@uiur
Last active September 9, 2015 07:43
Show Gist options
  • Save uiur/4c0f693df6e76d8add34 to your computer and use it in GitHub Desktop.
Save uiur/4c0f693df6e76d8add34 to your computer and use it in GitHub Desktop.
extract call expression value
var fs = require('fs')
var babel = require('babel-core')
var estraverse = require('estraverse-fb')
var match = require('escallmatch')('I18n.t(message, [params])')
var code = fs.readFileSync(process.argv[2], 'utf8')
estraverse.traverse(babel.parse(code), {
enter: function (node) {
if (match.test(node)) {
var first = node.arguments[0]
if (first.value) {
console.log(first.value)
} else {
if (first.type === 'ConditionalExpression') {
console.log(first.consequent.value)
console.log(first.alternate.value)
return
}
console.error(node.arguments)
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment