-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
[compiler] Type inference for tagged template literals #30869
Merged
+271
−58
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,67 +63,63 @@ function useFragment(_arg1, _arg2) { | |
} | ||
|
||
function Component(props) { | ||
const $ = _c(9); | ||
let t0; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t0 = graphql` | ||
const $ = _c(8); | ||
const post = useFragment( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this fixture has a locally defined |
||
graphql` | ||
fragment F on T { | ||
id | ||
} | ||
`; | ||
$[0] = t0; | ||
} else { | ||
t0 = $[0]; | ||
} | ||
const post = useFragment(t0, props.post); | ||
let t1; | ||
if ($[1] !== post) { | ||
`, | ||
props.post, | ||
); | ||
let t0; | ||
if ($[0] !== post) { | ||
const allUrls = []; | ||
|
||
const { media: t2, comments: t3, urls: t4 } = post; | ||
const media = t2 === undefined ? null : t2; | ||
const { media: t1, comments: t2, urls: t3 } = post; | ||
const media = t1 === undefined ? null : t1; | ||
let t4; | ||
if ($[2] !== t2) { | ||
t4 = t2 === undefined ? [] : t2; | ||
$[2] = t2; | ||
$[3] = t4; | ||
} else { | ||
t4 = $[3]; | ||
} | ||
const comments = t4; | ||
let t5; | ||
if ($[3] !== t3) { | ||
if ($[4] !== t3) { | ||
t5 = t3 === undefined ? [] : t3; | ||
$[3] = t3; | ||
$[4] = t5; | ||
$[4] = t3; | ||
$[5] = t5; | ||
} else { | ||
t5 = $[4]; | ||
t5 = $[5]; | ||
} | ||
const comments = t5; | ||
const urls = t5; | ||
let t6; | ||
if ($[5] !== t4) { | ||
t6 = t4 === undefined ? [] : t4; | ||
$[5] = t4; | ||
$[6] = t6; | ||
} else { | ||
t6 = $[6]; | ||
} | ||
const urls = t6; | ||
let t7; | ||
if ($[7] !== comments.length) { | ||
t7 = (e) => { | ||
if ($[6] !== comments.length) { | ||
t6 = (e) => { | ||
if (!comments.length) { | ||
return; | ||
} | ||
|
||
console.log(comments.length); | ||
}; | ||
$[7] = comments.length; | ||
$[8] = t7; | ||
$[6] = comments.length; | ||
$[7] = t6; | ||
} else { | ||
t7 = $[8]; | ||
t6 = $[7]; | ||
} | ||
const onClick = t7; | ||
const onClick = t6; | ||
|
||
allUrls.push(...urls); | ||
t1 = <Stringify media={media} allUrls={allUrls} onClick={onClick} />; | ||
$[1] = post; | ||
$[2] = t1; | ||
t0 = <Stringify media={media} allUrls={allUrls} onClick={onClick} />; | ||
$[0] = post; | ||
$[1] = t0; | ||
} else { | ||
t1 = $[2]; | ||
t0 = $[1]; | ||
} | ||
return t1; | ||
return t0; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
|
Oops, something went wrong.
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.
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.
Hmm I don't quite understand -- what does creating an intermediate
returnType
do here?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 doesn't really matter in practice, but this ensures we have a place to put the inferred return type of the function (eg from its signature) separately from what we infer about how it's lvalue is used. For example in
foo() && ...
, we would inver the lvalue of thefoo()
call is a primitive bc of the logical expression, but that means the actual call expression's return type information is lost. This way we can still track the actual function return type.