Skip to content
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
5 changes: 5 additions & 0 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,11 @@ impl<'a> Declaration<'a> {
Declaration::TSImportEqualsDeclaration(_) => false,
}
}

/// Returns `true` if this declaration is a TypeScript type or interface declaration.
pub fn is_type(&self) -> bool {
matches!(self, Self::TSTypeAliasDeclaration(_) | Self::TSInterfaceDeclaration(_))
}
}

impl VariableDeclaration<'_> {
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,9 @@ impl Gen for ExportNamedDeclaration<'_> {
p.add_source_mapping(self.span);
p.print_indent();
p.print_str("export");
if self.export_kind.is_type() {
if self.export_kind.is_type()
&& !self.declaration.as_ref().is_some_and(oxc_ast::ast::Declaration::is_type)
{
p.print_str(" type ");
}
if let Some(decl) = &self.declaration {
Expand Down
7 changes: 6 additions & 1 deletion crates/oxc_parser/src/js/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,18 @@ impl<'a> ParserImpl<'a> {
self.ctx = self.ctx.union_ambient_if(modifiers.contains_declare());

let declaration = self.parse_declaration(decl_span, &modifiers)?;
let export_kind = if declaration.is_type() {
ImportOrExportKind::Type
} else {
ImportOrExportKind::Value
};
self.ctx = reserved_ctx;
Ok(self.ast.alloc_export_named_declaration(
self.end_span(span),
Some(declaration),
self.ast.vec(),
None,
ImportOrExportKind::Value,
export_kind,
NONE,
))
}
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_prettier/src/format/print/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ pub fn print_export_declaration<'a>(
}
}
ExportDeclarationLike::ExportNamedDeclaration(decl) => {
if decl.export_kind.is_type() {
if decl.export_kind.is_type()
&& !decl.declaration.as_ref().is_some_and(oxc_ast::ast::Declaration::is_type)
{
parts.push(text!(" type"));
}
if let Some(decl) = &decl.declaration {
Expand Down
Loading