Skip to content

Commit

Permalink
fix(codegen): print export @decorator declare abstract class Foo co…
Browse files Browse the repository at this point in the history
…rrectly
  • Loading branch information
Boshen committed Aug 28, 2024
1 parent 7fa2fa3 commit 6f428db
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_codegen/tests/integration/snapshots/ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,6 @@ c = foo<string>;

d = x satisfies y;
d = ((x) satisfies y);

export @x declare abstract class C {}
export @x declare abstract class C {}
1 change: 1 addition & 0 deletions crates/oxc_codegen/tests/integration/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fn ts() {
"b = (x as y);",
"c = foo<string>;",
"d = x satisfies y;",
"export @x declare abstract class C {}",
];

let snapshot = cases.into_iter().fold(String::new(), |mut w, case| {
Expand Down

0 comments on commit 6f428db

Please sign in to comment.