Fix isInJsxText after JSXOpeningElement with type arguments (#34958)

* Fix `isInJsxText` after JSXOpeningElement with type arguments

* Do the same thing a different way
This commit is contained in:
Andrew Branch
2019-11-06 15:02:45 -08:00
committed by GitHub
parent b9fe84e591
commit f2146a627c
2 changed files with 28 additions and 1 deletions
+10 -1
View File
@@ -1688,7 +1688,16 @@ namespace ts.Completions {
if (contextToken.kind === SyntaxKind.GreaterThanToken && contextToken.parent) {
if (contextToken.parent.kind === SyntaxKind.JsxOpeningElement) {
return true;
// Two possibilities:
// 1. <div>/**/
// - contextToken: GreaterThanToken (before cursor)
// - location: JSXElement
// - different parents (JSXOpeningElement, JSXElement)
// 2. <Component<string> /**/>
// - contextToken: GreaterThanToken (before cursor)
// - location: GreaterThanToken (after cursor)
// - same parent (JSXOpeningElement)
return location.parent.kind !== SyntaxKind.JsxOpeningElement;
}
if (contextToken.parent.kind === SyntaxKind.JsxClosingElement || contextToken.parent.kind === SyntaxKind.JsxSelfClosingElement) {
@@ -0,0 +1,18 @@
/// <reference path="fourslash.ts" />
// @Filename: /a.tsx
////declare const React: any;
////declare function CustomComponent<T>(props: { name: string }): JSX.Element;
////const element1 = <CustomComponent<string> /*1*/></CustomComponent>;
////const element2 = <CustomComponent<string> /*2*/ />;
['1', '2'].forEach(marker =>
verify.completions({
marker,
exact: [{
name: 'name',
kind: 'JSX attribute',
kindModifiers: 'declare'
}]
})
);