Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ast)!: add missing AssignmentTargetProperty::computed #8097

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
2 changes: 2 additions & 0 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,8 @@ pub struct AssignmentTargetPropertyProperty<'a> {
pub span: Span,
pub name: PropertyKey<'a>,
pub binding: AssignmentTargetMaybeDefault<'a>,
/// Property was declared with a computed key
pub computed: bool,
}

/// `a++, b++` in `let a = 1, b = 2; let result = (a++, b++);`
Expand Down
6 changes: 4 additions & 2 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,12 @@ const _: () = {
assert!(offset_of!(AssignmentTargetPropertyIdentifier, binding) == 8usize);
assert!(offset_of!(AssignmentTargetPropertyIdentifier, init) == 40usize);

assert!(size_of::<AssignmentTargetPropertyProperty>() == 40usize);
assert!(size_of::<AssignmentTargetPropertyProperty>() == 48usize);
assert!(align_of::<AssignmentTargetPropertyProperty>() == 8usize);
assert!(offset_of!(AssignmentTargetPropertyProperty, span) == 0usize);
assert!(offset_of!(AssignmentTargetPropertyProperty, name) == 8usize);
assert!(offset_of!(AssignmentTargetPropertyProperty, binding) == 24usize);
assert!(offset_of!(AssignmentTargetPropertyProperty, computed) == 40usize);

assert!(size_of::<SequenceExpression>() == 40usize);
assert!(align_of::<SequenceExpression>() == 8usize);
Expand Down Expand Up @@ -1861,11 +1862,12 @@ const _: () = {
assert!(offset_of!(AssignmentTargetPropertyIdentifier, binding) == 8usize);
assert!(offset_of!(AssignmentTargetPropertyIdentifier, init) == 28usize);

assert!(size_of::<AssignmentTargetPropertyProperty>() == 24usize);
assert!(size_of::<AssignmentTargetPropertyProperty>() == 28usize);
assert!(align_of::<AssignmentTargetPropertyProperty>() == 4usize);
assert!(offset_of!(AssignmentTargetPropertyProperty, span) == 0usize);
assert!(offset_of!(AssignmentTargetPropertyProperty, name) == 8usize);
assert!(offset_of!(AssignmentTargetPropertyProperty, binding) == 16usize);
assert!(offset_of!(AssignmentTargetPropertyProperty, computed) == 24usize);

assert!(size_of::<SequenceExpression>() == 24usize);
assert!(align_of::<SequenceExpression>() == 4usize);
Expand Down
15 changes: 12 additions & 3 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2871,15 +2871,17 @@ impl<'a> AstBuilder<'a> {
/// - span: The [`Span`] covering this node
/// - name
/// - binding
/// - computed: Property was declared with a computed key
#[inline]
pub fn assignment_target_property_assignment_target_property_property(
self,
span: Span,
name: PropertyKey<'a>,
binding: AssignmentTargetMaybeDefault<'a>,
computed: bool,
) -> AssignmentTargetProperty<'a> {
AssignmentTargetProperty::AssignmentTargetPropertyProperty(
self.alloc(self.assignment_target_property_property(span, name, binding)),
self.alloc(self.assignment_target_property_property(span, name, binding, computed)),
)
}

Expand Down Expand Up @@ -2927,14 +2929,16 @@ impl<'a> AstBuilder<'a> {
/// - span: The [`Span`] covering this node
/// - name
/// - binding
/// - computed: Property was declared with a computed key
#[inline]
pub fn assignment_target_property_property(
self,
span: Span,
name: PropertyKey<'a>,
binding: AssignmentTargetMaybeDefault<'a>,
computed: bool,
) -> AssignmentTargetPropertyProperty<'a> {
AssignmentTargetPropertyProperty { span, name, binding }
AssignmentTargetPropertyProperty { span, name, binding, computed }
}

/// Build an [`AssignmentTargetPropertyProperty`], and store it in the memory arena.
Expand All @@ -2945,14 +2949,19 @@ impl<'a> AstBuilder<'a> {
/// - span: The [`Span`] covering this node
/// - name
/// - binding
/// - computed: Property was declared with a computed key
#[inline]
pub fn alloc_assignment_target_property_property(
self,
span: Span,
name: PropertyKey<'a>,
binding: AssignmentTargetMaybeDefault<'a>,
computed: bool,
) -> Box<'a, AssignmentTargetPropertyProperty<'a>> {
Box::new_in(self.assignment_target_property_property(span, name, binding), self.allocator)
Box::new_in(
self.assignment_target_property_property(span, name, binding, computed),
self.allocator,
)
}

/// Build a [`SequenceExpression`].
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@ impl<'new_alloc> CloneIn<'new_alloc> for AssignmentTargetPropertyProperty<'_> {
span: CloneIn::clone_in(&self.span, allocator),
name: CloneIn::clone_in(&self.name, allocator),
binding: CloneIn::clone_in(&self.binding, allocator),
computed: CloneIn::clone_in(&self.computed, allocator),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast/src/generated/derive_content_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,7 @@ impl ContentEq for AssignmentTargetPropertyProperty<'_> {
fn content_eq(&self, other: &Self) -> bool {
ContentEq::content_eq(&self.name, &other.name)
&& ContentEq::content_eq(&self.binding, &other.binding)
&& ContentEq::content_eq(&self.computed, &other.computed)
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast/src/generated/derive_content_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ impl ContentHash for AssignmentTargetPropertyProperty<'_> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
ContentHash::content_hash(&self.name, state);
ContentHash::content_hash(&self.binding, state);
ContentHash::content_hash(&self.computed, state);
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ impl Serialize for AssignmentTargetPropertyProperty<'_> {
self.span.serialize(serde::__private::ser::FlatMapSerializer(&mut map))?;
map.serialize_entry("name", &self.name)?;
map.serialize_entry("binding", &self.binding)?;
map.serialize_entry("computed", &self.computed)?;
map.end()
}
}
Expand Down
8 changes: 6 additions & 2 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2112,9 +2112,13 @@ impl Gen for AssignmentTargetPropertyProperty<'_> {
ident.print(p, ctx);
}
key @ match_expression!(PropertyKey) => {
p.print_ascii_byte(b'[');
if self.computed {
p.print_ascii_byte(b'[');
}
key.to_expression().print_expr(p, Precedence::Comma, Context::empty());
p.print_ascii_byte(b']');
if self.computed {
p.print_ascii_byte(b']');
}
}
}
p.print_colon();
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ fn assignment() {
test_minify("a %= async () => {}", "a%=async()=>{};");
test_minify("a -= (1, 2)", "a-=(1,2);");
test_minify("({ x: x = flag1 = true } = {})", "({x=flag1=true}={});");

test_minify("({ 0: x } = foo);", "({0:x}=foo);");
test_minify("({ [0]: x } = foo);", "({[0]:x}=foo);");
test_minify("({ a: x } = foo);", "({a:x}=foo);");
test_minify("({ [a.b]: x } = foo);", "({[a.b]:x}=foo);");
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_parser/src/js/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ impl<'a> CoverGrammar<'a, ObjectProperty<'a>> for AssignmentTargetProperty<'a> {
property.span,
property.key,
binding,
property.computed,
))
}
}
Expand Down
18 changes: 18 additions & 0 deletions crates/oxc_traverse/src/generated/ancestor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4455,6 +4455,8 @@ pub(crate) const OFFSET_ASSIGNMENT_TARGET_PROPERTY_PROPERTY_NAME: usize =
offset_of!(AssignmentTargetPropertyProperty, name);
pub(crate) const OFFSET_ASSIGNMENT_TARGET_PROPERTY_PROPERTY_BINDING: usize =
offset_of!(AssignmentTargetPropertyProperty, binding);
pub(crate) const OFFSET_ASSIGNMENT_TARGET_PROPERTY_PROPERTY_COMPUTED: usize =
offset_of!(AssignmentTargetPropertyProperty, computed);

#[repr(transparent)]
#[derive(Clone, Copy, Debug)]
Expand All @@ -4479,6 +4481,14 @@ impl<'a, 't> AssignmentTargetPropertyPropertyWithoutName<'a, 't> {
as *const AssignmentTargetMaybeDefault<'a>)
}
}

#[inline]
pub fn computed(self) -> &'t bool {
unsafe {
&*((self.0 as *const u8).add(OFFSET_ASSIGNMENT_TARGET_PROPERTY_PROPERTY_COMPUTED)
as *const bool)
}
}
}

impl<'a, 't> GetAddress for AssignmentTargetPropertyPropertyWithoutName<'a, 't> {
Expand Down Expand Up @@ -4511,6 +4521,14 @@ impl<'a, 't> AssignmentTargetPropertyPropertyWithoutBinding<'a, 't> {
as *const PropertyKey<'a>)
}
}

#[inline]
pub fn computed(self) -> &'t bool {
unsafe {
&*((self.0 as *const u8).add(OFFSET_ASSIGNMENT_TARGET_PROPERTY_PROPERTY_COMPUTED)
as *const bool)
}
}
}

impl<'a, 't> GetAddress for AssignmentTargetPropertyPropertyWithoutBinding<'a, 't> {
Expand Down
1 change: 1 addition & 0 deletions npm/oxc-types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ export interface AssignmentTargetPropertyProperty extends Span {
type: 'AssignmentTargetPropertyProperty';
name: PropertyKey;
binding: AssignmentTargetMaybeDefault;
computed: boolean;
}

export interface SequenceExpression extends Span {
Expand Down
Loading