Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/oxc_parser/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,11 @@ pub fn new_dynamic_import(span: Span) -> OxcDiagnostic {
.with_help("Wrap this with parenthesis")
}

#[cold]
pub fn new_super(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("'new super()' is not allowed").with_label(span)
}

#[cold]
pub fn private_name_constructor(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Classes can't have an element named '#constructor'").with_label(span)
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_parser/src/js/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,10 @@ impl<'a, C: Config> ParserImpl<'a, C> {
self.error(diagnostics::new_dynamic_import(self.end_span(rhs_span)));
}

if matches!(callee, Expression::Super(_)) {
self.error(diagnostics::new_super(self.end_span(rhs_span)));
}

let span = self.end_span(span);

if optional {
Expand Down
8 changes: 8 additions & 0 deletions tasks/coverage/snapshots/parser_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9957,6 +9957,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────
help: Replace with `super()` or `super.prop` or `super[prop]`

× 'new super()' is not allowed
╭─[babel/packages/babel-parser/test/fixtures/esprima/es2015-super-property/invalid_super_id/input.js:2:17]
1 │ class A {
2 │ foo() { new super + 3 }
· ─────
3 │ }
╰────

× TS(2337): Super calls are not permitted outside constructors or in nested functions inside constructors.
╭─[babel/packages/babel-parser/test/fixtures/esprima/es2015-super-property/invalid_super_id/input.js:2:13]
1 │ class A {
Expand Down
12 changes: 9 additions & 3 deletions tasks/coverage/snapshots/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ commit: c9e7428b
parser_typescript Summary:
AST Parsed : 9828/9831 (99.97%)
Positive Passed: 9817/9831 (99.86%)
Negative Passed: 1532/2587 (59.22%)
Negative Passed: 1533/2587 (59.26%)
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/FunctionDeclaration3.ts

Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/FunctionDeclaration4.ts
Expand Down Expand Up @@ -882,8 +882,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/superCallIns

Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/superInConstructorParam1.ts

Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/superNewCall1.ts

Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/superPropertyAccess2.ts

Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/superPropertyAccessInSuperCall01.ts
Expand Down Expand Up @@ -11824,6 +11822,14 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc
53 │ },
╰────

× 'new super()' is not allowed
╭─[typescript/tests/cases/compiler/superNewCall1.ts:9:13]
8 │ constructor() {
9 │ new super(value => String(value));
· ─────────────────────────────
10 │ }
╰────

× 'super' can only be used with function calls or in property accesses
╭─[typescript/tests/cases/compiler/superWithTypeArgument.ts:7:9]
6 │ constructor() {
Expand Down
Loading