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
32 changes: 22 additions & 10 deletions crates/oxc_semantic/src/checker/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,36 @@ pub fn check_class<'a>(class: &Class<'a>, ctx: &SemanticBuilder<'a>) {
}

if !class.r#declare && !ctx.in_declare_scope() {
let mut is_in_overload_group = false;
for (a, b) in class.body.body.iter().map(Some).chain(vec![None]).tuple_windows() {
if let Some(ClassElement::MethodDefinition(a)) = a
&& !a.r#type.is_abstract()
&& !a.optional
&& a.value.r#type == FunctionType::TSEmptyBodyFunctionExpression
&& b.is_none_or(|b| match b {
ClassElement::StaticBlock(_)
| ClassElement::PropertyDefinition(_)
| ClassElement::AccessorProperty(_)
| ClassElement::TSIndexSignature(_) => true,
ClassElement::MethodDefinition(b) => b.key.static_name() != a.key.static_name(),
})
{
if a.kind.is_constructor() {
ctx.error(diagnostics::constructor_implementation_missing(a.key.span()));
let next_is_same = b.is_some_and(|b| {
matches!(b,
ClassElement::MethodDefinition(b)
if b.key.static_name() == a.key.static_name()
)
});
if next_is_same {
is_in_overload_group = true;
} else if a.key.static_name().is_some() || is_in_overload_group {
// Report error for:
// 1. Methods with static names that are not followed by an implementation
// 2. The last overload in a computed-name overload group (e.g. [Symbol.iterator])
if a.kind.is_constructor() {
ctx.error(diagnostics::constructor_implementation_missing(a.key.span()));
} else {
ctx.error(diagnostics::function_implementation_missing(a.key.span()));
}
is_in_overload_group = false;
} else {
ctx.error(diagnostics::function_implementation_missing(a.key.span()));
is_in_overload_group = false;
}
} else {
is_in_overload_group = false;
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions tasks/coverage/snapshots/parser_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12028,14 +12028,6 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/typesc
3 β”‚ #method();
╰────

Γ— TS(2391): Function implementation is missing or not immediately following the declaration.
╭─[babel/packages/babel-parser/test/fixtures/estree/typescript/invalid-class-method-empty-body/input.js:3:3]
2 β”‚ method();
3 β”‚ #method();
Β· ───────
4 β”‚ declare method();
╰────

Γ— TS(2391): Function implementation is missing or not immediately following the declaration.
╭─[babel/packages/babel-parser/test/fixtures/estree/typescript/invalid-class-method-empty-body/input.js:4:11]
3 β”‚ #method();
Expand Down
22 changes: 1 addition & 21 deletions tasks/coverage/snapshots/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: 95e3aaa9

parser_typescript Summary:
AST Parsed : 9843/9843 (100.00%)
Positive Passed: 9839/9843 (99.96%)
Positive Passed: 9841/9843 (99.98%)
Negative Passed: 1529/2557 (59.80%)
Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/FunctionDeclaration3.ts

Expand Down Expand Up @@ -2074,26 +2074,6 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/async/es6/asy
132 β”‚ }
╰────

Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName11.ts

Γ— TS(2391): Function implementation is missing or not immediately following the declaration.
╭─[typescript/tests/cases/conformance/parser/ecmascript5/ComputedPropertyNames/parserES5ComputedPropertyName11.ts:2:5]
1 β”‚ class C {
2 β”‚ [e]();
Β· ─
3 β”‚ }
╰────

Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName11.ts

Γ— TS(2391): Function implementation is missing or not immediately following the declaration.
╭─[typescript/tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName11.ts:2:5]
1 β”‚ class C {
2 β”‚ [e]();
Β· ─
3 β”‚ }
╰────

Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarations.14.ts

Γ— 'using' declarations are not allowed at the top level of a script
Expand Down
Loading