@samitouri / QOS-React / commits / a5a58164ea

[compiler] Simplify FunctionExpression node

Rather than storing the entire babel node, store only the required information which is the node type. This will be useful for when we synthesize new functions that don't have a corresponding babel node. ghstack-source-id: 9098cbdbc4b1e9a6e7dafa2e7645f6f4854e1eac Pull Request resolved: https://github.com/facebook/react/pull/30544

Sathya Gunsasekaran committed Jul 31, 2024 at 14:35 UTC a5a58164eaf166195ca8c9e78b2a171febb137b6
3 files changed +6 -6
compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts
+1 -1
@@ -3270,7 +3270,7 @@ function lowerFunctionToValue(
3270 return {
3271 kind: 'FunctionExpression',
3272 name,
3273 - expr: expr.node,
3273 + type: expr.node.type,
3274 loc: exprLoc,
3275 loweredFunc,
3276 };
compiler/packages/babel-plugin-react-compiler/src/HIR/HIR.ts
+4 -4
@@ -1076,10 +1076,10 @@ export type FunctionExpression = {
1076 kind: 'FunctionExpression';
1077 name: string | null;
1078 loweredFunc: LoweredFunction;
1079 - expr:
1080 - | t.ArrowFunctionExpression
1081 - | t.FunctionExpression
1082 - | t.FunctionDeclaration;
1079 + type:
1080 + | 'ArrowFunctionExpression'
1081 + | 'FunctionExpression'
1082 + | 'FunctionDeclaration';
1083 loc: SourceLocation;
1084 };
1085
compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/CodegenReactiveFunction.ts
+1 -1
@@ -1997,7 +1997,7 @@ function codegenInstructionValue(
1997 ),
1998 reactiveFunction,
1999 ).unwrap();
2000 - if (instrValue.expr.type === 'ArrowFunctionExpression') {
2000 + if (instrValue.type === 'ArrowFunctionExpression') {
2001 let body: t.BlockStatement | t.Expression = fn.body;
2002 if (body.body.length === 1 && loweredFunc.directives.length == 0) {
2003 const stmt = body.body[0]!;