Skip to content

Commit 320c09f

Browse files
committed
feat(ast, parser, linter, codegen, formatter)!: rename CommentKind::Block to CommentKind::SinglelineBlock (#16501)
#16479 introduced a new kind called `CommentKind::MultilineBlock`, which means a block comment that has at least one line break. Therefore, `CommentKind::Block` means it is a single-line block. In this PR, rename `CommentKind::Block` to `CommentKind::SinglelineBlock` to make the kind name more descriptive.
1 parent c7db70b commit 320c09f

File tree

10 files changed

+31
-24
lines changed

10 files changed

+31
-24
lines changed

crates/oxc_ast/src/ast/comment.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ pub enum CommentKind {
1515
/// Line comment
1616
#[default]
1717
Line = 0,
18-
/// Block comment
19-
Block = 1,
18+
/// Singleline comment
19+
#[estree(rename = "Block")]
20+
SinglelineBlock = 1,
2021
/// Multiline block comment (contains line breaks)
2122
#[estree(rename = "Block")]
2223
MultilineBlock = 2,
@@ -175,7 +176,7 @@ impl Comment {
175176
pub fn content_span(&self) -> Span {
176177
match self.kind {
177178
CommentKind::Line => Span::new(self.span.start + 2, self.span.end),
178-
CommentKind::Block | CommentKind::MultilineBlock => {
179+
CommentKind::SinglelineBlock | CommentKind::MultilineBlock => {
179180
Span::new(self.span.start + 2, self.span.end - 2)
180181
}
181182
}
@@ -187,10 +188,10 @@ impl Comment {
187188
self.kind == CommentKind::Line
188189
}
189190

190-
/// Returns `true` if this is a block comment.
191+
/// Returns `true` if this is a singleline or multiline block comment.
191192
#[inline]
192193
pub fn is_block(self) -> bool {
193-
matches!(self.kind, CommentKind::Block | CommentKind::MultilineBlock)
194+
matches!(self.kind, CommentKind::SinglelineBlock | CommentKind::MultilineBlock)
194195
}
195196

196197
/// Returns `true` if this is a multi-line block comment.

crates/oxc_ast/src/generated/derive_estree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3233,7 +3233,7 @@ impl ESTree for CommentKind {
32333233
fn serialize<S: Serializer>(&self, serializer: S) {
32343234
match self {
32353235
Self::Line => JsonSafeString("Line").serialize(serializer),
3236-
Self::Block => JsonSafeString("Block").serialize(serializer),
3236+
Self::SinglelineBlock => JsonSafeString("Block").serialize(serializer),
32373237
Self::MultilineBlock => JsonSafeString("Block").serialize(serializer),
32383238
}
32393239
}

crates/oxc_ast/src/trivia.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,11 @@ mod test {
225225

226226
#[test]
227227
fn test_is_inside_comment() {
228-
let comments =
229-
vec![Comment::new(0, 4, CommentKind::Line), Comment::new(10, 20, CommentKind::Block)]
230-
.into_boxed_slice();
228+
let comments = vec![
229+
Comment::new(0, 4, CommentKind::Line),
230+
Comment::new(10, 20, CommentKind::SinglelineBlock),
231+
]
232+
.into_boxed_slice();
231233

232234
assert!(is_inside_comment(&comments, 2));
233235
assert!(!is_inside_comment(&comments, 5));
@@ -237,9 +239,11 @@ mod test {
237239

238240
#[test]
239241
fn test_get_comment_at() {
240-
let comments =
241-
vec![Comment::new(0, 4, CommentKind::Line), Comment::new(10, 20, CommentKind::Block)]
242-
.into_boxed_slice();
242+
let comments = vec![
243+
Comment::new(0, 4, CommentKind::Line),
244+
Comment::new(10, 20, CommentKind::SinglelineBlock),
245+
]
246+
.into_boxed_slice();
243247

244248
// Inside first comment
245249
let comment = get_comment_at(&comments, 2);

crates/oxc_codegen/src/comment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl Codegen<'_> {
128128
};
129129
let comment_source = comment.span.source_text(source_text);
130130
match comment.kind {
131-
CommentKind::Line | CommentKind::Block => {
131+
CommentKind::Line | CommentKind::SinglelineBlock => {
132132
self.print_str_escaping_script_close_tag(comment_source);
133133
}
134134
CommentKind::MultilineBlock => {

crates/oxc_formatter/src/formatter/trivia.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'a> Format<'a> for FormatLeadingComments<'a> {
111111
write!(f, comment);
112112

113113
match comment.kind {
114-
CommentKind::Block | CommentKind::MultilineBlock => {
114+
CommentKind::SinglelineBlock | CommentKind::MultilineBlock => {
115115
match f.source_text().lines_after(comment.span.end) {
116116
0 => {
117117
let should_nestle =

crates/oxc_linter/src/rules/typescript/prefer_function_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ fn check_member(member: &TSSignature, node: &AstNode<'_>, ctx: &LintContext<'_>)
174174
let single_line_comment: String = format!("//{comment}\n");
175175
comments_vec.push(single_line_comment);
176176
}
177-
CommentKind::Block | CommentKind::MultilineBlock => {
177+
CommentKind::SinglelineBlock | CommentKind::MultilineBlock => {
178178
let multi_line_comment: String = format!("/*{comment}*/\n");
179179
comments_vec.push(multi_line_comment);
180180
}

crates/oxc_napi/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ pub fn convert_utf8_to_utf16(
3333
Comment {
3434
r#type: match comment.kind {
3535
CommentKind::Line => String::from("Line"),
36-
CommentKind::Block | CommentKind::MultilineBlock => String::from("Block"),
36+
CommentKind::SinglelineBlock | CommentKind::MultilineBlock => {
37+
String::from("Block")
38+
}
3739
},
3840
value,
3941
start: span.start,

crates/oxc_parser/src/lexer/comment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'a> Lexer<'a> {
154154
self.trivia_builder.add_block_comment(
155155
self.token.start(),
156156
self.offset(),
157-
CommentKind::Block,
157+
CommentKind::SinglelineBlock,
158158
self.source.whole(),
159159
);
160160
Kind::Skip

crates/oxc_parser/src/lexer/trivia_builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ mod test {
334334
let expected = [
335335
Comment {
336336
span: Span::new(9, 24),
337-
kind: CommentKind::Block,
337+
kind: CommentKind::SinglelineBlock,
338338
position: CommentPosition::Leading,
339339
attached_to: 70,
340340
newlines: CommentNewlines::Leading | CommentNewlines::Trailing,
@@ -350,15 +350,15 @@ mod test {
350350
},
351351
Comment {
352352
span: Span::new(54, 69),
353-
kind: CommentKind::Block,
353+
kind: CommentKind::SinglelineBlock,
354354
position: CommentPosition::Leading,
355355
attached_to: 70,
356356
newlines: CommentNewlines::Leading,
357357
content: CommentContent::None,
358358
},
359359
Comment {
360360
span: Span::new(76, 92),
361-
kind: CommentKind::Block,
361+
kind: CommentKind::SinglelineBlock,
362362
position: CommentPosition::Trailing,
363363
attached_to: 0,
364364
newlines: CommentNewlines::None,
@@ -398,15 +398,15 @@ token /* Trailing 1 */
398398
let expected = vec![
399399
Comment {
400400
span: Span::new(20, 35),
401-
kind: CommentKind::Block,
401+
kind: CommentKind::SinglelineBlock,
402402
position: CommentPosition::Leading,
403403
attached_to: 36,
404404
newlines: CommentNewlines::Leading | CommentNewlines::Trailing,
405405
content: CommentContent::None,
406406
},
407407
Comment {
408408
span: Span::new(42, 58),
409-
kind: CommentKind::Block,
409+
kind: CommentKind::SinglelineBlock,
410410
position: CommentPosition::Trailing,
411411
attached_to: 0,
412412
newlines: CommentNewlines::Trailing,

crates/oxc_parser/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,10 +717,10 @@ mod test {
717717
let source_type = SourceType::default().with_typescript(true);
718718
let sources = [
719719
("// line comment", CommentKind::Line),
720-
("/* line comment */", CommentKind::Block),
720+
("/* line comment */", CommentKind::SinglelineBlock),
721721
(
722722
"type Foo = ( /* Require properties which are not generated automatically. */ 'bar')",
723-
CommentKind::Block,
723+
CommentKind::SinglelineBlock,
724724
),
725725
];
726726
for (source, kind) in sources {

0 commit comments

Comments
 (0)