Skip to content

Commit e716d97

Browse files
committed
fix: Duplicate comments showing up when using ignore comment.
Fixes #21.
1 parent 950f255 commit e716d97

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "dprint-plugin-typescript"
33
description = "TypeScript code formatting plugin for Dprint."
44
keywords = ["formatting", "formatter", "typescript"]
5-
version = "0.19.6"
5+
version = "0.19.7"
66
authors = ["David Sherret <[email protected]>"]
77
edition = "2018"
88
license = "MIT"
@@ -12,6 +12,14 @@ repository = "https://github.com/dprint/dprint-plugin-typescript"
1212
[lib]
1313
crate-type = ["lib", "cdylib"]
1414

15+
[profile.release]
16+
opt-level = 3
17+
debug = false
18+
lto = true
19+
debug-assertions = false
20+
overflow-checks = false
21+
panic = "abort"
22+
1523
[dependencies]
1624
dprint-core = "0.23.0"
1725
swc_common = "=0.6.1"

src/parsing/parser.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ fn parse_node_with_inner_parse<'a>(node: Node<'a>, context: &mut Context<'a>, in
8383
if has_ignore_comment {
8484
items.push_str(""); // force the current line indentation
8585
items.extend(parser_helpers::parse_raw_string(&node.text(context)));
86+
87+
// mark any previous comments as handled
88+
for comment in context.comments.trailing_comments_with_previous(node_hi) {
89+
if comment.lo() < node_hi {
90+
context.mark_comment_handled(comment);
91+
}
92+
}
8693
} else {
8794
items.extend(inner_parse(parse_node_inner(node, context), context));
8895
}

tests/specs/issues/issue0021.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
== should format as-is ==
2+
// dprint-ignore
3+
const identity = [
4+
1, 0, 0,
5+
0, 1, 0,
6+
0, 0, 1,
7+
];
8+
9+
// or even...
10+
11+
const identity = /* dprint-ignore */ [
12+
1, 0, 0,
13+
0, 1, 0,
14+
0, 0, 1,
15+
];
16+
17+
[expect]
18+
// dprint-ignore
19+
const identity = [
20+
1, 0, 0,
21+
0, 1, 0,
22+
0, 0, 1,
23+
];
24+
25+
// or even...
26+
27+
const identity = /* dprint-ignore */ [
28+
1, 0, 0,
29+
0, 1, 0,
30+
0, 0, 1,
31+
];

0 commit comments

Comments
 (0)