Unverified Commit c232d385 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add string children case for newNextLinkBehavior codemod (#36516)

parent 5907e9d3
import Link from 'next/link'
export default function Page() {
return (
<Link href="/about">
Link
</Link>
);
}
\ No newline at end of file
import Link from 'next/link'
export default function Page() {
return (
<Link href="/about">
Link
</Link>
);
}
\ No newline at end of file
......@@ -8,7 +8,8 @@ const fixtures = [
'add-legacy-behavior',
'excludes-links-with-legacybehavior-prop',
'children-interpolation',
'spread-props'
'spread-props',
'link-string'
]
for (const fixture of fixtures) {
......
......@@ -36,6 +36,19 @@ export default function transformer(file: FileInfo, api: API) {
if ($link.size() === 0) {
return
}
const linkChildrenNodes = $link.get('children')
// Text-only link children are already correct with the new behavior
// `next/link` would previously auto-wrap typeof 'string' children already
if (
linkChildrenNodes.value &&
linkChildrenNodes.value.length === 1 &&
linkChildrenNodes.value[0].type === 'JSXText'
) {
return
}
// Direct child elements referenced
const $childrenElements = $link.childElements()
const $childrenWithA = $childrenElements.filter((childPath) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment