Skip to content

Instantly share code, notes, and snippets.

@dawsbot
Last active January 12, 2019 13:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dawsbot/427812e838daf33f9299e6964c1bef13 to your computer and use it in GitHub Desktop.
Save dawsbot/427812e838daf33f9299e6964c1bef13 to your computer and use it in GitHub Desktop.
jscodeshift mod
'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