From 5c4c00123d16b0d26e078e8dee9d529e9c99ea4d Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:30:38 +0000 Subject: [PATCH] fix(codegen): print `export @decorator declare abstract class Foo` correctly (#5303) --- crates/oxc_codegen/src/gen.rs | 12 ++++++------ .../oxc_codegen/tests/integration/snapshots/ts.snap | 3 +++ crates/oxc_codegen/tests/integration/ts.rs | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 03f390a9e95ec..7d5aee94b09d6 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -2158,16 +2158,16 @@ impl<'a> Gen for MetaProperty<'a> { impl<'a> Gen for Class<'a> { fn gen(&self, p: &mut Codegen, ctx: Context) { p.add_source_mapping(self.span.start); - if self.declare { - p.print_str("declare "); - } - if self.r#abstract { - p.print_str("abstract "); - } let n = p.code_len(); let wrap = self.is_expression() && (p.start_of_stmt == n || p.start_of_default_export == n); p.wrap(wrap, |p| { self.decorators.gen(p, ctx); + if self.declare { + p.print_str("declare "); + } + if self.r#abstract { + p.print_str("abstract "); + } p.print_str("class"); if let Some(id) = &self.id { p.print_hard_space(); diff --git a/crates/oxc_codegen/tests/integration/snapshots/ts.snap b/crates/oxc_codegen/tests/integration/snapshots/ts.snap index a4eaa09690546..5584266fafe65 100644 --- a/crates/oxc_codegen/tests/integration/snapshots/ts.snap +++ b/crates/oxc_codegen/tests/integration/snapshots/ts.snap @@ -106,3 +106,6 @@ c = foo; d = x satisfies y; d = ((x) satisfies y); + +export @x declare abstract class C {} +export @x declare abstract class C {} diff --git a/crates/oxc_codegen/tests/integration/ts.rs b/crates/oxc_codegen/tests/integration/ts.rs index 326e0da8efc09..7944aae11295a 100644 --- a/crates/oxc_codegen/tests/integration/ts.rs +++ b/crates/oxc_codegen/tests/integration/ts.rs @@ -50,6 +50,7 @@ fn ts() { "b = (x as y);", "c = foo;", "d = x satisfies y;", + "export @x declare abstract class C {}", ]; let snapshot = cases.into_iter().fold(String::new(), |mut w, case| {