refactor(formatter_core): remove JS-only method (#28099)

Just inlined in `oxc_formatter`.
This commit is contained in:
leaysgur committed 2026-10-22 07:45:34 +00:00
1 parent 5f1fd3dcb9
commit f1d90329e2
3 files changed
+7 -14

No files matched your search

@@ -200,7 +200,7 @@ impl<'a, 'b> AssignmentLike<'a, 'b> {
// Handle computed properties
if property.computed {
write!(f, ["[", property.key(), "]"]);
f.source_text().span_width(property.key.span()) + 2 < text_width_for_break
f.source_text().text_for(&property.key).width() + 2 < text_width_for_break
} else if property.shorthand {
let PropertyKey::StaticIdentifier(ident) = &property.key else {
unreachable!("Expected static identifier for shorthand property");
@@ -230,7 +230,7 @@ impl<'a, 'b> AssignmentLike<'a, 'b> {
// Handle computed properties
if property.computed {
write!(f, ["[", property.key(), "]"]);
f.source_text().span_width(property.key.span()) + 2 < text_width_for_break
f.source_text().text_for(&property.key).width() + 2 < text_width_for_break
} else {
let width = write_member_name(&property.key(), f);
@@ -243,7 +243,7 @@ impl<'a, 'b> AssignmentLike<'a, 'b> {
if property.computed {
write!(f, ["[", property.name(), "]"]);
f.source_text().span_width(property.name.span()) + 2 < text_width_for_break
f.source_text().text_for(&property.name).width() + 2 < text_width_for_break
} else {
let width = write_member_name(&property.name(), f);
+3 -2
View File
@@ -1,5 +1,6 @@
use unicode_width::UnicodeWidthStr;
use oxc_ast::ast::*;
use oxc_span::GetSpan;
use oxc_syntax::identifier::is_identifier_name_patched;
use crate::{
@@ -87,7 +88,7 @@ pub fn write_member_name<'a>(
} else {
write!(f, key);
f.source_text().span_width(key.span())
f.source_text().text_for(key).width()
}
}
+1 -9
View File
@@ -1,8 +1,6 @@
use std::ops::Deref;
use unicode_width::UnicodeWidthStr;
use oxc_span::{GetSpan, Span};
use oxc_span::GetSpan;
/// Source text wrapper providing mechanical byte/offset access for the formatter.
///
@@ -110,10 +108,4 @@ impl<'a> SourceText<'a> {
pub fn text_for<T: GetSpan>(&self, obj: &T) -> &'a str {
obj.span().source_text(self.text)
}
// Utility methods
/// Get the display width of span, the same measure as a printed string's width (wide characters count as 2)
pub fn span_width(&self, span: Span) -> usize {
self.text_for(&span).width()
}
}