Skip to content

Commit 2a559af

Browse files
committed
fix(ast)!: change Class::implements to Vec<TSClassImplements>
fixes #10421
1 parent 3d7bcac commit 2a559af

File tree

15 files changed

+41
-90
lines changed

15 files changed

+41
-90
lines changed

crates/oxc_ast/src/ast/js.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,8 +1941,7 @@ pub struct Class<'a> {
19411941
/// // ^^^
19421942
/// ```
19431943
#[ts]
1944-
#[estree(via = ClassImplements)]
1945-
pub implements: Option<Vec<'a, TSClassImplements<'a>>>,
1944+
pub implements: Vec<'a, TSClassImplements<'a>>,
19461945
pub body: Box<'a, ClassBody<'a>>,
19471946
/// Whether the class is abstract
19481947
///

crates/oxc_ast/src/generated/ast_builder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ impl<'a> AstBuilder<'a> {
575575
type_parameters: T1,
576576
super_class: Option<Expression<'a>>,
577577
super_type_arguments: T2,
578-
implements: Option<Vec<'a, TSClassImplements<'a>>>,
578+
implements: Vec<'a, TSClassImplements<'a>>,
579579
body: T3,
580580
r#abstract: bool,
581581
declare: bool,
@@ -627,7 +627,7 @@ impl<'a> AstBuilder<'a> {
627627
type_parameters: T1,
628628
super_class: Option<Expression<'a>>,
629629
super_type_arguments: T2,
630-
implements: Option<Vec<'a, TSClassImplements<'a>>>,
630+
implements: Vec<'a, TSClassImplements<'a>>,
631631
body: T3,
632632
r#abstract: bool,
633633
declare: bool,
@@ -4001,7 +4001,7 @@ impl<'a> AstBuilder<'a> {
40014001
type_parameters: T1,
40024002
super_class: Option<Expression<'a>>,
40034003
super_type_arguments: T2,
4004-
implements: Option<Vec<'a, TSClassImplements<'a>>>,
4004+
implements: Vec<'a, TSClassImplements<'a>>,
40054005
body: T3,
40064006
r#abstract: bool,
40074007
declare: bool,
@@ -4053,7 +4053,7 @@ impl<'a> AstBuilder<'a> {
40534053
type_parameters: T1,
40544054
super_class: Option<Expression<'a>>,
40554055
super_type_arguments: T2,
4056-
implements: Option<Vec<'a, TSClassImplements<'a>>>,
4056+
implements: Vec<'a, TSClassImplements<'a>>,
40574057
body: T3,
40584058
r#abstract: bool,
40594059
declare: bool,
@@ -6316,7 +6316,7 @@ impl<'a> AstBuilder<'a> {
63166316
type_parameters: T1,
63176317
super_class: Option<Expression<'a>>,
63186318
super_type_arguments: T2,
6319-
implements: Option<Vec<'a, TSClassImplements<'a>>>,
6319+
implements: Vec<'a, TSClassImplements<'a>>,
63206320
body: T3,
63216321
r#abstract: bool,
63226322
declare: bool,
@@ -6369,7 +6369,7 @@ impl<'a> AstBuilder<'a> {
63696369
type_parameters: T1,
63706370
super_class: Option<Expression<'a>>,
63716371
super_type_arguments: T2,
6372-
implements: Option<Vec<'a, TSClassImplements<'a>>>,
6372+
implements: Vec<'a, TSClassImplements<'a>>,
63736373
body: T3,
63746374
r#abstract: bool,
63756375
declare: bool,
@@ -6425,7 +6425,7 @@ impl<'a> AstBuilder<'a> {
64256425
type_parameters: T1,
64266426
super_class: Option<Expression<'a>>,
64276427
super_type_arguments: T2,
6428-
implements: Option<Vec<'a, TSClassImplements<'a>>>,
6428+
implements: Vec<'a, TSClassImplements<'a>>,
64296429
body: T3,
64306430
r#abstract: bool,
64316431
declare: bool,
@@ -6480,7 +6480,7 @@ impl<'a> AstBuilder<'a> {
64806480
type_parameters: T1,
64816481
super_class: Option<Expression<'a>>,
64826482
super_type_arguments: T2,
6483-
implements: Option<Vec<'a, TSClassImplements<'a>>>,
6483+
implements: Vec<'a, TSClassImplements<'a>>,
64846484
body: T3,
64856485
r#abstract: bool,
64866486
declare: bool,
@@ -8070,7 +8070,7 @@ impl<'a> AstBuilder<'a> {
80708070
type_parameters: T1,
80718071
super_class: Option<Expression<'a>>,
80728072
super_type_arguments: T2,
8073-
implements: Option<Vec<'a, TSClassImplements<'a>>>,
8073+
implements: Vec<'a, TSClassImplements<'a>>,
80748074
body: T3,
80758075
r#abstract: bool,
80768076
declare: bool,
@@ -8122,7 +8122,7 @@ impl<'a> AstBuilder<'a> {
81228122
type_parameters: T1,
81238123
super_class: Option<Expression<'a>>,
81248124
super_type_arguments: T2,
8125-
implements: Option<Vec<'a, TSClassImplements<'a>>>,
8125+
implements: Vec<'a, TSClassImplements<'a>>,
81268126
body: T3,
81278127
r#abstract: bool,
81288128
declare: bool,

crates/oxc_ast/src/generated/derive_estree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ impl ESTree for Class<'_> {
14631463
state.serialize_ts_field("decorators", &self.decorators);
14641464
state.serialize_ts_field("typeParameters", &self.type_parameters);
14651465
state.serialize_ts_field("superTypeArguments", &self.super_type_arguments);
1466-
state.serialize_ts_field("implements", &crate::serialize::ClassImplements(self));
1466+
state.serialize_ts_field("implements", &self.implements);
14671467
state.serialize_ts_field("abstract", &self.r#abstract);
14681468
state.serialize_ts_field("declare", &self.declare);
14691469
state.end();

crates/oxc_ast/src/serialize.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -987,30 +987,6 @@ impl ESTree for ExpressionStatementDirective<'_, '_> {
987987
}
988988
}
989989

990-
/// Serializer for `implements` field of `Class`.
991-
///
992-
/// This field is only used in TS AST.
993-
/// `None` is serialized as empty array (`[]`).
994-
#[ast_meta]
995-
#[estree(
996-
ts_type = "Array<TSClassImplements>",
997-
raw_deser = "
998-
const classImplements = DESER[Option<Vec<TSClassImplements>>](POS_OFFSET.implements);
999-
classImplements === null ? [] : classImplements
1000-
"
1001-
)]
1002-
pub struct ClassImplements<'a, 'b>(pub &'b Class<'a>);
1003-
1004-
impl ESTree for ClassImplements<'_, '_> {
1005-
fn serialize<S: Serializer>(&self, serializer: S) {
1006-
if let Some(implements) = &self.0.implements {
1007-
implements.serialize(serializer);
1008-
} else {
1009-
[(); 0].serialize(serializer);
1010-
}
1011-
}
1012-
}
1013-
1014990
/// Serializer for `global` field of `TSModuleDeclaration`.
1015991
#[ast_meta]
1016992
#[estree(ts_type = "boolean", raw_deser = "THIS.kind === 'global'")]

crates/oxc_ast_visit/src/generated/visit.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,9 +2551,7 @@ pub mod walk {
25512551
if let Some(super_type_arguments) = &it.super_type_arguments {
25522552
visitor.visit_ts_type_parameter_instantiation(super_type_arguments);
25532553
}
2554-
if let Some(implements) = &it.implements {
2555-
visitor.visit_ts_class_implementses(implements);
2556-
}
2554+
visitor.visit_ts_class_implementses(&it.implements);
25572555
visitor.visit_class_body(&it.body);
25582556
visitor.leave_scope();
25592557
visitor.leave_node(kind);

crates/oxc_ast_visit/src/generated/visit_mut.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,9 +2637,7 @@ pub mod walk_mut {
26372637
if let Some(super_type_arguments) = &mut it.super_type_arguments {
26382638
visitor.visit_ts_type_parameter_instantiation(super_type_arguments);
26392639
}
2640-
if let Some(implements) = &mut it.implements {
2641-
visitor.visit_ts_class_implementses(implements);
2642-
}
2640+
visitor.visit_ts_class_implementses(&mut it.implements);
26432641
visitor.visit_class_body(&mut it.body);
26442642
visitor.leave_scope();
26452643
visitor.leave_node(kind);

crates/oxc_codegen/src/gen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,9 +2341,9 @@ impl Gen for Class<'_> {
23412341
super_type_parameters.print(p, ctx);
23422342
}
23432343
}
2344-
if let Some(implements) = self.implements.as_ref() {
2344+
if !self.implements.is_empty() {
23452345
p.print_str(" implements ");
2346-
p.print_list(implements, ctx);
2346+
p.print_list(&self.implements, ctx);
23472347
}
23482348
p.print_soft_space();
23492349
self.body.print(p, ctx);

crates/oxc_parser/src/js/class.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use crate::{
1313
type Extends<'a> =
1414
Vec<'a, (Expression<'a>, Option<Box<'a, TSTypeParameterInstantiation<'a>>>, Span)>;
1515

16-
type Implements<'a> = Vec<'a, TSClassImplements<'a>>;
17-
1816
/// Section 15.7 Class Definitions
1917
impl<'a> ParserImpl<'a> {
2018
// `start_span` points at the start of all decoractors and `class` keyword.
@@ -110,9 +108,9 @@ impl<'a> ParserImpl<'a> {
110108

111109
pub(crate) fn parse_heritage_clause(
112110
&mut self,
113-
) -> Result<(Option<Extends<'a>>, Option<Implements<'a>>)> {
111+
) -> Result<(Option<Extends<'a>>, Vec<'a, TSClassImplements<'a>>)> {
114112
let mut extends = None;
115-
let mut implements = None;
113+
let mut implements = self.ast.vec();
116114

117115
loop {
118116
match self.cur_kind() {
@@ -121,20 +119,20 @@ impl<'a> ParserImpl<'a> {
121119
self.error(diagnostics::extends_clause_already_seen(
122120
self.cur_token().span(),
123121
));
124-
} else if implements.is_some() {
122+
} else if !implements.is_empty() {
125123
self.error(diagnostics::extends_clause_must_precede_implements(
126124
self.cur_token().span(),
127125
));
128126
}
129127
extends = Some(self.parse_extends_clause()?);
130128
}
131129
Kind::Implements => {
132-
if implements.is_some() {
130+
if !implements.is_empty() {
133131
self.error(diagnostics::implements_clause_already_seen(
134132
self.cur_token().span(),
135133
));
136134
}
137-
implements = Some(self.parse_ts_implements_clause()?);
135+
implements.extend(self.parse_ts_implements_clause()?);
138136
}
139137
_ => break,
140138
}

crates/oxc_parser/src/ts/types.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,10 @@ impl<'a> ParserImpl<'a> {
157157
pub(crate) fn parse_ts_implements_clause(&mut self) -> Result<Vec<'a, TSClassImplements<'a>>> {
158158
self.expect(Kind::Implements)?;
159159
let first = self.parse_ts_implement_name()?;
160-
let mut implements = self.ast.vec();
161-
implements.push(first);
162-
160+
let mut implements = self.ast.vec1(first);
163161
while self.eat(Kind::Comma) {
164162
implements.push(self.parse_ts_implement_name()?);
165163
}
166-
167164
Ok(implements)
168165
}
169166

crates/oxc_semantic/src/builder.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
707707
if let Some(super_type_parameters) = &class.super_type_arguments {
708708
self.visit_ts_type_parameter_instantiation(super_type_parameters);
709709
}
710-
if let Some(implements) = &class.implements {
711-
self.visit_ts_class_implementses(implements);
712-
}
710+
self.visit_ts_class_implementses(&class.implements);
713711
self.visit_class_body(&class.body);
714712

715713
self.leave_scope();

0 commit comments

Comments
 (0)