Skip to content

Commit

Permalink
fix(codegen): correct accessibility emit for class formal-parameters/…
Browse files Browse the repository at this point in the history
…methods/properties
  • Loading branch information
escaton committed Jul 3, 2024
1 parent 7768d23 commit 653952d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
19 changes: 9 additions & 10 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,12 +682,12 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for FunctionBody<'a> {
impl<'a, const MINIFY: bool> Gen<MINIFY> for FormalParameter<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
self.decorators.gen(p, ctx);
if self.readonly {
p.print_str(b"readonly ");
}
if let Some(accessibility) = self.accessibility {
accessibility.gen(p, ctx);
}
if self.readonly {
p.print_str(b"readonly ");
}
self.pattern.gen(p, ctx);
}
}
Expand Down Expand Up @@ -2378,12 +2378,12 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for MethodDefinition<'a> {
p.add_source_mapping(self.span.start);
self.decorators.gen(p, ctx);

if self.r#type == MethodDefinitionType::TSAbstractMethodDefinition {
p.print_str(b"abstract ");
}
if let Some(accessibility) = &self.accessibility {
accessibility.gen(p, ctx);
}
if self.r#type == MethodDefinitionType::TSAbstractMethodDefinition {
p.print_str(b"abstract ");
}
if self.r#static {
p.print_str(b"static ");
}
Expand Down Expand Up @@ -2440,13 +2440,12 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for PropertyDefinition<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
p.add_source_mapping(self.span.start);
self.decorators.gen(p, ctx);
if self.r#type == PropertyDefinitionType::TSAbstractPropertyDefinition {
p.print_str(b"abstract ");
}
if let Some(accessibility) = &self.accessibility {
accessibility.gen(p, ctx);
}

if self.r#type == PropertyDefinitionType::TSAbstractPropertyDefinition {
p.print_str(b"abstract ");
}
if self.r#static {
p.print_str(b"static ");
}
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_codegen/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ fn typescript() {
test_ts("let foo: { <T>(t: T): void }", "let foo: {<T>(t: T): void};\n", false);
test_ts("function <const T>(){}", "function<const T>() {}\n", false);
test_ts("class A {m?(): void}", "class A {\n\tm?(): void;\n}\n", false);
test_ts("class A {constructor(public readonly a: number) {}}", "class A {\n\tconstructor(public readonly a: number) {}\n}\n", false);
test_ts("abstract class A {private abstract static m() {}}", "abstract class A {\n\tprivate abstract static m() {}\n}\n", false);
test_ts("abstract class A {private abstract static readonly prop: string}", "abstract class A {\n\tprivate abstract static readonly prop: string;\n}\n", false)
}

fn test_comment_helper(source_text: &str, expected: &str) {
Expand Down

0 comments on commit 653952d

Please sign in to comment.