[λ] Remove unused params in FunctionExpression

This commit is contained in:
Sathya Gunasekaran
2023-02-06 14:03:13 +00:00
parent cd108cd430
commit 500cfddc3a
4 changed files with 11 additions and 34 deletions
+9 -27
View File
@@ -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>;
-1
View File
@@ -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.
+2 -5
View File
@@ -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;
}