Skip to content

Commit

Permalink
fix(codegen): print some missing typescript attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jun 30, 2024
1 parent dc6d45e commit cda89c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,9 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for Class<'a> {
if let Some(id) = &self.id {
p.print_hard_space();
id.gen(p, ctx);
if let Some(type_parameters) = self.type_parameters.as_ref() {
type_parameters.gen(p, ctx);
}
}
if let Some(super_class) = self.super_class.as_ref() {
p.print_str(b" extends ");
Expand Down Expand Up @@ -2444,6 +2447,9 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for PropertyDefinition<'a> {
if self.r#static {
p.print_str(b"static ");
}
if self.readonly {
p.print_str(b"readonly ");
}
if self.computed {
p.print(b'[');
}
Expand Down Expand Up @@ -2818,6 +2824,10 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for TSMappedType<'a> {
p.print_str(b" = ");
default.gen(p, ctx);
}
if let Some(name_type) = &self.name_type {
p.print_str(b" as ");
name_type.gen(p, ctx);
}
p.print_str(b"]");
match self.optional {
TSMappedTypeModifierOperator::True => {
Expand Down Expand Up @@ -3255,6 +3265,9 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for TSTupleElement<'a> {
impl<'a, const MINIFY: bool> Gen<MINIFY> for TSNamedTupleMember<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
self.label.gen(p, ctx);
if self.optional {
p.print_str(b"?");
}
p.print_str(b":");
p.print_soft_space();
self.element_type.gen(p, ctx);
Expand Down
10 changes: 10 additions & 0 deletions crates/oxc_codegen/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ fn typescript() {
"export { Foo, type Bar } from 'foo';\n",
false,
);
test_ts(
"type A<T> = { [K in keyof T as K extends string ? B<K> : K ]: T[K] }",
"type A<T> = { [K in keyof T as K extends string ? B<K> : K] : T[K]};\n",
false,
);
test_ts(
"class A {readonly type = 'frame'}",
"class A {\n\treadonly type = 'frame';\n}\n",
false,
);
}

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

0 comments on commit cda89c9

Please sign in to comment.