mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
@@ -312,9 +312,55 @@ const BUILTIN_HOOKS: Array<[string, BuiltInType]> = [
|
||||
returnValueKind: ValueKind.Frozen,
|
||||
}),
|
||||
],
|
||||
[
|
||||
"useInsertionEffect",
|
||||
addHook(DEFAULT_SHAPES, [], {
|
||||
positionalParams: [],
|
||||
restParam: Effect.Freeze,
|
||||
returnType: { kind: "Poly" },
|
||||
calleeEffect: Effect.Read,
|
||||
hookKind: "useLayoutEffect",
|
||||
returnValueKind: ValueKind.Frozen,
|
||||
}),
|
||||
],
|
||||
];
|
||||
|
||||
TYPED_GLOBALS.push(["React", addObject(DEFAULT_SHAPES, null, BUILTIN_HOOKS)]);
|
||||
TYPED_GLOBALS.push([
|
||||
"React",
|
||||
addObject(DEFAULT_SHAPES, null, [
|
||||
...BUILTIN_HOOKS,
|
||||
[
|
||||
"createElement",
|
||||
addFunction(DEFAULT_SHAPES, [], {
|
||||
positionalParams: [],
|
||||
restParam: Effect.Freeze,
|
||||
returnType: { kind: "Poly" },
|
||||
calleeEffect: Effect.Read,
|
||||
returnValueKind: ValueKind.Frozen,
|
||||
}),
|
||||
],
|
||||
[
|
||||
"cloneElement",
|
||||
addFunction(DEFAULT_SHAPES, [], {
|
||||
positionalParams: [],
|
||||
restParam: Effect.Freeze,
|
||||
returnType: { kind: "Poly" },
|
||||
calleeEffect: Effect.Read,
|
||||
returnValueKind: ValueKind.Frozen,
|
||||
}),
|
||||
],
|
||||
[
|
||||
"createRef",
|
||||
addFunction(DEFAULT_SHAPES, [], {
|
||||
positionalParams: [],
|
||||
restParam: Effect.Capture, // createRef takes no paramters
|
||||
returnType: { kind: "Object", shapeId: BuiltInUseRefId },
|
||||
calleeEffect: Effect.Read,
|
||||
returnValueKind: ValueKind.Mutable,
|
||||
}),
|
||||
],
|
||||
]),
|
||||
]);
|
||||
|
||||
export type Global = BuiltInType | PolyType;
|
||||
export type GlobalRegistry = Map<string, Global>;
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import React from "react";
|
||||
import { shallowCopy } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const childProps = { style: { width: props.width } };
|
||||
const element = React.createElement("div", childProps, ["hello world"]);
|
||||
shallowCopy(childProps); // function that in theory could mutate, we assume not bc createElement freezes
|
||||
return element;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { unstable_useMemoCache as useMemoCache } from "react";
|
||||
import React from "react";
|
||||
import { shallowCopy } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(5);
|
||||
let t0;
|
||||
if ($[0] !== props.width) {
|
||||
t0 = { style: { width: props.width } };
|
||||
$[0] = props.width;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
const childProps = t0;
|
||||
let t2;
|
||||
if ($[2] !== childProps) {
|
||||
let t1;
|
||||
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t1 = ["hello world"];
|
||||
$[4] = t1;
|
||||
} else {
|
||||
t1 = $[4];
|
||||
}
|
||||
t2 = React.createElement("div", childProps, t1);
|
||||
$[2] = childProps;
|
||||
$[3] = t2;
|
||||
} else {
|
||||
t2 = $[3];
|
||||
}
|
||||
const element = t2;
|
||||
shallowCopy(childProps);
|
||||
return element;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import React from "react";
|
||||
import { shallowCopy } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const childProps = { style: { width: props.width } };
|
||||
const element = React.createElement("div", childProps, ["hello world"]);
|
||||
shallowCopy(childProps); // function that in theory could mutate, we assume not bc createElement freezes
|
||||
return element;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
Reference in New Issue
Block a user