Unverified Commit f6906fcf authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

codemod: skip promise.all on params (#70972)

parent 3f01d2fc
interface Props {
params: Promise<{
slug: string;
}>
searchParams: Promise<{
a: string;
}>
}
export default async function Page(props: Props) {
const [
params,
searchParams
] = await Promise.all([props.params, props.searchParams])
}
export async function generateMetadata(props: Props) {
const [
params,
] = await Promise.all([props.params, props.searchParams])
}
interface Props {
params: Promise<{
slug: string;
}>
searchParams: Promise<{
a: string;
}>
}
export default async function Page(props: Props) {
const [
params,
searchParams
] = await Promise.all([props.params, props.searchParams])
}
export async function generateMetadata(props: Props) {
const [
params,
] = await Promise.all([props.params, props.searchParams])
}
......@@ -50,6 +50,10 @@ function awaitMemberAccessOfProp(
memberAccess.forEach((memberAccessPath) => {
const member = memberAccessPath.value
if (isParentPromiseAllCallExpression(memberAccessPath, j)) {
return
}
// check if it's already awaited
if (memberAccessPath.parentPath?.value.type === 'AwaitExpression') {
return
......@@ -88,6 +92,26 @@ function isParentUseCallExpression(path: ASTPath<any>, j: API['jscodeshift']) {
return false
}
function isParentPromiseAllCallExpression(
path: ASTPath<any>,
j: API['jscodeshift']
) {
const argsParent = path.parent
const callParent = argsParent?.parent
if (
j.ArrayExpression.check(argsParent.value) &&
j.CallExpression.check(callParent.value) &&
j.MemberExpression.check(callParent.value.callee) &&
j.Identifier.check(callParent.value.callee.object) &&
callParent.value.callee.object.name === 'Promise' &&
j.Identifier.check(callParent.value.callee.property) &&
callParent.value.callee.property.name === 'all'
) {
return true
}
return false
}
function applyUseAndRenameAccessedProp(
propIdName: string,
path: ASTPath<FunctionScope>,
......
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