Skip to content

Commit

Permalink
Fix completion record for labeled statement
Browse files Browse the repository at this point in the history
`{labelAlthoughIMeantItToBeAKey: value}` strikes again :)
  • Loading branch information
addaleax committed Apr 20, 2021
1 parent 21ef7c8 commit 67d5842
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Expand Up @@ -21,6 +21,9 @@ const x = (n) => do {
}
{ break; "l" }
case 7:
{ a: "m" }
break;
case 8:
}
}

Expand All @@ -31,4 +34,5 @@ expect(x(3)).toBeUndefined()
expect(x(4)).toBe("g")
expect(x(5)).toBe("j")
expect(x(6)).toBe("k")
expect(x(7)).toBeUndefined()
expect(x(7)).toBe("m")
expect(x(8)).toBeUndefined()
Expand Up @@ -21,5 +21,8 @@ const x = (n) => do {
}
{ break; "l" }
case 7:
{ a: "m" }
break;
case 8:
}
}
Expand Up @@ -62,5 +62,9 @@ const x = n => function () {
}

case 7:
{
a: return "m";
}
case 8:
}
}();
7 changes: 6 additions & 1 deletion packages/babel-traverse/src/path/family.ts
Expand Up @@ -210,7 +210,12 @@ function _getCompletionRecords(
if (path.isIfStatement()) {
records = addCompletionRecords(path.get("consequent"), records, context);
records = addCompletionRecords(path.get("alternate"), records, context);
} else if (path.isDoExpression() || path.isFor() || path.isWhile()) {
} else if (
path.isDoExpression() ||
path.isFor() ||
path.isWhile() ||
path.isLabeledStatement()
) {
// @ts-expect-error(flow->ts): todo
records = addCompletionRecords(path.get("body"), records, context);
} else if (path.isProgram() || path.isBlockStatement()) {
Expand Down

0 comments on commit 67d5842

Please sign in to comment.