Skip to content

Commit 00eb220

Browse files
pyBlobKarl Krausgabritto
authored
Fix completion of partial identifier inside a JsxExpression (#52572)
Co-authored-by: Karl Kraus <karl.kraus@avantagarde-talents.de> Co-authored-by: Gabriela Araujo Britto <gabrielaa@microsoft.com>
1 parent c9b5f2b commit 00eb220

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/services/completions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2899,7 +2899,8 @@ function getCompletionData(
28992899
// First case is for `<div foo={true} [||] />` or `<div foo={true} [||] ></div>`,
29002900
// `parent` will be `{true}` and `previousToken` will be `}`
29012901
// Second case is for `<div foo={true} t[||] ></div>`
2902-
if (previousToken.kind === SyntaxKind.CloseBraceToken || (previousToken.kind === SyntaxKind.Identifier || previousToken.parent.kind === SyntaxKind.JsxAttribute)) {
2902+
// Second case must not match for `<div foo={undefine[||]}></div>`
2903+
if (previousToken.kind === SyntaxKind.CloseBraceToken || (previousToken.kind === SyntaxKind.Identifier && previousToken.parent.kind === SyntaxKind.JsxAttribute)) {
29032904
isJsxIdentifierExpected = true;
29042905
}
29052906
break;

src/testRunner/tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,4 @@ import "./unittests/tsserver/typingsInstaller";
190190
import "./unittests/tsserver/versionCache";
191191
import "./unittests/tsserver/watchEnvironment";
192192
import "./unittests/debugDeprecation";
193-
import "./unittests/tsserver/inconsistentErrorInEditor";
193+
import "./unittests/tsserver/inconsistentErrorInEditor";
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /a.tsx
4+
// @jsx: react
5+
//// declare namespace JSX {
6+
//// interface IntrinsicElements {
7+
//// div: { a: string, b: string }
8+
//// }
9+
//// }
10+
//// const value = "test";
11+
//// <div a={v/**/} />
12+
13+
verify.completions(
14+
{
15+
marker: "",
16+
isNewIdentifierLocation: false,
17+
preferences: {
18+
includeCompletionsWithSnippetText: true,
19+
includeCompletionsWithInsertText: true,
20+
jsxAttributeCompletionStyle: "auto",
21+
},
22+
includes: {
23+
name: "value",
24+
kind: "const",
25+
kindModifiers: "",
26+
sortText: completion.SortText.LocationPriority,
27+
insertText: undefined,
28+
},
29+
},
30+
);

0 commit comments

Comments
 (0)