Skip to content

Commit

Permalink
feat: Handle Buttons when upgrading Icons (#1266)
Browse files Browse the repository at this point in the history
feat: Handle Buttons when upgrading Icons
  • Loading branch information
ptbrowne authored Nov 26, 2019
2 parents 88fdea8 + 57342ed commit c0339b0
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions codemods/new-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ const makeSureUseNewName = source => {
}
}

const updateToNewIcon = (j, jsxComponent) => {
const iconAttr = jsxComponent.node.attributes.find(
attr => attr.name.name == 'icon'
)
if (!iconAttr) {
return
}
const newName = oldToNewNames[iconAttr.value.value]
if (newName) {
iconAttr.value = j.literal(newName)
}
}

export default function transformer(file, api) {
const j = api.jscodeshift
const root = j(file.source)
Expand All @@ -64,18 +77,10 @@ export default function transformer(file, api) {
makeSureUseNewName(iDec.source)
})
const jsxIcons = root.find(j.JSXOpeningElement, { name: { name: 'Icon' } })
jsxIcons.forEach(jsxIcon => {
const iconAttr = jsxIcon.node.attributes.find(
attr => attr.name.name == 'icon'
)
if (!iconAttr) {
return
}
const newName = oldToNewNames[iconAttr.value.value]
if (newName) {
iconAttr.value = j.literal(newName)
}
})
jsxIcons.forEach(jsxIcon => updateToNewIcon(j, jsxIcon))

const buttons = root.find(j.JSXOpeningElement, { name: { name: 'Button' } })
buttons.forEach(jsxButton => updateToNewIcon(j, jsxButton))

return root.toSource()
}

0 comments on commit c0339b0

Please sign in to comment.