diff --git a/packages/babel-plugin-proposal-pipeline-operator/src/fsharpVisitor.js b/packages/babel-plugin-proposal-pipeline-operator/src/fsharpVisitor.js index f66b0f5ccc21..88f94412073a 100644 --- a/packages/babel-plugin-proposal-pipeline-operator/src/fsharpVisitor.js +++ b/packages/babel-plugin-proposal-pipeline-operator/src/fsharpVisitor.js @@ -5,7 +5,7 @@ const fsharpVisitor = { const { scope } = path; const { node } = path; const { operator, left } = node; - let right = node.right.body; + let { right } = node; if (operator !== "|>") return; let optimizeArrow = @@ -35,10 +35,7 @@ const fsharpVisitor = { const placeholder = scope.generateUidIdentifierBasedOnNode(param || left); scope.push({ id: placeholder }); if (param) { - path - .get("right") - .get("body") - .scope.rename(param.name, placeholder.name); + path.get("right").scope.rename(param.name, placeholder.name); } const applied = diff --git a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions-parenless/exec.js b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions-parenless/exec.js index 1ff62e57a0bb..0e23684373b2 100644 --- a/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions-parenless/exec.js +++ b/packages/babel-plugin-proposal-pipeline-operator/test/fixtures/fsharp/arrow-functions-parenless/exec.js @@ -1,29 +1,34 @@ const y = 2; -// parenthised until parser is fixed + const f = (x) => (x |> (y) => y + 1) |> (z) => z * y +const _f = (x) => x + |> (y) => y + 1 + |> (z) => z * y + const g = (x) => x - |> (y => { return ( + |> (y) => ( y + 1 - |> (z) => z * y); - } + |> (z) => z * y ) -const h = (x) => x +const _g = (x) => x |> (y => ( y + 1 |> (z) => z * y) ) -const i = (x) => x - |> (y) => ( +const __g = (x) => x + |> (y => { return ( y + 1 - |> (z) => z * y + |> (z) => z * y); + } ) -expect(f(1)).toBe(4); -expect(g(1)).toBe(2); -expect(h(1)).toBe(2); -expect(i(1)).toBe(2); +expect( f(1)).toBe(4); +expect( _f(1)).toBe(4); +expect( g(1)).toBe(2); +expect( _g(1)).toBe(2); +expect(__g(1)).toBe(2);