Skip to content

Commit

Permalink
feat(codegen): print TSImport remaining fields (#3695)
Browse files Browse the repository at this point in the history
```ts
type A = import("./a", { with: { "type": "json"}}).Name<T>
```
  • Loading branch information
Dunqing committed Jun 15, 2024
1 parent a94a72d commit 4a004e2
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3028,7 +3028,44 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for TSImportType<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
p.print_str(b"import(");
self.argument.gen(p, ctx);
if let Some(attributes) = &self.attributes {
p.print_str(", ");
attributes.gen(p, ctx);
}
p.print_str(b")");
if let Some(qualifier) = &self.qualifier {
p.print(b'.');
qualifier.gen(p, ctx);
}
if let Some(type_parameters) = &self.type_parameters {
type_parameters.gen(p, ctx);
}
}
}

impl<'a, const MINIFY: bool> Gen<MINIFY> for TSImportAttributes<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
// { with: { ... } }
p.print_str(b"{ with: { ");
p.print_list(&self.elements, ctx);
p.print_str(b" }}");
}
}

impl<'a, const MINIFY: bool> Gen<MINIFY> for TSImportAttribute<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
self.name.gen(p, ctx);
p.print_str(": ");
self.value.gen_expr(p, Precedence::Member, ctx);
}
}

impl<'a, const MINIFY: bool> Gen<MINIFY> for TSImportAttributeName<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
match self {
TSImportAttributeName::Identifier(ident) => ident.gen(p, ctx),
TSImportAttributeName::StringLiteral(literal) => literal.gen(p, ctx),
}
}
}

Expand Down

0 comments on commit 4a004e2

Please sign in to comment.