Skip to content

Commit

Permalink
fix jsx completions after attributes (#39859)
Browse files Browse the repository at this point in the history
closes #39530
  • Loading branch information
Zzzen committed Aug 13, 2020
1 parent edc88c5 commit 0ed523b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions tests/cases/fourslash/completionsJsxAttribute2.ts
Original file line number Diff line number Diff line change
@@ -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"] });

0 comments on commit 0ed523b

Please sign in to comment.