feat(codegen): minify class method async*fn(){} (#8083)

This commit is contained in:
Boshen 2024-12-24 00:35:29 +00:00
parent 55d6eb9507
commit f8f067bfc6
3 changed files with 27 additions and 14 deletions

View file

@ -1220,6 +1220,7 @@ impl Gen for IdentifierReference<'_> {
impl Gen for IdentifierName<'_> {
fn gen(&self, p: &mut Codegen, _ctx: Context) {
p.print_space_before_identifier();
p.add_source_mapping(self.span);
p.print_str(self.name.as_str());
}
@ -2665,36 +2666,47 @@ impl Gen for MethodDefinition<'_> {
decorator.print(p, ctx);
p.print_hard_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 == MethodDefinitionType::TSAbstractMethodDefinition {
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();
}
match &self.kind {
MethodDefinitionKind::Constructor | MethodDefinitionKind::Method => {}
MethodDefinitionKind::Get => {
p.print_str("get ");
p.print_space_before_identifier();
p.add_source_mapping(self.span);
p.print_str("get");
p.print_soft_space();
}
MethodDefinitionKind::Set => {
p.print_str("set ");
p.print_space_before_identifier();
p.add_source_mapping(self.span);
p.print_str("set");
p.print_soft_space();
}
}
if self.value.r#async {
p.print_str("async ");
p.print_space_before_identifier();
p.add_source_mapping(self.span);
p.print_str("async");
p.print_soft_space();
}
if self.value.generator {
p.add_source_mapping(self.span);
p.print_str("*");
}
if self.computed {
p.print_ascii_byte(b'[');
}

View file

@ -51,11 +51,12 @@ fn private_in() {
}
#[test]
fn access_property() {
fn class() {
test(
"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]

View file

@ -15,7 +15,7 @@ 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.59 kB | 646.76 kB | 163.94 kB | 163.73 kB | three.js
1.25 MB | 661.60 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
@ -23,5 +23,5 @@ Original | minified | minified | gzip | gzip | Fixture
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.71 kB | 915.50 kB | typescript.js
10.95 MB | 3.54 MB | 3.49 MB | 909.70 kB | 915.50 kB | typescript.js