Unverified Commit 214e0d32 authored by Hendrik Liebau's avatar Hendrik Liebau Committed by GitHub

Forbid `super` in static class methods with server function directives (#73061)

parent 12c483aa
......@@ -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 {
......
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
......
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
......
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:19:1]
18 | // arguments is not allowed here
19 | console.log(arguments)
: ^^^^^^^^^
10 | // this is not allowed here
20 | // this is not allowed here
`----
x "use cache" functions cannot use `this`.
|
,-[input.js:11:1]
10 | // this is not allowed here
11 | return this.foo()
,-[input.js:21:1]
20 | // this is not allowed here
21 | return this.foo()
: ^^^^
12 | }
22 | }
`----
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