code modifications with jscodeshift
codemod -m -d src/ --extensions php,html \
'<font *color="?(.*?)"?>(.*?)</font>' \
'<span style="color: \1;">\2</span>'function() {}() => {}Object.assign({}, a, b){...a, ...b}React.createClass({
render: function() {...}
})class X extends Component {
render() {...}
}Automatically change language constructs throughout the whole code base
var X = React.createClass({
mixins: [ReactGraphQL.Mixin],
statics: {
queries: {
viewer: () => query`
viewer { name }
`,
},
},
render() {...},
})
module.exports = Xvar X = React.createClass({
render() {...}
})
module.exports = Relay.createContainer(X, {
queries: {
viewer: () => query`
viewer { name }
`,
},
})var X = React.createClass({
mixins: [ReactGraphQL.Mixin],
statics: {
queries: {
viewer: () => query`
viewer { name }
`,
},
},
render() {...},
})
module.exports = Xvar X = React.createClass({
render() {...}
})
module.exports = Relay.createContainer(X, {
queries: {
viewer: () => query`
viewer { name }
`,
},
})Or switching from ava, tape or mocha to Jest
or upgrading from React.createClass to ES6 classes
(there's codemods for both cases)
// simple example
j(file.source)
.find(j.Identifier)
.filter(path => /* check something */)
// structural pattern matching example
j(file.source)
.find(j.CallExpression, {
callee: {
object: {
name: 'console',
},
property: {
name: 'log',
},
},
})// create AST nodes by hand
var identifier = {
type: 'Identifier',
name: 'hello',
};
// or use a tool, for example: ast-types
var identifier = j.identifier('hello');// update a property of an AST node:
someAstNodeIdentifier.name = 'Hallo Hamburg!';
// replace an entire AST node / subtree:
j(path).replaceWith(myNewASTNode);
// insert a new AST node:
j(path).insertBefore(myNewASTNode);
j(path).insertAfter(myNewASTNode);Thank you for your attention!