diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 04f45d246..cfda1f6e5 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -1857,6 +1857,17 @@ impl<'a> ModuleDeclaration<'a> { pub fn is_default_export(&self) -> bool { matches!(self, Self::ExportDefaultDeclaration(_)) } + + pub fn source(&self) -> Option<&StringLiteral> { + match self { + Self::ImportDeclaration(decl) => Some(&decl.source), + Self::ExportAllDeclaration(decl) => Some(&decl.source), + Self::ExportNamedDeclaration(decl) => decl.source.as_ref(), + Self::ExportDefaultDeclaration(_) + | Self::TSExportAssignment(_) + | Self::TSNamespaceExportDeclaration(_) => None, + } + } } #[derive(Debug, Hash)] diff --git a/crates/oxc_prettier/src/format/mod.rs b/crates/oxc_prettier/src/format/mod.rs index fbed5e080..eb7c5c061 100644 --- a/crates/oxc_prettier/src/format/mod.rs +++ b/crates/oxc_prettier/src/format/mod.rs @@ -831,13 +831,22 @@ impl<'a> Format<'a> for ExportSpecifier { impl<'a> Format<'a> for ModuleExportName { fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> { - Doc::Line + match self { + Self::Identifier(ident) => ident.format(p), + Self::StringLiteral(literal) => literal.format(p), + } } } impl<'a> Format<'a> for ExportAllDeclaration<'a> { fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> { - Doc::Line + let mut parts = p.vec(); + parts.push(ss!(" *")); + if let Some(exported) = &self.exported { + parts.push(ss!(" as ")); + parts.push(exported.format(p)); + } + Doc::Array(parts) } } diff --git a/crates/oxc_prettier/src/format/module.rs b/crates/oxc_prettier/src/format/module.rs index a8442ea5d..009ed3d59 100644 --- a/crates/oxc_prettier/src/format/module.rs +++ b/crates/oxc_prettier/src/format/module.rs @@ -25,6 +25,11 @@ pub(super) fn print_export_declaration<'a>( ModuleDeclaration::TSNamespaceExportDeclaration(decl) => decl.format(p), }); + if let Some(source) = decl.source() { + parts.push(ss!(" from ")); + parts.push(source.format(p)); + } + if let Some(doc) = print_semicolon_after_export_declaration(p, decl) { parts.push(doc); }