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
97153cc8
Unverified
Commit
97153cc8
authored
Oct 29, 2024
by
Jiachi Liu
Committed by
GitHub
Oct 29, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
codemod: add separator to the parenthenese expr (#71993)
parent
89ba33ac
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
4 deletions
+35
-4
async-api-11.output.tsx
...xt-async-request-api-dynamic-apis/async-api-11.output.tsx
+2
-2
async-api-19.output.tsx
...xt-async-request-api-dynamic-apis/async-api-19.output.tsx
+1
-1
async-api-25.input.tsx
...ext-async-request-api-dynamic-apis/async-api-25.input.tsx
+6
-0
async-api-25.output.tsx
...xt-async-request-api-dynamic-apis/async-api-25.output.tsx
+6
-0
next-async-dynamic-api.ts
...ransforms/lib/async-request-api/next-async-dynamic-api.ts
+20
-1
No files found.
packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-apis/async-api-11.output.tsx
View file @
97153cc8
import
{
headers
,
type
UnsafeUnwrappedHeaders
}
from
'next/headers'
;
export
function
MyComp
()
{
(
headers
()
as
unknown
as
UnsafeUnwrappedHeaders
)
void
(
headers
()
as
unknown
as
UnsafeUnwrappedHeaders
)
}
export
function
generateContentfulMetadata
()
{
(
headers
()
as
unknown
as
UnsafeUnwrappedHeaders
)
void
(
headers
()
as
unknown
as
UnsafeUnwrappedHeaders
)
}
packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-apis/async-api-19.output.tsx
View file @
97153cc8
...
...
@@ -8,6 +8,6 @@ export function myFun() {
export
function
myFun2
()
{
return
function
()
{
(
headers
()
as
unknown
as
UnsafeUnwrappedHeaders
)
void
(
headers
()
as
unknown
as
UnsafeUnwrappedHeaders
)
};
}
packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-apis/async-api-25.input.tsx
0 → 100644
View file @
97153cc8
import
{
cookies
}
from
'next/headers'
export
function
myFunc
()
{
const
c
=
cookies
()
cookies
()
}
packages/next-codemod/transforms/__testfixtures__/next-async-request-api-dynamic-apis/async-api-25.output.tsx
0 → 100644
View file @
97153cc8
import
{
cookies
,
type
UnsafeUnwrappedCookies
}
from
'next/headers'
;
export
function
myFunc
()
{
const
c
=
(
cookies
()
as
unknown
as
UnsafeUnwrappedCookies
)
void
(
cookies
()
as
unknown
as
UnsafeUnwrappedCookies
)
}
packages/next-codemod/transforms/lib/async-request-api/next-async-dynamic-api.ts
View file @
97153cc8
...
...
@@ -338,7 +338,26 @@ function castTypesOrAddComment(
)
// Replace the original expression with the new cast expression,
// also wrap () around the new cast expression.
j
(
path
).
replaceWith
(
j
.
parenthesizedExpression
(
newCastExpression
))
const
parent
=
path
.
parent
.
value
const
wrappedExpression
=
j
.
parenthesizedExpression
(
newCastExpression
)
path
.
replace
(
wrappedExpression
)
// If the wrapped expression `(<expression>)` is the beginning of an expression statement,
// add a void operator to separate the statement, to avoid syntax error that being treated as part of previous statement.
// example:
// input:
// <expression>
// <expression>
// output:
// (<expression> as ...)
// void (<expression> as ...)
if
(
j
.
ExpressionStatement
.
check
(
parent
)
&&
parent
.
expression
===
path
.
node
)
{
// append a semicolon to the start of the expression statement
parent
.
expression
=
j
.
unaryExpression
(
'void'
,
parent
.
expression
)
}
modified
=
true
// If cast types are not imported, add them to the import list
...
...
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