You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
module.exports=function(file,api){constj=api.jscodeshift;constroot=j(file.source);// Find all JSX elements with the name 'Controller'constcontrollerPaths=root.findJSXElements("Controller");// Process the found JSX elementscontrollerPaths.forEach((path)=>{constrenderAttribute=path.node.openingElement.attributes.find((attr)=>attr.name.name==="render");if(renderAttribute&&renderAttribute.value.type==="JSXExpressionContainer"&&renderAttribute.value.expression.type==="ArrowFunctionExpression"){// Find the first JSXElement within the ArrowFunctionExpressionconstrenderFunctionBodyNode=renderAttribute.value.expression.body;if(renderFunctionBodyNode){constidAttribute=j.jsxAttribute(j.jsxIdentifier("id"),j.jsxExpressionContainer(j.identifier("outer")));// Create a new JSXElement with div as its opening elementconstwrappedRenderFunctionBodyNode=j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier("div"),[idAttribute]),j.jsxClosingElement(j.jsxIdentifier("div")),[renderFunctionBodyNode]);// Replace the existing JSXElement with the new oneconstrenderFunctionBodyPaths=j(renderFunctionBodyNode);constrenderFunctionBodyPath=renderFunctionBodyPaths.get(0);renderFunctionBodyPath.replace(wrappedRenderFunctionBodyNode)}}});returnroot.toSource();};
is the codemod doing something wrong or is this a bug?
The text was updated successfully, but these errors were encountered:
i'm having a problem w/ replacing JSX nodes within render props:
https://astexplorer.net/#/gist/870412de2b8bc7bfd6bfa04cd4600680/381203659283e923155a6b62ed4739df11ba0c2d
input:
expected output:
v0.11.0 actual output:
v0.15.0 actual output:
[input was unmodified]
codemod:
is the codemod doing something wrong or is this a bug?
The text was updated successfully, but these errors were encountered: