Last active
September 9, 2015 07:43
-
-
Save uiur/4c0f693df6e76d8add34 to your computer and use it in GitHub Desktop.
extract call expression value
This file contains hidden or 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
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