@@ -12146,7 +12146,8 @@ namespace ts {
12146
12146
* Get JSX attributes type by trying to resolve openingLikeElement as a stateless function component.
12147
12147
* Return all attributes type of resolved call signature including candidate signatures.
12148
12148
* This function assumes that the caller handled other possible element type of the JSX element.
12149
- * This function is a behavior used by language service when looking up completion in JSX element.,
12149
+ * This function is a behavior used by language service when looking up completion in JSX element.
12150
+ *
12150
12151
* @param openingLikeElement a JSX opening-like element to find attributes type
12151
12152
* @param elementType a type of the opening-like element. This elementType can't be an union type
12152
12153
* @param elemInstanceType an element instance type (the result of newing or invoking this tag)
@@ -12203,10 +12204,12 @@ namespace ts {
12203
12204
* declare function Foo(attr: { p1: string}): JSX.Element;
12204
12205
* <Foo p1={10} />; // This function will try resolve "Foo" and return an attributes type of "Foo" which is "{ p1: string }"
12205
12206
*
12206
- * The function is intended to initially be called from getAttributesTypeFromJsxOpeningLikeElement which already handle JSX-intrinsic-element.
12207
+ * The function is intended to initially be called from getAttributesTypeFromJsxOpeningLikeElement which already handle JSX-intrinsic-element..
12208
+ * This function will try to resolve custom JSX attributes type in following order: string literal, stateless function, and stateful component
12209
+ *
12207
12210
* @param openingLikeElement a non-intrinsic JSXOPeningLikeElement
12208
12211
* @param shouldIncludeAllStatelessAttributesType a boolean indicating whether to include all attributes types from all stateless function signature
12209
- * @param elementType an instance type of the given opening-like element
12212
+ * @param elementType an instance type of the given opening-like element. If undefined, the function will check type openinglikeElement's tagname.
12210
12213
* @param elementClassType a JSX-ElementClass type. This is a result of looking up ElementClass interface in the JSX global (imported from react.d.ts)
12211
12214
* @return attributes type if able to resolve the type of node
12212
12215
* anyType if there is no type ElementAttributesProperty or there is an error
@@ -12352,6 +12355,7 @@ namespace ts {
12352
12355
/**
12353
12356
* Get attributes type of the given custom opening-like JSX element.
12354
12357
* The function is intended to be called from a function which has handle intrinsic JSX element already.
12358
+ *
12355
12359
* @param node a custom JSX opening-like element
12356
12360
*/
12357
12361
function getCustomJsxElementAttributesType(node: JsxOpeningLikeElement, shouldIncludeAllStatelessAttributesType: boolean): Type {
@@ -12364,10 +12368,12 @@ namespace ts {
12364
12368
}
12365
12369
12366
12370
/**
12367
- * Get all possible attributes type,especially in the case of overload stateless function component, of the given JSX opening-like element.
12371
+ * Get all possible attributes type, especially for an overload stateless function component, of the given JSX opening-like element.
12368
12372
* This function is called by language service (see: completions-tryGetGlobalSymbols)
12373
+ *
12369
12374
* Because in language service, the given JSX opening-like element may be incomplete and therefore, we can't resolve to exact signature if the element
12370
12375
* is a stateless function component so the best thing to do is return all attributes type from all overloads.
12376
+ *
12371
12377
* @param node a JSX opening-like element to get attributes type for
12372
12378
*/
12373
12379
function getAllAttributesTypeFromJsxOpeningLikeElement(node: JsxOpeningLikeElement): Type {
@@ -12381,6 +12387,7 @@ namespace ts {
12381
12387
12382
12388
/**
12383
12389
* Get the attributes type which is the type that indicate which attributes are valid on the given JSXOpeningLikeElement.
12390
+ *
12384
12391
* @param node a JSXOpeningLikeElement node
12385
12392
* @return an attributes type of the given node
12386
12393
*/
@@ -14052,10 +14059,15 @@ namespace ts {
14052
14059
}
14053
14060
14054
14061
/**
14055
- *
14056
- * @param openingLikeElement
14057
- * @param elementType
14058
- * @param candidatesOutArray
14062
+ * This function is similar to getResolvedSignature but exclusively for trying to resolve JSX stateless-function component.
14063
+ * The main reason we have to use this function because, the caller of this function will already check the type of openingLikeElement's tagname
14064
+ * pass the type as elementType. The elementType can not be a union (as such case should be handled by the caller of this function)
14065
+ * At this point, it is still not sure whether the opening-like element is a stateless function component or not.
14066
+ *
14067
+ * @param openingLikeElement an opening-like JSX element to try to resolve as JSX stateless function
14068
+ * @param elementType an element type of the opneing-like element by checking opening-like element's tagname.
14069
+ * @param candidatesOutArray an array of signature to be filled in by the function. It is passed by signature help in the language service;
14070
+ * the function will fill it up with appropriate candidate signatures
14059
14071
*/
14060
14072
function getResolvedJsxStatelessFunctionSignature(openingLikeElement: JsxOpeningLikeElement, elementType: Type, candidatesOutArray: Signature[]): Signature {
14061
14073
Debug.assert(!(elementType.flags & TypeFlags.Union));
@@ -14080,7 +14092,7 @@ namespace ts {
14080
14092
}
14081
14093
14082
14094
/**
14083
- * Try treating a given opening-like element as stateless function component and try to resolve a signature.
14095
+ * Try treating a given opening-like element as stateless function component and resolve a tag-name to a function signature.
14084
14096
* @param openingLikeElement an JsxOpeningLikeElement we want to try resolve its state-less function if possible
14085
14097
* @param elementType a type of the opening-like JSX element, a result of resolving tagName in opening-like element.
14086
14098
* @param candidatesOutArray an array of signature to be filled in by the function. It is passed by signature help in the language service;
0 commit comments