Skip to content

Commit

Permalink
chore: revert AssignmentTargetPropertyIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Feb 10, 2025
1 parent 1251d7c commit a65ad49
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 61 deletions.
9 changes: 1 addition & 8 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,16 +882,9 @@ pub enum AssignmentTargetProperty<'a> {
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
#[estree(
rename = "Property",
add_fields(kind = "\"init\"", method = false, shorthand = true, computed = false),
add_ts = "kind: \"init\"; method: false; shorthand: false; computed: false"
)]
pub struct AssignmentTargetPropertyIdentifier<'a> {
pub span: Span,
#[estree(rename = "key")]
pub binding: IdentifierReference<'a>,
#[estree(rename = "value", via = crate::serialize::AssignmentTargetPropertyIdentifierValue(self), ts_type = "IdentifierReference | AssignmentTargetWithDefault")]
pub init: Option<Expression<'a>>,
}

Expand Down Expand Up @@ -2229,7 +2222,7 @@ pub struct ImportExpression<'a> {
pub struct ImportDeclaration<'a> {
pub span: Span,
/// `None` for `import 'foo'`, `Some([])` for `import {} from 'foo'`
#[estree(via = crate::serialize::OptionVecDefault(&self.specifiers), ts_type = "Array<ImportDeclarationSpecifier>")]
#[estree(via = crate::serialize::OptionVecDefault, ts_type = "Array<ImportDeclarationSpecifier>")]
pub specifiers: Option<Vec<'a, ImportDeclarationSpecifier<'a>>>,
pub source: StringLiteral<'a>,
pub phase: Option<ImportPhase>,
Expand Down
18 changes: 7 additions & 11 deletions crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,18 +707,11 @@ impl Serialize for AssignmentTargetProperty<'_> {
impl Serialize for AssignmentTargetPropertyIdentifier<'_> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "Property")?;
map.serialize_entry("type", "AssignmentTargetPropertyIdentifier")?;
map.serialize_entry("start", &self.span.start)?;
map.serialize_entry("end", &self.span.end)?;
map.serialize_entry("key", &self.binding)?;
map.serialize_entry(
"value",
&crate::serialize::AssignmentTargetPropertyIdentifierValue(self),
)?;
map.serialize_entry("kind", &"init")?;
map.serialize_entry("method", &false)?;
map.serialize_entry("shorthand", &true)?;
map.serialize_entry("computed", &false)?;
map.serialize_entry("binding", &self.binding)?;
map.serialize_entry("init", &self.init)?;
map.end()
}
}
Expand Down Expand Up @@ -1685,7 +1678,10 @@ impl Serialize for ImportDeclaration<'_> {
map.serialize_entry("type", "ImportDeclaration")?;
map.serialize_entry("start", &self.span.start)?;
map.serialize_entry("end", &self.span.end)?;
map.serialize_entry("specifiers", &crate::serialize::OptionVecDefault(&self.specifiers))?;
map.serialize_entry(
"specifiers",
&crate::serialize::OptionVecDefault::from(&self.specifiers),
)?;
map.serialize_entry("source", &self.source)?;
map.serialize_entry("phase", &self.phase)?;
map.serialize_entry("withClause", &self.with_clause)?;
Expand Down
30 changes: 0 additions & 30 deletions crates/oxc_ast/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,33 +298,3 @@ impl Serialize for JSXMemberExpressionObject<'_> {
}
}
}

pub struct AssignmentTargetPropertyIdentifierValue<'a>(
pub &'a AssignmentTargetPropertyIdentifier<'a>,
);

impl Serialize for AssignmentTargetPropertyIdentifierValue<'_> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
if let Some(init) = &self.0.init {
AssignmentTargetPropertyIdentifierValueAssignmentPattern {
span: self.0.span,
left: &self.0.binding,
right: init,
}
.serialize(serializer)
} else {
self.0.binding.serialize(serializer)
}
}
}

/// wrapper to serialize same as `AssignmentTargetWithDefault`
/// but without extra enum/Box for `AssignmentTargetWithDefault.binding`
#[derive(Serialize)]
#[serde(tag = "type", rename = "AssignmentPattern")]
pub struct AssignmentTargetPropertyIdentifierValueAssignmentPattern<'a> {
#[serde(flatten)]
pub span: Span,
pub left: &'a IdentifierReference<'a>,
pub right: &'a Expression<'a>,
}
10 changes: 3 additions & 7 deletions npm/oxc-types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,9 @@ export interface AssignmentTargetWithDefault extends Span {
export type AssignmentTargetProperty = AssignmentTargetPropertyIdentifier | AssignmentTargetPropertyProperty;

export interface AssignmentTargetPropertyIdentifier extends Span {
type: 'Property';
key: IdentifierReference;
value: IdentifierReference | AssignmentTargetWithDefault;
kind: 'init';
method: false;
shorthand: false;
computed: false;
type: 'AssignmentTargetPropertyIdentifier';
binding: IdentifierReference;
init: Expression | null;
}

export interface AssignmentTargetPropertyProperty extends Span {
Expand Down
10 changes: 5 additions & 5 deletions tasks/ast_tools/src/derives/estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::borrow::Cow;

use proc_macro2::TokenStream;
use quote::quote;
use syn::{parse_str, Expr};
use syn::{parse_str, Type};

use crate::{
schema::{Def, EnumDef, FieldDef, Schema, StructDef, TypeDef, VariantDef, Visibility},
Expand Down Expand Up @@ -186,9 +186,9 @@ fn parse_estree_attr(location: AttrLocation, part: AttrPart) -> Result<()> {
/// Generate body of `serialize` method for a struct.
fn generate_body_for_struct(struct_def: &StructDef, schema: &Schema) -> TokenStream {
if let Some(via_str) = struct_def.estree.via.as_deref() {
let via_expr = parse_str::<Expr>(via_str).unwrap();
let via_ty = parse_str::<Type>(via_str).unwrap();
return quote! {
#via_expr.serialize(serializer)
#via_ty::from(self).serialize(serializer)
};
}

Expand Down Expand Up @@ -297,8 +297,8 @@ impl<'s> StructSerializerGenerator<'s> {

let mut value = quote!( #self_path.#field_name_ident );
if let Some(via_str) = field.estree.via.as_deref() {
let via_expr = parse_str::<Expr>(via_str).unwrap();
value = quote!( #via_expr );
let via_ty = parse_str::<Type>(via_str).unwrap();
value = quote!( #via_ty::from(&#value) );
} else if let Some(append_field_index) = field.estree.append_field_index {
let append_from_ident = struct_def.fields[append_field_index].ident();
value = quote! {
Expand Down

0 comments on commit a65ad49

Please sign in to comment.