@@ -224,24 +224,36 @@ fn abstract_accessor_cannot_have_implementation(accessor_name: &str, span: Span)
224
224
)
225
225
}
226
226
227
+ /// 'abstract' modifier can only appear on a class, method, or property declaration. (1242)
228
+ fn illegal_abstract_modifier ( span : Span ) -> OxcDiagnostic {
229
+ OxcDiagnostic :: error ( "TS(1242): 'abstract' modifier can only appear on a class, method, or property declaration." )
230
+ . with_label ( span)
231
+ }
232
+
227
233
pub fn check_method_definition < ' a > ( method : & MethodDefinition < ' a > , ctx : & SemanticBuilder < ' a > ) {
228
- if method. r#type . is_abstract ( ) && method. value . body . is_some ( ) {
229
- let ( method_name, span) = method. key . prop_name ( ) . unwrap_or_else ( || {
230
- let key_span = method. key . span ( ) ;
231
- ( & ctx. source_text [ key_span] , key_span)
232
- } ) ;
233
- match method. kind {
234
- MethodDefinitionKind :: Method => {
235
- ctx. error ( abstract_method_cannot_have_implementation ( method_name, span) ) ;
236
- }
237
- MethodDefinitionKind :: Get | MethodDefinitionKind :: Set => {
238
- ctx. error ( abstract_accessor_cannot_have_implementation ( method_name, span) ) ;
234
+ if method. r#type . is_abstract ( ) {
235
+ // constructors cannot be abstract, no matter what
236
+ if method. kind . is_constructor ( ) {
237
+ ctx. error ( illegal_abstract_modifier ( method. key . span ( ) ) ) ;
238
+ } else if method. value . body . is_some ( ) {
239
+ // abstract class elements cannot have bodies or initializers
240
+ let ( method_name, span) = method. key . prop_name ( ) . unwrap_or_else ( || {
241
+ let key_span = method. key . span ( ) ;
242
+ ( & ctx. source_text [ key_span] , key_span)
243
+ } ) ;
244
+ match method. kind {
245
+ MethodDefinitionKind :: Method => {
246
+ ctx. error ( abstract_method_cannot_have_implementation ( method_name, span) ) ;
247
+ }
248
+ MethodDefinitionKind :: Get | MethodDefinitionKind :: Set => {
249
+ ctx. error ( abstract_accessor_cannot_have_implementation ( method_name, span) ) ;
250
+ }
251
+ // abstract classes can have concrete methods. Constructors cannot
252
+ // have abstract modifiers, but this gets checked during parsing
253
+ MethodDefinitionKind :: Constructor => { }
239
254
}
240
- // abstract classes can have concrete methods. Constructors cannot
241
- // have abstract modifiers, but this gets checked during parsing
242
- MethodDefinitionKind :: Constructor => { }
255
+ ctx. error ( abstract_method_cannot_have_implementation ( method_name, span) ) ;
243
256
}
244
- ctx. error ( abstract_method_cannot_have_implementation ( method_name, span) ) ;
245
257
}
246
258
}
247
259
0 commit comments