Skip to content

Commit

Permalink
Merge pull request #129 from fink-lang/fix-do-expr
Browse files Browse the repository at this point in the history
fix: scoping in do-expr transformation
  • Loading branch information
kollhof authored Aug 3, 2021
2 parents 6c0c6bd + fbd2170 commit 2abbd98
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 65 deletions.
88 changes: 44 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 18 additions & 17 deletions src/js/do-expression.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/lang/conditionals/match.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -661,14 +661,18 @@ exports[`match value assertions compiles do-expr 1`] = `
const ˆvalue_1 = bar;
ifvalue_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;
}
}
Expand Down

0 comments on commit 2abbd98

Please sign in to comment.