Skip to content

Commit 2dfc3bd

Browse files
committed
feat(formatter): remove Tag::StartVerbatim and Tag::EndVerbatim (#15370)
No usage for this. From my understanding, this is used to handle invalid syntax, but our AST always produces a valid AST, so it is useless
1 parent 88c7530 commit 2dfc3bd

File tree

7 files changed

+16
-380
lines changed

7 files changed

+16
-380
lines changed

crates/oxc_formatter/src/formatter/format_element/document.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ impl<'a> Format<'a> for &[FormatElement<'a>] {
169169
fn fmt(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
170170
use Tag::{
171171
EndAlign, EndConditionalContent, EndDedent, EndEntry, EndFill, EndGroup, EndIndent,
172-
EndIndentIfGroupBreaks, EndLabelled, EndLineSuffix, EndVerbatim, StartAlign,
172+
EndIndentIfGroupBreaks, EndLabelled, EndLineSuffix, StartAlign,
173173
StartConditionalContent, StartDedent, StartEntry, StartFill, StartGroup, StartIndent,
174-
StartIndentIfGroupBreaks, StartLabelled, StartLineSuffix, StartVerbatim,
174+
StartIndentIfGroupBreaks, StartLabelled, StartLineSuffix,
175175
};
176176

177177
write!(f, [ContentArrayStart])?;
@@ -391,10 +391,6 @@ impl<'a> Format<'a> for &[FormatElement<'a>] {
391391
write!(f, [token("line_suffix(")])?;
392392
}
393393

394-
StartVerbatim(_) => {
395-
write!(f, [token("verbatim(")])?;
396-
}
397-
398394
StartGroup(group) => {
399395
write!(f, [token("group(")])?;
400396

@@ -499,8 +495,7 @@ impl<'a> Format<'a> for &[FormatElement<'a>] {
499495
| EndIndent
500496
| EndGroup
501497
| EndLineSuffix
502-
| EndDedent(_)
503-
| EndVerbatim => {
498+
| EndDedent(_) => {
504499
write!(f, [ContentArrayEnd, token(")")])?;
505500
}
506501
}

crates/oxc_formatter/src/formatter/format_element/tag.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ pub enum Tag {
5656
StartLineSuffix,
5757
EndLineSuffix,
5858

59-
/// A token that tracks tokens/nodes that are printed as verbatim.
60-
StartVerbatim(VerbatimKind),
61-
EndVerbatim,
62-
6359
/// Special semantic element marking the content with a label.
6460
/// This does not directly influence how the content will be printed.
6561
///
@@ -82,7 +78,6 @@ impl Tag {
8278
| Tag::StartFill
8379
| Tag::StartEntry
8480
| Tag::StartLineSuffix
85-
| Tag::StartVerbatim(_)
8681
| Tag::StartLabelled(_)
8782
)
8883
}
@@ -95,9 +90,9 @@ impl Tag {
9590
pub const fn kind(&self) -> TagKind {
9691
use Tag::{
9792
EndAlign, EndConditionalContent, EndDedent, EndEntry, EndFill, EndGroup, EndIndent,
98-
EndIndentIfGroupBreaks, EndLabelled, EndLineSuffix, EndVerbatim, StartAlign,
93+
EndIndentIfGroupBreaks, EndLabelled, EndLineSuffix, StartAlign,
9994
StartConditionalContent, StartDedent, StartEntry, StartFill, StartGroup, StartIndent,
100-
StartIndentIfGroupBreaks, StartLabelled, StartLineSuffix, StartVerbatim,
95+
StartIndentIfGroupBreaks, StartLabelled, StartLineSuffix,
10196
};
10297

10398
match self {
@@ -110,7 +105,6 @@ impl Tag {
110105
StartFill | EndFill => TagKind::Fill,
111106
StartEntry | EndEntry => TagKind::Entry,
112107
StartLineSuffix | EndLineSuffix => TagKind::LineSuffix,
113-
StartVerbatim(_) | EndVerbatim => TagKind::Verbatim,
114108
StartLabelled(_) | EndLabelled => TagKind::Labelled,
115109
}
116110
}
@@ -130,7 +124,6 @@ pub enum TagKind {
130124
Fill,
131125
Entry,
132126
LineSuffix,
133-
Verbatim,
134127
Labelled,
135128
}
136129

@@ -278,21 +271,3 @@ pub trait Label {
278271
/// Returns the name of the label that is shown in debug builds.
279272
fn debug_name(&self) -> &'static str;
280273
}
281-
282-
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
283-
pub enum VerbatimKind {
284-
Bogus,
285-
Suppressed,
286-
/// This was intentionally skipped, not as a result of suppression.
287-
Skipped,
288-
Verbatim {
289-
/// the length of the formatted node
290-
length: TextSize,
291-
},
292-
}
293-
294-
impl VerbatimKind {
295-
pub const fn is_bogus(self) -> bool {
296-
matches!(self, VerbatimKind::Bogus)
297-
}
298-
}

crates/oxc_formatter/src/formatter/mod.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ pub mod formatter;
2929
pub mod group_id;
3030
pub mod macros;
3131
pub mod prelude;
32-
#[cfg(debug_assertions)]
33-
pub mod printed_tokens;
3432
pub mod printer;
3533
pub mod separated;
3634
mod source_text;
@@ -44,7 +42,6 @@ mod text_range;
4442
mod text_size;
4543
pub mod token;
4644
pub mod trivia;
47-
mod verbatim;
4845

4946
use std::{
5047
fmt::{Debug, Display},
@@ -142,17 +139,16 @@ pub type PrintResult<T> = Result<T, PrintError>;
142139
pub struct Printed {
143140
code: String,
144141
range: Option<TextRange>,
145-
verbatim_ranges: Vec<TextRange>,
146142
}
147143

148144
impl Printed {
149-
pub fn new(code: String, range: Option<TextRange>, verbatim_source: Vec<TextRange>) -> Self {
150-
Self { code, range, verbatim_ranges: verbatim_source }
145+
pub fn new(code: String, range: Option<TextRange>) -> Self {
146+
Self { code, range }
151147
}
152148

153149
/// Construct an empty formatter result
154150
pub fn new_empty() -> Self {
155-
Self { code: String::new(), range: None, verbatim_ranges: Vec::new() }
151+
Self { code: String::new(), range: None }
156152
}
157153

158154
/// Range of the input source file covered by this formatted code,
@@ -170,23 +166,6 @@ impl Printed {
170166
pub fn into_code(self) -> String {
171167
self.code
172168
}
173-
174-
/// The text in the formatted code that has been formatted as verbatim.
175-
pub fn verbatim(&self) -> impl Iterator<Item = (TextRange, &str)> {
176-
panic!();
177-
std::iter::empty()
178-
// self.verbatim_ranges.iter().map(|range| (*range, &self.code[*range]))
179-
}
180-
181-
/// Ranges of the formatted code that have been formatted as verbatim.
182-
pub fn verbatim_ranges(&self) -> &[TextRange] {
183-
&self.verbatim_ranges
184-
}
185-
186-
/// Takes the ranges of nodes that have been formatted as verbatim, replacing them with an empty list.
187-
pub fn take_verbatim_ranges(&mut self) -> Vec<TextRange> {
188-
std::mem::take(&mut self.verbatim_ranges)
189-
}
190169
}
191170

192171
// Public return type of the formatter

crates/oxc_formatter/src/formatter/prelude.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// pub use super::verbatim::{
2-
// format_bogus_node, format_or_verbatim, format_suppressed_node, format_verbatim_node,
3-
// format_verbatim_skipped,
4-
// };
51
pub use super::{Buffer as _, BufferExtensions, Format, Format as _, FormatResult};
62
pub use super::{
73
builders::*,

crates/oxc_formatter/src/formatter/printed_tokens.rs

Lines changed: 0 additions & 82 deletions
This file was deleted.

crates/oxc_formatter/src/formatter/printer/mod.rs

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'a> Printer<'a> {
6767
}
6868
}
6969

70-
Ok(Printed::new(self.state.buffer, None, self.state.verbatim_markers))
70+
Ok(Printed::new(self.state.buffer, None))
7171
}
7272

7373
/// Prints a single element and push the following elements to queue
@@ -80,9 +80,9 @@ impl<'a> Printer<'a> {
8080
) -> PrintResult<()> {
8181
use Tag::{
8282
EndAlign, EndConditionalContent, EndDedent, EndEntry, EndFill, EndGroup, EndIndent,
83-
EndIndentIfGroupBreaks, EndLabelled, EndLineSuffix, EndVerbatim, StartAlign,
83+
EndIndentIfGroupBreaks, EndLabelled, EndLineSuffix, StartAlign,
8484
StartConditionalContent, StartDedent, StartEntry, StartFill, StartGroup, StartIndent,
85-
StartIndentIfGroupBreaks, StartLabelled, StartLineSuffix, StartVerbatim,
85+
StartIndentIfGroupBreaks, StartLabelled, StartLineSuffix,
8686
};
8787

8888
let args = stack.top();
@@ -236,29 +236,11 @@ impl<'a> Printer<'a> {
236236
indent_stack.push_suffix(indent_stack.indention());
237237
self.state.line_suffixes.extend(args, queue.iter_content(TagKind::LineSuffix));
238238
}
239-
240-
FormatElement::Tag(StartVerbatim(kind)) => {
241-
todo!()
242-
// if let VerbatimKind::Verbatim { length } = kind {
243-
// self.state.verbatim_markers.push(TextRange::at(
244-
// TextSize::from(self.state.buffer.len() as u32),
245-
// *length,
246-
// ));
247-
// }
248-
249-
// stack.push(TagKind::Verbatim, args);
250-
}
251-
252239
FormatElement::Tag(tag @ (StartLabelled(_) | StartEntry)) => {
253240
stack.push(tag.kind(), args);
254241
}
255242
FormatElement::Tag(
256-
tag @ (EndLabelled
257-
| EndEntry
258-
| EndGroup
259-
| EndConditionalContent
260-
| EndVerbatim
261-
| EndFill),
243+
tag @ (EndLabelled | EndEntry | EndGroup | EndConditionalContent | EndFill),
262244
) => {
263245
stack.pop(tag.kind())?;
264246
}
@@ -696,7 +678,6 @@ struct PrinterState<'a> {
696678
line_width: usize,
697679
has_empty_line: bool,
698680
line_suffixes: LineSuffixes<'a>,
699-
verbatim_markers: Vec<TextRange>,
700681
group_modes: GroupModes,
701682
// Re-used queue to measure if a group fits. Optimisation to avoid re-allocating a new
702683
// vec everytime a group gets measured
@@ -938,9 +919,9 @@ impl<'a, 'print> FitsMeasurer<'a, 'print> {
938919
fn fits_element(&mut self, element: &'a FormatElement) -> PrintResult<Fits> {
939920
use Tag::{
940921
EndAlign, EndConditionalContent, EndDedent, EndEntry, EndFill, EndGroup, EndIndent,
941-
EndIndentIfGroupBreaks, EndLabelled, EndLineSuffix, EndVerbatim, StartAlign,
922+
EndIndentIfGroupBreaks, EndLabelled, EndLineSuffix, StartAlign,
942923
StartConditionalContent, StartDedent, StartEntry, StartFill, StartGroup, StartIndent,
943-
StartIndentIfGroupBreaks, StartLabelled, StartLineSuffix, StartVerbatim,
924+
StartIndentIfGroupBreaks, StartLabelled, StartLineSuffix,
944925
};
945926

946927
let args = self.stack.top();
@@ -1124,18 +1105,11 @@ impl<'a, 'print> FitsMeasurer<'a, 'print> {
11241105
return invalid_end_tag(TagKind::LineSuffix, self.stack.top_kind());
11251106
}
11261107

1127-
FormatElement::Tag(
1128-
tag @ (StartFill | StartVerbatim(_) | StartLabelled(_) | StartEntry),
1129-
) => {
1108+
FormatElement::Tag(tag @ (StartFill | StartLabelled(_) | StartEntry)) => {
11301109
self.stack.push(tag.kind(), args);
11311110
}
11321111
FormatElement::Tag(
1133-
tag @ (EndLabelled
1134-
| EndEntry
1135-
| EndGroup
1136-
| EndConditionalContent
1137-
| EndVerbatim
1138-
| EndFill),
1112+
tag @ (EndLabelled | EndEntry | EndGroup | EndConditionalContent | EndFill),
11391113
) => {
11401114
self.stack.pop(tag.kind())?;
11411115
}

0 commit comments

Comments
 (0)