Skip to content

Commit c976976

Browse files
committed
fix: #123 - Trailing whitespaces should be trimmed inside block comments.
Closes #123.
1 parent 8fbf4b8 commit c976976

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ wasm = ["serde_json", "dprint-core/wasm"]
2525
tracing = ["dprint-core/tracing"]
2626

2727
[dependencies]
28-
dprint-core = { version = "0.37.0", features = ["formatting"] }
28+
dprint-core = { version = "0.38.0", features = ["formatting"] }
2929
fnv = "1.0.7"
3030
swc_common = "0.10.14"
3131
swc_ecmascript = { version = "0.31.0", features = ["parser"] }

src/parsing/parser.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4829,18 +4829,10 @@ fn parse_comment(comment: &Comment, context: &mut Context) -> Option<PrintItems>
48294829

48304830
// mark handled and parse
48314831
context.mark_comment_handled(comment);
4832-
return Some(match comment.kind {
4833-
CommentKind::Block => parse_comment_block(comment),
4832+
Some(match comment.kind {
4833+
CommentKind::Block => parser_helpers::parse_js_like_comment_block(&comment.text),
48344834
CommentKind::Line => parser_helpers::parse_js_like_comment_line(&comment.text, context.config.comment_line_force_space_after_slashes),
4835-
});
4836-
4837-
fn parse_comment_block(comment: &Comment) -> PrintItems {
4838-
let mut items = PrintItems::new();
4839-
items.push_str("/*");
4840-
items.extend(parse_raw_string(&comment.text));
4841-
items.push_str("*/");
4842-
items
4843-
}
4835+
})
48444836
}
48454837

48464838
fn parse_first_line_trailing_comments<'a>(node: &dyn Spanned, first_member: Option<Span>, context: &mut Context<'a>) -> PrintItems {

tests/specs/issues/issue0123.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
== should remove trailing whitespace in block comments ==
2+
/* aa
3+
*/
4+
function a() {}
5+
6+
[expect]
7+
/* aa
8+
*/
9+
function a() {}

0 commit comments

Comments
 (0)