mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[λ] Remove unused params in FunctionExpression
This commit is contained in:
@@ -1359,33 +1359,15 @@ function lowerExpression(
|
||||
};
|
||||
}
|
||||
loweredFunc = lowering.unwrap();
|
||||
|
||||
let hasError = false;
|
||||
const params: Array<string> = [];
|
||||
for (const p of expr.get("params")) {
|
||||
if (!p.isIdentifier()) {
|
||||
builder.errors.push({
|
||||
reason: `(BuildHIR::lowerExpression) Handle ${p.type} params in FunctionExpression`,
|
||||
severity: ErrorSeverity.Todo,
|
||||
nodePath: p,
|
||||
});
|
||||
hasError = true;
|
||||
continue;
|
||||
}
|
||||
params.push(p.node.name);
|
||||
}
|
||||
return hasError
|
||||
? { kind: "UnsupportedNode", node: exprNode, loc: exprLoc }
|
||||
: {
|
||||
kind: "FunctionExpression",
|
||||
name,
|
||||
params,
|
||||
loweredFunc,
|
||||
dependencies: captured.refs,
|
||||
mutatedDeps: [],
|
||||
expr: expr.node,
|
||||
loc: exprLoc,
|
||||
};
|
||||
return {
|
||||
kind: "FunctionExpression",
|
||||
name,
|
||||
loweredFunc,
|
||||
dependencies: captured.refs,
|
||||
mutatedDeps: [],
|
||||
expr: expr.node,
|
||||
loc: exprLoc,
|
||||
};
|
||||
}
|
||||
case "TaggedTemplateExpression": {
|
||||
const expr = exprPath as NodePath<t.TaggedTemplateExpression>;
|
||||
|
||||
@@ -469,7 +469,6 @@ export type JsxAttribute =
|
||||
export type FunctionExpression = {
|
||||
kind: "FunctionExpression";
|
||||
name: string | null;
|
||||
params: Array<string>;
|
||||
dependencies: Array<Place>;
|
||||
// TODO(gsn): Remove this mutatedDeps array and use dependencies as single
|
||||
// source of truth.
|
||||
|
||||
@@ -333,14 +333,11 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
|
||||
break;
|
||||
}
|
||||
case "FunctionExpression": {
|
||||
const params = instrValue.params.join(",");
|
||||
const body = generate(instrValue.expr).code;
|
||||
const fn = generate(instrValue.expr).code;
|
||||
const deps = instrValue.dependencies
|
||||
.map((i) => printIdentifier(i.identifier))
|
||||
.join(",");
|
||||
value = `Function ${instrValue.name ?? ""} @deps[${deps}] (${
|
||||
params ?? ""
|
||||
}){${body}}`;
|
||||
value = `Function @deps[${deps}]{${fn}}`;
|
||||
break;
|
||||
}
|
||||
case "TaggedTemplateExpression": {
|
||||
|
||||
@@ -673,7 +673,6 @@ function codegenInstructionValue(
|
||||
case "FunctionExpression": {
|
||||
const id =
|
||||
instrValue.name !== null ? t.identifier(instrValue.name) : null;
|
||||
const params = instrValue.params.map((p) => t.identifier(p));
|
||||
value = instrValue.expr;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user