Add intra expression inference sites based on JSX attributes (#52837)

This commit is contained in:
Mateusz Burzyński
2023-03-15 10:42:40 -07:00
committed by GitHub
parent 2b9d792828
commit 78089b4964
4 changed files with 692 additions and 3 deletions
+9 -3
View File
@@ -30230,7 +30230,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
*/
function createJsxAttributesTypeFromAttributesProperty(openingLikeElement: JsxOpeningLikeElement, checkMode: CheckMode | undefined) {
const attributes = openingLikeElement.attributes;
const attributesType = getContextualType(attributes, ContextFlags.None);
const contextualType = getContextualType(attributes, ContextFlags.None);
const allAttributesTable = strictNullChecks ? createSymbolTable() : undefined;
let attributesTable = createSymbolTable();
let spread: Type = emptyJsxObjectType;
@@ -30259,12 +30259,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (attributeDecl.name.escapedText === jsxChildrenPropertyName) {
explicitlySpecifyChildrenAttribute = true;
}
if (attributesType) {
const prop = getPropertyOfType(attributesType, member.escapedName);
if (contextualType) {
const prop = getPropertyOfType(contextualType, member.escapedName);
if (prop && prop.declarations && isDeprecatedSymbol(prop)) {
addDeprecatedSuggestion(attributeDecl.name, prop.declarations, attributeDecl.name.escapedText as string);
}
}
if (contextualType && checkMode && checkMode & CheckMode.Inferential && !(checkMode & CheckMode.SkipContextSensitive) && isContextSensitive(attributeDecl)) {
const inferenceContext = getInferenceContext(attributes);
Debug.assert(inferenceContext); // In CheckMode.Inferential we should always have an inference context
const inferenceNode = (attributeDecl.initializer as JsxExpression).expression!;
addIntraExpressionInferenceSite(inferenceContext, inferenceNode, exprType);
}
}
else {
Debug.assert(attributeDecl.kind === SyntaxKind.JsxSpreadAttribute);