Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
c232d385
Unverified
Commit
c232d385
authored
Apr 27, 2022
by
Tim Neutkens
Committed by
GitHub
Apr 27, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add string children case for newNextLinkBehavior codemod (#36516)
parent
5907e9d3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
1 deletion
+31
-1
link-string.input.js
...transforms/__testfixtures__/new-link/link-string.input.js
+8
-0
link-string.output.js
...ransforms/__testfixtures__/new-link/link-string.output.js
+8
-0
new-link.test.js
packages/next-codemod/transforms/__tests__/new-link.test.js
+2
-1
new-link.ts
packages/next-codemod/transforms/new-link.ts
+13
-0
No files found.
packages/next-codemod/transforms/__testfixtures__/new-link/link-string.input.js
0 → 100644
View file @
c232d385
import
Link
from
'next/link'
export
default
function
Page
()
{
return
(
<
Link
href
=
"/about"
>
Link
<
/Link
>
);
}
\ No newline at end of file
packages/next-codemod/transforms/__testfixtures__/new-link/link-string.output.js
0 → 100644
View file @
c232d385
import
Link
from
'next/link'
export
default
function
Page
()
{
return
(
<
Link
href
=
"/about"
>
Link
<
/Link
>
);
}
\ No newline at end of file
packages/next-codemod/transforms/__tests__/new-link.test.js
View file @
c232d385
...
@@ -8,7 +8,8 @@ const fixtures = [
...
@@ -8,7 +8,8 @@ const fixtures = [
'add-legacy-behavior'
,
'add-legacy-behavior'
,
'excludes-links-with-legacybehavior-prop'
,
'excludes-links-with-legacybehavior-prop'
,
'children-interpolation'
,
'children-interpolation'
,
'spread-props'
'spread-props'
,
'link-string'
]
]
for
(
const
fixture
of
fixtures
)
{
for
(
const
fixture
of
fixtures
)
{
...
...
packages/next-codemod/transforms/new-link.ts
View file @
c232d385
...
@@ -36,6 +36,19 @@ export default function transformer(file: FileInfo, api: API) {
...
@@ -36,6 +36,19 @@ export default function transformer(file: FileInfo, api: API) {
if
(
$link
.
size
()
===
0
)
{
if
(
$link
.
size
()
===
0
)
{
return
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
// Direct child elements referenced
const
$childrenElements
=
$link
.
childElements
()
const
$childrenElements
=
$link
.
childElements
()
const
$childrenWithA
=
$childrenElements
.
filter
((
childPath
)
=>
{
const
$childrenWithA
=
$childrenElements
.
filter
((
childPath
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment