Skip to content

Instantly share code, notes, and snippets.

@mofas
Last active March 26, 2016 12:29
Show Gist options
  • Save mofas/1ca00cdb8670f4ab19c5 to your computer and use it in GitHub Desktop.
Save mofas/1ca00cdb8670f4ab19c5 to your computer and use it in GitHub Desktop.
CodeMod: remove const {PureRenderMixin} = React.addons;
let React = {};
React.addons = {
PureRenderMixin: null,
};
const {PureRenderMixin} = React.addons;
const {a, b} = React.addons;
export default function transformer(file, api) {
const j = api.jscodeshift;
return j(file.source)
.find(j.MemberExpression, {
type: "MemberExpression",
object: {
name: "React",
},
property: {
name: "addons",
}
})
.forEach(p => {
let hasPureMixinObj = false;
j(p.parent)
.find(j.Identifier, {name: "PureRenderMixin"})
.forEach(d=>{
if(d.value && d.value.type === 'Identifier' &&
d.parent.parent.value.type === 'ObjectPattern'
){
hasPureMixinObj = true;
}
});
if(hasPureMixinObj){
p.parent.prune();
}
}).toSource()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment