generated from codeclubvn/react-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
remove-svg-attr.cjs
31 lines (31 loc) · 1.24 KB
/
remove-svg-attr.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// remove-svg-attr.js
module.exports = function ({ types: t }) {
return {
visitor: {
JSXElement(path) {
const { node } = path
if (
t.isJSXIdentifier(node.openingElement.name, { name: 'svg' })
) {
// Traverse the children of the `svg` element
node.children.forEach((child) => {
// Check if the child is a JSXElement
if (t.isJSXElement(child)) {
// Iterate through the attributes of the JSXElement
child.openingElement.attributes =
child.openingElement.attributes.filter(
(attribute) =>
!(
t.isJSXAttribute(attribute) &&
t.isJSXIdentifier(attribute.name, {
name: 'fill',
})
),
)
}
})
}
},
},
}
}