Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/oxc_estree/src/serialize/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use oxc_data_structures::code_buffer::CodeBuffer;

/// Formatter trait.
pub trait Formatter {
/// `true` if formatter produces compact JSON (not pretty-printed JSON).
const IS_COMPACT: bool;

/// Create new [`Formatter`].
fn new() -> Self;

Expand Down Expand Up @@ -30,6 +33,8 @@ pub trait Formatter {
pub struct CompactFormatter;

impl Formatter for CompactFormatter {
const IS_COMPACT: bool = true;

#[inline(always)]
fn new() -> Self {
Self
Expand Down Expand Up @@ -71,6 +76,8 @@ pub struct PrettyFormatter {
}

impl Formatter for PrettyFormatter {
const IS_COMPACT: bool = false;

#[inline(always)]
fn new() -> Self {
Self { indent: 0 }
Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_estree/src/serialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ pub trait ESTree {

/// Trait for serializers.
pub trait Serializer {
/// `true` if output should contain TS fields
/// `true` if output should contain TS fields.
const INCLUDE_TS_FIELDS: bool;

/// `true` if serializer's formatter produces compact JSON (not pretty-printed JSON).
const IS_COMPACT: bool = Self::Formatter::IS_COMPACT;

/// Type of `Formatter` this serializer uses.
type Formatter: Formatter;

Expand Down
Loading