-
Notifications
You must be signed in to change notification settings - Fork 49.7k
[compiler][newinference] Update fixtures #33471
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 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
49 changes: 49 additions & 0 deletions
49
...piler/src/__tests__/fixtures/compiler/error.invalid-hoisting-setstate.expect.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
|
|
||
| ## Input | ||
|
|
||
| ```javascript | ||
| import {useEffect, useState} from 'react'; | ||
| import {Stringify} from 'shared-runtime'; | ||
|
|
||
| function Foo() { | ||
| /** | ||
| * Previously, this lowered to | ||
| * $1 = LoadContext capture setState | ||
| * $2 = FunctionExpression deps=$1 context=setState | ||
| * [[ at this point, we freeze the `LoadContext setState` instruction, but it will never be referenced again ]] | ||
| * | ||
| * Now, this function expression directly references `setState`, which freezes | ||
| * the source `DeclareContext HoistedConst setState`. Freezing source identifiers | ||
| * (instead of the one level removed `LoadContext`) is more semantically correct | ||
| * for everything *other* than hoisted context declarations. | ||
| * | ||
| * $2 = Function context=setState | ||
| */ | ||
| useEffect(() => setState(2), []); | ||
|
|
||
| const [state, setState] = useState(0); | ||
| return <Stringify state={state} />; | ||
| } | ||
|
|
||
| export const FIXTURE_ENTRYPOINT = { | ||
| fn: Foo, | ||
| params: [{}], | ||
| sequentialRenders: [{}, {}], | ||
| }; | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| ## Error | ||
|
|
||
| ``` | ||
| 18 | useEffect(() => setState(2), []); | ||
| 19 | | ||
| > 20 | const [state, setState] = useState(0); | ||
| | ^^^^^^^^ InvalidReact: Updating a value used previously in an effect function or as an effect dependency is not allowed. Consider moving the mutation before calling useEffect(). Found mutation of `setState` (20:20) | ||
| 21 | return <Stringify state={state} />; | ||
| 22 | } | ||
| 23 | | ||
| ``` | ||
|
|
||
|
|
File renamed without changes.
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
61 changes: 61 additions & 0 deletions
61
...tests__/fixtures/compiler/error.invalid-jsx-captures-context-variable.expect.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
|
|
||
| ## Input | ||
|
|
||
| ```javascript | ||
| import {Stringify, useIdentity} from 'shared-runtime'; | ||
|
|
||
| function Component({prop1, prop2}) { | ||
| 'use memo'; | ||
|
|
||
| const data = useIdentity( | ||
| new Map([ | ||
| [0, 'value0'], | ||
| [1, 'value1'], | ||
| ]) | ||
| ); | ||
| let i = 0; | ||
| const items = []; | ||
| items.push( | ||
| <Stringify | ||
| key={i} | ||
| onClick={() => data.get(i) + prop1} | ||
| shouldInvokeFns={true} | ||
| /> | ||
| ); | ||
| i = i + 1; | ||
| items.push( | ||
| <Stringify | ||
| key={i} | ||
| onClick={() => data.get(i) + prop2} | ||
| shouldInvokeFns={true} | ||
| /> | ||
| ); | ||
| return <>{items}</>; | ||
| } | ||
|
|
||
| export const FIXTURE_ENTRYPOINT = { | ||
| fn: Component, | ||
| params: [{prop1: 'prop1', prop2: 'prop2'}], | ||
| sequentialRenders: [ | ||
| {prop1: 'prop1', prop2: 'prop2'}, | ||
| {prop1: 'prop1', prop2: 'prop2'}, | ||
| {prop1: 'changed', prop2: 'prop2'}, | ||
| ], | ||
| }; | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| ## Error | ||
|
|
||
| ``` | ||
| 19 | /> | ||
| 20 | ); | ||
| > 21 | i = i + 1; | ||
| | ^ InvalidReact: Updating a value used previously in JSX is not allowed. Consider moving the mutation before the JSX. Found mutation of `i` (21:21) | ||
| 22 | items.push( | ||
| 23 | <Stringify | ||
| 24 | key={i} | ||
| ``` | ||
|
|
||
|
|
||
File renamed without changes.
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
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
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
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
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
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
92 changes: 92 additions & 0 deletions
92
...alled-function-capturing-mutable-values-memoizes-with-captures-values.expect.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
|
|
||
| ## Input | ||
|
|
||
| ```javascript | ||
| // @flow | ||
| /** | ||
| * This hook returns a function that when called with an input object, | ||
| * will return the result of mapping that input with the supplied map | ||
| * function. Results are cached, so if the same input is passed again, | ||
| * the same output object will be returned. | ||
| * | ||
| * Note that this technically violates the rules of React and is unsafe: | ||
| * hooks must return immutable objects and be pure, and a function which | ||
| * captures and mutates a value when called is inherently not pure. | ||
| * | ||
| * However, in this case it is technically safe _if_ the mapping function | ||
| * is pure *and* the resulting objects are never modified. This is because | ||
| * the function only caches: the result of `returnedFunction(someInput)` | ||
| * strictly depends on `returnedFunction` and `someInput`, and cannot | ||
| * otherwise change over time. | ||
| */ | ||
| hook useMemoMap<TInput: interface {}, TOutput>( | ||
| map: TInput => TOutput | ||
| ): TInput => TOutput { | ||
| return useMemo(() => { | ||
| // The original issue is that `cache` was not memoized together with the returned | ||
| // function. This was because neither appears to ever be mutated — the function | ||
| // is known to mutate `cache` but the function isn't called. | ||
| // | ||
| // The fix is to detect cases like this — functions that are mutable but not called - | ||
| // and ensure that their mutable captures are aliased together into the same scope. | ||
| const cache = new WeakMap<TInput, TOutput>(); | ||
| return input => { | ||
| let output = cache.get(input); | ||
| if (output == null) { | ||
| output = map(input); | ||
| cache.set(input, output); | ||
| } | ||
| return output; | ||
| }; | ||
| }, [map]); | ||
| } | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| ## Error | ||
|
|
||
| ``` | ||
| 19 | map: TInput => TOutput | ||
| 20 | ): TInput => TOutput { | ||
| > 21 | return useMemo(() => { | ||
| | ^^^^^^^^^^^^^^^ | ||
| > 22 | // The original issue is that `cache` was not memoized together with the returned | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 23 | // function. This was because neither appears to ever be mutated — the function | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 24 | // is known to mutate `cache` but the function isn't called. | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 25 | // | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 26 | // The fix is to detect cases like this — functions that are mutable but not called - | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 27 | // and ensure that their mutable captures are aliased together into the same scope. | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 28 | const cache = new WeakMap<TInput, TOutput>(); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 29 | return input => { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 30 | let output = cache.get(input); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 31 | if (output == null) { | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 32 | output = map(input); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 33 | cache.set(input, output); | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 34 | } | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 35 | return output; | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 36 | }; | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| > 37 | }, [map]); | ||
| | ^^^^^^^^^^^^ InvalidReact: This argument is a function which may reassign or mutate local variables after render, which can cause inconsistent behavior on subsequent renders. Consider using state instead (21:37) | ||
|
|
||
| InvalidReact: The function modifies a local variable here (33:33) | ||
| 38 | } | ||
| 39 | | ||
| ``` | ||
|
|
||
|
|
File renamed without changes.
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
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
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
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
Oops, something went wrong.
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.
the reassignment is mutating a value captured by jsx, this should have been rejected