Skip to content

Commit 0417e3f

Browse files
author
Andy
authored
Merge pull request microsoft#14050 from Microsoft/tsx_completion
Detect non-tag uses of `<` in TSX completions
2 parents 72877ed + aa5c88f commit 0417e3f

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

src/services/completions.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -915,13 +915,29 @@ namespace ts.Completions {
915915
}
916916
}
917917
else if (sourceFile.languageVariant === LanguageVariant.JSX) {
918-
if (kind === SyntaxKind.LessThanToken) {
919-
isRightOfOpenTag = true;
920-
location = contextToken;
921-
}
922-
else if (kind === SyntaxKind.SlashToken && contextToken.parent.kind === SyntaxKind.JsxClosingElement) {
923-
isStartingCloseTag = true;
924-
location = contextToken;
918+
switch (contextToken.parent.kind) {
919+
case SyntaxKind.JsxClosingElement:
920+
if (kind === SyntaxKind.SlashToken) {
921+
isStartingCloseTag = true;
922+
location = contextToken;
923+
}
924+
break;
925+
926+
case SyntaxKind.BinaryExpression:
927+
if (!((contextToken.parent as BinaryExpression).left.flags & NodeFlags.ThisNodeHasError)) {
928+
// It has a left-hand side, so we're not in an opening JSX tag.
929+
break;
930+
}
931+
// fall through
932+
933+
case SyntaxKind.JsxSelfClosingElement:
934+
case SyntaxKind.JsxElement:
935+
case SyntaxKind.JsxOpeningElement:
936+
if (kind === SyntaxKind.LessThanToken) {
937+
isRightOfOpenTag = true;
938+
location = contextToken;
939+
}
940+
break;
925941
}
926942
}
927943
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////var x: Array<numb/*a*/;
4+
////[].map<numb/*b*/;
5+
////1 < Infini/*c*/;
6+
7+
for (const marker of ["a", "b"]) {
8+
goTo.marker(marker);
9+
verify.completionListContains("number");
10+
verify.not.completionListContains("SVGNumber");
11+
};
12+
13+
goTo.marker("c");
14+
verify.completionListContains("Infinity");

0 commit comments

Comments
 (0)