mirror of
https://github.com/danbulant/oxc
synced 2026-05-21 05:08:45 +00:00
refactor(prettier) Remove flat_contents from IfBreak (#1324)
This commit is contained in:
parent
71b3f48af1
commit
9c170b89ff
4 changed files with 17 additions and 19 deletions
|
|
@ -31,19 +31,13 @@ pub enum Doc<'a> {
|
|||
/// no matter if the expression fits on one line or not.
|
||||
Hardline,
|
||||
/// Print something if the current `group` or the current element of `fill` breaks and something else if it doesn't.
|
||||
IfBreak(IfBreak<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct IfBreak<'a> {
|
||||
pub break_contents: Vec<'a, Doc<'a>>,
|
||||
pub flat_contents: Vec<'a, Doc<'a>>,
|
||||
IfBreak(Vec<'a, Doc<'a>>),
|
||||
}
|
||||
|
||||
impl<'a> Doc<'a> {
|
||||
#[must_use]
|
||||
pub fn if_break(break_contents: Vec<'a, Doc<'a>>, flat_contents: Vec<'a, Doc<'a>>) -> Self {
|
||||
Doc::IfBreak(IfBreak { break_contents, flat_contents })
|
||||
pub fn if_break(break_contents: Vec<'a, Doc<'a>>) -> Self {
|
||||
Doc::IfBreak(break_contents)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -780,7 +780,7 @@ impl<'a> Format<'a> for ArrayExpression<'a> {
|
|||
let mut if_break_comma = p.vec();
|
||||
if_break_comma.push(Doc::Str(","));
|
||||
|
||||
parts_inner.push(Doc::if_break(if_break_comma, p.vec()));
|
||||
parts_inner.push(Doc::if_break(if_break_comma));
|
||||
|
||||
parts.push(group!(p, Doc::Indent(parts_inner)));
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ impl<'a> Command<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||
pub enum Mode {
|
||||
Break,
|
||||
Flat,
|
||||
|
|
|
|||
|
|
@ -7,10 +7,7 @@ mod command;
|
|||
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use crate::{
|
||||
doc::{Doc, IfBreak},
|
||||
PrettierOptions,
|
||||
};
|
||||
use crate::{doc::Doc, PrettierOptions};
|
||||
|
||||
use self::command::{Command, Indent, Mode};
|
||||
|
||||
|
|
@ -125,10 +122,17 @@ impl<'a> Printer<'a> {
|
|||
self.pos = self.indent(indent.length);
|
||||
}
|
||||
|
||||
fn handle_if_break(&mut self, if_break: IfBreak<'a>, indent: Indent, mode: Mode) {
|
||||
let IfBreak { break_contents, .. } = if_break;
|
||||
self.cmds
|
||||
.extend(break_contents.into_iter().rev().map(|doc| Command::new(indent, mode, doc)));
|
||||
fn handle_if_break(
|
||||
&mut self,
|
||||
if_break: oxc_allocator::Vec<'a, Doc<'a>>,
|
||||
indent: Indent,
|
||||
mode: Mode,
|
||||
) {
|
||||
if mode == Mode::Break {
|
||||
self.cmds.extend(
|
||||
if_break.into_iter().rev().map(|doc| Command::new(indent, Mode::Break, doc)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_possible_wrap)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue