diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index c677317ef3b3a..a4737cd0f1440 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -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'['); } diff --git a/crates/oxc_codegen/tests/integration/unit.rs b/crates/oxc_codegen/tests/integration/unit.rs index ed017b5f85e31..a474a92a0dc39 100644 --- a/crates/oxc_codegen/tests/integration/unit.rs +++ b/crates/oxc_codegen/tests/integration/unit.rs @@ -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] diff --git a/tasks/minsize/minsize.snap b/tasks/minsize/minsize.snap index cae51a72ab199..85b5bc50b1097 100644 --- a/tasks/minsize/minsize.snap +++ b/tasks/minsize/minsize.snap @@ -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