mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(prettier): add print_class (#1355)
This commit is contained in:
parent
a3658ca5f9
commit
2aca2d0894
2 changed files with 27 additions and 1 deletions
17
crates/oxc_prettier/src/format/class.rs
Normal file
17
crates/oxc_prettier/src/format/class.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#[allow(clippy::wildcard_imports)]
|
||||
use oxc_ast::ast::*;
|
||||
|
||||
use crate::{doc::Doc, ss, Format, Prettier};
|
||||
|
||||
impl<'a> Prettier<'a> {
|
||||
pub(super) fn print_class(&mut self, class: &Class<'a>) -> Doc<'a> {
|
||||
let mut parts = self.vec();
|
||||
parts.push(ss!("class "));
|
||||
if let Some(id) = &class.id {
|
||||
parts.push(id.format(self));
|
||||
}
|
||||
parts.push(ss!(" "));
|
||||
parts.push(class.body.format(self));
|
||||
Doc::Array(parts)
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ mod arrow_function;
|
|||
mod binaryish;
|
||||
mod block;
|
||||
mod call_expression;
|
||||
mod class;
|
||||
mod function;
|
||||
mod function_parameters;
|
||||
mod module;
|
||||
|
|
@ -1074,7 +1075,15 @@ impl<'a> Format<'a> for MetaProperty {
|
|||
|
||||
impl<'a> Format<'a> for Class<'a> {
|
||||
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
|
||||
Doc::Line
|
||||
p.print_class(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Format<'a> for ClassBody<'a> {
|
||||
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
|
||||
let mut parts = p.vec();
|
||||
parts.push(ss!("{}"));
|
||||
Doc::Array(parts)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue