Skip to content

Commit

Permalink
Fix exports
Browse files Browse the repository at this point in the history
  • Loading branch information
leaysgur committed Nov 26, 2024
1 parent d774b8c commit 0e727bf
Show file tree
Hide file tree
Showing 27 changed files with 90 additions and 82 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/comments/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use oxc_allocator::Vec;
use oxc_span::Span;

use crate::{
ir::doc::{Doc, DocBuilder},
ir::{Doc, DocBuilder},
Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
array,
comments::{CommentFlags, DanglingCommentsPrintOptions},
group, hardline, if_break,
ir::doc::{Doc, DocBuilder, Fill, Group},
ir::{Doc, DocBuilder, Fill, Group},
line, softline, text, Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/arrow_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use oxc_ast::ast::*;

use crate::{
group,
ir::doc::{Doc, DocBuilder},
ir::{Doc, DocBuilder},
text, Format, Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use oxc_ast::{
use super::{binaryish::should_inline_logical_expression, class::ClassMemberish};
use crate::{
array, group, indent,
ir::doc::{Doc, DocBuilder, Group, IndentIfBreak},
ir::{Doc, DocBuilder, Group, IndentIfBreak},
line, space, text, Format, Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/binaryish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
binaryish::BinaryishOperator,
comments::CommentFlags,
group,
ir::doc::{Doc, DocBuilder, Group},
ir::{Doc, DocBuilder, Group},
line, space, text, Format, Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use oxc_ast::{ast::*, AstKind};
use super::{statement, Format};
use crate::{
hardline,
ir::doc::{Doc, DocBuilder},
ir::{Doc, DocBuilder},
text, Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/call_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{
};
use crate::{
array, conditional_group, group_break, hardline, if_break, indent,
ir::doc::{Doc, DocBuilder, Group},
ir::{Doc, DocBuilder, Group},
line, softline, text,
utils::will_break,
Format, Prettier,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/call_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use oxc_span::{GetSpan, Span};

use super::call_arguments::print_call_arguments;
use crate::{
ir::doc::{Doc, DocBuilder, Group},
ir::{Doc, DocBuilder, Group},
text, Format, Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
array,
format::{assignment, Separator},
group, hardline, indent,
ir::doc::{Doc, DocBuilder, Group, IfBreak},
ir::{Doc, DocBuilder, Group, IfBreak},
line, softline, space, text, Format, Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
dynamic_text,
format::function_parameters::should_group_function_parameters,
group, if_break, indent,
ir::doc::{Doc, DocBuilder},
ir::{Doc, DocBuilder},
softline, space, text, Format, Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/function_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use oxc_ast::{ast::*, AstKind};
use crate::{
comments::CommentFlags,
hardline, if_break, indent,
ir::doc::{Doc, DocBuilder, Group},
ir::{Doc, DocBuilder, Group},
line, softline, space, text, Format, Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/misc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use oxc_ast::{ast::*, AstKind};
use oxc_span::Span;

use crate::{array, indent, ir::doc::Doc, line, space, text, DocBuilder, Prettier};
use crate::{array, indent, ir::Doc, line, space, text, DocBuilder, Prettier};

pub(super) fn adjust_clause<'a>(
p: &Prettier<'a>,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{
array, dynamic_text,
format::{array::Array, object::ObjectLike, template_literal::TemplateLiteralPrinter},
group, hardline, indent,
ir::doc::{Doc, DocBuilder, Group, Separator},
ir::{Doc, DocBuilder, Group, Separator},
line, softline, space, text, wrap, Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use oxc_ast::ast::*;

use crate::{
group, if_break, indent,
ir::doc::{Doc, DocBuilder, Separator},
ir::{Doc, DocBuilder, Separator},
line, softline, space, text, Format, Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use oxc_span::Span;
use super::{misc, Format};
use crate::{
dynamic_text, group, if_break,
ir::doc::{Doc, DocBuilder, Group},
ir::{Doc, DocBuilder, Group},
line, softline, text, Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use oxc_span::GetSpan;
use super::Format;
use crate::{
hardline,
ir::doc::{Doc, DocBuilder},
ir::{Doc, DocBuilder},
Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/template_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use oxc_ast::ast::*;

use crate::{
format::Format,
ir::doc::{Doc, DocBuilder},
ir::{Doc, DocBuilder},
text, Prettier,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/format/ternary.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use oxc_ast::ast::*;

use crate::{group, indent, ir::doc::Doc, line, text, DocBuilder, Format, Prettier};
use crate::{group, indent, ir::Doc, line, text, DocBuilder, Format, Prettier};

pub(super) fn print_ternary<'a>(p: &mut Prettier<'a>, expr: &ConditionalExpression<'a>) -> Doc<'a> {
group![
Expand Down
54 changes: 54 additions & 0 deletions crates/oxc_prettier/src/ir/builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use oxc_allocator::{Allocator, Box, String, Vec};

use crate::{
array,
ir::{Doc, Line},
line, text,
};

#[derive(Clone, Copy)]
pub enum Separator {
#[allow(unused)]
Softline,
Hardline,
CommaLine, // [",", line]
}

pub trait DocBuilder<'a> {
fn allocator(&self) -> &'a Allocator;

#[inline]
fn vec<T>(&self) -> Vec<'a, T> {
Vec::new_in(self.allocator())
}
fn vec_single<T>(&self, value: T) -> Vec<'a, T> {
let mut vec = Vec::with_capacity_in(1, self.allocator());
vec.push(value);
vec
}

#[inline]
fn string(&self, s: &str) -> Doc<'a> {
Doc::Str(String::from_str_in(s, self.allocator()).into_bump_str())
}

#[inline]
fn boxed(&self, doc: Doc<'a>) -> Box<'a, Doc<'a>> {
Box::new_in(doc, self.allocator())
}

fn join(&self, separator: Separator, docs: std::vec::Vec<Doc<'a>>) -> Vec<'a, Doc<'a>> {
let mut parts = self.vec();
for (i, doc) in docs.into_iter().enumerate() {
if i != 0 {
parts.push(match separator {
Separator::Softline => Doc::Line(Line::softline()),
Separator::Hardline => Doc::Line(Line::hardline()),
Separator::CommaLine => array![self, text!(","), line!()],
});
}
parts.push(doc);
}
parts
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ir::doc::{Doc, Line};
use crate::ir::{Doc, Line};

impl<'a> std::fmt::Display for Doc<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Expand Down
50 changes: 0 additions & 50 deletions crates/oxc_prettier/src/ir/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
//! References:
//! * <https://github.com/prettier/prettier/blob/3.3.3/commands.md>
use std::fmt;

use oxc_allocator::{Allocator, Box, String, Vec};

use crate::{array, line, text, GroupId};
Expand Down Expand Up @@ -164,51 +162,3 @@ pub struct IfBreak<'a> {
pub flat_content: Box<'a, Doc<'a>>,
pub group_id: Option<GroupId>,
}

#[derive(Clone, Copy)]
pub enum Separator {
#[allow(unused)]
Softline,
Hardline,
CommaLine, // [",", line]
}

/// Doc Builder
pub trait DocBuilder<'a> {
fn allocator(&self) -> &'a Allocator;

#[inline]
fn vec<T>(&self) -> Vec<'a, T> {
Vec::new_in(self.allocator())
}
fn vec_single<T>(&self, value: T) -> Vec<'a, T> {
let mut vec = Vec::with_capacity_in(1, self.allocator());
vec.push(value);
vec
}

#[inline]
fn string(&self, s: &str) -> Doc<'a> {
Doc::Str(String::from_str_in(s, self.allocator()).into_bump_str())
}

#[inline]
fn boxed(&self, doc: Doc<'a>) -> Box<'a, Doc<'a>> {
Box::new_in(doc, self.allocator())
}

fn join(&self, separator: Separator, docs: std::vec::Vec<Doc<'a>>) -> Vec<'a, Doc<'a>> {
let mut parts = self.vec();
for (i, doc) in docs.into_iter().enumerate() {
if i != 0 {
parts.push(match separator {
Separator::Softline => Doc::Line(Line::softline()),
Separator::Hardline => Doc::Line(Line::hardline()),
Separator::CommaLine => array![self, text!(","), line!()],
});
}
parts.push(doc);
}
parts
}
}
8 changes: 6 additions & 2 deletions crates/oxc_prettier/src/ir/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
mod debug;
pub mod doc;
mod builder;
mod display;
mod doc;

pub use builder::*;
pub use doc::*;
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use oxc_syntax::identifier::is_line_terminator;
pub use crate::options::{ArrowParens, EndOfLine, PrettierOptions, QuoteProps, TrailingComma};
use crate::{
format::Format,
ir::doc::{Doc, DocBuilder},
ir::{Doc, DocBuilder},
printer::Printer,
};

Expand Down
14 changes: 7 additions & 7 deletions crates/oxc_prettier/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ macro_rules! indent_if_break {
#[macro_export]
macro_rules! line {
() => {{
use $crate::ir::doc::Line;
use $crate::ir::Line;
Doc::Line(Line::default())
}};
}

#[macro_export]
macro_rules! softline {
() => {{
use $crate::ir::doc::Line;
use $crate::ir::Line;
Doc::Line(Line::softline())
}};
}

#[macro_export]
macro_rules! hardline {
() => {{
use $crate::ir::doc::Line;
use $crate::ir::Line;
[Doc::Line(Line::hardline()), Doc::BreakParent]
}};
}
Expand All @@ -84,7 +84,7 @@ macro_rules! array {
#[macro_export]
macro_rules! group {
($p:ident, $( $x:expr ),* $(,)?) => {{
use $crate::ir::doc::Group;
use $crate::ir::Group;
let mut temp_vec = $p.vec();
$(
temp_vec.push($x);
Expand All @@ -96,7 +96,7 @@ macro_rules! group {
#[macro_export]
macro_rules! conditional_group {
($p:ident, $c: expr, $( $x:expr ),* $(,)?) => {{
use $crate::ir::doc::Group;
use $crate::ir::Group;
let mut temp_vec = $p.vec();
$(
temp_vec.push($x);
Expand All @@ -109,7 +109,7 @@ macro_rules! conditional_group {
#[macro_export]
macro_rules! group_break {
($p:ident, $( $x:expr ),* $(,)?) => {{
use $crate::ir::doc::Group;
use $crate::ir::Group;
let mut temp_vec = $p.vec();
$(
temp_vec.push($x);
Expand All @@ -121,7 +121,7 @@ macro_rules! group_break {
#[macro_export]
macro_rules! if_break {
($p:ident, $s:expr, $flat:expr, $group_id:expr) => {{
use $crate::ir::doc::IfBreak;
use $crate::ir::IfBreak;
Doc::IfBreak(IfBreak {
break_contents: $p.boxed(Doc::Str($s)),
flat_content: $p.boxed(Doc::Str($flat)),
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/printer/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ir::doc::Doc;
use crate::ir::Doc;

pub struct Command<'a> {
pub indent: Indent,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/printer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use oxc_allocator::Allocator;
use rustc_hash::FxHashMap;

use crate::{
ir::doc::{Doc, DocBuilder, Fill, IfBreak, IndentIfBreak, Line},
ir::{Doc, DocBuilder, Fill, IfBreak, IndentIfBreak, Line},
printer::command::{Command, Indent, Mode},
GroupId, PrettierOptions,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_prettier/src/utils/document.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ir::doc::{Doc, IndentIfBreak};
use crate::ir::{Doc, IndentIfBreak};

pub fn will_break(doc: &mut Doc<'_>) -> bool {
let check_array =
Expand Down

0 comments on commit 0e727bf

Please sign in to comment.