Skip to content

Instantly share code, notes, and snippets.

@dawsbot
Last active January 12, 2019 13:36
Show Gist options
  • 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