Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"] });