Skip to content

Commit 198243b

Browse files
authored
fix(semantic): dont parse @ as jsdoc tags inside quotes (#13571)
Fixes #13570
1 parent 89084d7 commit 198243b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

crates/oxc_linter/src/rules/jsdoc/check_tag_names.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,17 @@ fn test() {
606606
",
607607
Some(serde_json::json!([ { "definedTags": [] } ])),
608608
None,
609+
),
610+
// https://github.com/oxc-project/oxc/issues/13570
611+
(
612+
"
613+
/**
614+
* @import { Page } from '@playwright/test';
615+
*/
616+
function quux (foo) { }
617+
",
618+
Some(serde_json::json!([ { "definedTags": [] } ])),
619+
None,
609620
),
610621
(
611622
"

crates/oxc_semantic/src/jsdoc/parser/parse.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ pub fn parse_jsdoc(
3838
// This includes inline code blocks or markdown-style code inside comments.
3939
let mut in_backticks = false;
4040

41+
// Track whether we're currently inside quotes '...' or "..."
42+
// This includes package names when doing a @import
43+
let mut in_double_quotes = false;
44+
let mut in_single_quotes = false;
45+
4146
// This flag tells us if we have already found the main comment block.
4247
// The first part before any @tags is considered the comment. Everything after is a tag.
4348
let mut comment_found = false;
@@ -52,8 +57,12 @@ pub fn parse_jsdoc(
5257
while let Some(ch) = chars.next() {
5358
// A `@` is only considered the start of a tag if we are not nested inside
5459
// braces, square brackets, or backtick-quoted sections
55-
let can_parse =
56-
curly_brace_depth == 0 && square_brace_depth == 0 && brace_depth == 0 && !in_backticks;
60+
let can_parse = curly_brace_depth == 0
61+
&& square_brace_depth == 0
62+
&& brace_depth == 0
63+
&& !in_backticks
64+
&& !in_double_quotes
65+
&& !in_single_quotes;
5766

5867
match ch {
5968
// NOTE: For now, only odd backtick(s) are handled.
@@ -67,6 +76,8 @@ pub fn parse_jsdoc(
6776
in_backticks = !in_backticks;
6877
}
6978
}
79+
'"' => in_double_quotes = !in_double_quotes,
80+
'\'' => in_single_quotes = !in_single_quotes,
7081
'{' => curly_brace_depth += 1,
7182
'}' => curly_brace_depth = curly_brace_depth.saturating_sub(1),
7283
'(' => brace_depth += 1,

0 commit comments

Comments
 (0)