From 7383f438a0b42dcab6618db96db7ee573d345568 Mon Sep 17 00:00:00 2001 From: Jan Klaas Kollhof Date: Sun, 18 Jul 2021 07:57:20 +0200 Subject: [PATCH] feat(partial): improve partial handling --- package-lock.json | 159 ++++++++++++++++-------- package.json | 2 +- src/lang/arithmitic/init.fnk | 16 ++- src/lang/arithmitic/init.test.fnk | 10 ++ src/lang/arithmitic/init.test.fnk.snap | 8 ++ src/lang/assignment/init.fnk | 13 +- src/lang/block/init.fnk | 1 - src/lang/call/call.fnk | 48 +++++-- src/lang/call/call.test.fnk | 26 +++- src/lang/call/call.test.fnk.snap | 24 ++++ src/lang/call/pipe.fnk | 3 +- src/lang/call/pipe.test.fnk | 3 +- src/lang/call/pipe.test.fnk.snap | 5 +- src/lang/comparison/init.fnk | 7 +- src/lang/comparison/init.test.fnk | 11 ++ src/lang/comparison/init.test.fnk.snap | 10 ++ src/lang/conditionals/match.fnk | 11 +- src/lang/func/init.test.fnk | 2 - src/lang/literals/list.fnk | 15 ++- src/lang/literals/list.test.fnk | 9 ++ src/lang/literals/list.test.fnk.snap | 6 + src/lang/literals/record.fnk | 13 +- src/lang/literals/record.test.fnk | 11 ++ src/lang/literals/record.test.fnk.snap | 12 ++ src/lang/logical/in.fnk | 10 +- src/lang/logical/in.test.fnk | 10 ++ src/lang/logical/in.test.fnk.snap | 8 ++ src/lang/logical/init.fnk | 14 ++- src/lang/logical/init.test.fnk | 11 ++ src/lang/logical/init.test.fnk.snap | 8 ++ src/lang/partial/init.fnk | 66 +++++----- src/lang/partial/init.test.fnk | 24 ---- src/lang/partial/init.test.fnk.snap | 18 --- src/lang/prop-access/init.fnk | 24 ++-- src/lang/prop-access/init.test.fnk | 11 +- src/lang/prop-access/init.test.fnk.snap | 8 ++ src/lang/spread/init.fnk | 9 +- 37 files changed, 445 insertions(+), 201 deletions(-) delete mode 100644 src/lang/partial/init.test.fnk delete mode 100644 src/lang/partial/init.test.fnk.snap diff --git a/package-lock.json b/package-lock.json index b766659..2e42d2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "@fink/cli": "^8.0.0", "@fink/jest": "^7.2.0", "@fink/larix": "^19.0.0", - "@fink/loxia": "^21.6.1", + "@fink/loxia": "^22.0.0", "commitizen": "^4.1.2", "cz-conventional-changelog": "^3.1.0", "jest-cli": "^27.0.0", @@ -740,6 +740,15 @@ "@fink/loxia": ">=14.0.2" } }, + "node_modules/@fink/cli/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/jest": { "version": "7.4.0", "resolved": "https://registry.npmjs.org/@fink/jest/-/jest-7.4.0.tgz", @@ -758,10 +767,19 @@ "@fink/loxia": ">=14.0.0" } }, - "node_modules/@fink/js-interop": { + "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", + "integrity": "sha512-ZcdMF4EXHVgX+KG5T17eB+q5YsTTFAwvTWBZ1mb5U+owBad9mnIPzDYyET2OSK6zrD3CX4qDGSLai5pDm1/DAw==", "engines": { "node": ">=14.13.0" } @@ -780,23 +798,23 @@ } }, "node_modules/@fink/loxia": { - "version": "21.6.1", - "resolved": "https://registry.npmjs.org/@fink/loxia/-/loxia-21.6.1.tgz", - "integrity": "sha512-yvZrKpGe9fQaBKpSd6qxj8ji2Rqh81bODMIQJ8UygDUFWHN5uQ0k/UYXHyJQjOChBneA1u0qUmqVwxjo++aPoA==", + "version": "22.0.0", + "resolved": "https://registry.npmjs.org/@fink/loxia/-/loxia-22.0.0.tgz", + "integrity": "sha512-ySlRbnHd4e9wF2qLb2TXkaXGKDJXNXqnvbonncMyS2IB2UbOVtYvSae48LzAR19luSPCxCJKs5rmm4Fi+dUNlw==", "dev": true, "dependencies": { "@babel/core": "^7.10.5", "@babel/traverse": "^7.10.5", "@babel/types": "^7.10.5", - "@fink/js-interop": ">2.2", + "@fink/js-interop": ">=2.5", "@fink/snippet": "^2.2.0", - "@fink/std-lib": "^8.3.0" + "@fink/std-lib": "^8.5.0" }, "engines": { "node": ">=14.13.0" }, "peerDependencies": { - "@fink/js-interop": ">2.2" + "@fink/js-interop": ">=2.5" } }, "node_modules/@fink/prattler": { @@ -834,6 +852,14 @@ "node": ">=14.0.0" } }, + "node_modules/@fink/std-lib/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==", + "engines": { + "node": ">=14.13.0" + } + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -2597,9 +2623,9 @@ "dev": true }, "node_modules/cjs-module-lexer": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/cjs-module-lexer/-/cjs-module-lexer-1.2.1.tgz", - "integrity": "sha512-jVamGdJPDeuQilKhvVn1h3knuMOZzr8QDnpk+M9aMlCaMkTDd6fBWPhiDqFvFZ07pL0liqabAiuy8SY4jGHeaw==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cjs-module-lexer/-/cjs-module-lexer-1.2.2.tgz", + "integrity": "sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==", "dev": true }, "node_modules/clean-stack": { @@ -3349,9 +3375,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.3.775", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.775.tgz", - "integrity": "sha512-EGuiJW4yBPOTj2NtWGZcX93ZE8IGj33HJAx4d3ouE2zOfW2trbWU+t1e0yzLr1qQIw81++txbM3BH52QwSRE6Q==" + "version": "1.3.778", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.778.tgz", + "integrity": "sha512-Lw04qJaPtWdq0d7qKHJTgkam+FhFi3hm/scf1EyqJWdjO3ZIGUJhNmZJRXWb7yb/bRYXQyVGSpa9RqVpjjWMQw==" }, "node_modules/emittery": { "version": "0.8.1", @@ -7449,9 +7475,9 @@ } }, "node_modules/npm": { - "version": "7.19.1", - "resolved": "https://registry.npmjs.org/npm/-/npm-7.19.1.tgz", - "integrity": "sha512-aN3hZzGkPzKOyhjXtOhnQTGumorFhgpOU6xfuQsF1nJKh4DhsgfOMG4s/SNx56r4xHPvM5m/sk914wzDgKba3A==", + "version": "7.20.0", + "resolved": "https://registry.npmjs.org/npm/-/npm-7.20.0.tgz", + "integrity": "sha512-59Eje4RcXP9EKYPIJvBvQGTyfEvZWaKdOx5+YZ+IJ+fqYhJJH5ng78qcdD8sFPyA1g1MFBR0DYXKfncwbxXpVA==", "bundleDependencies": [ "@npmcli/arborist", "@npmcli/ci-detect", @@ -7524,7 +7550,7 @@ ], "dev": true, "dependencies": { - "@npmcli/arborist": "^2.6.4", + "@npmcli/arborist": "^2.7.1", "@npmcli/ci-detect": "^1.2.0", "@npmcli/config": "^2.2.0", "@npmcli/package-json": "^1.0.1", @@ -7559,7 +7585,7 @@ "libnpmsearch": "^3.1.1", "libnpmteam": "^2.0.3", "libnpmversion": "^1.2.1", - "make-fetch-happen": "^9.0.3", + "make-fetch-happen": "^9.0.4", "minipass": "^3.1.3", "minipass-pipeline": "^1.2.4", "mkdirp": "^1.0.4", @@ -7575,7 +7601,7 @@ "npm-user-validate": "^1.0.1", "npmlog": "~4.1.2", "opener": "^1.5.2", - "pacote": "^11.3.3", + "pacote": "^11.3.5", "parse-conflict-json": "^1.1.1", "qrcode-terminal": "^0.12.0", "read": "~1.0.7", @@ -7635,7 +7661,7 @@ } }, "node_modules/npm/node_modules/@npmcli/arborist": { - "version": "2.6.4", + "version": "2.7.1", "dev": true, "inBundle": true, "license": "ISC", @@ -7653,6 +7679,7 @@ "common-ancestor-path": "^1.0.1", "json-parse-even-better-errors": "^2.3.1", "json-stringify-nice": "^1.1.4", + "mkdirp": "^1.0.4", "mkdirp-infer-owner": "^2.0.0", "npm-install-checks": "^4.0.0", "npm-package-arg": "^8.1.0", @@ -7665,7 +7692,9 @@ "promise-call-limit": "^1.0.1", "read-package-json-fast": "^2.0.2", "readdir-scoped-modules": "^1.1.0", + "rimraf": "^3.0.2", "semver": "^7.3.5", + "ssri": "^8.0.1", "tar": "^6.1.0", "treeverse": "^1.0.4", "walk-up-path": "^1.0.0" @@ -7712,7 +7741,7 @@ } }, "node_modules/npm/node_modules/@npmcli/git": { - "version": "2.0.9", + "version": "2.1.0", "dev": true, "inBundle": true, "license": "ISC", @@ -9142,7 +9171,7 @@ } }, "node_modules/npm/node_modules/make-fetch-happen": { - "version": "9.0.3", + "version": "9.0.4", "dev": true, "inBundle": true, "license": "ISC", @@ -9226,7 +9255,7 @@ } }, "node_modules/npm/node_modules/minipass-fetch": { - "version": "1.3.3", + "version": "1.3.4", "dev": true, "inBundle": true, "license": "MIT", @@ -9593,12 +9622,12 @@ } }, "node_modules/npm/node_modules/pacote": { - "version": "11.3.4", + "version": "11.3.5", "dev": true, "inBundle": true, "license": "ISC", "dependencies": { - "@npmcli/git": "^2.0.1", + "@npmcli/git": "^2.1.0", "@npmcli/installed-package-contents": "^1.0.6", "@npmcli/promise-spawn": "^1.2.0", "@npmcli/run-script": "^1.8.2", @@ -13334,6 +13363,14 @@ "@fink/std-lib": "^8.2.0", "minimatch": "^3.0.4", "yargs": "^17.0.0" + }, + "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/jest": { @@ -13345,12 +13382,20 @@ "@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": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/@fink/js-interop/-/js-interop-2.5.0.tgz", - "integrity": "sha512-gmH8xhmiaB7wM2w5GHSqKJPm4Pi6HvmGUJgZ46wh6n3mHlSTsbld5Dxfo3VLo+dYBlm1iCVDrhdys5Z0w8f2gw==" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@fink/js-interop/-/js-interop-3.0.0.tgz", + "integrity": "sha512-ZcdMF4EXHVgX+KG5T17eB+q5YsTTFAwvTWBZ1mb5U+owBad9mnIPzDYyET2OSK6zrD3CX4qDGSLai5pDm1/DAw==" }, "@fink/larix": { "version": "19.0.0", @@ -13363,17 +13408,17 @@ } }, "@fink/loxia": { - "version": "21.6.1", - "resolved": "https://registry.npmjs.org/@fink/loxia/-/loxia-21.6.1.tgz", - "integrity": "sha512-yvZrKpGe9fQaBKpSd6qxj8ji2Rqh81bODMIQJ8UygDUFWHN5uQ0k/UYXHyJQjOChBneA1u0qUmqVwxjo++aPoA==", + "version": "22.0.0", + "resolved": "https://registry.npmjs.org/@fink/loxia/-/loxia-22.0.0.tgz", + "integrity": "sha512-ySlRbnHd4e9wF2qLb2TXkaXGKDJXNXqnvbonncMyS2IB2UbOVtYvSae48LzAR19luSPCxCJKs5rmm4Fi+dUNlw==", "dev": true, "requires": { "@babel/core": "^7.10.5", "@babel/traverse": "^7.10.5", "@babel/types": "^7.10.5", - "@fink/js-interop": ">2.2", + "@fink/js-interop": ">=2.5", "@fink/snippet": "^2.2.0", - "@fink/std-lib": "^8.3.0" + "@fink/std-lib": "^8.5.0" } }, "@fink/prattler": { @@ -13400,6 +13445,13 @@ "integrity": "sha512-ouxm15qv8NOfLAkaOBSp19Y6IUdWNw8oDooa9SYZob+ZFa5P3LAYBHwrKV6L8xgYtpJUJmVf6I/Rd0jMzyblqQ==", "requires": { "@fink/js-interop": "^2.2.0" + }, + "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==" + } } }, "@istanbuljs/load-nyc-config": { @@ -14806,9 +14858,9 @@ "dev": true }, "cjs-module-lexer": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/cjs-module-lexer/-/cjs-module-lexer-1.2.1.tgz", - "integrity": "sha512-jVamGdJPDeuQilKhvVn1h3knuMOZzr8QDnpk+M9aMlCaMkTDd6fBWPhiDqFvFZ07pL0liqabAiuy8SY4jGHeaw==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cjs-module-lexer/-/cjs-module-lexer-1.2.2.tgz", + "integrity": "sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==", "dev": true }, "clean-stack": { @@ -15401,9 +15453,9 @@ "dev": true }, "electron-to-chromium": { - "version": "1.3.775", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.775.tgz", - "integrity": "sha512-EGuiJW4yBPOTj2NtWGZcX93ZE8IGj33HJAx4d3ouE2zOfW2trbWU+t1e0yzLr1qQIw81++txbM3BH52QwSRE6Q==" + "version": "1.3.778", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.778.tgz", + "integrity": "sha512-Lw04qJaPtWdq0d7qKHJTgkam+FhFi3hm/scf1EyqJWdjO3ZIGUJhNmZJRXWb7yb/bRYXQyVGSpa9RqVpjjWMQw==" }, "emittery": { "version": "0.8.1", @@ -18521,12 +18573,12 @@ "dev": true }, "npm": { - "version": "7.19.1", - "resolved": "https://registry.npmjs.org/npm/-/npm-7.19.1.tgz", - "integrity": "sha512-aN3hZzGkPzKOyhjXtOhnQTGumorFhgpOU6xfuQsF1nJKh4DhsgfOMG4s/SNx56r4xHPvM5m/sk914wzDgKba3A==", + "version": "7.20.0", + "resolved": "https://registry.npmjs.org/npm/-/npm-7.20.0.tgz", + "integrity": "sha512-59Eje4RcXP9EKYPIJvBvQGTyfEvZWaKdOx5+YZ+IJ+fqYhJJH5ng78qcdD8sFPyA1g1MFBR0DYXKfncwbxXpVA==", "dev": true, "requires": { - "@npmcli/arborist": "^2.6.4", + "@npmcli/arborist": "^2.7.1", "@npmcli/ci-detect": "^1.2.0", "@npmcli/config": "^2.2.0", "@npmcli/package-json": "^1.0.1", @@ -18561,7 +18613,7 @@ "libnpmsearch": "^3.1.1", "libnpmteam": "^2.0.3", "libnpmversion": "^1.2.1", - "make-fetch-happen": "^9.0.3", + "make-fetch-happen": "^9.0.4", "minipass": "^3.1.3", "minipass-pipeline": "^1.2.4", "mkdirp": "^1.0.4", @@ -18577,7 +18629,7 @@ "npm-user-validate": "^1.0.1", "npmlog": "~4.1.2", "opener": "^1.5.2", - "pacote": "^11.3.3", + "pacote": "^11.3.5", "parse-conflict-json": "^1.1.1", "qrcode-terminal": "^0.12.0", "read": "~1.0.7", @@ -18597,7 +18649,7 @@ }, "dependencies": { "@npmcli/arborist": { - "version": "2.6.4", + "version": "2.7.1", "bundled": true, "dev": true, "requires": { @@ -18614,6 +18666,7 @@ "common-ancestor-path": "^1.0.1", "json-parse-even-better-errors": "^2.3.1", "json-stringify-nice": "^1.1.4", + "mkdirp": "^1.0.4", "mkdirp-infer-owner": "^2.0.0", "npm-install-checks": "^4.0.0", "npm-package-arg": "^8.1.0", @@ -18626,7 +18679,9 @@ "promise-call-limit": "^1.0.1", "read-package-json-fast": "^2.0.2", "readdir-scoped-modules": "^1.1.0", + "rimraf": "^3.0.2", "semver": "^7.3.5", + "ssri": "^8.0.1", "tar": "^6.1.0", "treeverse": "^1.0.4", "walk-up-path": "^1.0.0" @@ -18658,7 +18713,7 @@ } }, "@npmcli/git": { - "version": "2.0.9", + "version": "2.1.0", "bundled": true, "dev": true, "requires": { @@ -19703,7 +19758,7 @@ } }, "make-fetch-happen": { - "version": "9.0.3", + "version": "9.0.4", "bundled": true, "dev": true, "requires": { @@ -19763,7 +19818,7 @@ } }, "minipass-fetch": { - "version": "1.3.3", + "version": "1.3.4", "bundled": true, "dev": true, "requires": { @@ -20016,11 +20071,11 @@ } }, "pacote": { - "version": "11.3.4", + "version": "11.3.5", "bundled": true, "dev": true, "requires": { - "@npmcli/git": "^2.0.1", + "@npmcli/git": "^2.1.0", "@npmcli/installed-package-contents": "^1.0.6", "@npmcli/promise-spawn": "^1.2.0", "@npmcli/run-script": "^1.8.2", diff --git a/package.json b/package.json index bd17ffd..97e19a4 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@fink/cli": "^8.0.0", "@fink/jest": "^7.2.0", "@fink/larix": "^19.0.0", - "@fink/loxia": "^21.6.1", + "@fink/loxia": "^22.0.0", "commitizen": "^4.1.2", "cz-conventional-changelog": "^3.1.0", "jest-cli": "^27.0.0", diff --git a/src/lang/arithmitic/init.fnk b/src/lang/arithmitic/init.fnk index 77c23fd..93991f1 100644 --- a/src/lang/arithmitic/init.fnk +++ b/src/lang/arithmitic/init.fnk @@ -2,7 +2,8 @@ babel_types = import '@babel/types' {binaryExpression, unaryExpression} = babel_types {add, any} = import '../context.fnk' -{transform} = import '../transform.fnk' + +{transform_with_partial_lr, transform_with_partial} = import '../partial/init.fnk' @@ -14,19 +15,22 @@ transform_op = rec: transform_arithmitic = fn {op, left, right}, ctx: {(op): operator=op} = transform_op - [left_js, right_ctx] = transform left, ctx - [right_js, end_ctx] = transform right, right_ctx + [left_js, right_js, next_ctx, wrap_partial] = transform_with_partial_lr left, right, ctx + js = binaryExpression operator, left_js, right_js - [js, end_ctx] + wrap_partial js, next_ctx + + transform_unary = fn {op, right}, ctx: - [right_js, next_ctx] = transform right, ctx + [wrap_partial, right_js, next_ctx] = transform_with_partial right, ctx + js = unaryExpression op, right_js - [js, next_ctx] + wrap_partial js, next_ctx diff --git a/src/lang/arithmitic/init.test.fnk b/src/lang/arithmitic/init.test.fnk index d47e8d6..9d31cf6 100644 --- a/src/lang/arithmitic/init.test.fnk +++ b/src/lang/arithmitic/init.test.fnk @@ -19,3 +19,13 @@ describe 'binary', fn: ' to_match_snapshot + + it 'compiles as partial', fn: + expect + fink2js ' + add = a + ? + b + ? + -? + ' + to_match_snapshot + diff --git a/src/lang/arithmitic/init.test.fnk.snap b/src/lang/arithmitic/init.test.fnk.snap index 3bb4c11..f309999 100644 --- a/src/lang/arithmitic/init.test.fnk.snap +++ b/src/lang/arithmitic/init.test.fnk.snap @@ -7,3 +7,11 @@ export const multi_line_assign = 123 + 234 + (-567 - 1111); export const group1 = (1 + 2) * 3; export const group2 = 34234 ** -34234 + 1;" `; + +exports[`binary compiles as partial 1`] = ` +"export const add = ˆpartial => a + ˆpartial; + +ˆpartial => b + ˆpartial; + +ˆpartial => -ˆpartial;" +`; diff --git a/src/lang/assignment/init.fnk b/src/lang/assignment/init.fnk index 7533546..0d9c9b8 100644 --- a/src/lang/assignment/init.fnk +++ b/src/lang/assignment/init.fnk @@ -11,7 +11,6 @@ babel_types = import '@babel/types' {transform_left: xform_left} = import '../../js/left.fnk' {wrap_with_comment_loc} = import '../comments/init.fnk' {add, any} = import '../context.fnk' -{transform_value} = import '../partial/init.fnk' {transform} = import '../transform.fnk' @@ -31,10 +30,8 @@ has_spread_not_last = fn {left}: [...exprs, ] = left.exprs [spread=false] = pipe exprs: - # TODO map ?.type == 'spread' - map fn {type}: type == 'spread' - #TODO filter is_spread - filter fn is_spread: is_spread + # TODO filter ?.type == 'spread' + filter fn {type}: type == 'spread' spread else: @@ -90,7 +87,7 @@ transform_spread_right = fn expr, ctx: {left, right} = expr [items, init_ctx] = unique_ident 'items', ctx # TODO: wrap declarator? - [init, next_ctx] = transform_value right, init_ctx + [init, next_ctx] = transform right, init_ctx items_init = wrap_with_comment_loc variableDeclaration @@ -148,7 +145,7 @@ transform_await_right = fn expr, ctx: [items, iter_ctx] = unique_ident 'items', ctx [iter, init_ctx] = unique_ident 'iter', iter_ctx - [init, next_ctx] = transform_value right, init_ctx + [init, next_ctx] = transform right, init_ctx items_init = wrap_with_comment_loc variableDeclaration 'const', [variableDeclarator items, init] @@ -214,7 +211,7 @@ transform_assign_left = fn node, ctx: transform_assign_right = fn node, ctx: - transform_value node.right, ctx + transform node.right, ctx diff --git a/src/lang/block/init.fnk b/src/lang/block/init.fnk index b9548b3..3ae4012 100644 --- a/src/lang/block/init.fnk +++ b/src/lang/block/init.fnk @@ -30,7 +30,6 @@ block_statement = fn expr, ctx: [js, next_ctx] - exprs_block = fn exprs, ctx: pipe exprs: map_with_ctx block_statement diff --git a/src/lang/call/call.fnk b/src/lang/call/call.fnk index 7fd184d..ff696af 100644 --- a/src/lang/call/call.fnk +++ b/src/lang/call/call.fnk @@ -1,12 +1,14 @@ babel_types = import '@babel/types' {callExpression, identifier} = babel_types -{is_empty, length} = import '@fink/std-lib/iter.fnk' + +{map, filter, zip, is_empty, length} = import '@fink/std-lib/iter.fnk' {transform, map_with_ctx, collect_with_ctx} = import '../transform.fnk' +{transform_with_partial, partial_wrapper, no_wrapper} = import '../partial/init.fnk' -transform_args = fn args, ctx: +transform_multiple_args = fn args, ctx: pipe args: map_with_ctx fn expr, arg_ctx: match expr: @@ -21,26 +23,46 @@ transform_args = fn args, ctx: transform_single_arg = fn [expr], ctx: match expr: {type: 'empty'}: - [[], ctx] - # remove in favour of using _ as empty? + [[], ctx] + # TODO: remove in favour of using _ as empty? {type: 'group', exprs: is_empty ?}: [[], ctx] else: - [arg, next_ctx] = transform expr, ctx - [[arg], next_ctx] - + transform_multiple_args [expr], ctx -transform_call = fn node, ctx: - [callee, args_ctx] = transform node.callee, ctx - [args, end_ctx] = match node.args: +transform_args = fn args, ctx, default_wrap_partial: + [js_args, next_ctx] = match args: 1 == length ?: - transform_single_arg node.args, args_ctx + transform_single_arg args, ctx + else: + transform_multiple_args args, ctx + + [wrap_partial=default_wrap_partial] = pipe zip args, js_args: + filter fn [arg, js_arg]: match arg: + {type: 'partial'}: true + {type: 'spread', right: {type: 'partial'}}: true + {type: 'spread'}: js_arg.is_partial + else: false + map fn: partial_wrapper + + [wrap_partial, js_args, next_ctx] + + + + +transform_call = fn node, ctx: + [callee, wrap_partial, args, end_ctx] = match node.callee: + # TODO: small pipe foo | bar ?, spam + {type: 'call'}: + [callee, args_ctx] = transform node.callee, ctx + [callee, ...transform_args node.args, args_ctx, no_wrapper] else: - transform_args node.args, args_ctx + [wrap_partial_callee, callee, args_ctx] = transform_with_partial node.callee, ctx + [callee, ...transform_args node.args, args_ctx, wrap_partial_callee] js = callExpression callee, args - [js, end_ctx] + wrap_partial js, end_ctx diff --git a/src/lang/call/call.test.fnk b/src/lang/call/call.test.fnk index 3678ea6..744581e 100644 --- a/src/lang/call/call.test.fnk +++ b/src/lang/call/call.test.fnk @@ -4,7 +4,6 @@ describe 'call', fn: it 'compiles', fn: - expect fink2js ' call1 = a ni, x=123, ...x @@ -17,4 +16,29 @@ describe 'call', fn: to_match_snapshot + it 'compiles as partial', fn: + expect + fink2js ' + foo ? + foo ?, 123 + foo ...? + foo ...?.bar + ? 123 + ? bar, spam + ?.bar spam + ' + to_match_snapshot + + + it 'compiles with partial args', fn: + expect + fink2js ' + filter ? == 1 + filter ? or foo ? + filter not ? + map ?.foo + map ? % 2 == 0 + ' + to_match_snapshot + diff --git a/src/lang/call/call.test.fnk.snap b/src/lang/call/call.test.fnk.snap index 4c93cd3..e162330 100644 --- a/src/lang/call/call.test.fnk.snap +++ b/src/lang/call/call.test.fnk.snap @@ -8,3 +8,27 @@ export const call4 = a(); export const call5 = a(x => x * 2); export const call6 = a(foo, undefined, bar);" `; + +exports[`call compiles as partial 1`] = ` +"ˆpartial => foo(ˆpartial); + +ˆpartial => foo(ˆpartial, 123); + +ˆpartial => foo(...ˆpartial); + +ˆpartial => foo(...ˆpartial.bar); + +ˆpartial => ˆpartial(123); + +ˆpartial => ˆpartial(bar, spam); + +ˆpartial => ˆpartial.bar(spam);" +`; + +exports[`call compiles with partial args 1`] = ` +"filter(ˆpartial => ˆpartial === 1); +filter(ˆpartial => ˆpartial || foo(ˆpartial)); +filter(ˆpartial => !ˆpartial); +map(ˆpartial => ˆpartial.foo); +map(ˆpartial => ˆpartial % 2 === 0);" +`; diff --git a/src/lang/call/pipe.fnk b/src/lang/call/pipe.fnk index c2d7d31..587aa0c 100644 --- a/src/lang/call/pipe.fnk +++ b/src/lang/call/pipe.fnk @@ -3,14 +3,13 @@ babel_types = import '@babel/types' {is_empty} = import '@fink/std-lib/iter.fnk' {assign, lets, undef, unique_ident} = import '../../js/types.fnk' -{transform_value} = import '../partial/init.fnk' {wrap_with_comment_loc} = import '../comments/init.fnk' {transform, map_with_ctx, collect_with_ctx} = import '../transform.fnk' transform_callee = fn result: fn expr, ctx: - [callee, next_ctx] = transform_value expr, ctx + [callee, next_ctx] = transform expr, ctx js = wrap_with_comment_loc assign result, callExpression callee, [result] diff --git a/src/lang/call/pipe.test.fnk b/src/lang/call/pipe.test.fnk index 37d991d..b16030b 100644 --- a/src/lang/call/pipe.test.fnk +++ b/src/lang/call/pipe.test.fnk @@ -2,6 +2,7 @@ {describe, it, expect, to_match_snapshot} = import '@fink/jest/test.fnk' + describe 'pipe', fn: it 'compiles', fn: @@ -9,7 +10,7 @@ describe 'pipe', fn: fink2js ' pipe: foo - bar ?, {foo, ...?} + bar ?, {foo} spam [...?] diff --git a/src/lang/call/pipe.test.fnk.snap b/src/lang/call/pipe.test.fnk.snap index 652d32f..af9ac9c 100644 --- a/src/lang/call/pipe.test.fnk.snap +++ b/src/lang/call/pipe.test.fnk.snap @@ -6,8 +6,7 @@ exports[`pipe compiles 1`] = ` ˆpipe_result_1 = foo(ˆpipe_result_1); ˆpipe_result_1 = (ˆpartial => bar(ˆpartial, { - foo, - ...ˆpartial + foo }))(ˆpipe_result_1); ˆpipe_result_1 = spam(ˆpipe_result_1); @@ -21,7 +20,7 @@ exports[`pipe compiles 1`] = ` `; exports[`small pipe | handles precedence 1`] = ` -"export const foo = ˆpartial => matches(rx\`[a-z]\`, ˆpartial)(\`foo\`); +"export const foo = (ˆpartial => matches(rx\`[a-z]\`, ˆpartial))(\`foo\`); export const bar = [ham(spam), ni(shrub)];" `; diff --git a/src/lang/comparison/init.fnk b/src/lang/comparison/init.fnk index 5f9858c..d3b80e2 100644 --- a/src/lang/comparison/init.fnk +++ b/src/lang/comparison/init.fnk @@ -2,7 +2,7 @@ babel_types = import '@babel/types' {binaryExpression, logicalExpression} = babel_types {add, any} = import '../context.fnk' -{transform} = import '../transform.fnk' +{transform_with_partial_lr} = import '../partial/init.fnk' @@ -15,8 +15,7 @@ transform_op = rec: transform_comp = fn {op, left, right}, ctx: {(op): operator=op} = transform_op - [bin_left, next_ctx] = transform left, ctx - [bin_right, end_ctx] = transform right, next_ctx + [bin_left, bin_right, next_ctx, wrap_partial] = transform_with_partial_lr left, right, ctx js = match left: {op: ? in ['<', '>', '<=', '>=', '==', '!=']}: @@ -26,7 +25,7 @@ transform_comp = fn {op, left, right}, ctx: else: binaryExpression operator, bin_left, bin_right - [js, end_ctx] + wrap_partial js, next_ctx diff --git a/src/lang/comparison/init.test.fnk b/src/lang/comparison/init.test.fnk index 26d7640..20f969e 100644 --- a/src/lang/comparison/init.test.fnk +++ b/src/lang/comparison/init.test.fnk @@ -27,3 +27,14 @@ describe 'comparison', fn: lteq = a <= b <= c " to_match_snapshot + + + it 'compiles as partials', fn: + expect + fink2js " + 1 == len ? + ? != 123 + ? > 3 + 1 < ? <= 3 + " + to_match_snapshot diff --git a/src/lang/comparison/init.test.fnk.snap b/src/lang/comparison/init.test.fnk.snap index f87e051..4d5eabc 100644 --- a/src/lang/comparison/init.test.fnk.snap +++ b/src/lang/comparison/init.test.fnk.snap @@ -1,5 +1,15 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`comparison compiles as partials 1`] = ` +"ˆpartial => 1 === len(ˆpartial); + +ˆpartial => ˆpartial !== 123; + +ˆpartial => ˆpartial > 3; + +ˆpartial => 1 < ˆpartial && ˆpartial <= 3;" +`; + exports[`comparison compiles combined 1`] = ` "export const lt = a < b && b < c; export const gt = a > b && b > c; diff --git a/src/lang/conditionals/match.fnk b/src/lang/conditionals/match.fnk index db5c191..fcd1c65 100644 --- a/src/lang/conditionals/match.fnk +++ b/src/lang/conditionals/match.fnk @@ -10,9 +10,9 @@ babel_types = import '@babel/types' {eq, not_nullish, typof, consts, unique_ident} = import '../../js/types.fnk' {get_key} = import '../literals/record.fnk' -{is_partial} = import '../partial/init.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' @@ -32,12 +32,11 @@ is_iterable = fn value: comp = fn id, expected, ctx: value_ctx = {...ctx, partial_ident: id} - # TODO: test how deep `?` goes - [value, {partial_ident: _, ...next_ctx}] = transform expected, value_ctx + [wrap_with_partial, value, {partial_ident: _, ...next_ctx}] = transform_with_partial expected, value_ctx, false - cond = match expected: - is_partial ?: value - else: eq id, value + cond = match wrap_with_partial: + false: eq id, value + else: value [cond, next_ctx] diff --git a/src/lang/func/init.test.fnk b/src/lang/func/init.test.fnk index 03992fa..b6c2d7a 100644 --- a/src/lang/func/init.test.fnk +++ b/src/lang/func/init.test.fnk @@ -82,5 +82,3 @@ describe 'func', fn: to_match_snapshot - - diff --git a/src/lang/literals/list.fnk b/src/lang/literals/list.fnk index 38cd018..4d00964 100644 --- a/src/lang/literals/list.fnk +++ b/src/lang/literals/list.fnk @@ -1,8 +1,10 @@ babel_types = import '@babel/types' {arrayExpression} = babel_types {null} = import '@fink/js-interop/nullish.fnk' +{map, filter, zip} = import '@fink/std-lib/iter.fnk' {transform, map_with_ctx, collect_with_ctx} = import '../transform.fnk' +{partial_wrapper, no_wrapper} = import '../partial/init.fnk' @@ -16,5 +18,16 @@ transform_list = fn node, ctx: transform elem, elem_ctx collect_with_ctx ctx + # TODO: same as in call.fnk + [wrap_partial=no_wrapper] = pipe zip node.exprs, elems: + filter fn [arg, js_arg]: match arg: + {type: 'partial'}: true + {type: 'spread', right.type: 'partial'}: true + {type: 'spread'}: js_arg.is_partial + else: false + map fn: + partial_wrapper + js = arrayExpression elems - [js, next_ctx] + + wrap_partial js, next_ctx diff --git a/src/lang/literals/list.test.fnk b/src/lang/literals/list.test.fnk index 06b5d39..46b95d4 100644 --- a/src/lang/literals/list.test.fnk +++ b/src/lang/literals/list.test.fnk @@ -18,6 +18,15 @@ describe 'list', fn: to_match_snapshot + it 'compiles as partial', fn: + expect + fink2js ' + [1, ...?, 9] + [?, ?] + ' + to_match_snapshot + + describe 'unpacking list', fn: it 'compiles', fn: expect diff --git a/src/lang/literals/list.test.fnk.snap b/src/lang/literals/list.test.fnk.snap index 78ec7d2..2d81132 100644 --- a/src/lang/literals/list.test.fnk.snap +++ b/src/lang/literals/list.test.fnk.snap @@ -7,6 +7,12 @@ export const array3 = [1, 2, 4, a(), a(), ...b]; export const array4 = [a + 1 + 45 + b + c, [1, 2], (3 + 3) * 2];" `; +exports[`list compiles as partial 1`] = ` +"ˆpartial => [1, ...ˆpartial, 9]; + +ˆpartial => [ˆpartial, ˆpartial];" +`; + exports[`unpacking list compiles 1`] = ` "const [a, b, c] = ni; const [,, d] = ni; diff --git a/src/lang/literals/record.fnk b/src/lang/literals/record.fnk index 6f8310b..b5b4646 100644 --- a/src/lang/literals/record.fnk +++ b/src/lang/literals/record.fnk @@ -6,9 +6,12 @@ babel_types = import '@babel/types' } = babel_types {filter, filter_ac, while, is_empty} = import '@fink/std-lib/iter.fnk' +{map, zip} = import '@fink/std-lib/iter.fnk' {raw_str, unique_ident, ident, lets} = import '../../js/types.fnk' {transform, map_with_ctx, collect_with_ctx} = import '../transform.fnk' +{partial_wrapper, no_wrapper} = import '../partial/init.fnk' + optional = true not_computed = false @@ -122,8 +125,16 @@ transform_record = fn expr, ctx: map_with_ctx transform collect_with_ctx ctx + [wrap_partial=no_wrapper] = pipe zip expr.exprs, props: + filter fn [prop, js_prop]: match prop: + {right.type: 'partial'}: true + {type: 'spread'}: js_prop.is_partial + else: false + map fn: + partial_wrapper + js = objectExpression props - [js, next_ctx] + wrap_partial js, next_ctx diff --git a/src/lang/literals/record.test.fnk b/src/lang/literals/record.test.fnk index 1af7baf..4e1a8bc 100644 --- a/src/lang/literals/record.test.fnk +++ b/src/lang/literals/record.test.fnk @@ -95,6 +95,17 @@ describe 'record', fn: +describe 'partial', fn: + it 'compiles', fn: + expect + fink2js ' + {foo: bar, ...?} + {foo: ?, bar: spam} + ' + to_match_snapshot + + + describe 'calculated props', fn: it 'compiles', fn: expect diff --git a/src/lang/literals/record.test.fnk.snap b/src/lang/literals/record.test.fnk.snap index a686511..2131aef 100644 --- a/src/lang/literals/record.test.fnk.snap +++ b/src/lang/literals/record.test.fnk.snap @@ -7,6 +7,18 @@ exports[`calculated props compiles 1`] = ` };" `; +exports[`partial compiles 1`] = ` +"ˆpartial => ({ + foo: bar, + ...ˆpartial +}); + +ˆpartial => ({ + foo: ˆpartial, + bar: spam +});" +`; + exports[`record compiles idents that are not js prop-names 1`] = ` "export const foo = { foo: bar, diff --git a/src/lang/logical/in.fnk b/src/lang/logical/in.fnk index 283f7df..359248b 100644 --- a/src/lang/logical/in.fnk +++ b/src/lang/logical/in.fnk @@ -1,24 +1,22 @@ babel_types = import '@babel/types' {identifier, callExpression} = babel_types -{transform} = import '../transform.fnk' - {use_runtime_fn} = import '../runtime.fnk' +{transform_with_partial_lr} = import '../partial/init.fnk' transform_in = fn node, ctx: runtime_fn = '_${node.op}_' - runtime_ctx = use_runtime_fn runtime_fn, ctx + expr_ctx = use_runtime_fn runtime_fn, ctx - [right, next_ctx] = transform node.right, runtime_ctx - [left, end_ctx] = transform node.left, next_ctx + [left, right, next_ctx, wrap_partial] = transform_with_partial_lr node.left, node.right, expr_ctx js = callExpression identifier runtime_fn [left, right] - [js, end_ctx] + wrap_partial js, next_ctx diff --git a/src/lang/logical/in.test.fnk b/src/lang/logical/in.test.fnk index 31fa7c7..0775070 100644 --- a/src/lang/logical/in.test.fnk +++ b/src/lang/logical/in.test.fnk @@ -26,9 +26,19 @@ describe 'in', fn: to_match_snapshot + it 'compiles as partial', fn: + expect + fink2js " + ? in [1, 2, 3] + foo in ? + " + to_match_snapshot + + it 'compiles with custom runtime import', fn: expect fink2js " {_in_} = import './foo.fnk' " to_match_snapshot + diff --git a/src/lang/logical/in.test.fnk.snap b/src/lang/logical/in.test.fnk.snap index 11fb9fb..db2c2bd 100644 --- a/src/lang/logical/in.test.fnk.snap +++ b/src/lang/logical/in.test.fnk.snap @@ -1,5 +1,13 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`in compiles as partial 1`] = ` +"import { _in_ } from \\"@fink/js-interop/runtime.js\\"; + +ˆpartial => _in_(ˆpartial, [1, 2, 3]); + +ˆpartial => _in_(foo, ˆpartial);" +`; + exports[`in compiles with custom runtime 1`] = ` "import { better_in as _in_ } from \\"./foo.js\\"; export const foo = _in_(1, [1, 2, 3]); diff --git a/src/lang/logical/init.fnk b/src/lang/logical/init.fnk index a00236f..528fb1b 100644 --- a/src/lang/logical/init.fnk +++ b/src/lang/logical/init.fnk @@ -2,9 +2,9 @@ babel_types = import '@babel/types' {logicalExpression, unaryExpression} = babel_types {add, add_with_runtime, any} = import '../context.fnk' -{transform} = import '../transform.fnk' {transform_in} = import './in.fnk' +{transform_with_partial_lr, transform_with_partial} = import '../partial/init.fnk' @@ -17,20 +17,22 @@ transform_op = rec: transform_not = fn node, ctx: {(node.op): op} = transform_op - [right, next_ctx] = transform node.right, ctx + [wrap_partial, right, next_ctx] = transform_with_partial node.right, ctx + js = unaryExpression op, right - [js, next_ctx] + + wrap_partial js, next_ctx transform_logical = fn node, ctx: {(node.op): op} = transform_op - [left, next_ctx] = transform node.left, ctx - [right, end_ctx] = transform node.right, next_ctx + [left, right, next_ctx, wrap_partial] = transform_with_partial_lr node.left, node.right, ctx + js = logicalExpression op, left, right - [js, end_ctx] + wrap_partial js, next_ctx diff --git a/src/lang/logical/init.test.fnk b/src/lang/logical/init.test.fnk index e1e9721..9d2f7cd 100644 --- a/src/lang/logical/init.test.fnk +++ b/src/lang/logical/init.test.fnk @@ -11,3 +11,14 @@ describe 'logical', fn: spam = not a " to_match_snapshot + + + it 'compiles as partial', fn: + expect + fink2js " + ? or foo ? + ? and spam + not ? + " + to_match_snapshot + diff --git a/src/lang/logical/init.test.fnk.snap b/src/lang/logical/init.test.fnk.snap index 445837a..86ecd0c 100644 --- a/src/lang/logical/init.test.fnk.snap +++ b/src/lang/logical/init.test.fnk.snap @@ -5,3 +5,11 @@ exports[`logical compiles 1`] = ` export const bar = a && b && c; export const spam = !a;" `; + +exports[`logical compiles as partial 1`] = ` +"ˆpartial => ˆpartial || foo(ˆpartial); + +ˆpartial => ˆpartial && spam; + +ˆpartial => !ˆpartial;" +`; diff --git a/src/lang/partial/init.fnk b/src/lang/partial/init.fnk index 457c2a1..300bf08 100644 --- a/src/lang/partial/init.fnk +++ b/src/lang/partial/init.fnk @@ -1,52 +1,52 @@ babel_types = import '@babel/types' -{identifier} = babel_types - -{map, filter} = import '@fink/std-lib/iter.fnk' +{identifier, arrowFunctionExpression} = babel_types {add} = import '../context.fnk' {transform} = import '../transform.fnk' -has_partial = fn exprs: - [partial=false] = pipe exprs: - # TODO map is_partial - map fn expr: is_partial expr - # TODO filter ? - filter fn partial: partial - partial +partial_wrapper = fn js, ctx: + {partial_ident} = ctx + name = match partial_ident: + {name: {}}: + partial_ident.name + else: + '${ctx.ident_prefix}partial' + + partial_id = identifier name + [{is_partial: true, ...arrowFunctionExpression [partial_id], js}, ctx] -is_partial = fn node: - match node: - {type: 'partial'}: true - {left: is_partial ?}: true - {right: is_partial ?}: true - {type: 'call', callee: is_partial ?}: true - {type: 'call'}: has_partial node.args - {type: 'list'}: has_partial node.exprs - {type: 'rec'}: has_partial node.exprs - {type: 'group'}: has_partial node.exprs - else: false +no_wrapper = fn js, ctx: [js, ctx] -transform_value = fn node, ctx: - partial_or_node = match node: - is_partial ?: - rec: - type: 'func' - op: 'fn' - args: [{type: 'partial', value: '?'}] - exprs: [node] - comments: node.comments - loc: node.loc +transform_with_partial = fn expr, ctx, default_wrapper=no_wrapper: + [js, next_ctx] = match expr: + {type: 'partial'}: + [js, next_ctx] = transform expr, ctx + [{params: [js], body: js, is_partial: true}, next_ctx] else: - node + transform expr, ctx + + match js: + {is_partial: true}: + [partial_wrapper, js.body, next_ctx] + else: + [default_wrapper, js, next_ctx] + + + + +transform_with_partial_lr = fn left, right, ctx: + [wrapper_l, js_l, right_ctx] = transform_with_partial left, ctx + [wrapper, js_r, next_ctx] = transform_with_partial right, right_ctx, wrapper_l + + [js_l, js_r, next_ctx, wrapper] - transform partial_or_node, ctx diff --git a/src/lang/partial/init.test.fnk b/src/lang/partial/init.test.fnk deleted file mode 100644 index d1d8d11..0000000 --- a/src/lang/partial/init.test.fnk +++ /dev/null @@ -1,24 +0,0 @@ -{fink2js} = import '../../testing/generate.fnk' -{describe, it, expect, to_match_snapshot} = import '@fink/jest/test.fnk' - - -describe 'partial', fn: - it 'compiles assignment', fn: - expect - fink2js ' - foo1 = a * ? + 1 - foo2 = bar ? - foo3 = ?.bar spam - foo4 = ? () - foo5 = ? _ - foo6 = ? bar, spam - ' - to_match_snapshot - - expect - fink2js ' - foo1 = [1, ...?, 9] - foo2 = {foo, ...?} - ' - to_match_snapshot - diff --git a/src/lang/partial/init.test.fnk.snap b/src/lang/partial/init.test.fnk.snap deleted file mode 100644 index 3ceafe3..0000000 --- a/src/lang/partial/init.test.fnk.snap +++ /dev/null @@ -1,18 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`partial compiles assignment 1`] = ` -"export const foo1 = ˆpartial => a * ˆpartial + 1; -export const foo2 = ˆpartial => bar(ˆpartial); -export const foo3 = ˆpartial => ˆpartial.bar(spam); -export const foo4 = ˆpartial => ˆpartial(); -export const foo5 = ˆpartial => ˆpartial(); -export const foo6 = ˆpartial => ˆpartial(bar, spam);" -`; - -exports[`partial compiles assignment 2`] = ` -"export const foo1 = ˆpartial => [1, ...ˆpartial, 9]; -export const foo2 = ˆpartial => ({ - foo, - ...ˆpartial -});" -`; diff --git a/src/lang/prop-access/init.fnk b/src/lang/prop-access/init.fnk index c530bca..2708f4b 100644 --- a/src/lang/prop-access/init.fnk +++ b/src/lang/prop-access/init.fnk @@ -5,8 +5,7 @@ babel_types = import '@babel/types' {raw_str} = import '../../js/types.fnk' {add, any} = import '../context.fnk' -{transform} = import '../transform.fnk' - +{transform_with_partial} = import '../partial/init.fnk' safe_prop_ident = fn {loc, value}, ctx : @@ -19,18 +18,25 @@ safe_prop_ident = fn {loc, value}, ctx : -transform_member = fn {left, right}, ctx: - [memb_left, next_ctx] = transform left, ctx - - [computed, memb_right, end_ctx] = match right: +transform_right = fn right, ctx, default_wrap_partial: + match right: {type: 'ident'}: - safe_prop_ident right, next_ctx + [computed, js, next_ctx] = safe_prop_ident right, ctx + [computed, default_wrap_partial, js, next_ctx] + # TODO add support for foo.?.bar and foo.(?).bar else: - [true, ...transform right, next_ctx] + [wrap_partial, js, next_ctx] = transform_with_partial right, ctx, default_wrap_partial + [true, wrap_partial, js, next_ctx] + + + +transform_member = fn {left, right}, ctx: + [wrap_l, memb_left, right_ctx] = transform_with_partial left, ctx + [computed, wrap_partial, memb_right, next_ctx] = transform_right right, right_ctx, wrap_l js = memberExpression memb_left, memb_right, computed - [js, end_ctx] + wrap_partial js, next_ctx diff --git a/src/lang/prop-access/init.test.fnk b/src/lang/prop-access/init.test.fnk index a360fd9..dd27f52 100644 --- a/src/lang/prop-access/init.test.fnk +++ b/src/lang/prop-access/init.test.fnk @@ -4,7 +4,6 @@ describe 'member', fn: it 'compiles', fn: - expect fink2js " foo = spam.shrub @@ -16,3 +15,13 @@ describe 'member', fn: " to_match_snapshot + + it 'compiles partial', fn: + expect + fink2js " + ?.foo + ?.foo.bar + ?.foo == bar + " + to_match_snapshot + diff --git a/src/lang/prop-access/init.test.fnk.snap b/src/lang/prop-access/init.test.fnk.snap index fdcf791..991f55e 100644 --- a/src/lang/prop-access/init.test.fnk.snap +++ b/src/lang/prop-access/init.test.fnk.snap @@ -8,3 +8,11 @@ export const reserved_prop = item.arguments; export const js_safe_unicode = [item.π, item.ƒ]; export const js_unsfae = item[\\"foo-bar\\"];" `; + +exports[`member compiles partial 1`] = ` +"ˆpartial => ˆpartial.foo; + +ˆpartial => ˆpartial.foo.bar; + +ˆpartial => ˆpartial.foo === bar;" +`; diff --git a/src/lang/spread/init.fnk b/src/lang/spread/init.fnk index e2d8db6..0695736 100644 --- a/src/lang/spread/init.fnk +++ b/src/lang/spread/init.fnk @@ -7,8 +7,13 @@ babel_types = import '@babel/types' transform_spread = fn node, ctx: [right, next_ctx] = transform node.right, ctx - js = spreadElement right - [js, next_ctx] + match right: + {is_partial: true}: + js = spreadElement right.body + [{...js, is_partial: true}, next_ctx] + else: + js = spreadElement right + [js, next_ctx]