From 2d0675d56043f65790f0cb9ecce4a0a23456fe76 Mon Sep 17 00:00:00 2001 From: Jan Klaas Kollhof Date: Thu, 5 Nov 2020 18:16:08 +0100 Subject: [PATCH] fix(iterables): make sure ctx changes are not lost during module expr. compilation --- package-lock.json | 28 +++++++++++++--------------- src/lang/builtins.fnk | 3 ++- src/lang/iterable/map.test.fnk | 3 ++- src/lang/iterable/map.test.fnk.snap | 3 ++- src/lang/module/init.fnk | 22 ++++++++++++++-------- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index b43ea1d..20480cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -601,9 +601,9 @@ } }, "node_modules/@fink/loxia": { - "version": "18.1.0", - "resolved": "https://registry.npmjs.org/@fink/loxia/-/loxia-18.1.0.tgz", - "integrity": "sha512-z0EOPuwGo8ceSOFZhYf3HD/sBFzFD2tMhVXJ9HeSiLf2OI/EAH7e8fPyN08GYU41yEdzKP54kNi5LG3P9aYbBw==", + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/@fink/loxia/-/loxia-18.2.0.tgz", + "integrity": "sha512-MGdfJwGFOtUqbs23/TMqS6PLWjPdo9P0hIcCZ1E2bkS/r6GKCrIBR8+ytq5cngTVkWbw2u3Nd7Qc4trLKBA0Iw==", "dev": true, "dependencies": { "@babel/core": "^7.10.5", @@ -4433,9 +4433,9 @@ "dev": true }, "node_modules/fsevents": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.2.0.tgz", - "integrity": "sha512-pKnaUh2TNvk+/egJdBw1h46LwyLx8BzEq+MGCf/RMCVfEHHsGOCWG00dqk91kUPPArIIwMBg9T/virxwzP03cA==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.2.1.tgz", + "integrity": "sha512-bTLYHSeC0UH/EFXS9KqWnXuOl/wHK5Z/d+ghd5AsFMYN7wIGkUCOJyzy88+wJKkZPGON8u4Z9f6U4FdgURE9qA==", "dev": true, "hasInstallScript": true, "optional": true, @@ -17372,7 +17372,6 @@ "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.1.tgz", "integrity": "sha512-FOmRr+FmWEIG8uhZv6C2bTgEVXsHk08kE7mPlrBbEe+c3r9pjceVPgupIfNIhc4yx55H69OXANrUaSuu9eInKg==", "dev": true, - "optional": true, "bin": { "uuid": "dist/bin/uuid" } @@ -18382,9 +18381,9 @@ } }, "@fink/loxia": { - "version": "18.1.0", - "resolved": "https://registry.npmjs.org/@fink/loxia/-/loxia-18.1.0.tgz", - "integrity": "sha512-z0EOPuwGo8ceSOFZhYf3HD/sBFzFD2tMhVXJ9HeSiLf2OI/EAH7e8fPyN08GYU41yEdzKP54kNi5LG3P9aYbBw==", + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/@fink/loxia/-/loxia-18.2.0.tgz", + "integrity": "sha512-MGdfJwGFOtUqbs23/TMqS6PLWjPdo9P0hIcCZ1E2bkS/r6GKCrIBR8+ytq5cngTVkWbw2u3Nd7Qc4trLKBA0Iw==", "dev": true, "requires": { "@babel/core": "^7.10.5", @@ -21451,9 +21450,9 @@ "dev": true }, "fsevents": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.2.0.tgz", - "integrity": "sha512-pKnaUh2TNvk+/egJdBw1h46LwyLx8BzEq+MGCf/RMCVfEHHsGOCWG00dqk91kUPPArIIwMBg9T/virxwzP03cA==", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.2.1.tgz", + "integrity": "sha512-bTLYHSeC0UH/EFXS9KqWnXuOl/wHK5Z/d+ghd5AsFMYN7wIGkUCOJyzy88+wJKkZPGON8u4Z9f6U4FdgURE9qA==", "dev": true, "optional": true }, @@ -31604,8 +31603,7 @@ "version": "8.3.1", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.1.tgz", "integrity": "sha512-FOmRr+FmWEIG8uhZv6C2bTgEVXsHk08kE7mPlrBbEe+c3r9pjceVPgupIfNIhc4yx55H69OXANrUaSuu9eInKg==", - "dev": true, - "optional": true + "dev": true }, "v8-to-istanbul": { "version": "7.0.0", diff --git a/src/lang/builtins.fnk b/src/lang/builtins.fnk index 4ebfad4..12c6254 100644 --- a/src/lang/builtins.fnk +++ b/src/lang/builtins.fnk @@ -97,4 +97,5 @@ init_builtins = fn ctx: builtins: rec: names: [] used: [] - provided: [] + overrides: {} + defaults: {} diff --git a/src/lang/iterable/map.test.fnk b/src/lang/iterable/map.test.fnk index 402d745..42b184f 100644 --- a/src/lang/iterable/map.test.fnk +++ b/src/lang/iterable/map.test.fnk @@ -36,7 +36,8 @@ describe 'gen 2', fn: it 'uses multiple custom iterable impl.', fn: expect fink2js ' - {_map_, _filter_} = import "@fink/js-interop/iter.js" + {_map_} = import "./iter.fnk" + {_filter_} = import "./iter-filter.fnk" pipe [1, 2, 3]: map item: item * 2 map item: item / 2 diff --git a/src/lang/iterable/map.test.fnk.snap b/src/lang/iterable/map.test.fnk.snap index 969a0d7..1ec336e 100644 --- a/src/lang/iterable/map.test.fnk.snap +++ b/src/lang/iterable/map.test.fnk.snap @@ -64,7 +64,8 @@ exports[`gen 2 uses legacy iterables 1`] = ` `; exports[`gen 2 uses multiple custom iterable impl. 1`] = ` -"import { _map_, _filter_ } from \\"@fink/js-interop/iter.js\\"; +"import { _map_ } from \\"./iter.js\\"; +import { _filter_ } from \\"./iter-filter.js\\"; { let ˆpipe_result_1 = [1, 2, 3]; ˆpipe_result_1 = _map_((item) => item * 2, false, false)(ˆpipe_result_1); diff --git a/src/lang/module/init.fnk b/src/lang/module/init.fnk index 8088d81..47fbe70 100644 --- a/src/lang/module/init.fnk +++ b/src/lang/module/init.fnk @@ -37,11 +37,9 @@ ignorable_import = fn [expr, ctx]: false -# TODO: std-lib with_ctx = fn ctx: map item: [item, ctx] -# TODO: std-lib map_acc = fn map_fn: foo = {} # TODO: should be map [item, initial_acc], acc=initial_acc: @@ -49,6 +47,7 @@ map_acc = fn map_fn: ctx = match acc: foo: initial_acc else: acc + [result, next_ctx] = map_fn item, ctx [[result, next_ctx], next_ctx] @@ -67,7 +66,6 @@ add_builtin_overrides = fn expr, ctx: filter {right}: is_builtin right.value, ctx fold {right: {value: name}}, override_ctx=ctx: override_builtin name, uri, override_ctx - [expr, next_ctx] else: [expr, ctx] @@ -169,11 +167,19 @@ transform_module = fn node, ctx: [interpreter, first] = get_hashbang maybe_shebang_or_pragmas [body, end_ctx] = pipe [first, ...rest]: - with_ctx ctx - map_acc add_builtin_overrides - drop_if ignorable_import - map_acc transform_body_expr - collect_with_ctx ctx + map expr, expr_ctx=ctx: + [body_expr, body_ctx] = add_builtin_overrides expr, expr_ctx + [js_expr, next_ctx] = match body_expr: + ignorable_import [?, body_ctx]: + [false, body_ctx] + else: + transform_body_expr body_expr, body_ctx + [[js_expr, next_ctx], next_ctx] + + drop_if fn [js]: js == false + + fold [js, ctx], [jss]=[[]]: + [[...jss, js], ctx] insert_imports js = file