feat(prettier): print ExportAllDeclaration (#1381)

This commit is contained in:
Boshen 2023-11-17 21:16:55 +08:00 committed by GitHub
parent a305b84143
commit 9a21d1af7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 2 deletions

View file

@ -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)]

View file

@ -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)
}
}

View file

@ -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);
}