mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(prettier): print ExportAllDeclaration (#1381)
This commit is contained in:
parent
a305b84143
commit
9a21d1af7b
3 changed files with 27 additions and 2 deletions
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue