Unverified Commit 5a54933a authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

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

parent f91cdec4
export default function Page({ params, children }) {
return children
}
export function generateMetadata(props) {
return {}
}
export default function Page({ params, children }) {
return children
}
export function generateMetadata(props) {
return {}
}
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment