Created
August 30, 2016 19:48
-
-
Save tmcw/b5a068a27d1709ded991d1798b395a7f 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
D3FILES=`ag dispatch modules -l` | |
for f in $D3FILES; do | |
node ./import_d3.js $f | |
done |
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
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 + '")'; | |
})); |
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
/** | |
* 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