fix jsx completions after attributes (#39859)

closes #39530
This commit is contained in:
Zen 2020-08-14 07:14:12 +08:00 committed by GitHub
parent edc88c51ca
commit 0ed523bb60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View File

@ -1038,7 +1038,20 @@ namespace ts.Completions {
}
break;
case SyntaxKind.JsxExpression:
// For `<div foo={true} [||] ></div>`, `parent` will be `{true}` and `previousToken` will be `}`
if (previousToken.kind === SyntaxKind.CloseBraceToken && currentToken.kind === SyntaxKind.GreaterThanToken) {
isJsxIdentifierExpected = true;
}
break;
case SyntaxKind.JsxAttribute:
// For `<div className="x" [||] ></div>`, `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;

View File

@ -0,0 +1,27 @@
/// <reference path="fourslash.ts" />
// @jsx: preserve
// @Filename: /a.tsx
////declare namespace JSX {
//// interface Element {}
//// interface IntrinsicElements {
//// div: {
//// /** Doc */
//// foo: boolean;
//// bar: string;
//// "aria-foo": boolean;
//// }
//// }
////}
////
////<div foo /*1*/></div>;
////<div foo={true} /*2*/></div>;
////<div bar="test" /*3*/></div>;
////<div aria-foo /*4*/></div>;
verify.completions({ marker: "1", exact: ["bar", "aria-foo"] });
verify.completions({ marker: "2", exact: ["bar", "aria-foo"] });
verify.completions({ marker: "3", exact: ["foo", "aria-foo"] });
verify.completions({ marker: "4", exact: ["foo", "bar"] });