mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add type information for jsx/runtime
This commit is contained in:
@@ -346,42 +346,54 @@ const BUILTIN_HOOKS: Array<[string, BuiltInType]> = [
|
||||
],
|
||||
];
|
||||
|
||||
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,
|
||||
}),
|
||||
],
|
||||
]),
|
||||
]);
|
||||
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,
|
||||
}),
|
||||
],
|
||||
]),
|
||||
],
|
||||
[
|
||||
"_jsx",
|
||||
addFunction(DEFAULT_SHAPES, [], {
|
||||
positionalParams: [],
|
||||
restParam: Effect.Freeze,
|
||||
returnType: { kind: "Poly" },
|
||||
calleeEffect: Effect.Read,
|
||||
returnValueKind: ValueKind.Frozen,
|
||||
}),
|
||||
]
|
||||
);
|
||||
|
||||
export type Global = BuiltInType | PolyType;
|
||||
export type GlobalRegistry = Map<string, Global>;
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { shallowCopy } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const childprops = { style: { width: props.width } };
|
||||
const element = _jsx("div", {
|
||||
childprops: childprops,
|
||||
children: '"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 { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { shallowCopy } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const $ = useMemoCache(2);
|
||||
let element;
|
||||
if ($[0] !== props.width) {
|
||||
const childprops = { style: { width: props.width } };
|
||||
element = _jsx("div", { childprops, children: '"hello world"' });
|
||||
shallowCopy(childprops);
|
||||
$[0] = props.width;
|
||||
$[1] = element;
|
||||
} else {
|
||||
element = $[1];
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
export const FIXTURE_ENTRYPOINT = {
|
||||
fn: Component,
|
||||
params: [{}],
|
||||
};
|
||||
|
||||
```
|
||||
|
||||
### Eval output
|
||||
(kind: ok) <div childprops="[object Object]">"hello world"</div>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { shallowCopy } from "shared-runtime";
|
||||
|
||||
function Component(props) {
|
||||
const childprops = { style: { width: props.width } };
|
||||
const element = _jsx("div", {
|
||||
childprops: childprops,
|
||||
children: '"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