Skip to content

Instantly share code, notes, and snippets.

@dawsbot dawsbot/5to6-exports.js
Last active Jan 12, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.