Skip to content

Commit 06aeab8

Browse files
author
Andy
authored
Minor cleanup for label completions (#20502)
1 parent 8dca431 commit 06aeab8

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/services/completions.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ namespace ts.Completions {
4040
}
4141

4242
const contextToken = findPrecedingToken(position, sourceFile);
43-
if (isInBreakOrContinue(contextToken)) {
44-
return getLabelCompletionAtPosition(contextToken);
43+
if (contextToken && isBreakOrContinueStatement(contextToken.parent)
44+
&& (contextToken.kind === SyntaxKind.BreakKeyword || contextToken.kind === SyntaxKind.ContinueKeyword || contextToken.kind === SyntaxKind.Identifier)) {
45+
return getLabelCompletionAtPosition(contextToken.parent);
4546
}
4647

4748
const completionData = getCompletionData(typeChecker, log, sourceFile, position, allSourceFiles, options, compilerOptions.target);
@@ -228,13 +229,8 @@ namespace ts.Completions {
228229
return uniques;
229230
}
230231

231-
function isInBreakOrContinue(contextToken: Node): boolean {
232-
return contextToken && isBreakOrContinueStatement(contextToken.parent) &&
233-
(contextToken.kind === SyntaxKind.BreakKeyword || contextToken.kind === SyntaxKind.ContinueKeyword || contextToken.kind === SyntaxKind.Identifier);
234-
}
235-
236-
function getLabelCompletionAtPosition(contextToken: Node): CompletionInfo | undefined {
237-
const entries = getLabelStatementCompletions(contextToken.parent);
232+
function getLabelCompletionAtPosition(node: BreakOrContinueStatement): CompletionInfo | undefined {
233+
const entries = getLabelStatementCompletions(node);
238234
if (entries.length) {
239235
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries };
240236
}

0 commit comments

Comments
 (0)