Skip to content

Commit

Permalink
fix(ast): serialize JSXMemberExpressionObject to estree (#5883)
Browse files Browse the repository at this point in the history
Follow-on after #5882, part of #5354.

Make JSON AST ESTree-compatible for:

* `<Foo.bar />`
* `<this.foo />`
  • Loading branch information
overlookmotel committed Sep 19, 2024
1 parent a822c9d commit 0d10521
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub struct JSXMemberExpression<'a> {
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", derive(Tsify))]
#[serde(untagged)]
pub enum JSXMemberExpressionObject<'a> {
IdentifierReference(Box<'a, IdentifierReference<'a>>) = 0,
Expand Down
18 changes: 16 additions & 2 deletions crates/oxc_ast/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::ast::{
ArrayAssignmentTarget, ArrayPattern, AssignmentTargetMaybeDefault, AssignmentTargetProperty,
AssignmentTargetRest, BindingPattern, BindingPatternKind, BindingProperty, BindingRestElement,
Directive, Elision, FormalParameter, FormalParameterKind, FormalParameters, JSXElementName,
JSXIdentifier, ObjectAssignmentTarget, ObjectPattern, Program, RegExpFlags, Statement,
StringLiteral, TSModuleBlock, TSTypeAnnotation,
JSXIdentifier, JSXMemberExpressionObject, ObjectAssignmentTarget, ObjectPattern, Program,
RegExpFlags, Statement, StringLiteral, TSModuleBlock, TSTypeAnnotation,
};

pub struct EcmaFormatter;
Expand Down Expand Up @@ -265,3 +265,17 @@ impl<'a> Serialize for JSXElementName<'a> {
}
}
}

impl<'a> Serialize for JSXMemberExpressionObject<'a> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
match self {
Self::IdentifierReference(ident) => {
JSXIdentifier { span: ident.span, name: ident.name.clone() }.serialize(serializer)
}
Self::MemberExpression(expr) => expr.serialize(serializer),
Self::ThisExpression(expr) => {
JSXIdentifier { span: expr.span, name: "this".into() }.serialize(serializer)
}
}
}
}

0 comments on commit 0d10521

Please sign in to comment.