-
-
Save jhsu/94d876d980d5c5fcc313063d10f6f36d to your computer and use it in GitHub Desktop.
codemod for changing getFirst calls
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
export default function transformer(file, api) { | |
const j = api.jscodeshift; | |
return j(file.source) | |
.find(j.CallExpression, { | |
callee: { name: 'getFirst' }, | |
}) | |
.forEach(path => { | |
const [props, constructor, defaultValue] = path.value.arguments; | |
path.value.arguments = [props, constructor]; | |
if (defaultValue) { | |
j(path).replaceWith(j.logicalExpression('||', path.value, defaultValue)); | |
} | |
}) | |
.toSource(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment