@samitouri / QOS-React / commits / 500cfddc3a

[λ] Remove unused params in FunctionExpression

Sathya Gunasekaran committed Feb 6, 2023 at 14:03 UTC 500cfddc3a67c7b9521ab3285f926b2e571fec5e
4 files changed +11 -34
compiler/forget/src/HIR/BuildHIR.ts
+9 -27
@@ -1359,33 +1359,15 @@ function lowerExpression(
1359 };
1360 }
1361 loweredFunc = lowering.unwrap();
1362 -
1363 - let hasError = false;
1364 - const params: Array<string> = [];
1365 - for (const p of expr.get("params")) {
1366 - if (!p.isIdentifier()) {
1367 - builder.errors.push({
1368 - reason: `(BuildHIR::lowerExpression) Handle ${p.type} params in FunctionExpression`,
1369 - severity: ErrorSeverity.Todo,
1370 - nodePath: p,
1371 - });
1372 - hasError = true;
1373 - continue;
1374 - }
1375 - params.push(p.node.name);
1376 - }
1377 - return hasError
1378 - ? { kind: "UnsupportedNode", node: exprNode, loc: exprLoc }
1379 - : {
1380 - kind: "FunctionExpression",
1381 - name,
1382 - params,
1383 - loweredFunc,
1384 - dependencies: captured.refs,
1385 - mutatedDeps: [],
1386 - expr: expr.node,
1387 - loc: exprLoc,
1388 - };
1362 + return {
1363 + kind: "FunctionExpression",
1364 + name,
1365 + loweredFunc,
1366 + dependencies: captured.refs,
1367 + mutatedDeps: [],
1368 + expr: expr.node,
1369 + loc: exprLoc,
1370 + };
1371 }
1372 case "TaggedTemplateExpression": {
1373 const expr = exprPath as NodePath<t.TaggedTemplateExpression>;
compiler/forget/src/HIR/HIR.ts
-1
@@ -469,7 +469,6 @@ export type JsxAttribute =
469 export type FunctionExpression = {
470 kind: "FunctionExpression";
471 name: string | null;
472 - params: Array<string>;
472 dependencies: Array<Place>;
473 // TODO(gsn): Remove this mutatedDeps array and use dependencies as single
474 // source of truth.
compiler/forget/src/HIR/PrintHIR.ts
+2 -5
@@ -333,14 +333,11 @@ export function printInstructionValue(instrValue: ReactiveValue): string {
333 break;
334 }
335 case "FunctionExpression": {
336 - const params = instrValue.params.join(",");
337 - const body = generate(instrValue.expr).code;
336 + const fn = generate(instrValue.expr).code;
337 const deps = instrValue.dependencies
338 .map((i) => printIdentifier(i.identifier))
339 .join(",");
341 - value = `Function ${instrValue.name ?? ""} @deps[${deps}] (${
342 - params ?? ""
343 - }){${body}}`;
340 + value = `Function @deps[${deps}]{${fn}}`;
341 break;
342 }
343 case "TaggedTemplateExpression": {
compiler/forget/src/ReactiveScopes/CodegenReactiveFunction.ts
-1
@@ -673,7 +673,6 @@ function codegenInstructionValue(
673 case "FunctionExpression": {
674 const id =
675 instrValue.name !== null ? t.identifier(instrValue.name) : null;
676 - const params = instrValue.params.map((p) => t.identifier(p));
676 value = instrValue.expr;
677 break;
678 }