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
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/typescript/no_misused_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn test() {
use crate::tester::Tester;

let pass = vec![
"declare abstract class C { foo() {} get new();bar();}",
"declare abstract class C { foo(); get new();bar();}",
"class C { constructor();}",
"const foo = class { constructor();};",
"const foo = class { new(): X;};",
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_parser/src/js/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,12 @@ impl<'a> ParserImpl<'a> {
}
}
}

if self.ctx.has_ambient()
&& let Some(body) = &method.value.body
{
self.error(diagnostics::implementation_in_ambient(Span::empty(body.span.start)));
}
}

fn check_method_definition_accessor(&mut self, method: &MethodDefinition<'a>) {
Expand Down
40 changes: 40 additions & 0 deletions tasks/coverage/snapshots/parser_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc

Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/class/modifiers-override/input.ts

× TS(1183): An implementation cannot be declared in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/modifiers-override/input.ts:17:19]
16 │ declare class DeclaredClass extends BaseClass {
17 │ override test() {}
· ▲
18 │ }
╰────

× Identifier `show` has already been declared
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/modifiers-override/input.ts:2:12]
1 │ class MyClass extends BaseClass {
Expand Down Expand Up @@ -12510,6 +12518,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────
help: Allowed modifiers are: private, protected, public, static, abstract, override, async

× TS(1183): An implementation cannot be declared in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/declare-method/input.ts:2:17]
1 │ class A {
2 │ declare foo() {}
· ▲
3 │ }
╰────

× Expected a semicolon or an implicit semicolon after a statement, but found none
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/declare-new-line-abstract/input.ts:1:8]
1 │ declare abstract
Expand Down Expand Up @@ -12634,6 +12650,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────
help: Allowed modifiers are: private, protected, public, static, abstract, override, async

× TS(1183): An implementation cannot be declared in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/generator-method-with-modifiers/input.ts:7:16]
6 │ readonly *e() {}
7 │ declare *f() {}
· ▲
8 │ protected *g() {}
╰────

× TS(1244): Abstract methods can only appear within an abstract class.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/generator-method-with-modifiers/input.ts:5:13]
4 │ static *c() {}
Expand Down Expand Up @@ -12779,6 +12803,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────
help: Allowed modifiers are: private, protected, public, static, abstract, override, async

× TS(1183): An implementation cannot be declared in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/optional-generator-method-with-invalid-modifiers/input.ts:4:17]
3 │ readonly *e?() { }
4 │ declare *f?() { }
· ▲
5 │ }
╰────

× TS(1245): Method 'd?.d' cannot have an implementation because it is marked abstract.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/optional-generator-method-with-invalid-modifiers/input.ts:8:14]
7 │ class A {
Expand All @@ -12805,6 +12837,14 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
╰────
help: Allowed modifiers are: private, protected, public, static, abstract, override, async

× TS(1183): An implementation cannot be declared in ambient contexts.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/optional-generator-method-with-invalid-modifiers/input.ts:10:22]
9 │ readonly *[e?.e]?() { }
10 │ declare *[f?.f]?() { }
· ▲
11 │ }
╰────

× TS(1244): Abstract methods can only appear within an abstract class.
╭─[babel/packages/babel-parser/test/fixtures/typescript/class/optional-generator-method-with-invalid-modifiers/input.ts:2:13]
1 │ class C {
Expand Down
8 changes: 8 additions & 0 deletions tasks/coverage/snapshots/parser_misc.snap
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,14 @@ Negative Passed: 134/134 (100.00%)
╰────
help: Allowed modifiers are: private, protected, public, static, abstract, override, async

× TS(1183): An implementation cannot be declared in ambient contexts.
╭─[misc/fail/oxc-11713-24.ts:2:20]
1 │ class Foo {
2 │ declare method() {}
· ▲
3 │ }
╰────

× TS(1024): 'readonly' modifier can only appear on a property declaration or index signature.
╭─[misc/fail/oxc-11713-25.ts:2:3]
1 │ class Foo {
Expand Down
Loading
Loading