UNPKG

types-react-codemod

Version:

Collection of transforms for [jscodeshift](https://github.com/facebook/jscodeshift) related to `@types/react`.

26 lines (21 loc) 607 B
const parseSync = require("./utils/parseSync"); /** * @type {import('jscodeshift').Transform} */ const deprecatedReactTypeTransform = (file, api) => { const j = api.jscodeshift; const ast = parseSync(file); const changedIdentifiers = ast .find(j.Identifier, (node) => { return node.name === "ReactType"; }) .replaceWith(() => { return j.identifier("ElementType"); }); // Otherwise some files will be marked as "modified" because formatting changed if (changedIdentifiers.length > 0) { return ast.toSource(); } return file.source; }; export default deprecatedReactTypeTransform;