forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
51 deletions.
There are no files selected for viewing
101 changes: 50 additions & 51 deletions
101
packages/mui-codemod/src/v5.0.0/joy-rename-components-to-slots.js
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
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); | ||
} |