diff --git a/src/services/completions.ts b/src/services/completions.ts index 076cc32f3749c..c47b4dab95a07 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 0000000000000..9180c691f09f4 --- /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' + }] + }) +);