Skip to content

Commit

Permalink
feat(codege): minify whitespace in object getter / setter (#8080)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Dec 23, 2024
1 parent 1d5ae81 commit 618b6aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 7 additions & 3 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,18 +1665,22 @@ impl Gen for ObjectProperty<'_> {
PropertyKind::Init => false,
PropertyKind::Get => {
p.add_source_mapping(self.span);
p.print_str("get ");
p.print_str("get");
p.print_soft_space();
true
}
PropertyKind::Set => {
p.add_source_mapping(self.span);
p.print_str("set ");
p.print_str("set");
p.print_soft_space();
true
}
};
if self.method || is_accessor {
if func.r#async {
p.print_str("async ");
p.print_space_before_identifier();
p.print_str("async");
p.print_soft_space();
}
if func.generator {
p.print_str("*");
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,9 @@ fn directive() {
test_options("'\"'", "'\"';\n", double_quote.clone());
test_options(r#""'\"""#, "\"'\\\"\";\n", double_quote);
}

#[test]
fn getter_setter() {
test_minify("({ get [foo]() {} })", "({get[foo](){}});");
test_minify("({ set [foo]() {} })", "({set[foo](){}});");
}
4 changes: 2 additions & 2 deletions tasks/minsize/minsize.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ Original | minified | minified | gzip | gzip | Fixture

1.01 MB | 467.00 kB | 458.89 kB | 126.74 kB | 126.71 kB | bundle.min.js

1.25 MB | 661.60 kB | 646.76 kB | 163.94 kB | 163.73 kB | three.js
1.25 MB | 661.59 kB | 646.76 kB | 163.94 kB | 163.73 kB | three.js

2.14 MB | 740.48 kB | 724.14 kB | 181.35 kB | 181.07 kB | victory.js

3.20 MB | 1.02 MB | 1.01 MB | 332.01 kB | 331.56 kB | echarts.js

6.69 MB | 2.39 MB | 2.31 MB | 495.62 kB | 488.28 kB | antd.js

10.95 MB | 3.54 MB | 3.49 MB | 909.70 kB | 915.50 kB | typescript.js
10.95 MB | 3.54 MB | 3.49 MB | 909.71 kB | 915.50 kB | typescript.js

0 comments on commit 618b6aa

Please sign in to comment.