-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add intra expression inference sites based on JSX attributes #52837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add intra expression inference sites based on JSX attributes #52837
Conversation
src/compiler/checker.ts
Outdated
if (contextualType && checkMode && checkMode & CheckMode.Inferential && !(checkMode & CheckMode.SkipContextSensitive) && | ||
attributeDecl.initializer && isJsxExpression(attributeDecl.initializer) && attributeDecl.initializer.expression && isContextSensitive(attributeDecl.initializer.expression)) { | ||
const inferenceContext = getInferenceContext(attributes); | ||
Debug.assert(inferenceContext); // In CheckMode.Inferential we should always have an inference context | ||
const inferenceNode = attributeDecl.initializer.expression; | ||
addIntraExpressionInferenceSite(inferenceContext, inferenceNode, exprType); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's almost a 100% copy-paste from checkObjectLiteral
:
https://github.dev/microsoft/TypeScript/blob/d87d0adcd30ac285393bf3bfbbb4d94d50c4f3c9/src/compiler/checker.ts#L29941-L29947
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good, just a small nit.
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) && | ||
attributeDecl.initializer && isJsxExpression(attributeDecl.initializer) && attributeDecl.initializer.expression && isContextSensitive(attributeDecl.initializer.expression)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attributeDecl.initializer && isJsxExpression(attributeDecl.initializer) && attributeDecl.initializer.expression && isContextSensitive(attributeDecl.initializer.expression)) { | |
isContextSensitive(attributeDecl)) { |
since it handles attribute declarations and does all that unpacking and existence checking inside it already and there's no need to duplicate the checks. Just toss some !
on the reference below for control flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushed out the requested change
fixes #52798
fixes #52786