Add intra expression inference sites based on JSX attributes#52837
Merged
weswigham merged 3 commits intomicrosoft:mainfrom Mar 15, 2023
Merged
Add intra expression inference sites based on JSX attributes#52837weswigham merged 3 commits intomicrosoft:mainfrom
weswigham merged 3 commits intomicrosoft:mainfrom
Conversation
Andarist
commented
Feb 18, 2023
src/compiler/checker.ts
Outdated
Comment on lines
30199
to
30205
| 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); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
It's almost a 100% copy-paste from checkObjectLiteral:
https://github.dev/microsoft/TypeScript/blob/d87d0adcd30ac285393bf3bfbbb4d94d50c4f3c9/src/compiler/checker.ts#L29941-L29947
weswigham
requested changes
Mar 14, 2023
Member
weswigham
left a comment
There was a problem hiding this comment.
This looks pretty good, just a small nit.
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)) { |
Member
There was a problem hiding this comment.
Suggested change
| 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.
Contributor
Author
There was a problem hiding this comment.
pushed out the requested change
weswigham
approved these changes
Mar 15, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #52798
fixes #52786