import type { API, FileInfo } from 'jscodeshift' export default function transformer(file: FileInfo, api: API) { const j = api.jscodeshift.withParser('tsx') const $j = j(file.source) return $j .find(j.ImportDeclaration, { source: { value: 'next/link' } }) .forEach((path) => { const defaultImport = j(path).find(j.ImportDefaultSpecifier) if (defaultImport.size() === 0) { return } const variableName = j(path) .find(j.ImportDefaultSpecifier) .find(j.Identifier) .get('name').value if (!variableName) { return } const linkElements = $j.findJSXElements(variableName) const hasStylesJSX = $j.findJSXElements('style').some((stylePath) => { const $style = j(stylePath) const hasJSXProp = $style.find(j.JSXAttribute, { name: { name: 'jsx' } }).size() !== 0 return hasJSXProp }) linkElements.forEach((linkPath) => { const $link = j(linkPath).filter((childPath) => { // Exclude links with `legacybehavior` prop from modification return ( j(childPath) .find(j.JSXAttribute, { name: { name: 'legacyBehavior' } }) .size() === 0 ) }) if ($link.size() === 0) { return } // If file has