@yandex/ui
Version:
Yandex UI components
27 lines (25 loc) • 935 B
JavaScript
/**
* Удаляем props из jsx
*
* Было:
* <Button name='value'></Button>
* Стало:
* <Button></Button>
*/
module.exports.removeProps = (root, j, prop, valueProp = false, component) => {
root.find(j.JSXOpeningElement)
.forEach((node) => {
if (component !== undefined && !node.value.name.name.includes(component)) {
return;
}
node.value.attributes = node.value.attributes.filter((attribute) => {
const findProp = (attribute.name && attribute.name.name === prop);
// вырезаем только с определенным значеним
if (findProp && Boolean(valueProp)) {
const findPropValue = attribute.value && attribute.value.value === valueProp;
return !findPropValue;
}
return !findProp;
});
});
};