Add github_code/react__react from GitHub - direct commit (part 8)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-keys.js +36 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-call-in-ternary-test.expect.md +58 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-call-in-ternary-test.js +21 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-derived-in-ternary-consequent.expect.md +59 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-derived-in-ternary-consequent.js +16 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-in-ternary-consequent.expect.md +59 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-in-ternary-consequent.js +16 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-in-ternary-test.expect.md +52 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-in-ternary-test.js +16 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-spread-element.expect.md +43 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-spread-element.js +10 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-maybe-alias.expect.md +63 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-maybe-alias.js +19 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-3.expect.md +59 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-3.js +17 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-aliased-mutate-after.expect.md +57 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-aliased-mutate-after.js +16 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-derived-value.expect.md +64 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-derived-value.js +15 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-hook-dep.expect.md +55 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-hook-dep.js +15 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-mutated-after.expect.md +57 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-mutated-after.js +16 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand.expect.md +50 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand.js +13 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-mutated-in-consequent-alternate-both-return.expect.md +67 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-mutated-in-consequent-alternate-both-return.js +17 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-pattern-params.expect.md +63 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-pattern-params.js +11 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-properties.expect.md +25 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-properties.js +7 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-shorthand-method-1.expect.md +67 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-shorthand-method-1.js +16 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-shorthand-method-2.expect.md +76 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-shorthand-method-2.js +16 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-shorthand-method-nested.expect.md +72 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-shorthand-method-nested.js +23 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-values-mutation.expect.md +57 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-values-mutation.js +15 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-values.expect.md +103 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-values.js +39 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-chain-in-logical-expr.expect.md +37 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-chain-in-logical-expr.ts +11 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-chain-in-ternary.expect.md +37 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-chain-in-ternary.ts +11 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-chained.expect.md +29 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-chained.js +3 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-logical.expect.md +52 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-logical.js +13 -0
- github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-simple.expect.md +29 -0
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-keys.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @validatePreserveExistingMemoizationGuarantees
|
| 2 |
+
import {useMemo} from 'react';
|
| 3 |
+
import {Stringify} from 'shared-runtime';
|
| 4 |
+
|
| 5 |
+
// derived from https://github.com/facebook/react/issues/32261
|
| 6 |
+
function Component({items}) {
|
| 7 |
+
const record = useMemo(
|
| 8 |
+
() =>
|
| 9 |
+
Object.fromEntries(
|
| 10 |
+
items.map(item => [item.id, ref => <Stringify ref={ref} {...item} />])
|
| 11 |
+
),
|
| 12 |
+
[items]
|
| 13 |
+
);
|
| 14 |
+
|
| 15 |
+
// Without a declaration for Object.entries(), this would be assumed to mutate
|
| 16 |
+
// `record`, meaning existing memoization couldn't be preserved
|
| 17 |
+
return (
|
| 18 |
+
<div>
|
| 19 |
+
{Object.keys(record).map(id => (
|
| 20 |
+
<Stringify key={id} render={record[id]} />
|
| 21 |
+
))}
|
| 22 |
+
</div>
|
| 23 |
+
);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 27 |
+
fn: Component,
|
| 28 |
+
params: [
|
| 29 |
+
{
|
| 30 |
+
items: [
|
| 31 |
+
{id: '0', name: 'Hello'},
|
| 32 |
+
{id: '1', name: 'World!'},
|
| 33 |
+
],
|
| 34 |
+
},
|
| 35 |
+
],
|
| 36 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-call-in-ternary-test.expect.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {
|
| 6 |
+
createHookWrapper,
|
| 7 |
+
identity,
|
| 8 |
+
CONST_STRING0,
|
| 9 |
+
CONST_STRING1,
|
| 10 |
+
} from 'shared-runtime';
|
| 11 |
+
|
| 12 |
+
function useHook({value}) {
|
| 13 |
+
return {
|
| 14 |
+
getValue() {
|
| 15 |
+
return identity(value);
|
| 16 |
+
},
|
| 17 |
+
}.getValue()
|
| 18 |
+
? CONST_STRING0
|
| 19 |
+
: CONST_STRING1;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 23 |
+
fn: createHookWrapper(useHook),
|
| 24 |
+
params: [{value: 0}],
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
## Code
|
| 30 |
+
|
| 31 |
+
```javascript
|
| 32 |
+
import {
|
| 33 |
+
createHookWrapper,
|
| 34 |
+
identity,
|
| 35 |
+
CONST_STRING0,
|
| 36 |
+
CONST_STRING1,
|
| 37 |
+
} from "shared-runtime";
|
| 38 |
+
|
| 39 |
+
function useHook(t0) {
|
| 40 |
+
const { value } = t0;
|
| 41 |
+
return {
|
| 42 |
+
getValue() {
|
| 43 |
+
return identity(value);
|
| 44 |
+
},
|
| 45 |
+
}.getValue()
|
| 46 |
+
? CONST_STRING0
|
| 47 |
+
: CONST_STRING1;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 51 |
+
fn: createHookWrapper(useHook),
|
| 52 |
+
params: [{ value: 0 }],
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
### Eval output
|
| 58 |
+
(kind: ok) <div>{"result":"global string 1","shouldInvokeFns":true}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-call-in-ternary-test.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
createHookWrapper,
|
| 3 |
+
identity,
|
| 4 |
+
CONST_STRING0,
|
| 5 |
+
CONST_STRING1,
|
| 6 |
+
} from 'shared-runtime';
|
| 7 |
+
|
| 8 |
+
function useHook({value}) {
|
| 9 |
+
return {
|
| 10 |
+
getValue() {
|
| 11 |
+
return identity(value);
|
| 12 |
+
},
|
| 13 |
+
}.getValue()
|
| 14 |
+
? CONST_STRING0
|
| 15 |
+
: CONST_STRING1;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 19 |
+
fn: createHookWrapper(useHook),
|
| 20 |
+
params: [{value: 0}],
|
| 21 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-derived-in-ternary-consequent.expect.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {identity, createHookWrapper} from 'shared-runtime';
|
| 6 |
+
|
| 7 |
+
function useHook({isCond, value}) {
|
| 8 |
+
return isCond
|
| 9 |
+
? identity({
|
| 10 |
+
getValue() {
|
| 11 |
+
return value;
|
| 12 |
+
},
|
| 13 |
+
})
|
| 14 |
+
: 42;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 18 |
+
fn: createHookWrapper(useHook),
|
| 19 |
+
params: [{isCond: true, value: 0}],
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
## Code
|
| 25 |
+
|
| 26 |
+
```javascript
|
| 27 |
+
import { c as _c } from "react/compiler-runtime";
|
| 28 |
+
import { identity, createHookWrapper } from "shared-runtime";
|
| 29 |
+
|
| 30 |
+
function useHook(t0) {
|
| 31 |
+
const $ = _c(3);
|
| 32 |
+
const { isCond, value } = t0;
|
| 33 |
+
let t1;
|
| 34 |
+
if ($[0] !== isCond || $[1] !== value) {
|
| 35 |
+
t1 = isCond
|
| 36 |
+
? identity({
|
| 37 |
+
getValue() {
|
| 38 |
+
return value;
|
| 39 |
+
},
|
| 40 |
+
})
|
| 41 |
+
: 42;
|
| 42 |
+
$[0] = isCond;
|
| 43 |
+
$[1] = value;
|
| 44 |
+
$[2] = t1;
|
| 45 |
+
} else {
|
| 46 |
+
t1 = $[2];
|
| 47 |
+
}
|
| 48 |
+
return t1;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 52 |
+
fn: createHookWrapper(useHook),
|
| 53 |
+
params: [{ isCond: true, value: 0 }],
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
### Eval output
|
| 59 |
+
(kind: ok) <div>{"result":{"getValue":{"kind":"Function","result":0}},"shouldInvokeFns":true}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-derived-in-ternary-consequent.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {identity, createHookWrapper} from 'shared-runtime';
|
| 2 |
+
|
| 3 |
+
function useHook({isCond, value}) {
|
| 4 |
+
return isCond
|
| 5 |
+
? identity({
|
| 6 |
+
getValue() {
|
| 7 |
+
return value;
|
| 8 |
+
},
|
| 9 |
+
})
|
| 10 |
+
: 42;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 14 |
+
fn: createHookWrapper(useHook),
|
| 15 |
+
params: [{isCond: true, value: 0}],
|
| 16 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-in-ternary-consequent.expect.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {createHookWrapper} from 'shared-runtime';
|
| 6 |
+
|
| 7 |
+
function useHook({isCond, value}) {
|
| 8 |
+
return isCond
|
| 9 |
+
? {
|
| 10 |
+
getValue() {
|
| 11 |
+
return value;
|
| 12 |
+
},
|
| 13 |
+
}
|
| 14 |
+
: 42;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 18 |
+
fn: createHookWrapper(useHook),
|
| 19 |
+
params: [{isCond: true, value: 0}],
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
## Code
|
| 25 |
+
|
| 26 |
+
```javascript
|
| 27 |
+
import { c as _c } from "react/compiler-runtime";
|
| 28 |
+
import { createHookWrapper } from "shared-runtime";
|
| 29 |
+
|
| 30 |
+
function useHook(t0) {
|
| 31 |
+
const $ = _c(3);
|
| 32 |
+
const { isCond, value } = t0;
|
| 33 |
+
let t1;
|
| 34 |
+
if ($[0] !== isCond || $[1] !== value) {
|
| 35 |
+
t1 = isCond
|
| 36 |
+
? {
|
| 37 |
+
getValue() {
|
| 38 |
+
return value;
|
| 39 |
+
},
|
| 40 |
+
}
|
| 41 |
+
: 42;
|
| 42 |
+
$[0] = isCond;
|
| 43 |
+
$[1] = value;
|
| 44 |
+
$[2] = t1;
|
| 45 |
+
} else {
|
| 46 |
+
t1 = $[2];
|
| 47 |
+
}
|
| 48 |
+
return t1;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 52 |
+
fn: createHookWrapper(useHook),
|
| 53 |
+
params: [{ isCond: true, value: 0 }],
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
### Eval output
|
| 59 |
+
(kind: ok) <div>{"result":{"getValue":{"kind":"Function","result":0}},"shouldInvokeFns":true}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-in-ternary-consequent.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {createHookWrapper} from 'shared-runtime';
|
| 2 |
+
|
| 3 |
+
function useHook({isCond, value}) {
|
| 4 |
+
return isCond
|
| 5 |
+
? {
|
| 6 |
+
getValue() {
|
| 7 |
+
return value;
|
| 8 |
+
},
|
| 9 |
+
}
|
| 10 |
+
: 42;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 14 |
+
fn: createHookWrapper(useHook),
|
| 15 |
+
params: [{isCond: true, value: 0}],
|
| 16 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-in-ternary-test.expect.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {createHookWrapper, CONST_STRING0, CONST_STRING1} from 'shared-runtime';
|
| 6 |
+
|
| 7 |
+
function useHook({value}) {
|
| 8 |
+
return {
|
| 9 |
+
getValue() {
|
| 10 |
+
return identity(value);
|
| 11 |
+
},
|
| 12 |
+
}
|
| 13 |
+
? CONST_STRING0
|
| 14 |
+
: CONST_STRING1;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 18 |
+
fn: createHookWrapper(useHook),
|
| 19 |
+
params: [{value: 0}],
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
## Code
|
| 25 |
+
|
| 26 |
+
```javascript
|
| 27 |
+
import {
|
| 28 |
+
createHookWrapper,
|
| 29 |
+
CONST_STRING0,
|
| 30 |
+
CONST_STRING1,
|
| 31 |
+
} from "shared-runtime";
|
| 32 |
+
|
| 33 |
+
function useHook(t0) {
|
| 34 |
+
const { value } = t0;
|
| 35 |
+
return {
|
| 36 |
+
getValue() {
|
| 37 |
+
return identity(value);
|
| 38 |
+
},
|
| 39 |
+
}
|
| 40 |
+
? CONST_STRING0
|
| 41 |
+
: CONST_STRING1;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 45 |
+
fn: createHookWrapper(useHook),
|
| 46 |
+
params: [{ value: 0 }],
|
| 47 |
+
};
|
| 48 |
+
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
### Eval output
|
| 52 |
+
(kind: ok) <div>{"result":"global string 0","shouldInvokeFns":true}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-method-in-ternary-test.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {createHookWrapper, CONST_STRING0, CONST_STRING1} from 'shared-runtime';
|
| 2 |
+
|
| 3 |
+
function useHook({value}) {
|
| 4 |
+
return {
|
| 5 |
+
getValue() {
|
| 6 |
+
return identity(value);
|
| 7 |
+
},
|
| 8 |
+
}
|
| 9 |
+
? CONST_STRING0
|
| 10 |
+
: CONST_STRING1;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 14 |
+
fn: createHookWrapper(useHook),
|
| 15 |
+
params: [{value: 0}],
|
| 16 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-spread-element.expect.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
function Component(props) {
|
| 6 |
+
const x = {...props.foo};
|
| 7 |
+
return x;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 11 |
+
fn: Component,
|
| 12 |
+
params: ['TodoAdd'],
|
| 13 |
+
isComponent: 'TodoAdd',
|
| 14 |
+
};
|
| 15 |
+
|
| 16 |
+
```
|
| 17 |
+
|
| 18 |
+
## Code
|
| 19 |
+
|
| 20 |
+
```javascript
|
| 21 |
+
import { c as _c } from "react/compiler-runtime";
|
| 22 |
+
function Component(props) {
|
| 23 |
+
const $ = _c(2);
|
| 24 |
+
let t0;
|
| 25 |
+
if ($[0] !== props.foo) {
|
| 26 |
+
t0 = { ...props.foo };
|
| 27 |
+
$[0] = props.foo;
|
| 28 |
+
$[1] = t0;
|
| 29 |
+
} else {
|
| 30 |
+
t0 = $[1];
|
| 31 |
+
}
|
| 32 |
+
const x = t0;
|
| 33 |
+
return x;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 37 |
+
fn: Component,
|
| 38 |
+
params: ["TodoAdd"],
|
| 39 |
+
isComponent: "TodoAdd",
|
| 40 |
+
};
|
| 41 |
+
|
| 42 |
+
```
|
| 43 |
+
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-literal-spread-element.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function Component(props) {
|
| 2 |
+
const x = {...props.foo};
|
| 3 |
+
return x;
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 7 |
+
fn: Component,
|
| 8 |
+
params: ['TodoAdd'],
|
| 9 |
+
isComponent: 'TodoAdd',
|
| 10 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-maybe-alias.expect.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {createHookWrapper, setProperty} from 'shared-runtime';
|
| 6 |
+
function useHook(props) {
|
| 7 |
+
const x = {
|
| 8 |
+
getX() {
|
| 9 |
+
return props;
|
| 10 |
+
},
|
| 11 |
+
};
|
| 12 |
+
const y = {
|
| 13 |
+
getY() {
|
| 14 |
+
return 'y';
|
| 15 |
+
},
|
| 16 |
+
};
|
| 17 |
+
return setProperty(x, y);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 21 |
+
fn: createHookWrapper(useHook),
|
| 22 |
+
params: [{value: 0}],
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
## Code
|
| 28 |
+
|
| 29 |
+
```javascript
|
| 30 |
+
import { c as _c } from "react/compiler-runtime";
|
| 31 |
+
import { createHookWrapper, setProperty } from "shared-runtime";
|
| 32 |
+
function useHook(props) {
|
| 33 |
+
const $ = _c(2);
|
| 34 |
+
let t0;
|
| 35 |
+
if ($[0] !== props) {
|
| 36 |
+
const x = {
|
| 37 |
+
getX() {
|
| 38 |
+
return props;
|
| 39 |
+
},
|
| 40 |
+
};
|
| 41 |
+
const y = {
|
| 42 |
+
getY() {
|
| 43 |
+
return "y";
|
| 44 |
+
},
|
| 45 |
+
};
|
| 46 |
+
t0 = setProperty(x, y);
|
| 47 |
+
$[0] = props;
|
| 48 |
+
$[1] = t0;
|
| 49 |
+
} else {
|
| 50 |
+
t0 = $[1];
|
| 51 |
+
}
|
| 52 |
+
return t0;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 56 |
+
fn: createHookWrapper(useHook),
|
| 57 |
+
params: [{ value: 0 }],
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
### Eval output
|
| 63 |
+
(kind: ok) <div>{"result":{"getX":{"kind":"Function","result":{"value":0}},"wat0":{"getY":{"kind":"Function","result":"y"}}},"shouldInvokeFns":true}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-maybe-alias.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {createHookWrapper, setProperty} from 'shared-runtime';
|
| 2 |
+
function useHook(props) {
|
| 3 |
+
const x = {
|
| 4 |
+
getX() {
|
| 5 |
+
return props;
|
| 6 |
+
},
|
| 7 |
+
};
|
| 8 |
+
const y = {
|
| 9 |
+
getY() {
|
| 10 |
+
return 'y';
|
| 11 |
+
},
|
| 12 |
+
};
|
| 13 |
+
return setProperty(x, y);
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 17 |
+
fn: createHookWrapper(useHook),
|
| 18 |
+
params: [{value: 0}],
|
| 19 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-3.expect.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {createHookWrapper, mutate} from 'shared-runtime';
|
| 6 |
+
|
| 7 |
+
function useHook(a) {
|
| 8 |
+
const x = {a};
|
| 9 |
+
let obj = {
|
| 10 |
+
method() {
|
| 11 |
+
mutate(x);
|
| 12 |
+
return x;
|
| 13 |
+
},
|
| 14 |
+
};
|
| 15 |
+
return obj.method();
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 19 |
+
fn: createHookWrapper(useHook),
|
| 20 |
+
params: [{x: 1}],
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
## Code
|
| 26 |
+
|
| 27 |
+
```javascript
|
| 28 |
+
import { c as _c } from "react/compiler-runtime";
|
| 29 |
+
import { createHookWrapper, mutate } from "shared-runtime";
|
| 30 |
+
|
| 31 |
+
function useHook(a) {
|
| 32 |
+
const $ = _c(2);
|
| 33 |
+
let t0;
|
| 34 |
+
if ($[0] !== a) {
|
| 35 |
+
const x = { a };
|
| 36 |
+
const obj = {
|
| 37 |
+
method() {
|
| 38 |
+
mutate(x);
|
| 39 |
+
return x;
|
| 40 |
+
},
|
| 41 |
+
};
|
| 42 |
+
t0 = obj.method();
|
| 43 |
+
$[0] = a;
|
| 44 |
+
$[1] = t0;
|
| 45 |
+
} else {
|
| 46 |
+
t0 = $[1];
|
| 47 |
+
}
|
| 48 |
+
return t0;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 52 |
+
fn: createHookWrapper(useHook),
|
| 53 |
+
params: [{ x: 1 }],
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
### Eval output
|
| 59 |
+
(kind: ok) <div>{"result":{"a":{"x":1},"wat0":"joe"},"shouldInvokeFns":true}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-3.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {createHookWrapper, mutate} from 'shared-runtime';
|
| 2 |
+
|
| 3 |
+
function useHook(a) {
|
| 4 |
+
const x = {a};
|
| 5 |
+
let obj = {
|
| 6 |
+
method() {
|
| 7 |
+
mutate(x);
|
| 8 |
+
return x;
|
| 9 |
+
},
|
| 10 |
+
};
|
| 11 |
+
return obj.method();
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 15 |
+
fn: createHookWrapper(useHook),
|
| 16 |
+
params: [{x: 1}],
|
| 17 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-aliased-mutate-after.expect.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {createHookWrapper, mutate, mutateAndReturn} from 'shared-runtime';
|
| 6 |
+
function useHook({value}) {
|
| 7 |
+
const x = mutateAndReturn({value});
|
| 8 |
+
const obj = {
|
| 9 |
+
getValue() {
|
| 10 |
+
return value;
|
| 11 |
+
},
|
| 12 |
+
};
|
| 13 |
+
mutate(x);
|
| 14 |
+
return obj;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 18 |
+
fn: createHookWrapper(useHook),
|
| 19 |
+
params: [{value: 0}],
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
## Code
|
| 25 |
+
|
| 26 |
+
```javascript
|
| 27 |
+
import { c as _c } from "react/compiler-runtime";
|
| 28 |
+
import { createHookWrapper, mutate, mutateAndReturn } from "shared-runtime";
|
| 29 |
+
function useHook(t0) {
|
| 30 |
+
const $ = _c(2);
|
| 31 |
+
const { value } = t0;
|
| 32 |
+
let obj;
|
| 33 |
+
if ($[0] !== value) {
|
| 34 |
+
const x = mutateAndReturn({ value });
|
| 35 |
+
obj = {
|
| 36 |
+
getValue() {
|
| 37 |
+
return value;
|
| 38 |
+
},
|
| 39 |
+
};
|
| 40 |
+
mutate(x);
|
| 41 |
+
$[0] = value;
|
| 42 |
+
$[1] = obj;
|
| 43 |
+
} else {
|
| 44 |
+
obj = $[1];
|
| 45 |
+
}
|
| 46 |
+
return obj;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 50 |
+
fn: createHookWrapper(useHook),
|
| 51 |
+
params: [{ value: 0 }],
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
### Eval output
|
| 57 |
+
(kind: ok) <div>{"result":{"getValue":{"kind":"Function","result":0}},"shouldInvokeFns":true}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-aliased-mutate-after.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {createHookWrapper, mutate, mutateAndReturn} from 'shared-runtime';
|
| 2 |
+
function useHook({value}) {
|
| 3 |
+
const x = mutateAndReturn({value});
|
| 4 |
+
const obj = {
|
| 5 |
+
getValue() {
|
| 6 |
+
return value;
|
| 7 |
+
},
|
| 8 |
+
};
|
| 9 |
+
mutate(x);
|
| 10 |
+
return obj;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 14 |
+
fn: createHookWrapper(useHook),
|
| 15 |
+
params: [{value: 0}],
|
| 16 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-derived-value.expect.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {createHookWrapper, mutateAndReturn} from 'shared-runtime';
|
| 6 |
+
function useHook({value}) {
|
| 7 |
+
const x = mutateAndReturn({value});
|
| 8 |
+
const obj = {
|
| 9 |
+
getValue() {
|
| 10 |
+
return x;
|
| 11 |
+
},
|
| 12 |
+
};
|
| 13 |
+
return obj;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 17 |
+
fn: createHookWrapper(useHook),
|
| 18 |
+
params: [{value: 0}],
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
## Code
|
| 24 |
+
|
| 25 |
+
```javascript
|
| 26 |
+
import { c as _c } from "react/compiler-runtime";
|
| 27 |
+
import { createHookWrapper, mutateAndReturn } from "shared-runtime";
|
| 28 |
+
function useHook(t0) {
|
| 29 |
+
const $ = _c(4);
|
| 30 |
+
const { value } = t0;
|
| 31 |
+
let t1;
|
| 32 |
+
if ($[0] !== value) {
|
| 33 |
+
t1 = mutateAndReturn({ value });
|
| 34 |
+
$[0] = value;
|
| 35 |
+
$[1] = t1;
|
| 36 |
+
} else {
|
| 37 |
+
t1 = $[1];
|
| 38 |
+
}
|
| 39 |
+
const x = t1;
|
| 40 |
+
let t2;
|
| 41 |
+
if ($[2] !== x) {
|
| 42 |
+
t2 = {
|
| 43 |
+
getValue() {
|
| 44 |
+
return x;
|
| 45 |
+
},
|
| 46 |
+
};
|
| 47 |
+
$[2] = x;
|
| 48 |
+
$[3] = t2;
|
| 49 |
+
} else {
|
| 50 |
+
t2 = $[3];
|
| 51 |
+
}
|
| 52 |
+
const obj = t2;
|
| 53 |
+
return obj;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 57 |
+
fn: createHookWrapper(useHook),
|
| 58 |
+
params: [{ value: 0 }],
|
| 59 |
+
};
|
| 60 |
+
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
### Eval output
|
| 64 |
+
(kind: ok) <div>{"result":{"getValue":{"kind":"Function","result":{"value":0,"wat0":"joe"}}},"shouldInvokeFns":true}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-derived-value.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {createHookWrapper, mutateAndReturn} from 'shared-runtime';
|
| 2 |
+
function useHook({value}) {
|
| 3 |
+
const x = mutateAndReturn({value});
|
| 4 |
+
const obj = {
|
| 5 |
+
getValue() {
|
| 6 |
+
return x;
|
| 7 |
+
},
|
| 8 |
+
};
|
| 9 |
+
return obj;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 13 |
+
fn: createHookWrapper(useHook),
|
| 14 |
+
params: [{value: 0}],
|
| 15 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-hook-dep.expect.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {createHookWrapper} from 'shared-runtime';
|
| 6 |
+
import {useState} from 'react';
|
| 7 |
+
function useFoo() {
|
| 8 |
+
const [state, _setState] = useState(false);
|
| 9 |
+
return {
|
| 10 |
+
func() {
|
| 11 |
+
return state;
|
| 12 |
+
},
|
| 13 |
+
};
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 17 |
+
fn: createHookWrapper(useFoo),
|
| 18 |
+
params: [{}],
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
## Code
|
| 24 |
+
|
| 25 |
+
```javascript
|
| 26 |
+
import { c as _c } from "react/compiler-runtime";
|
| 27 |
+
import { createHookWrapper } from "shared-runtime";
|
| 28 |
+
import { useState } from "react";
|
| 29 |
+
function useFoo() {
|
| 30 |
+
const $ = _c(2);
|
| 31 |
+
const [state] = useState(false);
|
| 32 |
+
let t0;
|
| 33 |
+
if ($[0] !== state) {
|
| 34 |
+
t0 = {
|
| 35 |
+
func() {
|
| 36 |
+
return state;
|
| 37 |
+
},
|
| 38 |
+
};
|
| 39 |
+
$[0] = state;
|
| 40 |
+
$[1] = t0;
|
| 41 |
+
} else {
|
| 42 |
+
t0 = $[1];
|
| 43 |
+
}
|
| 44 |
+
return t0;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 48 |
+
fn: createHookWrapper(useFoo),
|
| 49 |
+
params: [{}],
|
| 50 |
+
};
|
| 51 |
+
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
### Eval output
|
| 55 |
+
(kind: ok) <div>{"result":{"func":{"kind":"Function","result":false}},"shouldInvokeFns":true}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-hook-dep.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {createHookWrapper} from 'shared-runtime';
|
| 2 |
+
import {useState} from 'react';
|
| 3 |
+
function useFoo() {
|
| 4 |
+
const [state, _setState] = useState(false);
|
| 5 |
+
return {
|
| 6 |
+
func() {
|
| 7 |
+
return state;
|
| 8 |
+
},
|
| 9 |
+
};
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 13 |
+
fn: createHookWrapper(useFoo),
|
| 14 |
+
params: [{}],
|
| 15 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-mutated-after.expect.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {createHookWrapper, mutate, mutateAndReturn} from 'shared-runtime';
|
| 6 |
+
function useHook({value}) {
|
| 7 |
+
const x = mutateAndReturn({value});
|
| 8 |
+
const obj = {
|
| 9 |
+
getValue() {
|
| 10 |
+
return x;
|
| 11 |
+
},
|
| 12 |
+
};
|
| 13 |
+
mutate(obj);
|
| 14 |
+
return obj;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 18 |
+
fn: createHookWrapper(useHook),
|
| 19 |
+
params: [{value: 0}],
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
## Code
|
| 25 |
+
|
| 26 |
+
```javascript
|
| 27 |
+
import { c as _c } from "react/compiler-runtime";
|
| 28 |
+
import { createHookWrapper, mutate, mutateAndReturn } from "shared-runtime";
|
| 29 |
+
function useHook(t0) {
|
| 30 |
+
const $ = _c(2);
|
| 31 |
+
const { value } = t0;
|
| 32 |
+
let obj;
|
| 33 |
+
if ($[0] !== value) {
|
| 34 |
+
const x = mutateAndReturn({ value });
|
| 35 |
+
obj = {
|
| 36 |
+
getValue() {
|
| 37 |
+
return x;
|
| 38 |
+
},
|
| 39 |
+
};
|
| 40 |
+
mutate(obj);
|
| 41 |
+
$[0] = value;
|
| 42 |
+
$[1] = obj;
|
| 43 |
+
} else {
|
| 44 |
+
obj = $[1];
|
| 45 |
+
}
|
| 46 |
+
return obj;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 50 |
+
fn: createHookWrapper(useHook),
|
| 51 |
+
params: [{ value: 0 }],
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
### Eval output
|
| 57 |
+
(kind: ok) <div>{"result":{"getValue":{"kind":"Function","result":{"value":0,"wat0":"joe"}},"wat0":"joe"},"shouldInvokeFns":true}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand-mutated-after.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {createHookWrapper, mutate, mutateAndReturn} from 'shared-runtime';
|
| 2 |
+
function useHook({value}) {
|
| 3 |
+
const x = mutateAndReturn({value});
|
| 4 |
+
const obj = {
|
| 5 |
+
getValue() {
|
| 6 |
+
return x;
|
| 7 |
+
},
|
| 8 |
+
};
|
| 9 |
+
mutate(obj);
|
| 10 |
+
return obj;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 14 |
+
fn: createHookWrapper(useHook),
|
| 15 |
+
params: [{value: 0}],
|
| 16 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand.expect.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
function Component() {
|
| 6 |
+
let obj = {
|
| 7 |
+
method() {
|
| 8 |
+
return 1;
|
| 9 |
+
},
|
| 10 |
+
};
|
| 11 |
+
return obj.method();
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 15 |
+
fn: Component,
|
| 16 |
+
params: [{x: 1}, {a: 2}, {b: 2}],
|
| 17 |
+
};
|
| 18 |
+
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
## Code
|
| 22 |
+
|
| 23 |
+
```javascript
|
| 24 |
+
import { c as _c } from "react/compiler-runtime";
|
| 25 |
+
function Component() {
|
| 26 |
+
const $ = _c(1);
|
| 27 |
+
let t0;
|
| 28 |
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
| 29 |
+
const obj = {
|
| 30 |
+
method() {
|
| 31 |
+
return 1;
|
| 32 |
+
},
|
| 33 |
+
};
|
| 34 |
+
t0 = obj.method();
|
| 35 |
+
$[0] = t0;
|
| 36 |
+
} else {
|
| 37 |
+
t0 = $[0];
|
| 38 |
+
}
|
| 39 |
+
return t0;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 43 |
+
fn: Component,
|
| 44 |
+
params: [{ x: 1 }, { a: 2 }, { b: 2 }],
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
### Eval output
|
| 50 |
+
(kind: ok) 1
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-method-shorthand.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function Component() {
|
| 2 |
+
let obj = {
|
| 3 |
+
method() {
|
| 4 |
+
return 1;
|
| 5 |
+
},
|
| 6 |
+
};
|
| 7 |
+
return obj.method();
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 11 |
+
fn: Component,
|
| 12 |
+
params: [{x: 1}, {a: 2}, {b: 2}],
|
| 13 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-mutated-in-consequent-alternate-both-return.expect.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {makeObject_Primitives} from 'shared-runtime';
|
| 6 |
+
|
| 7 |
+
function Component(props) {
|
| 8 |
+
const object = makeObject_Primitives();
|
| 9 |
+
if (props.cond) {
|
| 10 |
+
object.value = 1;
|
| 11 |
+
return object;
|
| 12 |
+
} else {
|
| 13 |
+
object.value = props.value;
|
| 14 |
+
return object;
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 19 |
+
fn: Component,
|
| 20 |
+
params: [{cond: false, value: [0, 1, 2]}],
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
## Code
|
| 26 |
+
|
| 27 |
+
```javascript
|
| 28 |
+
import { c as _c } from "react/compiler-runtime";
|
| 29 |
+
import { makeObject_Primitives } from "shared-runtime";
|
| 30 |
+
|
| 31 |
+
function Component(props) {
|
| 32 |
+
const $ = _c(3);
|
| 33 |
+
let t0;
|
| 34 |
+
if ($[0] !== props.cond || $[1] !== props.value) {
|
| 35 |
+
t0 = Symbol.for("react.early_return_sentinel");
|
| 36 |
+
bb0: {
|
| 37 |
+
const object = makeObject_Primitives();
|
| 38 |
+
if (props.cond) {
|
| 39 |
+
object.value = 1;
|
| 40 |
+
t0 = object;
|
| 41 |
+
break bb0;
|
| 42 |
+
} else {
|
| 43 |
+
object.value = props.value;
|
| 44 |
+
t0 = object;
|
| 45 |
+
break bb0;
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
$[0] = props.cond;
|
| 49 |
+
$[1] = props.value;
|
| 50 |
+
$[2] = t0;
|
| 51 |
+
} else {
|
| 52 |
+
t0 = $[2];
|
| 53 |
+
}
|
| 54 |
+
if (t0 !== Symbol.for("react.early_return_sentinel")) {
|
| 55 |
+
return t0;
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 60 |
+
fn: Component,
|
| 61 |
+
params: [{ cond: false, value: [0, 1, 2] }],
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
### Eval output
|
| 67 |
+
(kind: ok) {"a":0,"b":"value1","c":true,"value":[0,1,2]}
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-mutated-in-consequent-alternate-both-return.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {makeObject_Primitives} from 'shared-runtime';
|
| 2 |
+
|
| 3 |
+
function Component(props) {
|
| 4 |
+
const object = makeObject_Primitives();
|
| 5 |
+
if (props.cond) {
|
| 6 |
+
object.value = 1;
|
| 7 |
+
return object;
|
| 8 |
+
} else {
|
| 9 |
+
object.value = props.value;
|
| 10 |
+
return object;
|
| 11 |
+
}
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 15 |
+
fn: Component,
|
| 16 |
+
params: [{cond: false, value: [0, 1, 2]}],
|
| 17 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-pattern-params.expect.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
function component({a, b}) {
|
| 6 |
+
let y = {a};
|
| 7 |
+
let z = {b};
|
| 8 |
+
return {y, z};
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 12 |
+
fn: component,
|
| 13 |
+
params: ['TodoAdd'],
|
| 14 |
+
isComponent: 'TodoAdd',
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
## Code
|
| 20 |
+
|
| 21 |
+
```javascript
|
| 22 |
+
import { c as _c } from "react/compiler-runtime";
|
| 23 |
+
function component(t0) {
|
| 24 |
+
const $ = _c(7);
|
| 25 |
+
const { a, b } = t0;
|
| 26 |
+
let t1;
|
| 27 |
+
if ($[0] !== a) {
|
| 28 |
+
t1 = { a };
|
| 29 |
+
$[0] = a;
|
| 30 |
+
$[1] = t1;
|
| 31 |
+
} else {
|
| 32 |
+
t1 = $[1];
|
| 33 |
+
}
|
| 34 |
+
const y = t1;
|
| 35 |
+
let t2;
|
| 36 |
+
if ($[2] !== b) {
|
| 37 |
+
t2 = { b };
|
| 38 |
+
$[2] = b;
|
| 39 |
+
$[3] = t2;
|
| 40 |
+
} else {
|
| 41 |
+
t2 = $[3];
|
| 42 |
+
}
|
| 43 |
+
const z = t2;
|
| 44 |
+
let t3;
|
| 45 |
+
if ($[4] !== y || $[5] !== z) {
|
| 46 |
+
t3 = { y, z };
|
| 47 |
+
$[4] = y;
|
| 48 |
+
$[5] = z;
|
| 49 |
+
$[6] = t3;
|
| 50 |
+
} else {
|
| 51 |
+
t3 = $[6];
|
| 52 |
+
}
|
| 53 |
+
return t3;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 57 |
+
fn: component,
|
| 58 |
+
params: ["TodoAdd"],
|
| 59 |
+
isComponent: "TodoAdd",
|
| 60 |
+
};
|
| 61 |
+
|
| 62 |
+
```
|
| 63 |
+
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-pattern-params.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function component({a, b}) {
|
| 2 |
+
let y = {a};
|
| 3 |
+
let z = {b};
|
| 4 |
+
return {y, z};
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 8 |
+
fn: component,
|
| 9 |
+
params: ['TodoAdd'],
|
| 10 |
+
isComponent: 'TodoAdd',
|
| 11 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-properties.expect.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
function foo(a, b, c) {
|
| 6 |
+
const x = a.x;
|
| 7 |
+
const y = {...b.c.d};
|
| 8 |
+
y.z = c.d.e;
|
| 9 |
+
foo(a.b.c);
|
| 10 |
+
[a.b.c];
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
## Code
|
| 16 |
+
|
| 17 |
+
```javascript
|
| 18 |
+
function foo(a, b, c) {
|
| 19 |
+
const y = { ...b.c.d };
|
| 20 |
+
y.z = c.d.e;
|
| 21 |
+
foo(a.b.c);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
```
|
| 25 |
+
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-properties.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function foo(a, b, c) {
|
| 2 |
+
const x = a.x;
|
| 3 |
+
const y = {...b.c.d};
|
| 4 |
+
y.z = c.d.e;
|
| 5 |
+
foo(a.b.c);
|
| 6 |
+
[a.b.c];
|
| 7 |
+
}
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-shorthand-method-1.expect.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {createHookWrapper} from 'shared-runtime';
|
| 6 |
+
function useHook({a, b}) {
|
| 7 |
+
return {
|
| 8 |
+
x: function () {
|
| 9 |
+
return [a];
|
| 10 |
+
},
|
| 11 |
+
y() {
|
| 12 |
+
return [b];
|
| 13 |
+
},
|
| 14 |
+
};
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 18 |
+
fn: createHookWrapper(useHook),
|
| 19 |
+
params: [{a: 1, b: 2}],
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
## Code
|
| 25 |
+
|
| 26 |
+
```javascript
|
| 27 |
+
import { c as _c } from "react/compiler-runtime";
|
| 28 |
+
import { createHookWrapper } from "shared-runtime";
|
| 29 |
+
function useHook(t0) {
|
| 30 |
+
const $ = _c(5);
|
| 31 |
+
const { a, b } = t0;
|
| 32 |
+
let t1;
|
| 33 |
+
if ($[0] !== a) {
|
| 34 |
+
t1 = function () {
|
| 35 |
+
return [a];
|
| 36 |
+
};
|
| 37 |
+
$[0] = a;
|
| 38 |
+
$[1] = t1;
|
| 39 |
+
} else {
|
| 40 |
+
t1 = $[1];
|
| 41 |
+
}
|
| 42 |
+
let t2;
|
| 43 |
+
if ($[2] !== b || $[3] !== t1) {
|
| 44 |
+
t2 = {
|
| 45 |
+
x: t1,
|
| 46 |
+
y() {
|
| 47 |
+
return [b];
|
| 48 |
+
},
|
| 49 |
+
};
|
| 50 |
+
$[2] = b;
|
| 51 |
+
$[3] = t1;
|
| 52 |
+
$[4] = t2;
|
| 53 |
+
} else {
|
| 54 |
+
t2 = $[4];
|
| 55 |
+
}
|
| 56 |
+
return t2;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 60 |
+
fn: createHookWrapper(useHook),
|
| 61 |
+
params: [{ a: 1, b: 2 }],
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
### Eval output
|
| 67 |
+
(kind: ok) <div>{"result":{"x":{"kind":"Function","result":[1]},"y":{"kind":"Function","result":[2]}},"shouldInvokeFns":true}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-shorthand-method-1.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {createHookWrapper} from 'shared-runtime';
|
| 2 |
+
function useHook({a, b}) {
|
| 3 |
+
return {
|
| 4 |
+
x: function () {
|
| 5 |
+
return [a];
|
| 6 |
+
},
|
| 7 |
+
y() {
|
| 8 |
+
return [b];
|
| 9 |
+
},
|
| 10 |
+
};
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 14 |
+
fn: createHookWrapper(useHook),
|
| 15 |
+
params: [{a: 1, b: 2}],
|
| 16 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-shorthand-method-2.expect.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {createHookWrapper} from 'shared-runtime';
|
| 6 |
+
|
| 7 |
+
function useHook({a, b, c}) {
|
| 8 |
+
return {
|
| 9 |
+
x: [a],
|
| 10 |
+
y() {
|
| 11 |
+
return [b];
|
| 12 |
+
},
|
| 13 |
+
z: {c},
|
| 14 |
+
};
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 18 |
+
fn: createHookWrapper(useHook),
|
| 19 |
+
params: [{a: 1, b: 2, c: 2}],
|
| 20 |
+
};
|
| 21 |
+
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
## Code
|
| 25 |
+
|
| 26 |
+
```javascript
|
| 27 |
+
import { c as _c } from "react/compiler-runtime";
|
| 28 |
+
import { createHookWrapper } from "shared-runtime";
|
| 29 |
+
|
| 30 |
+
function useHook(t0) {
|
| 31 |
+
const $ = _c(8);
|
| 32 |
+
const { a, b, c } = t0;
|
| 33 |
+
let t1;
|
| 34 |
+
if ($[0] !== a) {
|
| 35 |
+
t1 = [a];
|
| 36 |
+
$[0] = a;
|
| 37 |
+
$[1] = t1;
|
| 38 |
+
} else {
|
| 39 |
+
t1 = $[1];
|
| 40 |
+
}
|
| 41 |
+
let t2;
|
| 42 |
+
if ($[2] !== b || $[3] !== c || $[4] !== t1) {
|
| 43 |
+
let t3;
|
| 44 |
+
if ($[6] !== c) {
|
| 45 |
+
t3 = { c };
|
| 46 |
+
$[6] = c;
|
| 47 |
+
$[7] = t3;
|
| 48 |
+
} else {
|
| 49 |
+
t3 = $[7];
|
| 50 |
+
}
|
| 51 |
+
t2 = {
|
| 52 |
+
x: t1,
|
| 53 |
+
y() {
|
| 54 |
+
return [b];
|
| 55 |
+
},
|
| 56 |
+
z: t3,
|
| 57 |
+
};
|
| 58 |
+
$[2] = b;
|
| 59 |
+
$[3] = c;
|
| 60 |
+
$[4] = t1;
|
| 61 |
+
$[5] = t2;
|
| 62 |
+
} else {
|
| 63 |
+
t2 = $[5];
|
| 64 |
+
}
|
| 65 |
+
return t2;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 69 |
+
fn: createHookWrapper(useHook),
|
| 70 |
+
params: [{ a: 1, b: 2, c: 2 }],
|
| 71 |
+
};
|
| 72 |
+
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
### Eval output
|
| 76 |
+
(kind: ok) <div>{"result":{"x":[1],"y":{"kind":"Function","result":[2]},"z":{"c":2}},"shouldInvokeFns":true}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-shorthand-method-2.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {createHookWrapper} from 'shared-runtime';
|
| 2 |
+
|
| 3 |
+
function useHook({a, b, c}) {
|
| 4 |
+
return {
|
| 5 |
+
x: [a],
|
| 6 |
+
y() {
|
| 7 |
+
return [b];
|
| 8 |
+
},
|
| 9 |
+
z: {c},
|
| 10 |
+
};
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 14 |
+
fn: createHookWrapper(useHook),
|
| 15 |
+
params: [{a: 1, b: 2, c: 2}],
|
| 16 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-shorthand-method-nested.expect.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {useState} from 'react';
|
| 6 |
+
import {createHookWrapper} from 'shared-runtime';
|
| 7 |
+
|
| 8 |
+
function useHook({value}) {
|
| 9 |
+
const [state] = useState(false);
|
| 10 |
+
|
| 11 |
+
return {
|
| 12 |
+
getX() {
|
| 13 |
+
return {
|
| 14 |
+
a: [],
|
| 15 |
+
getY() {
|
| 16 |
+
return value;
|
| 17 |
+
},
|
| 18 |
+
state,
|
| 19 |
+
};
|
| 20 |
+
},
|
| 21 |
+
};
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 25 |
+
fn: createHookWrapper(useHook),
|
| 26 |
+
params: [{value: 0}],
|
| 27 |
+
};
|
| 28 |
+
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
## Code
|
| 32 |
+
|
| 33 |
+
```javascript
|
| 34 |
+
import { c as _c } from "react/compiler-runtime";
|
| 35 |
+
import { useState } from "react";
|
| 36 |
+
import { createHookWrapper } from "shared-runtime";
|
| 37 |
+
|
| 38 |
+
function useHook(t0) {
|
| 39 |
+
const $ = _c(3);
|
| 40 |
+
const { value } = t0;
|
| 41 |
+
const [state] = useState(false);
|
| 42 |
+
let t1;
|
| 43 |
+
if ($[0] !== state || $[1] !== value) {
|
| 44 |
+
t1 = {
|
| 45 |
+
getX() {
|
| 46 |
+
return {
|
| 47 |
+
a: [],
|
| 48 |
+
getY() {
|
| 49 |
+
return value;
|
| 50 |
+
},
|
| 51 |
+
state,
|
| 52 |
+
};
|
| 53 |
+
},
|
| 54 |
+
};
|
| 55 |
+
$[0] = state;
|
| 56 |
+
$[1] = value;
|
| 57 |
+
$[2] = t1;
|
| 58 |
+
} else {
|
| 59 |
+
t1 = $[2];
|
| 60 |
+
}
|
| 61 |
+
return t1;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 65 |
+
fn: createHookWrapper(useHook),
|
| 66 |
+
params: [{ value: 0 }],
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
### Eval output
|
| 72 |
+
(kind: ok) <div>{"result":{"getX":{"kind":"Function","result":{"a":[],"getY":{"kind":"Function","result":0},"state":false}}},"shouldInvokeFns":true}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-shorthand-method-nested.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {useState} from 'react';
|
| 2 |
+
import {createHookWrapper} from 'shared-runtime';
|
| 3 |
+
|
| 4 |
+
function useHook({value}) {
|
| 5 |
+
const [state] = useState(false);
|
| 6 |
+
|
| 7 |
+
return {
|
| 8 |
+
getX() {
|
| 9 |
+
return {
|
| 10 |
+
a: [],
|
| 11 |
+
getY() {
|
| 12 |
+
return value;
|
| 13 |
+
},
|
| 14 |
+
state,
|
| 15 |
+
};
|
| 16 |
+
},
|
| 17 |
+
};
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 21 |
+
fn: createHookWrapper(useHook),
|
| 22 |
+
params: [{value: 0}],
|
| 23 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-values-mutation.expect.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {makeObject_Primitives, Stringify} from 'shared-runtime';
|
| 6 |
+
|
| 7 |
+
function Component(props) {
|
| 8 |
+
const object = {object: props.object};
|
| 9 |
+
const entries = Object.entries(object);
|
| 10 |
+
entries.map(([, value]) => {
|
| 11 |
+
value.updated = true;
|
| 12 |
+
});
|
| 13 |
+
return <Stringify entries={entries} />;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 17 |
+
fn: Component,
|
| 18 |
+
params: [{object: {key: makeObject_Primitives()}}],
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
```
|
| 22 |
+
|
| 23 |
+
## Code
|
| 24 |
+
|
| 25 |
+
```javascript
|
| 26 |
+
import { c as _c } from "react/compiler-runtime";
|
| 27 |
+
import { makeObject_Primitives, Stringify } from "shared-runtime";
|
| 28 |
+
|
| 29 |
+
function Component(props) {
|
| 30 |
+
const $ = _c(2);
|
| 31 |
+
let t0;
|
| 32 |
+
if ($[0] !== props.object) {
|
| 33 |
+
const object = { object: props.object };
|
| 34 |
+
const entries = Object.entries(object);
|
| 35 |
+
entries.map(_temp);
|
| 36 |
+
t0 = <Stringify entries={entries} />;
|
| 37 |
+
$[0] = props.object;
|
| 38 |
+
$[1] = t0;
|
| 39 |
+
} else {
|
| 40 |
+
t0 = $[1];
|
| 41 |
+
}
|
| 42 |
+
return t0;
|
| 43 |
+
}
|
| 44 |
+
function _temp(t0) {
|
| 45 |
+
const [, value] = t0;
|
| 46 |
+
value.updated = true;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 50 |
+
fn: Component,
|
| 51 |
+
params: [{ object: { key: makeObject_Primitives() } }],
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
### Eval output
|
| 57 |
+
(kind: ok) <div>{"entries":[["object",{"key":{"a":0,"b":"value1","c":true},"updated":true}]]}</div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-values-mutation.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {makeObject_Primitives, Stringify} from 'shared-runtime';
|
| 2 |
+
|
| 3 |
+
function Component(props) {
|
| 4 |
+
const object = {object: props.object};
|
| 5 |
+
const entries = Object.entries(object);
|
| 6 |
+
entries.map(([, value]) => {
|
| 7 |
+
value.updated = true;
|
| 8 |
+
});
|
| 9 |
+
return <Stringify entries={entries} />;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 13 |
+
fn: Component,
|
| 14 |
+
params: [{object: {key: makeObject_Primitives()}}],
|
| 15 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-values.expect.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
// @validatePreserveExistingMemoizationGuarantees
|
| 6 |
+
import {useMemo} from 'react';
|
| 7 |
+
import {Stringify} from 'shared-runtime';
|
| 8 |
+
|
| 9 |
+
// derived from https://github.com/facebook/react/issues/32261
|
| 10 |
+
function Component({items}) {
|
| 11 |
+
const record = useMemo(
|
| 12 |
+
() =>
|
| 13 |
+
Object.fromEntries(
|
| 14 |
+
items.map(item => [
|
| 15 |
+
item.id,
|
| 16 |
+
{id: item.id, render: ref => <Stringify ref={ref} {...item} />},
|
| 17 |
+
])
|
| 18 |
+
),
|
| 19 |
+
[items]
|
| 20 |
+
);
|
| 21 |
+
|
| 22 |
+
// Without a declaration for Object.entries(), this would be assumed to mutate
|
| 23 |
+
// `record`, meaning existing memoization couldn't be preserved
|
| 24 |
+
return (
|
| 25 |
+
<div>
|
| 26 |
+
{Object.values(record).map(({id, render}) => (
|
| 27 |
+
<Stringify key={id} render={render} />
|
| 28 |
+
))}
|
| 29 |
+
</div>
|
| 30 |
+
);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 34 |
+
fn: Component,
|
| 35 |
+
params: [
|
| 36 |
+
{
|
| 37 |
+
items: [
|
| 38 |
+
{id: '0', name: 'Hello'},
|
| 39 |
+
{id: '1', name: 'World!'},
|
| 40 |
+
],
|
| 41 |
+
},
|
| 42 |
+
],
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
## Code
|
| 48 |
+
|
| 49 |
+
```javascript
|
| 50 |
+
import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
|
| 51 |
+
import { useMemo } from "react";
|
| 52 |
+
import { Stringify } from "shared-runtime";
|
| 53 |
+
|
| 54 |
+
// derived from https://github.com/facebook/react/issues/32261
|
| 55 |
+
function Component(t0) {
|
| 56 |
+
const $ = _c(4);
|
| 57 |
+
const { items } = t0;
|
| 58 |
+
let t1;
|
| 59 |
+
if ($[0] !== items) {
|
| 60 |
+
t1 = Object.fromEntries(items.map(_temp));
|
| 61 |
+
$[0] = items;
|
| 62 |
+
$[1] = t1;
|
| 63 |
+
} else {
|
| 64 |
+
t1 = $[1];
|
| 65 |
+
}
|
| 66 |
+
const record = t1;
|
| 67 |
+
let t2;
|
| 68 |
+
if ($[2] !== record) {
|
| 69 |
+
t2 = <div>{Object.values(record).map(_temp2)}</div>;
|
| 70 |
+
$[2] = record;
|
| 71 |
+
$[3] = t2;
|
| 72 |
+
} else {
|
| 73 |
+
t2 = $[3];
|
| 74 |
+
}
|
| 75 |
+
return t2;
|
| 76 |
+
}
|
| 77 |
+
function _temp2(t0) {
|
| 78 |
+
const { id, render } = t0;
|
| 79 |
+
return <Stringify key={id} render={render} />;
|
| 80 |
+
}
|
| 81 |
+
function _temp(item) {
|
| 82 |
+
return [
|
| 83 |
+
item.id,
|
| 84 |
+
{ id: item.id, render: (ref) => <Stringify ref={ref} {...item} /> },
|
| 85 |
+
];
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 89 |
+
fn: Component,
|
| 90 |
+
params: [
|
| 91 |
+
{
|
| 92 |
+
items: [
|
| 93 |
+
{ id: "0", name: "Hello" },
|
| 94 |
+
{ id: "1", name: "World!" },
|
| 95 |
+
],
|
| 96 |
+
},
|
| 97 |
+
],
|
| 98 |
+
};
|
| 99 |
+
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
### Eval output
|
| 103 |
+
(kind: ok) <div><div>{"render":"[[ function params=1 ]]"}</div><div>{"render":"[[ function params=1 ]]"}</div></div>
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/object-values.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// @validatePreserveExistingMemoizationGuarantees
|
| 2 |
+
import {useMemo} from 'react';
|
| 3 |
+
import {Stringify} from 'shared-runtime';
|
| 4 |
+
|
| 5 |
+
// derived from https://github.com/facebook/react/issues/32261
|
| 6 |
+
function Component({items}) {
|
| 7 |
+
const record = useMemo(
|
| 8 |
+
() =>
|
| 9 |
+
Object.fromEntries(
|
| 10 |
+
items.map(item => [
|
| 11 |
+
item.id,
|
| 12 |
+
{id: item.id, render: ref => <Stringify ref={ref} {...item} />},
|
| 13 |
+
])
|
| 14 |
+
),
|
| 15 |
+
[items]
|
| 16 |
+
);
|
| 17 |
+
|
| 18 |
+
// Without a declaration for Object.entries(), this would be assumed to mutate
|
| 19 |
+
// `record`, meaning existing memoization couldn't be preserved
|
| 20 |
+
return (
|
| 21 |
+
<div>
|
| 22 |
+
{Object.values(record).map(({id, render}) => (
|
| 23 |
+
<Stringify key={id} render={render} />
|
| 24 |
+
))}
|
| 25 |
+
</div>
|
| 26 |
+
);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
export const FIXTURE_ENTRYPOINT = {
|
| 30 |
+
fn: Component,
|
| 31 |
+
params: [
|
| 32 |
+
{
|
| 33 |
+
items: [
|
| 34 |
+
{id: '0', name: 'Hello'},
|
| 35 |
+
{id: '1', name: 'World!'},
|
| 36 |
+
],
|
| 37 |
+
},
|
| 38 |
+
],
|
| 39 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-chain-in-logical-expr.expect.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {useNoAlias} from 'shared-runtime';
|
| 6 |
+
|
| 7 |
+
function useFoo(props: {value: {x: string; y: string} | null}) {
|
| 8 |
+
const value = props.value;
|
| 9 |
+
return useNoAlias(value?.x, value?.y) ?? {};
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
export const FIXTURE_ENTRYPONT = {
|
| 13 |
+
fn: useFoo,
|
| 14 |
+
props: [{value: null}],
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
## Code
|
| 20 |
+
|
| 21 |
+
```javascript
|
| 22 |
+
import { useNoAlias } from "shared-runtime";
|
| 23 |
+
|
| 24 |
+
function useFoo(props) {
|
| 25 |
+
const value = props.value;
|
| 26 |
+
return useNoAlias(value?.x, value?.y) ?? {};
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
export const FIXTURE_ENTRYPONT = {
|
| 30 |
+
fn: useFoo,
|
| 31 |
+
props: [{ value: null }],
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
### Eval output
|
| 37 |
+
(kind: exception) Fixture not implemented
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-chain-in-logical-expr.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {useNoAlias} from 'shared-runtime';
|
| 2 |
+
|
| 3 |
+
function useFoo(props: {value: {x: string; y: string} | null}) {
|
| 4 |
+
const value = props.value;
|
| 5 |
+
return useNoAlias(value?.x, value?.y) ?? {};
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
export const FIXTURE_ENTRYPONT = {
|
| 9 |
+
fn: useFoo,
|
| 10 |
+
props: [{value: null}],
|
| 11 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-chain-in-ternary.expect.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {useNoAlias} from 'shared-runtime';
|
| 6 |
+
|
| 7 |
+
function useFoo(props: {value: {x: string; y: string} | null}) {
|
| 8 |
+
const value = props.value;
|
| 9 |
+
return useNoAlias(value?.x, value?.y) ? {} : null;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
export const FIXTURE_ENTRYPONT = {
|
| 13 |
+
fn: useFoo,
|
| 14 |
+
props: [{value: null}],
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
## Code
|
| 20 |
+
|
| 21 |
+
```javascript
|
| 22 |
+
import { useNoAlias } from "shared-runtime";
|
| 23 |
+
|
| 24 |
+
function useFoo(props) {
|
| 25 |
+
const value = props.value;
|
| 26 |
+
return useNoAlias(value?.x, value?.y) ? {} : null;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
export const FIXTURE_ENTRYPONT = {
|
| 30 |
+
fn: useFoo,
|
| 31 |
+
props: [{ value: null }],
|
| 32 |
+
};
|
| 33 |
+
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
### Eval output
|
| 37 |
+
(kind: exception) Fixture not implemented
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-chain-in-ternary.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {useNoAlias} from 'shared-runtime';
|
| 2 |
+
|
| 3 |
+
function useFoo(props: {value: {x: string; y: string} | null}) {
|
| 4 |
+
const value = props.value;
|
| 5 |
+
return useNoAlias(value?.x, value?.y) ? {} : null;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
export const FIXTURE_ENTRYPONT = {
|
| 9 |
+
fn: useFoo,
|
| 10 |
+
props: [{value: null}],
|
| 11 |
+
};
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-chained.expect.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
function Component(props) {
|
| 6 |
+
return call?.(props.a)?.(props.b)?.(props.c);
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
```
|
| 10 |
+
|
| 11 |
+
## Code
|
| 12 |
+
|
| 13 |
+
```javascript
|
| 14 |
+
import { c as _c } from "react/compiler-runtime";
|
| 15 |
+
function Component(props) {
|
| 16 |
+
const $ = _c(2);
|
| 17 |
+
let t0;
|
| 18 |
+
if ($[0] !== props) {
|
| 19 |
+
t0 = call?.(props.a)?.(props.b)?.(props.c);
|
| 20 |
+
$[0] = props;
|
| 21 |
+
$[1] = t0;
|
| 22 |
+
} else {
|
| 23 |
+
t0 = $[1];
|
| 24 |
+
}
|
| 25 |
+
return t0;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
```
|
| 29 |
+
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-chained.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
function Component(props) {
|
| 2 |
+
return call?.(props.a)?.(props.b)?.(props.c);
|
| 3 |
+
}
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-logical.expect.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
import {useFragment} from 'shared-runtime';
|
| 6 |
+
|
| 7 |
+
function Component(props) {
|
| 8 |
+
const item = useFragment(
|
| 9 |
+
graphql`
|
| 10 |
+
fragment F on T {
|
| 11 |
+
id
|
| 12 |
+
}
|
| 13 |
+
`,
|
| 14 |
+
props.item
|
| 15 |
+
);
|
| 16 |
+
return item.items?.map(item => renderItem(item)) ?? [];
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
## Code
|
| 22 |
+
|
| 23 |
+
```javascript
|
| 24 |
+
import { c as _c } from "react/compiler-runtime";
|
| 25 |
+
import { useFragment } from "shared-runtime";
|
| 26 |
+
|
| 27 |
+
function Component(props) {
|
| 28 |
+
const $ = _c(2);
|
| 29 |
+
const item = useFragment(
|
| 30 |
+
graphql`
|
| 31 |
+
fragment F on T {
|
| 32 |
+
id
|
| 33 |
+
}
|
| 34 |
+
`,
|
| 35 |
+
props.item,
|
| 36 |
+
);
|
| 37 |
+
let t0;
|
| 38 |
+
if ($[0] !== item.items) {
|
| 39 |
+
t0 = item.items?.map(_temp) ?? [];
|
| 40 |
+
$[0] = item.items;
|
| 41 |
+
$[1] = t0;
|
| 42 |
+
} else {
|
| 43 |
+
t0 = $[1];
|
| 44 |
+
}
|
| 45 |
+
return t0;
|
| 46 |
+
}
|
| 47 |
+
function _temp(item_0) {
|
| 48 |
+
return renderItem(item_0);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
```
|
| 52 |
+
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-logical.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {useFragment} from 'shared-runtime';
|
| 2 |
+
|
| 3 |
+
function Component(props) {
|
| 4 |
+
const item = useFragment(
|
| 5 |
+
graphql`
|
| 6 |
+
fragment F on T {
|
| 7 |
+
id
|
| 8 |
+
}
|
| 9 |
+
`,
|
| 10 |
+
props.item
|
| 11 |
+
);
|
| 12 |
+
return item.items?.map(item => renderItem(item)) ?? [];
|
| 13 |
+
}
|
github_code/react__react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-call-simple.expect.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
## Input
|
| 3 |
+
|
| 4 |
+
```javascript
|
| 5 |
+
function Component(props) {
|
| 6 |
+
return foo?.(props);
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
```
|
| 10 |
+
|
| 11 |
+
## Code
|
| 12 |
+
|
| 13 |
+
```javascript
|
| 14 |
+
import { c as _c } from "react/compiler-runtime";
|
| 15 |
+
function Component(props) {
|
| 16 |
+
const $ = _c(2);
|
| 17 |
+
let t0;
|
| 18 |
+
if ($[0] !== props) {
|
| 19 |
+
t0 = foo?.(props);
|
| 20 |
+
$[0] = props;
|
| 21 |
+
$[1] = t0;
|
| 22 |
+
} else {
|
| 23 |
+
t0 = $[1];
|
| 24 |
+
}
|
| 25 |
+
return t0;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
```
|
| 29 |
+
|