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
3 changes: 1 addition & 2 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,8 +1941,7 @@ pub struct Class<'a> {
/// // ^^^
/// ```
#[ts]
#[estree(via = ClassImplements)]
pub implements: Option<Vec<'a, TSClassImplements<'a>>>,
pub implements: Vec<'a, TSClassImplements<'a>>,
pub body: Box<'a, ClassBody<'a>>,
/// Whether the class is abstract
///
Expand Down
20 changes: 10 additions & 10 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ impl<'a> AstBuilder<'a> {
type_parameters: T1,
super_class: Option<Expression<'a>>,
super_type_arguments: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
implements: Vec<'a, TSClassImplements<'a>>,
body: T3,
r#abstract: bool,
declare: bool,
Expand Down Expand Up @@ -627,7 +627,7 @@ impl<'a> AstBuilder<'a> {
type_parameters: T1,
super_class: Option<Expression<'a>>,
super_type_arguments: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
implements: Vec<'a, TSClassImplements<'a>>,
body: T3,
r#abstract: bool,
declare: bool,
Expand Down Expand Up @@ -4001,7 +4001,7 @@ impl<'a> AstBuilder<'a> {
type_parameters: T1,
super_class: Option<Expression<'a>>,
super_type_arguments: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
implements: Vec<'a, TSClassImplements<'a>>,
body: T3,
r#abstract: bool,
declare: bool,
Expand Down Expand Up @@ -4053,7 +4053,7 @@ impl<'a> AstBuilder<'a> {
type_parameters: T1,
super_class: Option<Expression<'a>>,
super_type_arguments: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
implements: Vec<'a, TSClassImplements<'a>>,
body: T3,
r#abstract: bool,
declare: bool,
Expand Down Expand Up @@ -6316,7 +6316,7 @@ impl<'a> AstBuilder<'a> {
type_parameters: T1,
super_class: Option<Expression<'a>>,
super_type_arguments: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
implements: Vec<'a, TSClassImplements<'a>>,
body: T3,
r#abstract: bool,
declare: bool,
Expand Down Expand Up @@ -6369,7 +6369,7 @@ impl<'a> AstBuilder<'a> {
type_parameters: T1,
super_class: Option<Expression<'a>>,
super_type_arguments: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
implements: Vec<'a, TSClassImplements<'a>>,
body: T3,
r#abstract: bool,
declare: bool,
Expand Down Expand Up @@ -6425,7 +6425,7 @@ impl<'a> AstBuilder<'a> {
type_parameters: T1,
super_class: Option<Expression<'a>>,
super_type_arguments: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
implements: Vec<'a, TSClassImplements<'a>>,
body: T3,
r#abstract: bool,
declare: bool,
Expand Down Expand Up @@ -6480,7 +6480,7 @@ impl<'a> AstBuilder<'a> {
type_parameters: T1,
super_class: Option<Expression<'a>>,
super_type_arguments: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
implements: Vec<'a, TSClassImplements<'a>>,
body: T3,
r#abstract: bool,
declare: bool,
Expand Down Expand Up @@ -8070,7 +8070,7 @@ impl<'a> AstBuilder<'a> {
type_parameters: T1,
super_class: Option<Expression<'a>>,
super_type_arguments: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
implements: Vec<'a, TSClassImplements<'a>>,
body: T3,
r#abstract: bool,
declare: bool,
Expand Down Expand Up @@ -8122,7 +8122,7 @@ impl<'a> AstBuilder<'a> {
type_parameters: T1,
super_class: Option<Expression<'a>>,
super_type_arguments: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
implements: Vec<'a, TSClassImplements<'a>>,
body: T3,
r#abstract: bool,
declare: bool,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ impl ESTree for Class<'_> {
state.serialize_ts_field("decorators", &self.decorators);
state.serialize_ts_field("typeParameters", &self.type_parameters);
state.serialize_ts_field("superTypeArguments", &self.super_type_arguments);
state.serialize_ts_field("implements", &crate::serialize::ClassImplements(self));
state.serialize_ts_field("implements", &self.implements);
state.serialize_ts_field("abstract", &self.r#abstract);
state.serialize_ts_field("declare", &self.declare);
state.end();
Expand Down
24 changes: 0 additions & 24 deletions crates/oxc_ast/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,30 +987,6 @@ impl ESTree for ExpressionStatementDirective<'_, '_> {
}
}

/// Serializer for `implements` field of `Class`.
///
/// This field is only used in TS AST.
/// `None` is serialized as empty array (`[]`).
#[ast_meta]
#[estree(
ts_type = "Array<TSClassImplements>",
raw_deser = "
const classImplements = DESER[Option<Vec<TSClassImplements>>](POS_OFFSET.implements);
classImplements === null ? [] : classImplements
"
)]
pub struct ClassImplements<'a, 'b>(pub &'b Class<'a>);

impl ESTree for ClassImplements<'_, '_> {
fn serialize<S: Serializer>(&self, serializer: S) {
if let Some(implements) = &self.0.implements {
implements.serialize(serializer);
} else {
[(); 0].serialize(serializer);
}
}
}

/// Serializer for `global` field of `TSModuleDeclaration`.
#[ast_meta]
#[estree(ts_type = "boolean", raw_deser = "THIS.kind === 'global'")]
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_ast_visit/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2551,9 +2551,7 @@ pub mod walk {
if let Some(super_type_arguments) = &it.super_type_arguments {
visitor.visit_ts_type_parameter_instantiation(super_type_arguments);
}
if let Some(implements) = &it.implements {
visitor.visit_ts_class_implementses(implements);
}
visitor.visit_ts_class_implementses(&it.implements);
visitor.visit_class_body(&it.body);
visitor.leave_scope();
visitor.leave_node(kind);
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_ast_visit/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2637,9 +2637,7 @@ pub mod walk_mut {
if let Some(super_type_arguments) = &mut it.super_type_arguments {
visitor.visit_ts_type_parameter_instantiation(super_type_arguments);
}
if let Some(implements) = &mut it.implements {
visitor.visit_ts_class_implementses(implements);
}
visitor.visit_ts_class_implementses(&mut it.implements);
visitor.visit_class_body(&mut it.body);
visitor.leave_scope();
visitor.leave_node(kind);
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2341,9 +2341,9 @@ impl Gen for Class<'_> {
super_type_parameters.print(p, ctx);
}
}
if let Some(implements) = self.implements.as_ref() {
if !self.implements.is_empty() {
p.print_str(" implements ");
p.print_list(implements, ctx);
p.print_list(&self.implements, ctx);
}
p.print_soft_space();
self.body.print(p, ctx);
Expand Down
12 changes: 5 additions & 7 deletions crates/oxc_parser/src/js/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use crate::{
type Extends<'a> =
Vec<'a, (Expression<'a>, Option<Box<'a, TSTypeParameterInstantiation<'a>>>, Span)>;

type Implements<'a> = Vec<'a, TSClassImplements<'a>>;

/// Section 15.7 Class Definitions
impl<'a> ParserImpl<'a> {
// `start_span` points at the start of all decoractors and `class` keyword.
Expand Down Expand Up @@ -110,9 +108,9 @@ impl<'a> ParserImpl<'a> {

pub(crate) fn parse_heritage_clause(
&mut self,
) -> Result<(Option<Extends<'a>>, Option<Implements<'a>>)> {
) -> Result<(Option<Extends<'a>>, Vec<'a, TSClassImplements<'a>>)> {
let mut extends = None;
let mut implements = None;
let mut implements = self.ast.vec();

loop {
match self.cur_kind() {
Expand All @@ -121,20 +119,20 @@ impl<'a> ParserImpl<'a> {
self.error(diagnostics::extends_clause_already_seen(
self.cur_token().span(),
));
} else if implements.is_some() {
} else if !implements.is_empty() {
self.error(diagnostics::extends_clause_must_precede_implements(
self.cur_token().span(),
));
}
extends = Some(self.parse_extends_clause()?);
}
Kind::Implements => {
if implements.is_some() {
if !implements.is_empty() {
self.error(diagnostics::implements_clause_already_seen(
self.cur_token().span(),
));
}
implements = Some(self.parse_ts_implements_clause()?);
implements.extend(self.parse_ts_implements_clause()?);
}
_ => break,
}
Expand Down
5 changes: 1 addition & 4 deletions crates/oxc_parser/src/ts/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,10 @@ impl<'a> ParserImpl<'a> {
pub(crate) fn parse_ts_implements_clause(&mut self) -> Result<Vec<'a, TSClassImplements<'a>>> {
self.expect(Kind::Implements)?;
let first = self.parse_ts_implement_name()?;
let mut implements = self.ast.vec();
implements.push(first);

let mut implements = self.ast.vec1(first);
while self.eat(Kind::Comma) {
implements.push(self.parse_ts_implement_name()?);
}

Ok(implements)
}

Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
if let Some(super_type_parameters) = &class.super_type_arguments {
self.visit_ts_type_parameter_instantiation(super_type_parameters);
}
if let Some(implements) = &class.implements {
self.visit_ts_class_implementses(implements);
}
self.visit_ts_class_implementses(&class.implements);
self.visit_class_body(&class.body);

self.leave_scope();
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/typescript/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl<'a> Traverse<'a> for TypeScriptAnnotations<'a, '_> {
fn enter_class(&mut self, class: &mut Class<'a>, _ctx: &mut TraverseCtx<'a>) {
class.type_parameters = None;
class.super_type_arguments = None;
class.implements = None;
class.implements.clear();
class.r#abstract = false;
}

Expand Down
24 changes: 12 additions & 12 deletions crates/oxc_traverse/src/generated/ancestor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7769,10 +7769,10 @@ impl<'a, 't> ClassWithoutDecorators<'a, 't> {
}

#[inline]
pub fn implements(self) -> &'t Option<Vec<'a, TSClassImplements<'a>>> {
pub fn implements(self) -> &'t Vec<'a, TSClassImplements<'a>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CLASS_IMPLEMENTS)
as *const Option<Vec<'a, TSClassImplements<'a>>>)
as *const Vec<'a, TSClassImplements<'a>>)
}
}

Expand Down Expand Up @@ -7852,10 +7852,10 @@ impl<'a, 't> ClassWithoutId<'a, 't> {
}

#[inline]
pub fn implements(self) -> &'t Option<Vec<'a, TSClassImplements<'a>>> {
pub fn implements(self) -> &'t Vec<'a, TSClassImplements<'a>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CLASS_IMPLEMENTS)
as *const Option<Vec<'a, TSClassImplements<'a>>>)
as *const Vec<'a, TSClassImplements<'a>>)
}
}

Expand Down Expand Up @@ -7937,10 +7937,10 @@ impl<'a, 't> ClassWithoutTypeParameters<'a, 't> {
}

#[inline]
pub fn implements(self) -> &'t Option<Vec<'a, TSClassImplements<'a>>> {
pub fn implements(self) -> &'t Vec<'a, TSClassImplements<'a>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CLASS_IMPLEMENTS)
as *const Option<Vec<'a, TSClassImplements<'a>>>)
as *const Vec<'a, TSClassImplements<'a>>)
}
}

Expand Down Expand Up @@ -8023,10 +8023,10 @@ impl<'a, 't> ClassWithoutSuperClass<'a, 't> {
}

#[inline]
pub fn implements(self) -> &'t Option<Vec<'a, TSClassImplements<'a>>> {
pub fn implements(self) -> &'t Vec<'a, TSClassImplements<'a>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CLASS_IMPLEMENTS)
as *const Option<Vec<'a, TSClassImplements<'a>>>)
as *const Vec<'a, TSClassImplements<'a>>)
}
}

Expand Down Expand Up @@ -8108,10 +8108,10 @@ impl<'a, 't> ClassWithoutSuperTypeArguments<'a, 't> {
}

#[inline]
pub fn implements(self) -> &'t Option<Vec<'a, TSClassImplements<'a>>> {
pub fn implements(self) -> &'t Vec<'a, TSClassImplements<'a>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CLASS_IMPLEMENTS)
as *const Option<Vec<'a, TSClassImplements<'a>>>)
as *const Vec<'a, TSClassImplements<'a>>)
}
}

Expand Down Expand Up @@ -8283,10 +8283,10 @@ impl<'a, 't> ClassWithoutBody<'a, 't> {
}

#[inline]
pub fn implements(self) -> &'t Option<Vec<'a, TSClassImplements<'a>>> {
pub fn implements(self) -> &'t Vec<'a, TSClassImplements<'a>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_CLASS_IMPLEMENTS)
as *const Option<Vec<'a, TSClassImplements<'a>>>)
as *const Vec<'a, TSClassImplements<'a>>)
}
}

Expand Down
10 changes: 4 additions & 6 deletions crates/oxc_traverse/src/generated/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2509,13 +2509,11 @@ unsafe fn walk_class<'a, Tr: Traverse<'a>>(
ctx.retag_stack(AncestorType::ClassSuperTypeArguments);
walk_ts_type_parameter_instantiation(traverser, (&mut **field) as *mut _, ctx);
}
if let Some(field) = &mut *((node as *mut u8).add(ancestor::OFFSET_CLASS_IMPLEMENTS)
as *mut Option<Vec<TSClassImplements>>)
ctx.retag_stack(AncestorType::ClassImplements);
for item in &mut *((node as *mut u8).add(ancestor::OFFSET_CLASS_IMPLEMENTS)
as *mut Vec<TSClassImplements>)
{
ctx.retag_stack(AncestorType::ClassImplements);
for item in field.iter_mut() {
walk_ts_class_implements(traverser, item as *mut _, ctx);
}
walk_ts_class_implements(traverser, item as *mut _, ctx);
}
ctx.retag_stack(AncestorType::ClassBody);
walk_class_body(
Expand Down
5 changes: 0 additions & 5 deletions napi/parser/deserialize-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -4991,11 +4991,6 @@ function deserializeVecTSClassImplements(pos) {
return arr;
}

function deserializeOptionVecTSClassImplements(pos) {
if (uint32[pos >> 2] === 0 && uint32[(pos + 4) >> 2] === 0) return null;
return deserializeVecTSClassImplements(pos);
}

function deserializeBoxClassBody(pos) {
return deserializeClassBody(uint32[pos >> 2]);
}
Expand Down
8 changes: 1 addition & 7 deletions napi/parser/deserialize-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,6 @@ function deserializeYieldExpression(pos) {
}

function deserializeClass(pos) {
const classImplements = deserializeOptionVecTSClassImplements(pos + 112);
return {
type: deserializeClassType(pos + 8),
start: deserializeU32(pos),
Expand All @@ -895,7 +894,7 @@ function deserializeClass(pos) {
decorators: deserializeVecDecorator(pos + 16),
typeParameters: deserializeOptionBoxTSTypeParameterDeclaration(pos + 80),
superTypeArguments: deserializeOptionBoxTSTypeParameterInstantiation(pos + 104),
implements: classImplements === null ? [] : classImplements,
implements: deserializeVecTSClassImplements(pos + 112),
abstract: deserializeBool(pos + 152),
declare: deserializeBool(pos + 153),
};
Expand Down Expand Up @@ -5079,11 +5078,6 @@ function deserializeVecTSClassImplements(pos) {
return arr;
}

function deserializeOptionVecTSClassImplements(pos) {
if (uint32[pos >> 2] === 0 && uint32[(pos + 4) >> 2] === 0) return null;
return deserializeVecTSClassImplements(pos);
}

function deserializeBoxClassBody(pos) {
return deserializeClassBody(uint32[pos >> 2]);
}
Expand Down
Loading