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
070ae8a7
Unverified
Commit
070ae8a7
authored
Aug 28, 2025
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Aug 28, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[codemod] Only change files when `new-link` transform makes changes (#83112)
parent
d574c6a6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
16 deletions
+24
-16
new-link.ts
packages/next-codemod/transforms/new-link.ts
+24
-16
No files found.
packages/next-codemod/transforms/new-link.ts
View file @
070ae8a7
...
@@ -9,10 +9,10 @@ export default function transformer(file: FileInfo, _api: API) {
...
@@ -9,10 +9,10 @@ export default function transformer(file: FileInfo, _api: API) {
const
j
=
createParserFromPath
(
file
.
path
)
const
j
=
createParserFromPath
(
file
.
path
)
const
$j
=
j
(
file
.
source
)
const
$j
=
j
(
file
.
source
)
let
hasChanges
=
false
return
$j
$j
.
find
(
j
.
ImportDeclaration
,
{
source
:
{
value
:
'next/link'
}
}).
forEach
(
.
find
(
j
.
ImportDeclaration
,
{
source
:
{
value
:
'next/link'
}
})
(
path
)
=>
{
.
forEach
((
path
)
=>
{
const
defaultImport
=
j
(
path
).
find
(
j
.
ImportDefaultSpecifier
)
const
defaultImport
=
j
(
path
).
find
(
j
.
ImportDefaultSpecifier
)
if
(
defaultImport
.
size
()
===
0
)
{
if
(
defaultImport
.
size
()
===
0
)
{
return
return
...
@@ -35,17 +35,17 @@ export default function transformer(file: FileInfo, _api: API) {
...
@@ -35,17 +35,17 @@ export default function transformer(file: FileInfo, _api: API) {
return
return
}
}
const
$legacyBehaviorProp
=
$link
const
$legacyBehaviorProp
s
=
$link
.
find
(
j
.
JSXAttribute
,
{
.
find
(
j
.
JSXAttribute
,
{
name
:
{
type
:
'JSXIdentifier'
,
name
:
'legacyBehavior'
},
name
:
{
type
:
'JSXIdentifier'
,
name
:
'legacyBehavior'
},
})
}
)
$legacyBehaviorProps
.
remove
(
)
.
remove
()
hasChanges
||=
$legacyBehaviorProps
.
size
()
>
0
$link
const
$passHrefProps
=
$link
.
find
(
j
.
JSXAttribute
,
{
.
find
(
j
.
JSXAttribute
,
{
name
:
{
type
:
'JSXIdentifier'
,
name
:
'passHref'
},
name
:
{
type
:
'JSXIdentifier'
,
name
:
'passHref'
},
})
}
)
$passHrefProps
.
remove
(
)
.
remove
()
hasChanges
||=
$passHrefProps
.
size
()
>
0
const
linkChildrenNodes
=
$link
.
get
(
'children'
)
const
linkChildrenNodes
=
$link
.
get
(
'children'
)
...
@@ -69,7 +69,7 @@ export default function transformer(file: FileInfo, _api: API) {
...
@@ -69,7 +69,7 @@ export default function transformer(file: FileInfo, _api: API) {
})
})
if
(
$childrenWithA
.
length
===
0
)
{
if
(
$childrenWithA
.
length
===
0
)
{
if
(
$legacyBehaviorProp
.
length
>
0
)
{
if
(
$legacyBehaviorProp
s
.
length
>
0
)
{
linkPath
.
node
.
children
.
unshift
(
linkPath
.
node
.
children
.
unshift
(
j
.
jsxText
(
'
\
n'
),
j
.
jsxText
(
'
\
n'
),
j
.
jsxExpressionContainer
.
from
({
j
.
jsxExpressionContainer
.
from
({
...
@@ -82,6 +82,7 @@ export default function transformer(file: FileInfo, _api: API) {
...
@@ -82,6 +82,7 @@ export default function transformer(file: FileInfo, _api: API) {
}),
}),
})
})
)
)
hasChanges
=
true
}
}
}
else
{
}
else
{
const
props
=
$childrenWithA
.
get
(
'attributes'
).
value
const
props
=
$childrenWithA
.
get
(
'attributes'
).
value
...
@@ -104,12 +105,19 @@ export default function transformer(file: FileInfo, _api: API) {
...
@@ -104,12 +105,19 @@ export default function transformer(file: FileInfo, _api: API) {
// Remove props from <a>
// Remove props from <a>
props
.
length
=
0
props
.
length
=
0
hasChanges
=
true
}
}
const
childrenProps
=
$childrenWithA
.
get
(
'children'
)
const
childrenProps
=
$childrenWithA
.
get
(
'children'
)
$childrenWithA
.
replaceWith
(
childrenProps
.
value
)
$childrenWithA
.
replaceWith
(
childrenProps
.
value
)
hasChanges
=
true
}
}
})
})
})
}
.
toSource
()
)
if
(
hasChanges
)
{
return
$j
.
toSource
()
}
return
file
.
source
}
}
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