Skip to content

Commit f0f3496

Browse files
Dustyn Loydacopybara-github
Dustyn Loyda
authored andcommitted
Update CheckJSDoc to also allow for type annotations on a comma expressions
PiperOrigin-RevId: 718166448
1 parent d0ffb41 commit f0f3496

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/com/google/javascript/jscomp/parsing/IRFactory.java

+4
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ private Comment getJSDocCommentAt(SourcePosition pos) {
755755

756756
case CALL_EXPRESSION:
757757
case CONDITIONAL_EXPRESSION:
758+
case COMMA_EXPRESSION:
758759
case BINARY_OPERATOR:
759760
case MEMBER_EXPRESSION:
760761
case MEMBER_LOOKUP_EXPRESSION:
@@ -955,6 +956,9 @@ private static ParseTree findNearestNode(ParseTree tree) {
955956
case UPDATE_EXPRESSION:
956957
tree = tree.asUpdateExpression().operand;
957958
continue;
959+
case COMMA_EXPRESSION:
960+
tree = tree.asCommaExpression().expressions.get(0);
961+
continue;
958962
default:
959963
return tree;
960964
}

test/com/google/javascript/jscomp/CheckJsDocTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -1311,4 +1311,11 @@ public void testIsUsedViaDotConstrucctor() {
13111311
testSame("class Foo {/** @usedViaDotConstructor */ constructor() {} }");
13121312
testWarning("/** @usedViaDotConstructor */ function A() {}", MISPLACED_ANNOTATION);
13131313
}
1314+
1315+
@Test
1316+
public void testMisplacedTypeAnnotationCommaExpression() {
1317+
testSame("var x = obj.method(/** @type {foo} */ (bar), baz);");
1318+
testSame("var x = (/** @type {foo} */ (obj.method()), bar);");
1319+
testSame("var x = (/** @type {foo} */ (bar), baz);");
1320+
}
13141321
}

0 commit comments

Comments
 (0)