Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codemod: should not transform when param is not used #71664

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading