Skip to content

Commit

Permalink
fix(codegen,mangler): do not print shorthand for ObjectProperty (#4350
Browse files Browse the repository at this point in the history
)

I'll fix the TODO's later.
  • Loading branch information
Boshen committed Jul 18, 2024
1 parent 21d0eee commit e624dff
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for ObjectPropertyKind<'a> {
}
}

// TODO: only print shorthand if key value are the same.
impl<'a, const MINIFY: bool> Gen<MINIFY> for ObjectProperty<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
if let Expression::FunctionExpression(func) = &self.value {
Expand Down Expand Up @@ -1561,16 +1562,12 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for ObjectProperty<'a> {
if self.computed {
p.print_char(b'[');
}
if !self.shorthand {
self.key.gen(p, ctx);
}
self.key.gen(p, ctx);
if self.computed {
p.print_char(b']');
}
if !self.shorthand {
p.print_colon();
p.print_soft_space();
}
p.print_colon();
p.print_soft_space();
self.value.gen_expr(p, Precedence::Assign, Context::default());
}
}
Expand Down Expand Up @@ -2538,7 +2535,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for ObjectPattern<'a> {
}
}

// NOTE: `shorthand` is not printed
// TODO: only print shorthand if key value are the same.
impl<'a, const MINIFY: bool> Gen<MINIFY> for BindingProperty<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
p.add_source_mapping(self.span.start);
Expand Down

0 comments on commit e624dff

Please sign in to comment.