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
f6906fcf
Unverified
Commit
f6906fcf
authored
Oct 08, 2024
by
Jiachi Liu
Committed by
GitHub
Oct 08, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
codemod: skip promise.all on params (#70972)
parent
3f01d2fc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
0 deletions
+66
-0
access-props-26.input.tsx
...async-request-api-dynamic-props/access-props-26.input.tsx
+21
-0
access-props-26.output.tsx
...sync-request-api-dynamic-props/access-props-26.output.tsx
+21
-0
next-async-dynamic-prop.ts
...ansforms/lib/async-request-api/next-async-dynamic-prop.ts
+24
-0
No files found.
packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-props/access-props-26.input.tsx
0 → 100644
View file @
f6906fcf
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
])
}
packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-props/access-props-26.output.tsx
0 → 100644
View file @
f6906fcf
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
])
}
packages/next-codemod/transforms/lib/async-request-api/next-async-dynamic-prop.ts
View file @
f6906fcf
...
...
@@ -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
>
,
...
...
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