diff --git a/src/services/services.ts b/src/services/services.ts index 8e670268498..72b4b617b3a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3392,23 +3392,36 @@ namespace ts { case SyntaxKind.LessThanSlashToken: case SyntaxKind.SlashToken: case SyntaxKind.Identifier: - if(parent && (parent.kind === SyntaxKind.JsxSelfClosingElement || parent.kind === SyntaxKind.JsxOpeningElement)) { + case SyntaxKind.JsxAttribute: + case SyntaxKind.JsxSpreadAttribute: + if (parent && (parent.kind === SyntaxKind.JsxSelfClosingElement || parent.kind === SyntaxKind.JsxOpeningElement)) { return parent; } break; + // The context token is the closing } or " of an attribute, which means + // its parent is a JsxExpression, whose parent is a JsxAttribute, + // whose parent is a JsxOpeningLikeElement + case SyntaxKind.StringLiteral: + if (parent && ((parent.kind === SyntaxKind.JsxAttribute) || (parent.kind === SyntaxKind.JsxSpreadAttribute))) { + return parent.parent; + } + + break; + case SyntaxKind.CloseBraceToken: - // The context token is the closing } of an attribute, which means - // its parent is a JsxExpression, whose parent is a JsxAttribute, - // whose parent is a JsxOpeningLikeElement - if(parent && + if (parent && parent.kind === SyntaxKind.JsxExpression && parent.parent && - parent.parent.kind === SyntaxKind.JsxAttribute) { + (parent.parent.kind === SyntaxKind.JsxAttribute)) { return parent.parent.parent; } + if (parent && parent.kind === SyntaxKind.JsxSpreadAttribute) { + return parent.parent; + } + break; } } diff --git a/tests/cases/fourslash/tsxCompletion6.ts b/tests/cases/fourslash/tsxCompletion6.ts new file mode 100644 index 00000000000..5bb01717be7 --- /dev/null +++ b/tests/cases/fourslash/tsxCompletion6.ts @@ -0,0 +1,15 @@ +/// + +//@Filename: file.tsx +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// div: { ONE: string; TWO: number; } +//// } +//// } +//// var x =
; + +goTo.marker(); + +verify.completionListContains("TWO"); +verify.not.completionListAllowsNewIdentifier(); diff --git a/tests/cases/fourslash/tsxCompletion7.ts b/tests/cases/fourslash/tsxCompletion7.ts new file mode 100644 index 00000000000..ca489b8e0c4 --- /dev/null +++ b/tests/cases/fourslash/tsxCompletion7.ts @@ -0,0 +1,17 @@ +/// + +//@Filename: file.tsx +//// declare module JSX { +//// interface Element { } +//// interface IntrinsicElements { +//// div: { ONE: string; TWO: number; } +//// } +//// } +//// let y = { ONE: '' }; +//// var x =
; + +goTo.marker(); + +verify.completionListContains("ONE"); +verify.completionListContains("TWO"); +verify.not.completionListAllowsNewIdentifier();