mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-26 09:19:04 -05:00
Merge pull request #4099 from RyanCavanaugh/betterTsxCompletion
Offer JSX attribute intellisense between string-literal props
This commit is contained in:
@@ -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 <JsxOpeningLikeElement>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 <JsxOpeningLikeElement>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 <JsxOpeningLikeElement>parent.parent.parent;
|
||||
}
|
||||
|
||||
if (parent && parent.kind === SyntaxKind.JsxSpreadAttribute) {
|
||||
return <JsxOpeningLikeElement>parent.parent;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
15
tests/cases/fourslash/tsxCompletion6.ts
Normal file
15
tests/cases/fourslash/tsxCompletion6.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//@Filename: file.tsx
|
||||
//// declare module JSX {
|
||||
//// interface Element { }
|
||||
//// interface IntrinsicElements {
|
||||
//// div: { ONE: string; TWO: number; }
|
||||
//// }
|
||||
//// }
|
||||
//// var x = <div ONE='hello' /**/ />;
|
||||
|
||||
goTo.marker();
|
||||
|
||||
verify.completionListContains("TWO");
|
||||
verify.not.completionListAllowsNewIdentifier();
|
||||
17
tests/cases/fourslash/tsxCompletion7.ts
Normal file
17
tests/cases/fourslash/tsxCompletion7.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//@Filename: file.tsx
|
||||
//// declare module JSX {
|
||||
//// interface Element { }
|
||||
//// interface IntrinsicElements {
|
||||
//// div: { ONE: string; TWO: number; }
|
||||
//// }
|
||||
//// }
|
||||
//// let y = { ONE: '' };
|
||||
//// var x = <div {...y} /**/ />;
|
||||
|
||||
goTo.marker();
|
||||
|
||||
verify.completionListContains("ONE");
|
||||
verify.completionListContains("TWO");
|
||||
verify.not.completionListAllowsNewIdentifier();
|
||||
Reference in New Issue
Block a user