Skip to content

Commit a0ebbfb

Browse files
author
Andy
authored
Fix JSX completions after boolean property (#26943)
1 parent 6fb0f68 commit a0ebbfb

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/services/completions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,10 @@ namespace ts.Completions {
986986
break;
987987
case SyntaxKind.Identifier:
988988
// For `<div x=[|f/**/|]`, `parent` will be `x` and `previousToken.parent` will be `f` (which is its own JsxAttribute)
989-
if (parent !== previousToken.parent && !(parent as JsxAttribute).initializer) {
989+
// Note for `<div someBool f>` we don't want to treat this as a jsx inializer, instead it's the attribute name.
990+
if (parent !== previousToken.parent &&
991+
!(parent as JsxAttribute).initializer &&
992+
findChildOfKind(parent, SyntaxKind.EqualsToken, sourceFile)) {
990993
isJsxInitializer = previousToken as Identifier;
991994
}
992995
}

tests/cases/fourslash/completionsJsxAttribute.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,22 @@
88
//// interface IntrinsicElements {
99
//// div: {
1010
//// /** Doc */
11-
//// foo: string
11+
//// foo: boolean;
12+
//// bar: string;
1213
//// }
1314
//// }
1415
////}
1516
////
1617
////<div /**/></div>;
1718

18-
goTo.marker();
19-
verify.completionEntryDetailIs("foo", "(JSX attribute) foo: string", "Doc", "JSX attribute", []);
19+
const exact: ReadonlyArray<FourSlashInterface.ExpectedCompletionEntry> = [
20+
{ name: "foo", kind: "JSX attribute", text: "(JSX attribute) foo: boolean", documentation: "Doc" },
21+
{ name: "bar", kind: "JSX attribute", text: "(JSX attribute) bar: string" },
22+
];
23+
verify.completions({ marker: "", exact });
2024
edit.insert("f");
21-
verify.completionEntryDetailIs("foo", "(JSX attribute) foo: string", "Doc", "JSX attribute", []);
22-
25+
verify.completions({ exact });
26+
edit.insert("oo ");
27+
verify.completions({ exact: exact[1] });
28+
edit.insert("b");
29+
verify.completions({ exact: exact[1] });

0 commit comments

Comments
 (0)