Skip to content

Commit

Permalink
fix(ast): estree compat AssignmentTargetPropertyProperty (#9005)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Feb 10, 2025
1 parent e0646d7 commit 1daa8fe
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 278 deletions.
8 changes: 8 additions & 0 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ pub struct ArrayAssignmentTarget<'a> {
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
#[estree(rename = "ObjectPattern")]
pub struct ObjectAssignmentTarget<'a> {
pub span: Span,
pub properties: Vec<'a, AssignmentTargetProperty<'a>>,
Expand Down Expand Up @@ -895,9 +896,16 @@ pub struct AssignmentTargetPropertyIdentifier<'a> {
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
#[estree(
rename = "Property",
add_fields(kind = "\"init\"", method = false, shorthand = false),
add_ts = "kind: \"init\"; method: false; shorthand: false"
)]
pub struct AssignmentTargetPropertyProperty<'a> {
pub span: Span,
#[estree(rename = "key")]
pub name: PropertyKey<'a>,
#[estree(rename = "value")]
pub binding: AssignmentTargetMaybeDefault<'a>,
/// Property was declared with a computed key
pub computed: bool,
Expand Down
11 changes: 7 additions & 4 deletions crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ impl Serialize for ArrayAssignmentTarget<'_> {
impl Serialize for ObjectAssignmentTarget<'_> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "ObjectAssignmentTarget")?;
map.serialize_entry("type", "ObjectPattern")?;
map.serialize_entry("start", &self.span.start)?;
map.serialize_entry("end", &self.span.end)?;
map.serialize_entry(
Expand Down Expand Up @@ -721,12 +721,15 @@ impl Serialize for AssignmentTargetPropertyIdentifier<'_> {
impl Serialize for AssignmentTargetPropertyProperty<'_> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "AssignmentTargetPropertyProperty")?;
map.serialize_entry("type", "Property")?;
map.serialize_entry("start", &self.span.start)?;
map.serialize_entry("end", &self.span.end)?;
map.serialize_entry("name", &self.name)?;
map.serialize_entry("binding", &self.binding)?;
map.serialize_entry("key", &self.name)?;
map.serialize_entry("value", &self.binding)?;
map.serialize_entry("computed", &self.computed)?;
map.serialize_entry("kind", &"init")?;
map.serialize_entry("method", &false)?;
map.serialize_entry("shorthand", &false)?;
map.end()
}
}
Expand Down
11 changes: 7 additions & 4 deletions npm/oxc-types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export interface ArrayAssignmentTarget extends Span {
}

export interface ObjectAssignmentTarget extends Span {
type: 'ObjectAssignmentTarget';
type: 'ObjectPattern';
properties: Array<AssignmentTargetProperty | AssignmentTargetRest>;
}

Expand All @@ -274,10 +274,13 @@ export interface AssignmentTargetPropertyIdentifier extends Span {
}

export interface AssignmentTargetPropertyProperty extends Span {
type: 'AssignmentTargetPropertyProperty';
name: PropertyKey;
binding: AssignmentTargetMaybeDefault;
type: 'Property';
key: PropertyKey;
value: AssignmentTargetMaybeDefault;
computed: boolean;
kind: 'init';
method: false;
shorthand: false;
}

export interface SequenceExpression extends Span {
Expand Down
Loading

0 comments on commit 1daa8fe

Please sign in to comment.