Skip to content

Commit 2c4c42f

Browse files
fix: comment after node should be ignored in strictness=relax
fix #2216
1 parent c8acfdd commit 2c4c42f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

crates/core/src/match_tree/match_node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ mod test {
295295
"import { foo, } from 'bar'",
296296
M::Relaxed,
297297
);
298+
matched("foo($A, $B)", "foo(1/*test*/, 2/*test*/)", M::Relaxed);
298299
unmatched(
299300
"import { foo } from 'bar'",
300301
"import { foo, bar, baz } from 'bar'",

crates/core/src/match_tree/strictness.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ impl MatchStrictness {
4646
M::Signature => false,
4747
}
4848
}
49+
50+
fn should_skip_comment(&self) -> bool {
51+
use MatchStrictness as M;
52+
match self {
53+
M::Cst | M::Smart | M::Ast => false,
54+
M::Relaxed | M::Signature | M::Template => true,
55+
}
56+
}
57+
4958
pub(crate) fn match_terminal(
5059
&self,
5160
is_named: bool,
@@ -62,16 +71,19 @@ impl MatchStrictness {
6271
if is_kind_matched && (!is_named || text == candidate.text()) {
6372
return MatchOneNode::MatchedBoth;
6473
}
74+
if self.should_skip_comment() && skip_comment(candidate) {
75+
return MatchOneNode::SkipCandidate;
76+
}
6577
let (skip_goal, skip_candidate) = match self {
6678
M::Cst => (false, false),
6779
M::Smart => (false, !candidate.is_named()),
6880
M::Ast => (!is_named, !candidate.is_named()),
69-
M::Relaxed => (!is_named, skip_comment_or_unnamed(candidate)),
81+
M::Relaxed => (!is_named, !candidate.is_named()),
7082
M::Signature => {
7183
if is_kind_matched {
7284
return MatchOneNode::MatchedBoth;
7385
}
74-
(!is_named, skip_comment_or_unnamed(candidate))
86+
(!is_named, !candidate.is_named())
7587
}
7688
M::Template => {
7789
if text == candidate.text() {

0 commit comments

Comments
 (0)