-
-
Save KevinTCoughlin/cb72a94a5b1ec084c0ec774c29944915 to your computer and use it in GitHub Desktop.
rename a prop for OUFR
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
import ts from 'typescript'; | |
import { migration } from '../../migration'; | |
import { mod } from 'riceburn'; | |
const inFooJsxTag = (node: ts.Node): boolean => { | |
if (!node) { | |
return false; | |
} | |
if (ts.isJsxSelfClosingElement(node) || ts.isJsxOpeningElement(node)) { | |
const tagName = node.tagName; | |
if (ts.isIdentifier(tagName)) { | |
return tagName.escapedText === 'Foo'; | |
} else { | |
return false; | |
} | |
} | |
if (!node.parent) { | |
return false; | |
} | |
return inFooJsxTag(node.parent); | |
}; | |
export default migration('rename prop bar to prop baz inside component foo', () => { | |
mod('**/*.tsx').asTypescript((node, modder) => { | |
if (ts.isIdentifier(node) && ts.isJsxAttribute(node.parent) && inFooJsxTag(node)) { | |
if (node.escapedText === 'isSelected') { | |
return modder.replace(node, 'selected'); | |
} | |
} | |
return undefined; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment