Last active
January 12, 2019 13:36
-
-
Save dawsbot/427812e838daf33f9299e6964c1bef13 to your computer and use it in GitHub Desktop.
jscodeshift mod
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
'use strict'; | |
export default function transformer(file, api) { | |
const j = api.jscodeshift; | |
const {expression, statement, statements} = j.template; | |
const root = j(file.source); | |
return root | |
.find(j.Program, { | |
body: [ | |
j.AssignmentExpression | |
] | |
}) | |
.replaceWith(rootPath => { | |
const nodePath = rootPath; | |
const properties = nodePath.get(0).node.body[0].expression.right.properties | |
let newProgram = []; | |
properties.forEach(elem => { | |
newProgram.push(j.exportNamedDeclaration( | |
null, | |
[ | |
j.exportSpecifier( | |
j.identifier('default'), | |
j.identifier(elem.key.name) | |
) | |
], | |
j.literal(elem.value.arguments[0].value) | |
)); | |
}); | |
return j.program(newProgram); | |
}).toSource({quote: 'single'}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment