UNPKG

types-react-codemod

Version:

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

31 lines (26 loc) 707 B
const parseSync = require("./utils/parseSync"); const { replaceReactType } = require("./utils/replaceType"); /** * @param {import('jscodeshift').FileInfo} file * @param {import('jscodeshift').API} api */ const deprecatedReactTextTransform = (file, api) => { const j = api.jscodeshift; const ast = parseSync(file); const hasChanges = replaceReactType( j, ast, "ReactText", () => { // `number | string` return j.tsUnionType([j.tsNumberKeyword(), j.tsStringKeyword()]); }, null, ); // Otherwise some files will be marked as "modified" because formatting changed if (hasChanges) { return ast.toSource(); } return file.source; }; module.exports = deprecatedReactTextTransform;