Skip to content

Commit 9c4f7ed

Browse files
committed
fix: keep parens around jsdoc type assertions
1 parent 1df6f22 commit 9c4f7ed

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/parsing/parser.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,6 +2421,13 @@ fn should_skip_paren_expr(node: &ParenExpr, context: &Context) -> bool {
24212421
return false;
24222422
}
24232423

2424+
// keep when there is a JSDoc type assertion
2425+
for c in node.leading_comments_fast(context.module) {
2426+
if c.kind == CommentKind::Block && c.text.starts_with("*") && c.text.contains("@type") {
2427+
return false;
2428+
}
2429+
}
2430+
24242431
if matches!(node.expr.kind(), NodeKind::ArrayLit) {
24252432
return true;
24262433
}

tests/specs/expressions/ParenExpr/ParenExpr_All.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,13 @@ test = () => {};
187187
[expect]
188188
({ prop: 5 }).prop;
189189
({ prop: 5 }).prop;
190+
191+
== should not remove when there's a JS doc type assertion ==
192+
typeAssertedNumber = /** @type {number} */ (numberOrString);
193+
// not a js doc so won't keep it
194+
typeAssertedNumber = /* @type {number} */ (numberOrString);
195+
196+
[expect]
197+
typeAssertedNumber = /** @type {number} */ (numberOrString);
198+
// not a js doc so won't keep it
199+
typeAssertedNumber = /* @type {number} */ numberOrString;

0 commit comments

Comments
 (0)