Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codegen): print export @decorator declare abstract class Foo correctly #5303

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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