oxc/crates/oxc_prettier/src/printer/command.rs
Boshen 7d9d04c569
refactor(prettier): align line with prettier (#1559)
This PR alines all the line types with prettier

```
const hardlineWithoutBreakParent = { type: DOC_TYPE_LINE, hard: true };
const literallineWithoutBreakParent = {
  type: DOC_TYPE_LINE,
  hard: true,
  literal: true,
};


const line = { type: DOC_TYPE_LINE };
const softline = { type: DOC_TYPE_LINE, soft: true };
const hardline = [hardlineWithoutBreakParent, breakParent];
const literalline = [literallineWithoutBreakParent, breakParent];
```

101598f94f/src/document/builders.js (L165-L175)
2023-11-27 23:11:53 +08:00

49 lines
856 B
Rust

use crate::doc::Doc;
pub struct Command<'a> {
pub indent: Indent,
pub mode: Mode,
pub doc: Doc<'a>,
}
impl<'a> Command<'a> {
pub fn new(indent: Indent, mode: Mode, doc: Doc<'a>) -> Self {
Self { indent, mode, doc }
}
pub fn with_mode(mut self, mode: Mode) -> Self {
self.mode = mode;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mode {
Break,
Flat,
}
impl Mode {
pub fn is_break(self) -> bool {
self == Self::Break
}
pub fn is_flat(self) -> bool {
self == Self::Flat
}
}
#[derive(Debug, Clone, Copy)]
pub struct Indent {
pub root: bool,
pub length: usize,
}
impl Indent {
pub fn root() -> Self {
Self { root: true, length: 0 }
}
pub fn new(length: usize) -> Self {
Self { root: false, length }
}
}