Skip to content

Commit d24d3d5

Browse files
committed
fix(semantic): dont parse @ as jsdoc tags inside quotes
1 parent 5648b31 commit d24d3d5

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-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: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ 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_quotes = false;
44+
4145
// This flag tells us if we have already found the main comment block.
4246
// The first part before any @tags is considered the comment. Everything after is a tag.
4347
let mut comment_found = false;
@@ -52,8 +56,11 @@ pub fn parse_jsdoc(
5256
while let Some(ch) = chars.next() {
5357
// A `@` is only considered the start of a tag if we are not nested inside
5458
// 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;
59+
let can_parse = curly_brace_depth == 0
60+
&& square_brace_depth == 0
61+
&& brace_depth == 0
62+
&& !in_backticks
63+
&& !in_quotes;
5764

5865
match ch {
5966
// NOTE: For now, only odd backtick(s) are handled.
@@ -67,6 +74,11 @@ pub fn parse_jsdoc(
6774
in_backticks = !in_backticks;
6875
}
6976
}
77+
'"' | '\'' => {
78+
if chars.peek().is_some_and(|&c| c != ch) {
79+
in_quotes = !in_quotes;
80+
}
81+
}
7082
'{' => curly_brace_depth += 1,
7183
'}' => curly_brace_depth = curly_brace_depth.saturating_sub(1),
7284
'(' => brace_depth += 1,

0 commit comments

Comments
 (0)