[hir] Remove flag for inlineUseMemo

This commit is contained in:
Joe Savona
2023-04-21 13:43:32 -07:00
parent b40de89805
commit 32dccd48d2
29 changed files with 17 additions and 54 deletions
+2 -4
View File
@@ -61,10 +61,8 @@ export function* run(
const hir = lower(func, env).unwrap();
yield log({ kind: "hir", name: "HIR", value: hir });
if (config?.inlineUseMemo) {
inlineUseMemo(hir);
yield log({ kind: "hir", name: "RewriteUseMemo", value: hir });
}
inlineUseMemo(hir);
yield log({ kind: "hir", name: "RewriteUseMemo", value: hir });
mergeConsecutiveBlocks(hir);
yield log({ kind: "hir", name: "MergeConsecutiveBlocks", value: hir });
-1
View File
@@ -40,7 +40,6 @@ const HOOK_PATTERN = /^_?use/;
export type EnvironmentConfig = Partial<{
customHooks: Map<string, Hook>;
memoizeJsxElements: boolean;
inlineUseMemo: boolean;
}>;
export class Environment {
@@ -55,7 +55,6 @@ describe("React Forget", () => {
},
],
]),
inlineUseMemo: options.environment?.inlineUseMemo ?? false,
},
logger: null,
gating: options.gating,
@@ -50,7 +50,6 @@ describe("React Forget (Disable memoization of JSX elements)", () => {
},
],
]),
inlineUseMemo: options.environment?.inlineUseMemo ?? false,
},
logger: null,
gating: options.gating,
@@ -2,7 +2,6 @@
## Input
```javascript
// @inlineUseMemo
function component(a, b) {
let x = useMemo(async () => {
await a;
@@ -16,7 +15,7 @@ function component(a, b) {
## Error
```
[ReactForget] Invariant: Did not expect useMemo callback to be async or a generator (3:5)
[ReactForget] Invariant: Did not expect useMemo callback to be async or a generator (2:4)
```
@@ -1,4 +1,3 @@
// @inlineUseMemo
function component(a, b) {
let x = useMemo(async () => {
await a;
@@ -2,7 +2,6 @@
## Input
```javascript
// @inlineUseMemo
function component(a, b) {
let x = useMemo((c) => a, []);
return x;
@@ -14,7 +13,7 @@ function component(a, b) {
## Error
```
[ReactForget] Invariant: Did not expect any arguments to useMemo callback (3:3)
[ReactForget] Invariant: Did not expect any arguments to useMemo callback (2:2)
```
@@ -1,4 +1,3 @@
// @inlineUseMemo
function component(a, b) {
let x = useMemo((c) => a, []);
return x;
@@ -2,7 +2,6 @@
## Input
```javascript
// @inlineUseMemo
function component(a, b) {
// we don't handle generators at all so this test isn't
// useful for now, but adding this test in case we do
@@ -20,13 +19,13 @@ function component(a, b) {
```
[ReactForget] TodoError: (BuildHIR::lowerExpression) Handle YieldExpression expressions
5 | // add support for generators in the future.
6 | let x = useMemo(function* () {
> 7 | yield a;
| ^^^^^^^
8 | }, []);
9 | return x;
10 | }
4 | // add support for generators in the future.
5 | let x = useMemo(function* () {
> 6 | yield a;
| ^^^^^^^
7 | }, []);
8 | return x;
9 | }
```
@@ -1,4 +1,3 @@
// @inlineUseMemo
function component(a, b) {
// we don't handle generators at all so this test isn't
// useful for now, but adding this test in case we do
@@ -2,7 +2,6 @@
## Input
```javascript
// @inlineUseMemo
function Component(props) {
const x = useMemo(() => {
if (props.cond) {
@@ -18,7 +17,7 @@ function Component(props) {
## Code
```javascript
import * as React from "react"; // @inlineUseMemo
import * as React from "react";
function Component(props) {
const $ = React.unstable_useMemoCache(4);
let t17 = undefined;
@@ -1,4 +1,3 @@
// @inlineUseMemo
function Component(props) {
const x = useMemo(() => {
if (props.cond) {
@@ -2,7 +2,6 @@
## Input
```javascript
// @inlineUseMemo
function Component(props) {
const [a, b] = useMemo(() => {
const items = [];
@@ -18,7 +17,7 @@ function Component(props) {
## Code
```javascript
import * as React from "react"; // @inlineUseMemo
import * as React from "react";
function Component(props) {
const $ = React.unstable_useMemoCache(10);
const c_0 = $[0] !== props.a;
@@ -1,4 +1,3 @@
// @inlineUseMemo
function Component(props) {
const [a, b] = useMemo(() => {
const items = [];
@@ -2,7 +2,6 @@
## Input
```javascript
// @inlineUseMemo
function component(a, b) {
let x = useMemo(() => {
if (a) {
@@ -17,7 +16,7 @@ function component(a, b) {
## Code
```javascript
import * as React from "react"; // @inlineUseMemo
import * as React from "react";
function component(a, b) {
const $ = React.unstable_useMemoCache(2);
let t14 = undefined;
@@ -1,4 +1,3 @@
// @inlineUseMemo
function component(a, b) {
let x = useMemo(() => {
if (a) {
@@ -2,7 +2,6 @@
## Input
```javascript
// @inlineUseMemo
function Component(props) {
const x = useMemo(() => {
label: {
@@ -17,7 +16,6 @@ function Component(props) {
## Code
```javascript
// @inlineUseMemo
function Component(props) {
const t9 = props.value;
const x = t9;
@@ -1,4 +1,3 @@
// @inlineUseMemo
function Component(props) {
const x = useMemo(() => {
label: {
@@ -2,7 +2,6 @@
## Input
```javascript
// @inlineUseMemo
function Component(props) {
const x = useMemo(() => props.a && props.b);
return x;
@@ -13,7 +12,6 @@ function Component(props) {
## Code
```javascript
// @inlineUseMemo
function Component(props) {
const t15 = props.a && props.b;
const x = t15;
@@ -1,4 +1,3 @@
// @inlineUseMemo
function Component(props) {
const x = useMemo(() => props.a && props.b);
return x;
@@ -2,7 +2,6 @@
## Input
```javascript
// @inlineUseMemo
function Component(props) {
const x = useMemo(() => {
let y = [];
@@ -23,7 +22,7 @@ function Component(props) {
## Code
```javascript
import * as React from "react"; // @inlineUseMemo
import * as React from "react";
function Component(props) {
const $ = React.unstable_useMemoCache(2);
const c_0 = $[0] !== props;
@@ -1,4 +1,3 @@
// @inlineUseMemo
function Component(props) {
const x = useMemo(() => {
let y = [];
@@ -2,7 +2,6 @@
## Input
```javascript
// @inlineUseMemo
function component(a) {
let x = useMemo(() => {
mutate(a);
@@ -15,7 +14,6 @@ function component(a) {
## Code
```javascript
// @inlineUseMemo
function component(a) {
mutate(a);
}
@@ -1,4 +1,3 @@
// @inlineUseMemo
function component(a) {
let x = useMemo(() => {
mutate(a);
@@ -2,7 +2,6 @@
## Input
```javascript
// @inlineUseMemo
function component(a) {
let x = useMemo(() => [a], [a]);
return <Foo x={x}></Foo>;
@@ -13,7 +12,7 @@ function component(a) {
## Code
```javascript
import * as React from "react"; // @inlineUseMemo
import * as React from "react";
function component(a) {
const $ = React.unstable_useMemoCache(4);
const c_0 = $[0] !== a;
@@ -1,4 +1,3 @@
// @inlineUseMemo
function component(a) {
let x = useMemo(() => [a], [a]);
return <Foo x={x}></Foo>;
@@ -2,7 +2,6 @@
## Input
```javascript
// @inlineUseMemo
function Component(props) {
const x = useMemo(() => {
switch (props.key) {
@@ -22,7 +21,6 @@ function Component(props) {
## Code
```javascript
// @inlineUseMemo
function Component(props) {
let t14 = undefined;
bb8: switch (props.key) {
@@ -1,4 +1,3 @@
// @inlineUseMemo
function Component(props) {
const x = useMemo(() => {
switch (props.key) {
@@ -91,7 +91,6 @@ export default function generateTestsFromFixtures(
let debug = false;
let enableOnlyOnUseForgetDirective = false;
let gating: GatingOptions | null = null;
let inlineUseMemo = true;
let panicOnBailout = true;
if (inputFile != null) {
@@ -113,9 +112,6 @@ export default function generateTestsFromFixtures(
importSpecifierName: "isForgetEnabled_Fixtures",
};
}
if (lines[0]!.indexOf("@inlineUseMemo") !== -1) {
inlineUseMemo = true;
}
if (lines[0]!.indexOf("@panicOnBailout false") !== -1) {
panicOnBailout = false;
}
@@ -125,7 +121,7 @@ export default function generateTestsFromFixtures(
let receivedOutput;
if (input !== null) {
receivedOutput = transform(input, basename, {
environment: { inlineUseMemo },
environment: {},
logger: null,
debug,
enableOnlyOnUseForgetDirective,