Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjORbj committed Dec 1, 2022
1 parent 7a830f3 commit 60ea322
Showing 1 changed file with 50 additions and 51 deletions.
101 changes: 50 additions & 51 deletions packages/mui-codemod/src/v5.0.0/joy-rename-components-to-slots.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,56 @@
function transformComponentsProp(attributeNode) {
attributeNode.name.name = 'slots';

const valueExpression = attributeNode.value.expression;
if (valueExpression?.type !== 'ObjectExpression') {
attributeNode.name.name = 'slots';

const valueExpression = attributeNode.value.expression;
if (valueExpression?.type !== 'ObjectExpression') {
return;
}

valueExpression.properties.forEach((property) => {
property.key.name = property.key.name[0].toLowerCase() + property.key.name.slice(1);

if (property.shorthand) {
property.shorthand = false;
}
});
}

function transformComponentsPropsProp(attributeNode) {
attributeNode.name.name = 'slotProps';
}

/**
* @param {import('jscodeshift').FileInfo} file
* @param {import('jscodeshift').API} api
*/
export default function transformer(file, api, options) {
const j = api.jscodeshift;
const root = j(file.source);
const printOptions = options.printOptions;

const transformed = root.findJSXElements().forEach((path) => {
if (path.node.type !== 'JSXElement') {
return;
}

valueExpression.properties.forEach((property) => {
property.key.name = property.key.name[0].toLowerCase() + property.key.name.slice(1);

if (property.shorthand) {
property.shorthand = false;
}
});
}

function transformComponentsPropsProp(attributeNode) {
attributeNode.name.name = 'slotProps';
}

/**
* @param {import('jscodeshift').FileInfo} file
* @param {import('jscodeshift').API} api
*/
export default function transformer(file, api, options) {
const j = api.jscodeshift;
const root = j(file.source);
const printOptions = options.printOptions;

const transformed = root.findJSXElements().forEach((path) => {
if (path.node.type !== "JSXElement") {

path.node.openingElement.attributes.forEach((node) => {
if (node.type !== 'JSXAttribute') {
return;
}

path.node.openingElement.attributes.forEach((node) => {
if (node.type !== 'JSXAttribute') {
return;
}

switch (node.name.name) {
case 'components':
transformComponentsProp(node);
break;

case 'componentsProps':
transformComponentsPropsProp(node);
break;

default:
}
});

switch (node.name.name) {
case 'components':
transformComponentsProp(node);
break;

case 'componentsProps':
transformComponentsPropsProp(node);
break;

default:
}
});

return transformed.toSource(printOptions);
}
});

return transformed.toSource(printOptions);
}

0 comments on commit 60ea322

Please sign in to comment.