Handle type argument lists as jsx completion starts (#28493)

* Handle type argument lists as jsx completion starts

* preceeding -> preceding
This commit is contained in:
Wesley Wigham
2018-11-12 16:30:04 -08:00
committed by GitHub
parent 40bd7c89ab
commit d99de73e85
2 changed files with 36 additions and 0 deletions

View File

@@ -1532,6 +1532,7 @@ namespace ts.Completions {
if (contextToken) {
const parent = contextToken.parent;
switch (contextToken.kind) {
case SyntaxKind.GreaterThanToken: // End of a type argument list
case SyntaxKind.LessThanSlashToken:
case SyntaxKind.SlashToken:
case SyntaxKind.Identifier:
@@ -1540,6 +1541,10 @@ namespace ts.Completions {
case SyntaxKind.JsxAttribute:
case SyntaxKind.JsxSpreadAttribute:
if (parent && (parent.kind === SyntaxKind.JsxSelfClosingElement || parent.kind === SyntaxKind.JsxOpeningElement)) {
if (contextToken.kind === SyntaxKind.GreaterThanToken) {
const precedingToken = findPrecedingToken(contextToken.pos, sourceFile, /*startNode*/ undefined);
if (!(parent as JsxOpeningLikeElement).typeArguments || (precedingToken && precedingToken.kind === SyntaxKind.SlashToken)) break;
}
return <JsxOpeningLikeElement>parent;
}
else if (parent.kind === SyntaxKind.JsxAttribute) {

View File

@@ -0,0 +1,31 @@
/// <reference path="fourslash.ts" />
// @jsx: preserve
// @skipLibCheck: true
// @Filename: file.tsx
//// declare module JSX {
//// interface Element { }
//// interface IntrinsicElements {
//// }
//// interface ElementAttributesProperty { props; }
//// }
////
////class Table<P> {
//// constructor(public props: P) {}
////}
////
////type Props = { widthInCol: number; text: string; };
////
/////**
//// * @param width {number} Table width in px
//// */
////function createTable(width) {
//// return <Table<Props> /*1*/ />
////}
////
////createTable(800);
verify.completions({
marker: "1",
includes: ["widthInCol", "text"]
});