diff --git a/compiler/forget/src/HIR/BuildHIR.ts b/compiler/forget/src/HIR/BuildHIR.ts index 0b0346e30f..a701683d6f 100644 --- a/compiler/forget/src/HIR/BuildHIR.ts +++ b/compiler/forget/src/HIR/BuildHIR.ts @@ -81,11 +81,14 @@ export function lower( const body = func.get("body"); if (body.isExpression()) { - builder.pushError({ - reason: "Support arrow functions", - severity: ErrorSeverity.Todo, - nodePath: body, - }); + const fallthrough = builder.reserve(); + const terminal: ReturnTerminal = { + kind: "return", + loc: GeneratedSource, + value: lowerExpressionToPlace(builder, body), + id: makeInstructionId(0), + }; + builder.terminateWithContinuation("block", terminal, fallthrough); } else if (body.isBlockStatement()) { lowerStatement(builder, body); } else { diff --git a/compiler/forget/src/__tests__/fixtures/hir/concise-arrow-expr.expect.md b/compiler/forget/src/__tests__/fixtures/hir/concise-arrow-expr.expect.md new file mode 100644 index 0000000000..64bab0f4c1 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/concise-arrow-expr.expect.md @@ -0,0 +1,49 @@ + +## Input + +```javascript +function component() { + let [x, setX] = useState(0); + const handler = (v) => setX(v); + return ; +} + +``` + +## Code + +```javascript +function component() { + const $ = React.useMemoCache(); + let t0; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + t0 = useState(0); + $[0] = t0; + } else { + t0 = $[0]; + } + const x = t0[0]; + const setX = t0[1]; + const c_1 = $[1] !== setX; + let handler; + if (c_1) { + handler = (v) => setX(v); + $[1] = setX; + $[2] = handler; + } else { + handler = $[2]; + } + const c_3 = $[3] !== handler; + let t4; + if (c_3) { + t4 = ; + $[3] = handler; + $[4] = t4; + } else { + t4 = $[4]; + } + return t4; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/concise-arrow-expr.js b/compiler/forget/src/__tests__/fixtures/hir/concise-arrow-expr.js new file mode 100644 index 0000000000..d04270e3ac --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/concise-arrow-expr.js @@ -0,0 +1,5 @@ +function component() { + let [x, setX] = useState(0); + const handler = (v) => setX(v); + return ; +}