Skip to content

Commit

Permalink
fix: Duplicate comments showing up when using ignore comment.
Browse files Browse the repository at this point in the history
Fixes #21.
  • Loading branch information
dsherret committed Jul 6, 2020
1 parent 950f255 commit e716d97
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "dprint-plugin-typescript"
description = "TypeScript code formatting plugin for Dprint."
keywords = ["formatting", "formatter", "typescript"]
version = "0.19.6"
version = "0.19.7"
authors = ["David Sherret <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -12,6 +12,14 @@ repository = "https://github.com/dprint/dprint-plugin-typescript"
[lib]
crate-type = ["lib", "cdylib"]

[profile.release]
opt-level = 3
debug = false
lto = true
debug-assertions = false
overflow-checks = false
panic = "abort"

[dependencies]
dprint-core = "0.23.0"
swc_common = "=0.6.1"
Expand Down
7 changes: 7 additions & 0 deletions src/parsing/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ fn parse_node_with_inner_parse<'a>(node: Node<'a>, context: &mut Context<'a>, in
if has_ignore_comment {
items.push_str(""); // force the current line indentation
items.extend(parser_helpers::parse_raw_string(&node.text(context)));

// mark any previous comments as handled
for comment in context.comments.trailing_comments_with_previous(node_hi) {
if comment.lo() < node_hi {
context.mark_comment_handled(comment);
}
}
} else {
items.extend(inner_parse(parse_node_inner(node, context), context));
}
Expand Down
31 changes: 31 additions & 0 deletions tests/specs/issues/issue0021.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
== should format as-is ==
// dprint-ignore
const identity = [
1, 0, 0,
0, 1, 0,
0, 0, 1,
];

// or even...

const identity = /* dprint-ignore */ [
1, 0, 0,
0, 1, 0,
0, 0, 1,
];

[expect]
// dprint-ignore
const identity = [
1, 0, 0,
0, 1, 0,
0, 0, 1,
];

// or even...

const identity = /* dprint-ignore */ [
1, 0, 0,
0, 1, 0,
0, 0, 1,
];

0 comments on commit e716d97

Please sign in to comment.