From f2146a627ce15a439e0fb3daffd1bc81d4b5a3af Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 6 Nov 2019 15:02:45 -0800 Subject: [PATCH] Fix `isInJsxText` after JSXOpeningElement with type arguments (#34958) * Fix `isInJsxText` after JSXOpeningElement with type arguments * Do the same thing a different way --- src/services/completions.ts | 11 ++++++++++- .../completionsJsxAttributeGeneric.ts | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionsJsxAttributeGeneric.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index 076cc32f374..c47b4dab95a 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -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.
/**/ + // - contextToken: GreaterThanToken (before cursor) + // - location: JSXElement + // - different parents (JSXOpeningElement, JSXElement) + // 2. /**/> + // - 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) { diff --git a/tests/cases/fourslash/completionsJsxAttributeGeneric.ts b/tests/cases/fourslash/completionsJsxAttributeGeneric.ts new file mode 100644 index 00000000000..9180c691f09 --- /dev/null +++ b/tests/cases/fourslash/completionsJsxAttributeGeneric.ts @@ -0,0 +1,18 @@ +/// + +// @Filename: /a.tsx +////declare const React: any; +////declare function CustomComponent(props: { name: string }): JSX.Element; +////const element1 = /*1*/>; +////const element2 = /*2*/ />; + +['1', '2'].forEach(marker => + verify.completions({ + marker, + exact: [{ + name: 'name', + kind: 'JSX attribute', + kindModifiers: 'declare' + }] + }) +);