Skip to content

Commit

Permalink
codemod: should not transform when param is not used
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Oct 22, 2024
1 parent cfd816d commit 077eea9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Page({ params, children }) {
return children
}

export function generateMetadata(props) {
return {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Page({ params, children }) {
return children
}

export function generateMetadata(props) {
return {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -695,17 +695,16 @@ 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, {
name: paramPropertyName,
})
.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
Expand Down

0 comments on commit 077eea9

Please sign in to comment.