Skip to content

Commit 8b9f2ae

Browse files
committed
feat(estree): add IS_COMPACT const to Formatter trait
1 parent aea71cc commit 8b9f2ae

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

crates/oxc_estree/src/serialize/formatter.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ use oxc_data_structures::code_buffer::CodeBuffer;
22

33
/// Formatter trait.
44
pub trait Formatter {
5+
/// `true` if formatter produces compact JSON (not pretty-printed JSON).
6+
const IS_COMPACT: bool;
7+
58
/// Create new [`Formatter`].
69
fn new() -> Self;
710

@@ -30,6 +33,8 @@ pub trait Formatter {
3033
pub struct CompactFormatter;
3134

3235
impl Formatter for CompactFormatter {
36+
const IS_COMPACT: bool = true;
37+
3338
#[inline(always)]
3439
fn new() -> Self {
3540
Self
@@ -71,6 +76,8 @@ pub struct PrettyFormatter {
7176
}
7277

7378
impl Formatter for PrettyFormatter {
79+
const IS_COMPACT: bool = false;
80+
7481
#[inline(always)]
7582
fn new() -> Self {
7683
Self { indent: 0 }

crates/oxc_estree/src/serialize/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ pub trait ESTree {
3535

3636
/// Trait for serializers.
3737
pub trait Serializer {
38-
/// `true` if output should contain TS fields
38+
/// `true` if output should contain TS fields.
3939
const INCLUDE_TS_FIELDS: bool;
4040

41+
/// `true` if serializer's formatter produces compact JSON (not pretty-printed JSON).
42+
const IS_COMPACT: bool = Self::Formatter::IS_COMPACT;
43+
4144
/// Type of `Formatter` this serializer uses.
4245
type Formatter: Formatter;
4346

0 commit comments

Comments
 (0)