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: 9 additions & 0 deletions crates/oxc_ast_visit/src/utf8_to_utf16/converter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use std::cmp::min;

use oxc_ast::ast::Program;
use oxc_span::Span;
use oxc_syntax::module_record::VisitMutModuleRecord;

use crate::VisitMut;

use super::Translation;

/// Offset converter, optimized for converting a sequence of offsets in ascending order.
Expand Down Expand Up @@ -280,6 +283,12 @@ impl<'t> Utf8ToUtf16Converter<'t> {
(next_index, range_end_utf8)
}

/// Convert all spans in AST to UTF-16.
#[inline] // Because it just delegates
pub fn convert_program(&mut self, program: &mut Program<'_>) {
self.visit_program(program);
}

/// Convert [`Span`] from UTF-8 offsets to UTF-16 offsets.
pub fn convert_span(&mut self, span: &mut Span) {
self.convert_offset(&mut span.start);
Expand Down
6 changes: 2 additions & 4 deletions crates/oxc_ast_visit/src/utf8_to_utf16/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use oxc_ast::ast::{Comment, Program};
use oxc_span::Span;
use oxc_syntax::module_record::{ModuleRecord, VisitMutModuleRecord};

use crate::VisitMut;

mod converter;
mod translation;
mod visit;
Expand Down Expand Up @@ -61,7 +59,7 @@ impl Utf8ToUtf16 {
/// Convert all spans in AST to UTF-16.
pub fn convert_program(&self, program: &mut Program<'_>) {
if let Some(mut converter) = self.converter() {
converter.visit_program(program);
converter.convert_program(program);
}
}

Expand All @@ -86,7 +84,7 @@ impl Utf8ToUtf16 {

// SAFETY: We just checked `translations` contains at least 2 entries
let mut converter = unsafe { Utf8ToUtf16Converter::new(&self.translations, true) };
converter.visit_program(program);
converter.convert_program(program);
}

/// Convert all spans in comments to UTF-16.
Expand Down
Loading