Skip to content

Commit 0ed523b

Browse files
authored
fix jsx completions after attributes (microsoft#39859)
closes microsoft#39530
1 parent edc88c5 commit 0ed523b

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/services/completions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,20 @@ namespace ts.Completions {
10381038
}
10391039
break;
10401040

1041+
case SyntaxKind.JsxExpression:
1042+
// For `<div foo={true} [||] ></div>`, `parent` will be `{true}` and `previousToken` will be `}`
1043+
if (previousToken.kind === SyntaxKind.CloseBraceToken && currentToken.kind === SyntaxKind.GreaterThanToken) {
1044+
isJsxIdentifierExpected = true;
1045+
}
1046+
break;
1047+
10411048
case SyntaxKind.JsxAttribute:
1049+
// For `<div className="x" [||] ></div>`, `parent` will be JsxAttribute and `previousToken` will be its initializer
1050+
if ((parent as JsxAttribute).initializer === previousToken &&
1051+
previousToken.end < position) {
1052+
isJsxIdentifierExpected = true;
1053+
break;
1054+
}
10421055
switch (previousToken.kind) {
10431056
case SyntaxKind.EqualsToken:
10441057
isJsxInitializer = true;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @jsx: preserve
4+
5+
// @Filename: /a.tsx
6+
////declare namespace JSX {
7+
//// interface Element {}
8+
//// interface IntrinsicElements {
9+
//// div: {
10+
//// /** Doc */
11+
//// foo: boolean;
12+
//// bar: string;
13+
//// "aria-foo": boolean;
14+
//// }
15+
//// }
16+
////}
17+
////
18+
////<div foo /*1*/></div>;
19+
////<div foo={true} /*2*/></div>;
20+
////<div bar="test" /*3*/></div>;
21+
////<div aria-foo /*4*/></div>;
22+
23+
24+
verify.completions({ marker: "1", exact: ["bar", "aria-foo"] });
25+
verify.completions({ marker: "2", exact: ["bar", "aria-foo"] });
26+
verify.completions({ marker: "3", exact: ["foo", "aria-foo"] });
27+
verify.completions({ marker: "4", exact: ["foo", "bar"] });

0 commit comments

Comments
 (0)