Fix JSX completions after boolean property (#26943)

This commit is contained in:
Andy
2018-09-06 14:15:12 -07:00
committed by GitHub
parent 6fb0f6818a
commit a0ebbfb8f0
2 changed files with 16 additions and 6 deletions

View File

@@ -986,7 +986,10 @@ namespace ts.Completions {
break;
case SyntaxKind.Identifier:
// For `<div x=[|f/**/|]`, `parent` will be `x` and `previousToken.parent` will be `f` (which is its own JsxAttribute)
if (parent !== previousToken.parent && !(parent as JsxAttribute).initializer) {
// Note for `<div someBool f>` we don't want to treat this as a jsx inializer, instead it's the attribute name.
if (parent !== previousToken.parent &&
!(parent as JsxAttribute).initializer &&
findChildOfKind(parent, SyntaxKind.EqualsToken, sourceFile)) {
isJsxInitializer = previousToken as Identifier;
}
}

View File

@@ -8,15 +8,22 @@
//// interface IntrinsicElements {
//// div: {
//// /** Doc */
//// foo: string
//// foo: boolean;
//// bar: string;
//// }
//// }
////}
////
////<div /**/></div>;
goTo.marker();
verify.completionEntryDetailIs("foo", "(JSX attribute) foo: string", "Doc", "JSX attribute", []);
const exact: ReadonlyArray<FourSlashInterface.ExpectedCompletionEntry> = [
{ name: "foo", kind: "JSX attribute", text: "(JSX attribute) foo: boolean", documentation: "Doc" },
{ name: "bar", kind: "JSX attribute", text: "(JSX attribute) bar: string" },
];
verify.completions({ marker: "", exact });
edit.insert("f");
verify.completionEntryDetailIs("foo", "(JSX attribute) foo: string", "Doc", "JSX attribute", []);
verify.completions({ exact });
edit.insert("oo ");
verify.completions({ exact: exact[1] });
edit.insert("b");
verify.completions({ exact: exact[1] });