Skip to content

Commit a0793ae

Browse files
author
Kanchalai Tanglertsampan
committed
Rename resolvedJsxType to be resolvedJSXElementAttributesType for clarification
1 parent cd5a6cc commit a0793ae

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

src/compiler/checker.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10870,17 +10870,22 @@ namespace ts {
1087010870
}
1087110871

1087210872
/**
10873-
* Given React element instance type and the class type, resolve the Jsx type
10874-
* Pass elemType to handle individual type in the union typed element type.
10875-
*/
10876-
function getResolvedJsxType(node: JsxOpeningLikeElement, elemType?: Type, elemClassType?: Type): Type {
10873+
* Resolve attributes type of the given node. The function is intended to initally be called from getJsxElementAttributesType which already handle JSX-intrinsic-element.
10874+
* @param node a non-instrinsic JSXOPeningLikeElement
10875+
* @param elemType an instance type of the given node
10876+
* @param elemClassType a JSX-ElementClass type. This is a result of looking up ElementClass interface in the JSX global (imported from react.d.ts)
10877+
* @return attributes'type if able to resolve the type of node
10878+
* anyType if there is no type ElementAttributesProperty or there is an error
10879+
* emptyObjectType if there is no "prop" in the element instance type
10880+
**/
10881+
function resolveJsxElementAttributesType(node: JsxOpeningLikeElement, elemType?: Type, elemClassType?: Type): Type {
1087710882
if (!elemType) {
1087810883
elemType = checkExpression(node.tagName);
1087910884
}
1088010885
if (elemType.flags & TypeFlags.Union) {
1088110886
const types = (<TypeOperatorType>elemType).types;
1088210887
return getUnionType(types.map(type => {
10883-
return getResolvedJsxType(node, type, elemClassType);
10888+
return resolveJsxElementAttributesType(node, type, elemClassType);
1088410889
}), /*subtypeReduction*/ true);
1088510890
}
1088610891

@@ -10990,30 +10995,31 @@ namespace ts {
1099010995
}
1099110996

1099210997
/**
10993-
* Given an opening/self-closing element, get the 'element attributes type', i.e. the type that tells
10994-
* us which attributes are valid on a given element.
10998+
* Get the attributes type which is the type that indicate which attributes are valid on the given JSXOpeningLikeElement.
10999+
* @param node a JSXOpeningLikeElement node
11000+
* @return an attributes type of the given node
1099511001
*/
1099611002
function getJsxElementAttributesType(node: JsxOpeningLikeElement): Type {
1099711003
const links = getNodeLinks(node);
10998-
if (!links.resolvedJsxType) {
11004+
if (!links.resolvedJsxElementAttributesType) {
1099911005
if (isJsxIntrinsicIdentifier(node.tagName)) {
1100011006
const symbol = getIntrinsicTagSymbol(node);
1100111007
if (links.jsxFlags & JsxFlags.IntrinsicNamedElement) {
11002-
return links.resolvedJsxType = getTypeOfSymbol(symbol);
11008+
return links.resolvedJsxElementAttributesType = getTypeOfSymbol(symbol);
1100311009
}
1100411010
else if (links.jsxFlags & JsxFlags.IntrinsicIndexedElement) {
11005-
return links.resolvedJsxType = getIndexInfoOfSymbol(symbol, IndexKind.String).type;
11011+
return links.resolvedJsxElementAttributesType = getIndexInfoOfSymbol(symbol, IndexKind.String).type;
1100611012
}
1100711013
else {
11008-
return links.resolvedJsxType = unknownType;
11014+
return links.resolvedJsxElementAttributesType = unknownType;
1100911015
}
1101011016
}
1101111017
else {
1101211018
const elemClassType = getJsxGlobalElementClassType();
11013-
return links.resolvedJsxType = getResolvedJsxType(node, undefined, elemClassType);
11019+
return links.resolvedJsxElementAttributesType = resolveJsxElementAttributesType(node, undefined, elemClassType);
1101411020
}
1101511021
}
11016-
return links.resolvedJsxType;
11022+
return links.resolvedJsxElementAttributesType;
1101711023
}
1101811024

1101911025
/**

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,7 @@ namespace ts {
23632363
isVisible?: boolean; // Is this node visible
23642364
hasReportedStatementInAmbientContext?: boolean; // Cache boolean if we report statements in ambient context
23652365
jsxFlags?: JsxFlags; // flags for knowing what kind of element/attributes we're dealing with
2366-
resolvedJsxType?: Type; // resolved element attributes type of a JSX openinglike element
2366+
resolvedJsxElementAttributesType?: Type; // resolved element attributes type of a JSX openinglike element
23672367
hasSuperCall?: boolean; // recorded result when we try to find super-call. We only try to find one if this flag is undefined, indicating that we haven't made an attempt.
23682368
superCall?: ExpressionStatement; // Cached first super-call found in the constructor. Used in checking whether super is called before this-accessing
23692369
switchTypes?: Type[]; // Cached array of switch case expression types

0 commit comments

Comments
 (0)