Last active
December 20, 2019 09:06
-
-
Save rajasegar/1901843ef265595d1e398897cdf3175d to your computer and use it in GitHub Desktop.
JARVIS codemod gist
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
bar.baz(); |
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
{ | |
"lang": "Javascript", | |
"parser": "recast", | |
"version": "1.0", | |
"nodeOp": "replace" | |
} |
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
bar(); |
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
module.exports = function transformer(file, api) { | |
const j = api.jscodeshift; | |
const root = j(file.source); | |
const body = root.get().value.program.body; | |
let helloWorld = "HELLO WORLD GIST TRANSFORM"; | |
root.find(j.CallExpression, { | |
callee: { | |
name: "foo" | |
} | |
}).replaceWith(path => { | |
return j.callExpression(j.memberExpression(j.identifier("foo"), j.identifier("bar"), false), []); | |
}); | |
return root.toSource(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment