mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Change function parameters to type Place
So that we can infer a Capability of Freeze for components
This commit is contained in:
@@ -12,7 +12,6 @@ import { invariant } from "../CompilerError";
|
||||
import {
|
||||
Capability,
|
||||
HIRFunction,
|
||||
Identifier,
|
||||
IfTerminal,
|
||||
InstructionKind,
|
||||
InstructionValue,
|
||||
@@ -55,10 +54,18 @@ export function lower(func: NodePath<t.Function>): HIRFunction {
|
||||
? builder.resolveIdentifier(func.node.id)
|
||||
: null;
|
||||
|
||||
const params: Array<Identifier> = [];
|
||||
const params: Array<Place> = [];
|
||||
func.node.params.forEach((param) => {
|
||||
todoInvariant(t.isIdentifier(param), "todo: support non-identifier params");
|
||||
params.push(builder.resolveIdentifier(param));
|
||||
const identifier = builder.resolveIdentifier(param);
|
||||
const place: Place = {
|
||||
kind: "Identifier",
|
||||
value: identifier,
|
||||
memberPath: null,
|
||||
capability: Capability.Unknown,
|
||||
path: null as any,
|
||||
};
|
||||
params.push(place);
|
||||
});
|
||||
|
||||
const body = func.get("body");
|
||||
|
||||
@@ -50,7 +50,7 @@ export default function codegen(fn: HIRFunction): t.Function {
|
||||
t.isFunctionDeclaration(node),
|
||||
"todo: handle other than function declaration"
|
||||
);
|
||||
const params = fn.params.map((param) => convertIdentifier(param));
|
||||
const params = fn.params.map((param) => convertIdentifier(param.value));
|
||||
return t.functionDeclaration(
|
||||
fn.id !== null ? convertIdentifier(fn.id) : null,
|
||||
params,
|
||||
|
||||
@@ -39,7 +39,7 @@ import { invariant } from "../CompilerError";
|
||||
export type ReactFunction = {
|
||||
path: NodePath<t.Function>;
|
||||
id: Identifier | null;
|
||||
params: Array<Identifier>;
|
||||
params: Array<Place>;
|
||||
returnScope: ScopeId;
|
||||
scopes: Map<ScopeId, ReactiveScope>;
|
||||
};
|
||||
@@ -61,7 +61,7 @@ export type ReactiveScope = {
|
||||
export type HIRFunction = {
|
||||
path: NodePath<t.Function>;
|
||||
id: Identifier | null;
|
||||
params: Array<Identifier>;
|
||||
params: Array<Place>;
|
||||
body: HIR;
|
||||
};
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ export default function inferReferenceCapability(fn: HIRFunction) {
|
||||
const place: Place = {
|
||||
kind: "Identifier",
|
||||
memberPath: null,
|
||||
value: param,
|
||||
value: param.value,
|
||||
path: null as any, // TODO
|
||||
capability: Capability.Freeze,
|
||||
};
|
||||
|
||||
@@ -64,7 +64,7 @@ export default function analyzeScopes(fn: HIRFunction): ReactFunction {
|
||||
inputs: new Set(
|
||||
fn.params.map((param) => ({
|
||||
kind: "Identifier",
|
||||
value: param,
|
||||
value: param.value,
|
||||
memberPath: null,
|
||||
capability: Capability.Freeze,
|
||||
path: null as any,
|
||||
|
||||
Reference in New Issue
Block a user