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
214e0d32
Unverified
Commit
214e0d32
authored
Nov 26, 2024
by
Hendrik Liebau
Committed by
GitHub
Nov 26, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Forbid `super` in static class methods with server function directives (#73061)
parent
12c483aa
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
10 deletions
+47
-10
server_actions.rs
...s/next-custom-transforms/src/transforms/server_actions.rs
+10
-0
input.js
...orms/tests/errors/server-actions/server-graph/26/input.js
+11
-1
output.js
...rms/tests/errors/server-actions/server-graph/26/output.js
+10
-1
output.stderr
...tests/errors/server-actions/server-graph/26/output.stderr
+16
-8
No files found.
crates/next-custom-transforms/src/transforms/server_actions.rs
View file @
214e0d32
...
...
@@ -2141,6 +2141,16 @@ impl<C: Comments> VisitMut for ServerActions<C> {
}
}
fn
visit_mut_super
(
&
mut
self
,
n
:
&
mut
Super
)
{
if
let
ThisStatus
::
Forbidden
{
directive
}
=
&
self
.this_status
{
emit_error
(
ServerActionsErrorKind
::
ForbiddenExpression
{
span
:
n
.span
,
expr
:
"super"
.into
(),
directive
:
directive
.clone
(),
});
}
}
fn
visit_mut_ident
(
&
mut
self
,
n
:
&
mut
Ident
)
{
if
n
.sym
==
*
"arguments"
{
if
let
ThisStatus
::
Forbidden
{
directive
}
=
&
self
.this_status
{
...
...
crates/next-custom-transforms/tests/errors/server-actions/server-graph/26/input.js
View file @
214e0d32
export
class
MyClass
{
import
{
BaseClass
}
from
'./base'
export
class
MyClass
extends
BaseClass
{
static
async
foo
()
{
// super is allowed here
super
.
foo
()
return
fetch
(
'https://example.com'
).
then
((
res
)
=>
res
.
json
())
}
static
async
bar
()
{
'use cache'
if
(
Math
.
random
()
>
0.5
)
{
// super is not allowed here
return
[
super
.
bar
()]
}
// arguments is not allowed here
console
.
log
(
arguments
)
// this is not allowed here
...
...
crates/next-custom-transforms/tests/errors/server-actions/server-graph/26/output.js
View file @
214e0d32
export
class
MyClass
{
import
{
BaseClass
}
from
'./base'
;
export
class
MyClass
extends
BaseClass
{
static
async
foo
()
{
// super is allowed here
super
.
foo
();
return
fetch
(
'https://example.com'
).
then
((
res
)
=>
res
.
json
());
}
static
async
bar
()
{
if
(
Math
.
random
()
>
0.5
)
{
// super is not allowed here
return
[
super
.
bar
()
];
}
// arguments is not allowed here
console
.
log
(
arguments
);
// this is not allowed here
...
...
crates/next-custom-transforms/tests/errors/server-actions/server-graph/26/output.stderr
View file @
214e0d32
x "use cache" functions cannot use `super`.
|
,-[input.js:15:1]
14 | // super is not allowed here
15 | return [super.bar()]
: ^^^^^
16 | }
`----
x "use cache" functions cannot use `arguments`.
|
,-[input.js:9:1]
8 | // arguments is not allowed here
9 | console.log(arguments)
,-[input.js:
1
9:1]
1
8 | // arguments is not allowed here
1
9 | console.log(arguments)
: ^^^^^^^^^
1
0 | // this is not allowed here
2
0 | // this is not allowed here
`----
x "use cache" functions cannot use `this`.
|
,-[input.js:
1
1:1]
1
0 | // this is not allowed here
1
1 | return this.foo()
,-[input.js:
2
1:1]
2
0 | // this is not allowed here
2
1 | return this.foo()
: ^^^^
1
2 | }
2
2 | }
`----
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