From 05e2e3a00f6885404c87a94c259e9196bba95414 Mon Sep 17 00:00:00 2001 From: Jan Klaas Kollhof Date: Tue, 20 Jul 2021 09:00:49 +0200 Subject: [PATCH] feat: improve pipes with partials by removing partial wrapper for callees --- package-lock.json | 49 +++++++++++--------------------- src/lang/call/pipe.fnk | 18 ++++++++---- src/lang/call/pipe.test.fnk.snap | 9 ++---- 3 files changed, 31 insertions(+), 45 deletions(-) diff --git a/package-lock.json b/package-lock.json index 99ccce8..c64d5bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -750,14 +750,14 @@ } }, "node_modules/@fink/jest": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@fink/jest/-/jest-7.4.0.tgz", - "integrity": "sha512-XnbvCsL/1SfMhT/HlVZeWVm2gZjWPtz/Y9iLenCyFvUOyyvs2QDQOk72KOAb0cwZuX7ynMNw63CTzVn5I8jF7w==", + "version": "7.4.1", + "resolved": "https://registry.npmjs.org/@fink/jest/-/jest-7.4.1.tgz", + "integrity": "sha512-KMCdulciMzLBBZkqvxfXT/0dULYUl/Hlo092+jR91TK0NqOb19miuDJ6rsBl6B/kbnPrIOm3oovaks2lHSq5FQ==", "dev": true, "dependencies": { "@babel/core": "^7.11.6", - "@fink/js-interop": "^2.3.1", - "@fink/std-lib": "^8.0.1" + "@fink/js-interop": "^3.0.0", + "@fink/std-lib": "^8.5.0" }, "engines": { "node": ">=14.0.0" @@ -767,15 +767,6 @@ "@fink/loxia": ">=14.0.0" } }, - "node_modules/@fink/jest/node_modules/@fink/js-interop": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/@fink/js-interop/-/js-interop-2.5.0.tgz", - "integrity": "sha512-gmH8xhmiaB7wM2w5GHSqKJPm4Pi6HvmGUJgZ46wh6n3mHlSTsbld5Dxfo3VLo+dYBlm1iCVDrhdys5Z0w8f2gw==", - "dev": true, - "engines": { - "node": ">=14.13.0" - } - }, "node_modules/@fink/js-interop": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@fink/js-interop/-/js-interop-3.0.0.tgz", @@ -3375,9 +3366,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.3.779", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.779.tgz", - "integrity": "sha512-nreave0y/1Qhmo8XtO6C/LpawNyC6U26+q7d814/e+tIqUK073pM+4xW7WUXyqCRa5K4wdxHmNMBAi8ap9nEew==" + "version": "1.3.780", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.780.tgz", + "integrity": "sha512-2KQ9OYm9WMUNpAPA/4aerURl3hwRc9tNlpsiEj3Y8Gf7LVf26NzyLIX2v0hSagQwrS9+cWab+28A2GPKDoVNRA==" }, "node_modules/emittery": { "version": "0.8.1", @@ -13374,22 +13365,14 @@ } }, "@fink/jest": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@fink/jest/-/jest-7.4.0.tgz", - "integrity": "sha512-XnbvCsL/1SfMhT/HlVZeWVm2gZjWPtz/Y9iLenCyFvUOyyvs2QDQOk72KOAb0cwZuX7ynMNw63CTzVn5I8jF7w==", + "version": "7.4.1", + "resolved": "https://registry.npmjs.org/@fink/jest/-/jest-7.4.1.tgz", + "integrity": "sha512-KMCdulciMzLBBZkqvxfXT/0dULYUl/Hlo092+jR91TK0NqOb19miuDJ6rsBl6B/kbnPrIOm3oovaks2lHSq5FQ==", "dev": true, "requires": { "@babel/core": "^7.11.6", - "@fink/js-interop": "^2.3.1", - "@fink/std-lib": "^8.0.1" - }, - "dependencies": { - "@fink/js-interop": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/@fink/js-interop/-/js-interop-2.5.0.tgz", - "integrity": "sha512-gmH8xhmiaB7wM2w5GHSqKJPm4Pi6HvmGUJgZ46wh6n3mHlSTsbld5Dxfo3VLo+dYBlm1iCVDrhdys5Z0w8f2gw==", - "dev": true - } + "@fink/js-interop": "^3.0.0", + "@fink/std-lib": "^8.5.0" } }, "@fink/js-interop": { @@ -15453,9 +15436,9 @@ "dev": true }, "electron-to-chromium": { - "version": "1.3.779", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.779.tgz", - "integrity": "sha512-nreave0y/1Qhmo8XtO6C/LpawNyC6U26+q7d814/e+tIqUK073pM+4xW7WUXyqCRa5K4wdxHmNMBAi8ap9nEew==" + "version": "1.3.780", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.780.tgz", + "integrity": "sha512-2KQ9OYm9WMUNpAPA/4aerURl3hwRc9tNlpsiEj3Y8Gf7LVf26NzyLIX2v0hSagQwrS9+cWab+28A2GPKDoVNRA==" }, "emittery": { "version": "0.8.1", diff --git a/src/lang/call/pipe.fnk b/src/lang/call/pipe.fnk index 587aa0c..e47e2ee 100644 --- a/src/lang/call/pipe.fnk +++ b/src/lang/call/pipe.fnk @@ -5,16 +5,22 @@ babel_types = import '@babel/types' {assign, lets, undef, unique_ident} = import '../../js/types.fnk' {wrap_with_comment_loc} = import '../comments/init.fnk' {transform, map_with_ctx, collect_with_ctx} = import '../transform.fnk' +{transform_with_partial} = import '../partial/init.fnk' -transform_callee = fn result: fn expr, ctx: - [callee, next_ctx] = transform expr, ctx +transform_pipe_step = fn result: fn expr, ctx: + callee_ctx = {...ctx, partial_ident: result} - js = wrap_with_comment_loc - assign result, callExpression callee, [result] - expr + [is_partial, callee, {partial_ident: _, ...next_ctx}] = transform_with_partial expr, callee_ctx, false + step = match is_partial: + false: + assign result, callExpression callee, [result] + else: + assign result, callee + + js = wrap_with_comment_loc step, expr [js, next_ctx] @@ -32,7 +38,7 @@ transform_pipe = fn node, ctx: [result, pipe_ctx] = unique_ident 'pipe_result', id_ctx [pipe_calls, next_ctx] = pipe exprs: - map_with_ctx transform_callee result + map_with_ctx transform_pipe_step result collect_with_ctx pipe_ctx js = doExpression diff --git a/src/lang/call/pipe.test.fnk.snap b/src/lang/call/pipe.test.fnk.snap index af9ac9c..0c0bcd6 100644 --- a/src/lang/call/pipe.test.fnk.snap +++ b/src/lang/call/pipe.test.fnk.snap @@ -4,14 +4,11 @@ exports[`pipe compiles 1`] = ` "{ let ˆpipe_result_1 = undefined; ˆpipe_result_1 = foo(ˆpipe_result_1); - - ˆpipe_result_1 = (ˆpartial => bar(ˆpartial, { + ˆpipe_result_1 = bar(ˆpipe_result_1, { foo - }))(ˆpipe_result_1); - + }); ˆpipe_result_1 = spam(ˆpipe_result_1); - - ˆpipe_result_1 = (ˆpartial => [...ˆpartial])(ˆpipe_result_1); + ˆpipe_result_1 = [...ˆpipe_result_1]; } { let ˆpipe_result_2 = [1, 2, 3];