Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created February 17, 2017 17:13
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 tmcw/82340be843d097fad7f49443ddc5e80f to your computer and use it in GitHub Desktop.
Save tmcw/82340be843d097fad7f49443ddc5e80f to your computer and use it in GitHub Desktop.
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