From f62cf272b6f87756ad64d2621454d5ca8a2d895c Mon Sep 17 00:00:00 2001 From: Zzzen <843968788@qq.com> Date: Sat, 1 Aug 2020 17:02:17 +0800 Subject: [PATCH] fix jsx completions after attributes closes #39530 --- src/services/completions.ts | 13 +++++++++ .../fourslash/completionsJsxAttribute2.ts | 27 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/cases/fourslash/completionsJsxAttribute2.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index 67b9f0d94ce80..2bec3132df955 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1038,7 +1038,20 @@ namespace ts.Completions { } break; + case SyntaxKind.JsxExpression: + // For `
`, `parent` will be `{true}` and `previousToken` will be `}` + if (previousToken.kind === SyntaxKind.CloseBraceToken && currentToken.kind === SyntaxKind.GreaterThanToken) { + isJsxIdentifierExpected = true; + } + break; + case SyntaxKind.JsxAttribute: + // For ``, `parent` will be JsxAttribute and `previousToken` will be its initializer + if ((parent as JsxAttribute).initializer === previousToken && + previousToken.end < position) { + isJsxIdentifierExpected = true; + break; + } switch (previousToken.kind) { case SyntaxKind.EqualsToken: isJsxInitializer = true; diff --git a/tests/cases/fourslash/completionsJsxAttribute2.ts b/tests/cases/fourslash/completionsJsxAttribute2.ts new file mode 100644 index 0000000000000..1b25f220a98d8 --- /dev/null +++ b/tests/cases/fourslash/completionsJsxAttribute2.ts @@ -0,0 +1,27 @@ +///