Skip to content

Commit f2146a6

Browse files
authored
Fix isInJsxText after JSXOpeningElement with type arguments (#34958)
* Fix `isInJsxText` after JSXOpeningElement with type arguments * Do the same thing a different way
1 parent b9fe84e commit f2146a6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/services/completions.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,16 @@ namespace ts.Completions {
16881688

16891689
if (contextToken.kind === SyntaxKind.GreaterThanToken && contextToken.parent) {
16901690
if (contextToken.parent.kind === SyntaxKind.JsxOpeningElement) {
1691-
return true;
1691+
// Two possibilities:
1692+
// 1. <div>/**/
1693+
// - contextToken: GreaterThanToken (before cursor)
1694+
// - location: JSXElement
1695+
// - different parents (JSXOpeningElement, JSXElement)
1696+
// 2. <Component<string> /**/>
1697+
// - contextToken: GreaterThanToken (before cursor)
1698+
// - location: GreaterThanToken (after cursor)
1699+
// - same parent (JSXOpeningElement)
1700+
return location.parent.kind !== SyntaxKind.JsxOpeningElement;
16921701
}
16931702

16941703
if (contextToken.parent.kind === SyntaxKind.JsxClosingElement || contextToken.parent.kind === SyntaxKind.JsxSelfClosingElement) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /a.tsx
4+
////declare const React: any;
5+
////declare function CustomComponent<T>(props: { name: string }): JSX.Element;
6+
////const element1 = <CustomComponent<string> /*1*/></CustomComponent>;
7+
////const element2 = <CustomComponent<string> /*2*/ />;
8+
9+
['1', '2'].forEach(marker =>
10+
verify.completions({
11+
marker,
12+
exact: [{
13+
name: 'name',
14+
kind: 'JSX attribute',
15+
kindModifiers: 'declare'
16+
}]
17+
})
18+
);

0 commit comments

Comments
 (0)