Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adjust span in non pretty serialiser too
  • Loading branch information
therewillbecode authored and overlookmotel committed Apr 3, 2025
commit 35ff46369351287aba7401c9f40fcd2e3afb95c1
7 changes: 6 additions & 1 deletion crates/oxc_ast/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ const JSON_CAPACITY_RATIO_PRETTY: usize = 80;

impl Program<'_> {
/// Serialize AST to ESTree JSON, including TypeScript fields.
pub fn to_estree_ts_json(&self) -> String {
pub fn to_estree_ts_json(&mut self) -> String {
// Set start span to first token of first statement.
if let Some(first_stat) = self.body.first() {
self.span = Span::new(first_stat.span().start, self.span.end);
}

let capacity = self.source_text.len() * JSON_CAPACITY_RATIO_COMPACT;
let mut serializer = CompactTSSerializer::with_capacity(capacity);
self.serialize(&mut serializer);
Expand Down