Skip to content

Commit de1ac81

Browse files
authored
Fix isNewIdentifierLocation after async (microsoft#46485)
1 parent ce676d0 commit de1ac81

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/services/completions.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,8 +2209,9 @@ namespace ts.Completions {
22092209
function isNewIdentifierDefinitionLocation(): boolean {
22102210
if (contextToken) {
22112211
const containingNodeKind = contextToken.parent.kind;
2212+
const tokenKind = keywordForNode(contextToken);
22122213
// Previous token may have been a keyword that was converted to an identifier.
2213-
switch (keywordForNode(contextToken)) {
2214+
switch (tokenKind) {
22142215
case SyntaxKind.CommaToken:
22152216
return containingNodeKind === SyntaxKind.CallExpression // func( a, |
22162217
|| containingNodeKind === SyntaxKind.Constructor // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */
@@ -2254,10 +2255,13 @@ namespace ts.Completions {
22542255
case SyntaxKind.TemplateMiddle:
22552256
return containingNodeKind === SyntaxKind.TemplateSpan; // `aa ${10} dd ${|
22562257

2257-
case SyntaxKind.PublicKeyword:
2258-
case SyntaxKind.PrivateKeyword:
2259-
case SyntaxKind.ProtectedKeyword:
2260-
return containingNodeKind === SyntaxKind.PropertyDeclaration; // class A{ public |
2258+
case SyntaxKind.AsyncKeyword:
2259+
return containingNodeKind === SyntaxKind.MethodDeclaration // const obj = { async c|()
2260+
|| containingNodeKind === SyntaxKind.ShorthandPropertyAssignment; // const obj = { async c|
2261+
}
2262+
2263+
if (isClassMemberCompletionKeyword(tokenKind)) {
2264+
return true;
22612265
}
22622266
}
22632267

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// const obj = {
4+
//// a() {},
5+
//// async b/*1*/
6+
//// };
7+
//// const obj2 = {
8+
//// async /*2*/
9+
//// };
10+
//// class Foo {
11+
//// async b/*3*/
12+
//// }
13+
//// class Foo2 {
14+
//// async /*4*/
15+
//// }
16+
//// class Bar {
17+
//// static async b/*5*/
18+
//// }
19+
20+
test.markerNames().forEach(marker => {
21+
verify.completions({
22+
marker,
23+
isNewIdentifierLocation: true
24+
});
25+
});

0 commit comments

Comments
 (0)