New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to convert to a NodePath
?
#64
Comments
Recast (ast-types actually) provides two APIs: One lets you access the underlying "raw" AST node, with Examples: var args = path.value.arguments; // array of AST nodes
var args = path.get('arguments'); // NodePath representing the array of AST nodes
var pathToFirstArg = path.get('arguments', 0); // or args.get(0) from above See also https://github.com/benjamn/ast-types#nodepath .
|
Perfect. Thanks, that helped me get there. Do you have any thoughts as to where I should put this codemod transform? I'm either going to start a repo myself or open a PR to a pre-existing collection of transforms. Do you have any opinions on where it should go? I imagine there is a lot of value for people who start without Babel/JSX and want to convert their codebase later to use JSX. |
Feel free to create your own repo or send a PR to https://github.com/cpojer/js-codemod which I have used as a collection of useful codemods that I ran at FB. |
@cpojer: What about https://github.com/reactjs/react-codemod ? Is that more for API changes between versions? |
Oh yeah, react-codemod is fine for React specific codemods. |
I'm trying to create a transformer that will go from:
to
I've gotten the first two examples, but I'm confused on recursively handling the children.
My interactive codemod is here: http://felix-kling.de/esprima_ast_explorer/#/hb6iLO9hTe/4
If I change
convertNodeToJSX
to:then I get printed out
So how can I convert the
CallExpression
to aNodePath
? Wrapping the element withj()
gives me:Or perhaps as a higher level question, is this even the right approach?
The text was updated successfully, but these errors were encountered: