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
5a54933a
Unverified
Commit
5a54933a
authored
Oct 23, 2024
by
Jiachi Liu
Committed by
GitHub
Oct 23, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
codemod: should not transform when param is not used (#71664)
parent
f91cdec4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
4 deletions
+17
-4
access-props-39.input.tsx
...async-request-api-dynamic-props/access-props-39.input.tsx
+7
-0
access-props-39.output.tsx
...sync-request-api-dynamic-props/access-props-39.output.tsx
+7
-0
next-async-dynamic-prop.ts
...ansforms/lib/async-request-api/next-async-dynamic-prop.ts
+3
-4
No files found.
packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-props/access-props-39.input.tsx
0 → 100644
View file @
5a54933a
export
default
function
Page
({
params
,
children
})
{
return
children
}
export
function
generateMetadata
(
props
)
{
return
{}
}
packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-props/access-props-39.output.tsx
0 → 100644
View file @
5a54933a
export
default
function
Page
({
params
,
children
})
{
return
children
}
export
function
generateMetadata
(
props
)
{
return
{}
}
packages/next-codemod/transforms/lib/async-request-api/next-async-dynamic-prop.ts
View file @
5a54933a
...
...
@@ -695,9 +695,8 @@ export function transformDynamicProps(
:
null
const
paramPropertyName
=
paramsPropertyName
||
matchedPropName
// if propName is not used in lower scope, and it stars with unused prefix `_`,
// also skip the transformation
// If propName is an identifier and not used in lower scope,
// also skip the transformation.
const
hasUsedInBody
=
j
(
functionBodyPath
)
.
find
(
j
.
Identifier
,
{
...
...
@@ -705,7 +704,7 @@ export function transformDynamicProps(
})
.
size
()
>
0
if
(
!
hasUsedInBody
&&
paramPropertyName
.
startsWith
(
'_'
))
continue
if
(
!
hasUsedInBody
&&
j
.
Identifier
.
check
(
paramsProperty
))
continue
// Search the usage of propName in the function body,
// if they're all awaited or wrapped with use(), skip the transformation
...
...
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