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
6 changes: 4 additions & 2 deletions crates/oxc_ast/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,10 @@ impl ESTree for FunctionFormalParameters<'_, '_> {
fn serialize<S: Serializer>(&self, serializer: S) {
let mut seq = serializer.serialize_sequence();

if let Some(this_param) = &self.0.this_param {
seq.serialize_ts_element(this_param);
if S::INCLUDE_TS_FIELDS {
if let Some(this_param) = &self.0.this_param {
seq.serialize_element(this_param);
}
}

for item in &self.0.params.items {
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_estree/src/serialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub trait ESTree {
// Internal methods we don't want to expose outside this crate are in [`SerializerPrivate`] trait.
#[expect(private_bounds)]
pub trait Serializer: SerializerPrivate {
/// `true` if output should contain TS fields
const INCLUDE_TS_FIELDS: bool;

/// Type of struct serializer this serializer uses.
type StructSerializer: StructSerializer;
/// Type of sequence serializer this serializer uses.
Expand Down Expand Up @@ -99,6 +102,9 @@ impl<C: Config, F: Formatter> Default for ESTreeSerializer<C, F> {
}

impl<'s, C: Config, F: Formatter> Serializer for &'s mut ESTreeSerializer<C, F> {
/// `true` if output should contain TS fields
const INCLUDE_TS_FIELDS: bool = C::INCLUDE_TS_FIELDS;

type StructSerializer = ESTreeStructSerializer<'s, C, F>;
type SequenceSerializer = ESTreeSequenceSerializer<'s, C, F>;

Expand Down
7 changes: 0 additions & 7 deletions crates/oxc_estree/src/serialize/sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::{Config, ESTree, ESTreeSerializer, Formatter, Serializer, SerializerP
pub trait SequenceSerializer {
/// Serialize sequence entry.
fn serialize_element<T: ESTree + ?Sized>(&mut self, value: &T);
fn serialize_ts_element<T: ESTree + ?Sized>(&mut self, value: &T);

/// Finish serializing sequence.
fn end(self);
Expand Down Expand Up @@ -44,12 +43,6 @@ impl<C: Config, F: Formatter> SequenceSerializer for ESTreeSequenceSerializer<'_
value.serialize(&mut *self.serializer);
}

fn serialize_ts_element<T: ESTree + ?Sized>(&mut self, value: &T) {
if C::INCLUDE_TS_FIELDS {
self.serialize_element(value);
}
}

/// Finish serializing sequence.
fn end(mut self) {
let (buffer, formatter) = self.serializer.buffer_and_formatter_mut();
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_estree/src/serialize/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ pub(super) enum StructState {
pub struct FlatStructSerializer<'p, P: StructSerializer>(pub &'p mut P);

impl<'p, P: StructSerializer> Serializer for FlatStructSerializer<'p, P> {
/// `true` if output should contain TS fields
const INCLUDE_TS_FIELDS: bool = P::Config::INCLUDE_TS_FIELDS;

type StructSerializer = Self;
type SequenceSerializer = ESTreeSequenceSerializer<'p, P::Config, P::Formatter>;

Expand Down