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
9 changes: 3 additions & 6 deletions crates/oxc_estree/src/serialize/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::iter;

use oxc_data_structures::code_buffer::CodeBuffer;

/// Formatter trait.
Expand Down Expand Up @@ -79,7 +77,7 @@ impl Formatter for PrettyFormatter {
}

fn before_first_element(&mut self, buffer: &mut CodeBuffer) {
self.indent += 2;
self.indent += 1;
self.push_new_line_and_indent(buffer);
}

Expand All @@ -92,15 +90,14 @@ impl Formatter for PrettyFormatter {
}

fn after_last_element(&mut self, buffer: &mut CodeBuffer) {
self.indent -= 2;
self.indent -= 1;
self.push_new_line_and_indent(buffer);
}
}

impl PrettyFormatter {
fn push_new_line_and_indent(&self, buffer: &mut CodeBuffer) {
buffer.print_ascii_byte(b'\n');
// SAFETY: Spaces are ASCII
unsafe { buffer.print_bytes_iter_unchecked(iter::repeat_n(b' ', self.indent)) };
buffer.print_indent(self.indent);
}
}
9 changes: 6 additions & 3 deletions crates/oxc_estree/src/serialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use std::mem;

use itoa::Buffer as ItoaBuffer;

use oxc_data_structures::{code_buffer::CodeBuffer, stack::NonEmptyStack};
use oxc_data_structures::{
code_buffer::{CodeBuffer, IndentChar},
stack::NonEmptyStack,
};

mod blanket;
mod concat;
Expand Down Expand Up @@ -110,7 +113,7 @@ impl<C: Config, F: Formatter> ESTreeSerializer<C, F> {
/// Create new [`ESTreeSerializer`].
pub fn new(ranges: bool) -> Self {
Self {
buffer: CodeBuffer::new(),
buffer: CodeBuffer::with_indent(IndentChar::Space, 2),
formatter: F::new(),
trace_path: NonEmptyStack::new(TracePathPart::Index(0)),
fixes_buffer: CodeBuffer::new(),
Expand All @@ -121,7 +124,7 @@ impl<C: Config, F: Formatter> ESTreeSerializer<C, F> {
/// Create new [`ESTreeSerializer`] with specified buffer capacity.
pub fn with_capacity(capacity: usize, ranges: bool) -> Self {
Self {
buffer: CodeBuffer::with_capacity(capacity),
buffer: CodeBuffer::with_capacity_and_indent(capacity, IndentChar::Space, 2),
formatter: F::new(),
trace_path: NonEmptyStack::new(TracePathPart::Index(0)),
fixes_buffer: CodeBuffer::new(),
Expand Down
Loading