Skip to content

Commit 621bafa

Browse files
committed
fix: eliminate debug panic when file contains a tab in a comment block or js doc
Closes #298.
1 parent cea7a7b commit 621bafa

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
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.46.0", features = ["formatting"] }
28+
dprint-core = { version = "0.46.3", features = ["formatting"] }
2929
fnv = "1.0.7"
3030
serde = { version = "1.0.118", features = ["derive"] }
3131
serde_json = { version = "1.0", optional = true }

src/parsing/parser.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5623,9 +5623,11 @@ fn parse_js_doc(comment: &Comment, _context: &mut Context) -> PrintItems {
56235623
text.push_str(if i == 0 { "*" } else { " *" });
56245624
if !line.is_empty() {
56255625
text.push_str(" ");
5626-
text.push_str(line);
56275626
}
56285627
items.push_string(text);
5628+
if !line.is_empty() {
5629+
items.extend(parse_raw_string(line));
5630+
}
56295631
}
56305632

56315633
if lines.len() > 1 && lines.last().map(|l| l.is_empty()).unwrap_or(false) {

tests/specs/comments/CommentBlocks_SameSpot.txt renamed to tests/specs/comments/CommentBlocks_All.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,11 @@ call(/* test */5);
7878

7979
[expect]
8080
call(/* test */ 5);
81+
82+
== should not panic for tab in comment block ==
83+
/* test test */
84+
/* test test */
85+
86+
[expect]
87+
/* test test */
88+
/* test test */

tests/specs/comments/CommentLines_All.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,11 @@
5959
// 1. Testing
6060
// 2. Testing
6161
// Testing
62+
63+
== should not panic for tab in comment ==
64+
// test test
65+
// test test
66+
67+
[expect]
68+
// test test
69+
// test test

tests/specs/comments/JSDocComments_All.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,15 @@ const t;
124124
* Test
125125
*/
126126
const t;
127+
128+
== should not panic for tab in js doc ==
129+
/** Testing
130+
* test test
131+
*/
132+
const t;
133+
134+
[expect]
135+
/** Testing
136+
* test test
137+
*/
138+
const t;

0 commit comments

Comments
 (0)