mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-27 22:39:59 -05:00
Introduce more caching and deferral into jsx checking (#25302)
* Introduce more caching and deferral into jsx checking * Accept baseline with removed duplicated error
This commit is contained in:
@@ -16365,14 +16365,18 @@ namespace ts {
|
||||
type.flags & TypeFlags.UnionOrIntersection && every((<UnionOrIntersectionType>type).types, isValidSpreadType));
|
||||
}
|
||||
|
||||
function checkJsxSelfClosingElement(node: JsxSelfClosingElement, checkMode: CheckMode | undefined): Type {
|
||||
checkJsxOpeningLikeElementOrOpeningFragment(node, checkMode);
|
||||
function checkJsxSelfClosingElementDeferred(node: JsxSelfClosingElement) {
|
||||
checkJsxOpeningLikeElementOrOpeningFragment(node, CheckMode.Normal);
|
||||
}
|
||||
|
||||
function checkJsxSelfClosingElement(node: JsxSelfClosingElement, _checkMode: CheckMode | undefined): Type {
|
||||
checkNodeDeferred(node);
|
||||
return getJsxElementTypeAt(node) || anyType;
|
||||
}
|
||||
|
||||
function checkJsxElement(node: JsxElement, checkMode: CheckMode | undefined): Type {
|
||||
function checkJsxElementDeferred(node: JsxElement) {
|
||||
// Check attributes
|
||||
checkJsxOpeningLikeElementOrOpeningFragment(node.openingElement, checkMode);
|
||||
checkJsxOpeningLikeElementOrOpeningFragment(node.openingElement, CheckMode.Normal);
|
||||
|
||||
// Perform resolution on the closing tag so that rename/go to definition/etc work
|
||||
if (isJsxIntrinsicIdentifier(node.closingElement.tagName)) {
|
||||
@@ -16381,6 +16385,10 @@ namespace ts {
|
||||
else {
|
||||
checkExpression(node.closingElement.tagName);
|
||||
}
|
||||
}
|
||||
|
||||
function checkJsxElement(node: JsxElement, _checkMode: CheckMode | undefined): Type {
|
||||
checkNodeDeferred(node);
|
||||
|
||||
return getJsxElementTypeAt(node) || anyType;
|
||||
}
|
||||
@@ -16661,12 +16669,24 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getJsxNamespaceAt(location: Node | undefined): Symbol {
|
||||
const namespaceName = getJsxNamespace(location);
|
||||
const resolvedNamespace = resolveName(location, namespaceName, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined, namespaceName, /*isUse*/ false);
|
||||
if (resolvedNamespace) {
|
||||
const candidate = getSymbol(getExportsOfSymbol(resolveSymbol(resolvedNamespace)), JsxNames.JSX, SymbolFlags.Namespace);
|
||||
if (candidate) {
|
||||
return candidate;
|
||||
const links = location && getNodeLinks(location);
|
||||
if (links && links.jsxNamespace) {
|
||||
return links.jsxNamespace;
|
||||
}
|
||||
if (!links || links.jsxNamespace !== false) {
|
||||
const namespaceName = getJsxNamespace(location);
|
||||
const resolvedNamespace = resolveName(location, namespaceName, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined, namespaceName, /*isUse*/ false);
|
||||
if (resolvedNamespace) {
|
||||
const candidate = getSymbol(getExportsOfSymbol(resolveSymbol(resolvedNamespace)), JsxNames.JSX, SymbolFlags.Namespace);
|
||||
if (candidate) {
|
||||
if (links) {
|
||||
links.jsxNamespace = candidate;
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
if (links) {
|
||||
links.jsxNamespace = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// JSX global fallback
|
||||
@@ -17146,7 +17166,7 @@ namespace ts {
|
||||
// sourceAttributesType is a type of an attributes properties.
|
||||
// i.e <div attr1={10} attr2="string" />
|
||||
// attr1 and attr2 are treated as JSXAttributes attached in the JsxOpeningLikeElement as "attributes".
|
||||
const sourceAttributesType = createJsxAttributesTypeFromAttributesProperty(openingLikeElement, checkMode);
|
||||
const sourceAttributesType = checkExpressionCached(openingLikeElement.attributes, checkMode);
|
||||
|
||||
// Check if sourceAttributesType assignable to targetAttributesType though this check will allow excess properties
|
||||
const isSourceAttributeTypeAssignableToTarget = isTypeAssignableTo(sourceAttributesType, targetAttributesType);
|
||||
@@ -26115,6 +26135,12 @@ namespace ts {
|
||||
case SyntaxKind.ClassExpression:
|
||||
checkClassExpressionDeferred(<ClassExpression>node);
|
||||
break;
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
checkJsxSelfClosingElementDeferred(<JsxSelfClosingElement>node);
|
||||
break;
|
||||
case SyntaxKind.JsxElement:
|
||||
checkJsxElementDeferred(<JsxElement>node);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3658,6 +3658,7 @@ namespace ts {
|
||||
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.
|
||||
superCall?: SuperCall; // Cached first super-call found in the constructor. Used in checking whether super is called before this-accessing
|
||||
switchTypes?: Type[]; // Cached array of switch case expression types
|
||||
jsxNamespace?: Symbol | false; // Resolved jsx namespace symbol for this node
|
||||
}
|
||||
|
||||
export const enum TypeFlags {
|
||||
|
||||
Reference in New Issue
Block a user