Skip to content

Commit

Permalink
feat(codegen): minify class{static[computed]} (#8088)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Dec 24, 2024
1 parent f873139 commit fccfda9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
40 changes: 29 additions & 11 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,7 @@ impl Gen for MethodDefinition<'_> {
p.add_source_mapping(self.span);
for decorator in &self.decorators {
decorator.print(p, ctx);
p.print_hard_space();
p.print_soft_space();
}
if let Some(accessibility) = &self.accessibility {
p.print_space_before_identifier();
Expand Down Expand Up @@ -2742,23 +2742,33 @@ impl Gen for PropertyDefinition<'_> {
p.add_source_mapping(self.span);
for decorator in &self.decorators {
decorator.print(p, ctx);
p.print_hard_space();
p.print_soft_space();
}
if self.declare {
p.print_str("declare ");
p.print_space_before_identifier();
p.print_str("declare");
p.print_soft_space();
}
if let Some(accessibility) = self.accessibility {
p.print_space_before_identifier();
p.print_str(accessibility.as_str());
p.print_hard_space();
p.print_soft_space();
}
if self.r#type == PropertyDefinitionType::TSAbstractPropertyDefinition {
p.print_str("abstract ");
p.print_space_before_identifier();
p.print_str("abstract");
p.print_soft_space();
}
if self.r#static {
p.print_str("static ");
p.print_space_before_identifier();
p.add_source_mapping(self.span);
p.print_str("static");
p.print_soft_space();
}
if self.readonly {
p.print_str("readonly ");
p.print_space_before_identifier();
p.print_str("readonly");
p.print_soft_space();
}
if self.computed {
p.print_ascii_byte(b'[');
Expand Down Expand Up @@ -2789,18 +2799,26 @@ impl Gen for AccessorProperty<'_> {
p.add_source_mapping(self.span);
for decorator in &self.decorators {
decorator.print(p, ctx);
p.print_hard_space();
p.print_soft_space();
}
if self.r#type.is_abstract() {
p.print_str("abstract ");
p.print_space_before_identifier();
p.add_source_mapping(self.span);
p.print_str("abstract");
p.print_soft_space();
}
if let Some(accessibility) = self.accessibility {
p.print_space_before_identifier();
p.print_str(accessibility.as_str());
p.print_hard_space();
p.print_soft_space();
}
if self.r#static {
p.print_str("static ");
p.print_space_before_identifier();
p.add_source_mapping(self.span);
p.print_str("static");
p.print_soft_space();
}
p.print_space_before_identifier();
p.print_str("accessor");
if self.computed {
p.print_soft_space();
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn class() {
"export default class Foo { @x @y accessor #aDef = 1 }",
"export default class Foo {\n\t@x @y accessor #aDef = 1;\n}\n",
);
test_minify("class F { static async * foo () {} }", "class F{static async*foo(){}}");
test_minify("class { static [computed] }", "class{static[computed]}");
}

#[test]
Expand Down

0 comments on commit fccfda9

Please sign in to comment.