Last active
June 15, 2017 08:49
-
-
Save romain-h/51241938bdeba55add4eebc0270606f2 to your computer and use it in GitHub Desktop.
[Codemods - Medium post]
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
root.find(j.ExpressionStatement, { | |
expression: { | |
type: 'AssignmentExpression', | |
operator: '=', | |
}, | |
}) | |
.filter(path => | |
path.value.expression.left && | |
isGBNamespaced(path.value.expression.left) | |
) | |
.forEach(assignment => { | |
const body = j.returnStatement(assignment.value.expression.right); | |
j(assignment) | |
.replaceWith( | |
j.expressionStatement( | |
j.callExpression( | |
j.identifier('define'), | |
[ | |
j.arrayExpression(files), | |
j.functionExpression(null, names, j.blockStatement([body])) | |
] | |
) | |
) | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment