Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created August 30, 2016 19:48
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/b5a068a27d1709ded991d1798b395a7f to your computer and use it in GitHub Desktop.
Save tmcw/b5a068a27d1709ded991d1798b395a7f to your computer and use it in GitHub Desktop.
D3FILES=`ag dispatch modules -l`
for f in $D3FILES; do
node ./import_d3.js $f
done
var fs = require('fs');
var path = require('path');
// var utilPath = path.join(path.relative(
// path.dirname(process.argv[2]),
// path.join(__dirname, './modules/util')), 'rebind');
// convert old-fashioned d3 event dispatching with new-fashioned
fs.writeFileSync(process.argv[2],
fs.readFileSync(process.argv[2], 'utf8').replace(/\sdispatch.(\w+)\((.*)?\)/g, function(res, p1, p2) {
if (p2) return ' dispatch.call("' + p1 + '", this, ' + p2 + ')';
return ' dispatch.call("' + p1 + '")';
}));
/**
* Unchains chained variable declarations.
*/
export default function transformer(file, api) {
const j = api.jscodeshift;
return j(file.source)
.find(j.VariableDeclaration)
.filter(p => {
if (p.node.declarations.length !== 1) return false;
var dec = p.node.declarations[0];
return dec.init &&
dec.init.type === 'CallExpression' &&
dec.init.callee.type === 'MemberExpression' &&
dec.init.callee.object.name === 'React' &&
dec.init.callee.property.name === 'createClass';
})
.replaceWith(p => {
p.node.kind = 'var';
return p.node;
})
.toSource();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment