From f224b5022e543703fbf9a0d3bf308f3ce5786b7d Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Fri, 31 Jul 2015 00:36:47 -0700 Subject: [PATCH] Offer JSX attribute intellisense between string-literal props and the closing tag. Fixes #4098 --- src/services/services.ts | 18 +++++++++++++----- tests/cases/fourslash/tsxCompletion6.ts | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 tests/cases/fourslash/tsxCompletion6.ts diff --git a/src/services/services.ts b/src/services/services.ts index 8e670268498..49490756470 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3392,16 +3392,24 @@ namespace ts { case SyntaxKind.LessThanSlashToken: case SyntaxKind.SlashToken: case SyntaxKind.Identifier: - if(parent && (parent.kind === SyntaxKind.JsxSelfClosingElement || parent.kind === SyntaxKind.JsxOpeningElement)) { + case SyntaxKind.JsxAttribute: + 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) { + 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) { 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();