Created
February 17, 2017 17:13
-
-
Save tmcw/82340be843d097fad7f49443ddc5e80f to your computer and use it in GitHub Desktop.
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
const babylon = require('babylon'); | |
const traverse = require('babel-traverse').default; | |
const generate = require('babel-generator').default; | |
const fs = require('fs'); | |
var inputs = process.argv.slice(2); | |
var opts = { | |
allowImportExportEverywhere: true, | |
sourceType: 'module', | |
plugins: [ | |
'jsx', | |
'flow', | |
'asyncFunctions', | |
'classConstructorCall', | |
'doExpressions', | |
'trailingFunctionCommas', | |
'objectRestSpread', | |
'decorators', | |
'classProperties', | |
'exportExtensions', | |
'exponentiationOperator', | |
'asyncGenerators', | |
'functionBind', | |
'functionSent' | |
] | |
}; | |
inputs.forEach(function (input) { | |
var ast = babylon.parse(fs.readFileSync(input, 'utf8'), opts); | |
traverse(ast, { | |
JSXOpeningElement(path) { | |
if (path.node.name.name === 'MagicImage') { | |
var options = path.node.attributes.find( | |
attr => attr.name.name === 'options'); | |
console.log(generate(options.value.expression, { quotes: 'double' })); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment