Skip to content

Commit

Permalink
Attach JSDoc to correct nodes in array pattern with elision
Browse files Browse the repository at this point in the history
e.g. const [, /** string */ str] = [];

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=208130879
  • Loading branch information
lauraharker authored and tjgq committed Aug 10, 2018
1 parent 5f15308 commit 6eba035
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/com/google/javascript/jscomp/parsing/parser/Parser.java
Expand Up @@ -3683,8 +3683,9 @@ private ParseTree parseArrayPattern(PatternKind kind) {
eat(TokenType.OPEN_SQUARE);
while (peek(TokenType.COMMA) || peekArrayPatternElement()) {
if (peek(TokenType.COMMA)) {
SourcePosition nullStart = getTreeStartLocation();
eat(TokenType.COMMA);
elements.add(new NullTree(getTreeLocation(getTreeStartLocation())));
elements.add(new NullTree(getTreeLocation(nullStart)));
} else {
elements.add(parsePatternAssignmentTarget(kind));

Expand Down
16 changes: 16 additions & 0 deletions test/com/google/javascript/jscomp/parsing/ParserTest.java
Expand Up @@ -1123,6 +1123,22 @@ public void testInlineJSDocAttachmentToArrayPatElementQualifiedNameWithDefault()
assertNodeHasJSDocInfoWithJSType(xYZName, STRING_TYPE);
}

public void testInlineJSDocAttachmentToArrayPatElementAfterElision() {
Node letNode =
parse("let [, /** string */ x] = [];")
.getFirstChild();
assertNode(letNode).hasType(Token.LET);

Node destructuringLhs = letNode.getFirstChild();
Node arrayPattern = destructuringLhs.getFirstChild();
Node empty = arrayPattern.getFirstChild();
assertNode(empty).hasToken(Token.EMPTY);
assertNode(empty).hasCharno(5);
assertNode(empty).hasLength(1);
Node xVarName = arrayPattern.getSecondChild();
assertNodeHasJSDocInfoWithJSType(xVarName, STRING_TYPE);
}

public void testInlineJSDocAttachmentToObjLitNormalProp() {
Node letNode = parse("let x = { normalProp: /** string */ normalPropTarget };").getFirstChild();
assertNode(letNode).hasType(Token.LET);
Expand Down

0 comments on commit 6eba035

Please sign in to comment.