From fbd21704324748c98ccbea7adb97f082ef4b0603 Mon Sep 17 00:00:00 2001 From: Jan Klaas Kollhof Date: Tue, 3 Aug 2021 09:49:07 +0200 Subject: [PATCH] fix: scoping in do-expr transformation --- package-lock.json | 88 +++++++++++------------ src/js/do-expression.fnk | 35 ++++----- src/lang/conditionals/match.test.fnk.snap | 12 ++-- 3 files changed, 70 insertions(+), 65 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5830782..0d1bbc3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -768,9 +768,9 @@ } }, "node_modules/@fink/js-interop": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@fink/js-interop/-/js-interop-3.1.0.tgz", - "integrity": "sha512-6r2aKDhz1zeuCRxOPkFHpBPUH4M24Qkerf1wsqBg/6DkN3lmTuJLrBdIC1kXhkmMjK4cIXAPyW8SHdPQUd/b0Q==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@fink/js-interop/-/js-interop-3.1.1.tgz", + "integrity": "sha512-LwV75E4AyyBdmy8vPYjKUtosRMWQSRmP9zn2oDnYeThruuYZ3Im9fqUvPHLCSpAvjHFM8lJxwwZ4GT7ev3aa5w==", "engines": { "node": ">=14.13.0" } @@ -1614,18 +1614,18 @@ } }, "node_modules/@octokit/openapi-types": { - "version": "9.2.0", - "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-9.2.0.tgz", - "integrity": "sha512-c4A1Xm0At+ypvBfEETREu519wLncJYQXvY+dBGg/V5YA51eg5EwdDsPPfcOMG0cuXscqRvsIgIySTmTJUdcTNA==", + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-9.3.0.tgz", + "integrity": "sha512-oz60hhL+mDsiOWhEwrj5aWXTOMVtQgcvP+sRzX4C3cH7WOK9QSAoEtjWh0HdOf6V3qpdgAmUMxnQPluzDWR7Fw==", "dev": true }, "node_modules/@octokit/plugin-paginate-rest": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.14.0.tgz", - "integrity": "sha512-S2uEu2uHeI7Vf+Lvj8tv3O5/5TCAa8GHS0dUQN7gdM7vKA6ZHAbR6HkAVm5yMb1mbedLEbxOuQ+Fa0SQ7tCDLA==", + "version": "2.15.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.15.0.tgz", + "integrity": "sha512-/vjcb0w6ggVRtsb8OJBcRR9oEm+fpdo8RJk45khaWw/W0c8rlB2TLCLyZt/knmC17NkX7T9XdyQeEY7OHLSV1g==", "dev": true, "dependencies": { - "@octokit/types": "^6.18.0" + "@octokit/types": "^6.23.0" }, "peerDependencies": { "@octokit/core": ">=2" @@ -1641,12 +1641,12 @@ } }, "node_modules/@octokit/plugin-rest-endpoint-methods": { - "version": "5.5.2", - "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.5.2.tgz", - "integrity": "sha512-1ArooY7AYQdUd2zyqWLFHQ6gver9PvZSiuM+EPAsDplv1Y6u8zHl6yZ7yGIgaf7xvWupwUkJS2WttGYyb1P0DQ==", + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.6.0.tgz", + "integrity": "sha512-2G7lIPwjG9XnTlNhe/TRnpI8yS9K2l68W4RP/ki3wqw2+sVeTK8hItPxkqEI30VeH0UwnzpuksMU/yHxiVVctw==", "dev": true, "dependencies": { - "@octokit/types": "^6.22.0", + "@octokit/types": "^6.23.0", "deprecation": "^2.3.1" }, "peerDependencies": { @@ -1679,24 +1679,24 @@ } }, "node_modules/@octokit/rest": { - "version": "18.7.2", - "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-18.7.2.tgz", - "integrity": "sha512-TAedgLqNRS+rdGqS9v00sqBeS6IgyLSoqqCDu6pmoadAB7xSjFHShxzaXUAbxxJjyHtb7mencRGzgH4W/V6Myg==", + "version": "18.8.0", + "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-18.8.0.tgz", + "integrity": "sha512-lsuNRhgzGnLMn/NmQTNCit/6jplFWiTUlPXhqN0zCMLwf2/9pseHzsnTW+Cjlp4bLMEJJNPa5JOzSLbSCOahKw==", "dev": true, "dependencies": { "@octokit/core": "^3.5.0", "@octokit/plugin-paginate-rest": "^2.6.2", "@octokit/plugin-request-log": "^1.0.2", - "@octokit/plugin-rest-endpoint-methods": "5.5.2" + "@octokit/plugin-rest-endpoint-methods": "5.6.0" } }, "node_modules/@octokit/types": { - "version": "6.22.0", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.22.0.tgz", - "integrity": "sha512-Y8GR0BJHQDpO09qw/ZQpN+DXrFzCWaE0pvK4frDm3zJ+h99AktsFfBoDazbCtHxiL8d0jD8xRH4BeynlKLeChg==", + "version": "6.23.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.23.0.tgz", + "integrity": "sha512-eG3clC31GSS7K3oBK6C6o7wyXPrkP+mu++eus8CSZdpRytJ5PNszYxudOQ0spWZQ3S9KAtoTG6v1WK5prJcJrA==", "dev": true, "dependencies": { - "@octokit/openapi-types": "^9.2.0" + "@octokit/openapi-types": "^9.3.0" } }, "node_modules/@semantic-release/commit-analyzer": { @@ -13420,9 +13420,9 @@ } }, "@fink/js-interop": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@fink/js-interop/-/js-interop-3.1.0.tgz", - "integrity": "sha512-6r2aKDhz1zeuCRxOPkFHpBPUH4M24Qkerf1wsqBg/6DkN3lmTuJLrBdIC1kXhkmMjK4cIXAPyW8SHdPQUd/b0Q==" + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@fink/js-interop/-/js-interop-3.1.1.tgz", + "integrity": "sha512-LwV75E4AyyBdmy8vPYjKUtosRMWQSRmP9zn2oDnYeThruuYZ3Im9fqUvPHLCSpAvjHFM8lJxwwZ4GT7ev3aa5w==" }, "@fink/larix": { "version": "20.0.0", @@ -14063,18 +14063,18 @@ } }, "@octokit/openapi-types": { - "version": "9.2.0", - "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-9.2.0.tgz", - "integrity": "sha512-c4A1Xm0At+ypvBfEETREu519wLncJYQXvY+dBGg/V5YA51eg5EwdDsPPfcOMG0cuXscqRvsIgIySTmTJUdcTNA==", + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-9.3.0.tgz", + "integrity": "sha512-oz60hhL+mDsiOWhEwrj5aWXTOMVtQgcvP+sRzX4C3cH7WOK9QSAoEtjWh0HdOf6V3qpdgAmUMxnQPluzDWR7Fw==", "dev": true }, "@octokit/plugin-paginate-rest": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.14.0.tgz", - "integrity": "sha512-S2uEu2uHeI7Vf+Lvj8tv3O5/5TCAa8GHS0dUQN7gdM7vKA6ZHAbR6HkAVm5yMb1mbedLEbxOuQ+Fa0SQ7tCDLA==", + "version": "2.15.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.15.0.tgz", + "integrity": "sha512-/vjcb0w6ggVRtsb8OJBcRR9oEm+fpdo8RJk45khaWw/W0c8rlB2TLCLyZt/knmC17NkX7T9XdyQeEY7OHLSV1g==", "dev": true, "requires": { - "@octokit/types": "^6.18.0" + "@octokit/types": "^6.23.0" } }, "@octokit/plugin-request-log": { @@ -14085,12 +14085,12 @@ "requires": {} }, "@octokit/plugin-rest-endpoint-methods": { - "version": "5.5.2", - "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.5.2.tgz", - "integrity": "sha512-1ArooY7AYQdUd2zyqWLFHQ6gver9PvZSiuM+EPAsDplv1Y6u8zHl6yZ7yGIgaf7xvWupwUkJS2WttGYyb1P0DQ==", + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.6.0.tgz", + "integrity": "sha512-2G7lIPwjG9XnTlNhe/TRnpI8yS9K2l68W4RP/ki3wqw2+sVeTK8hItPxkqEI30VeH0UwnzpuksMU/yHxiVVctw==", "dev": true, "requires": { - "@octokit/types": "^6.22.0", + "@octokit/types": "^6.23.0", "deprecation": "^2.3.1" } }, @@ -14120,24 +14120,24 @@ } }, "@octokit/rest": { - "version": "18.7.2", - "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-18.7.2.tgz", - "integrity": "sha512-TAedgLqNRS+rdGqS9v00sqBeS6IgyLSoqqCDu6pmoadAB7xSjFHShxzaXUAbxxJjyHtb7mencRGzgH4W/V6Myg==", + "version": "18.8.0", + "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-18.8.0.tgz", + "integrity": "sha512-lsuNRhgzGnLMn/NmQTNCit/6jplFWiTUlPXhqN0zCMLwf2/9pseHzsnTW+Cjlp4bLMEJJNPa5JOzSLbSCOahKw==", "dev": true, "requires": { "@octokit/core": "^3.5.0", "@octokit/plugin-paginate-rest": "^2.6.2", "@octokit/plugin-request-log": "^1.0.2", - "@octokit/plugin-rest-endpoint-methods": "5.5.2" + "@octokit/plugin-rest-endpoint-methods": "5.6.0" } }, "@octokit/types": { - "version": "6.22.0", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.22.0.tgz", - "integrity": "sha512-Y8GR0BJHQDpO09qw/ZQpN+DXrFzCWaE0pvK4frDm3zJ+h99AktsFfBoDazbCtHxiL8d0jD8xRH4BeynlKLeChg==", + "version": "6.23.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.23.0.tgz", + "integrity": "sha512-eG3clC31GSS7K3oBK6C6o7wyXPrkP+mu++eus8CSZdpRytJ5PNszYxudOQ0spWZQ3S9KAtoTG6v1WK5prJcJrA==", "dev": true, "requires": { - "@octokit/openapi-types": "^9.2.0" + "@octokit/openapi-types": "^9.3.0" } }, "@semantic-release/commit-analyzer": { diff --git a/src/js/do-expression.fnk b/src/js/do-expression.fnk index a1479a9..7dea38c 100644 --- a/src/js/do-expression.fnk +++ b/src/js/do-expression.fnk @@ -5,7 +5,7 @@ babel_types = import '@babel/types' isVariableDeclarator, isArrowFunctionExpression, isExpressionStatement isAssignmentExpression isReturnStatement - arrowFunctionExpression, callExpression + arrowFunctionExpression, callExpression, blockStatement } = babel_types {set_props} = import '@fink/js-interop/reflect.fnk' {undefined} = import '@fink/js-interop/nullish.fnk' @@ -34,10 +34,6 @@ simple = fn body, sl=false: match {sl, stmnt}: {sl: true, stmnt: isLabeledStatement ?}: stmnt.node.body - # TODO: - # {sl: true, stmnt: isIfStatement ?}: - # console.log body - # body.node else: simple stmnt else: @@ -120,6 +116,22 @@ replace_with_assign = fn target, path: consume_all +replace_with_simple_assign = fn target, path: + id = target.node.left + target.parentPath.insertBefore blockStatement path.node.body.body + + pipe last_expressions path: + map fn expr: + expr.replaceWith + wrap_with_comment_loc + assignmentExpression '=', id, expr.node.expression + expr.node.expression + + consume_all + + target.replaceWithMultiple [] + + transform_do_expr = fn path: {parentPath: parent} = path @@ -150,18 +162,7 @@ transform_do_expr = fn path: isAssignmentExpression ?: - id = parent.get 'left' - - pipe last_expressions path: - map fn expr: - expr.replaceWith - wrap_with_comment_loc - assignmentExpression '=', id.node, expr.node.expression - expr.node.expression - - consume_all - - parent.replaceWithMultiple path.node.body.body + replace_with_simple_assign parent, path else: # TODO: {spam.ham.ni: {foo, bar} = spam diff --git a/src/lang/conditionals/match.test.fnk.snap b/src/lang/conditionals/match.test.fnk.snap index 40837d2..ce09c16 100644 --- a/src/lang/conditionals/match.test.fnk.snap +++ b/src/lang/conditionals/match.test.fnk.snap @@ -661,14 +661,18 @@ exports[`match value assertions compiles do-expr 1`] = ` const ˆvalue_1 = bar; if (ˆvalue_1 === spam) { - ni; - _do_result = shrub(foobar); + { + ni; + _do_result = shrub(foobar); + } break ˆmatch_2; } { - shrub; - _do_result = spam(ni); + { + shrub; + _do_result = spam(ni); + } break ˆmatch_2; } }