Fix isNewIdentifierLocation after async (#46485)

This commit is contained in:
Andrew Branch 2021-10-22 12:28:04 -07:00 committed by GitHub
parent ce676d0963
commit de1ac8191e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 5 deletions

View file

@ -2209,8 +2209,9 @@ namespace ts.Completions {
function isNewIdentifierDefinitionLocation(): boolean {
if (contextToken) {
const containingNodeKind = contextToken.parent.kind;
const tokenKind = keywordForNode(contextToken);
// Previous token may have been a keyword that was converted to an identifier.
switch (keywordForNode(contextToken)) {
switch (tokenKind) {
case SyntaxKind.CommaToken:
return containingNodeKind === SyntaxKind.CallExpression // func( a, |
|| containingNodeKind === SyntaxKind.Constructor // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */
@ -2254,10 +2255,13 @@ namespace ts.Completions {
case SyntaxKind.TemplateMiddle:
return containingNodeKind === SyntaxKind.TemplateSpan; // `aa ${10} dd ${|
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
return containingNodeKind === SyntaxKind.PropertyDeclaration; // class A{ public |
case SyntaxKind.AsyncKeyword:
return containingNodeKind === SyntaxKind.MethodDeclaration // const obj = { async c|()
|| containingNodeKind === SyntaxKind.ShorthandPropertyAssignment; // const obj = { async c|
}
if (isClassMemberCompletionKeyword(tokenKind)) {
return true;
}
}

View file

@ -0,0 +1,25 @@
/// <reference path="fourslash.ts" />
//// const obj = {
//// a() {},
//// async b/*1*/
//// };
//// const obj2 = {
//// async /*2*/
//// };
//// class Foo {
//// async b/*3*/
//// }
//// class Foo2 {
//// async /*4*/
//// }
//// class Bar {
//// static async b/*5*/
//// }
test.markerNames().forEach(marker => {
verify.completions({
marker,
isNewIdentifierLocation: true
});
});