Last active
March 26, 2016 12:29
-
-
Save mofas/1ca00cdb8670f4ab19c5 to your computer and use it in GitHub Desktop.
CodeMod: remove const {PureRenderMixin} = React.addons;
This file contains hidden or 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
let React = {}; | |
React.addons = { | |
PureRenderMixin: null, | |
}; | |
const {PureRenderMixin} = React.addons; | |
const {a, b} = React.addons; |
This file contains hidden or 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
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