Skip to content

Commit

Permalink
Merge pull request #38 from fink-lang/empty-elem
Browse files Browse the repository at this point in the history
feat(array): add support for larix empty elem
  • Loading branch information
kollhof authored Apr 19, 2020
2 parents d981810 + acdfeee commit 19aaf58
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/lang/conditionals/attempt.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ transform_attempt = fn node, ctx:
err,
blockStatement:: [
expressionStatement::
# TODO: should return undef
arrayExpression:: [err, nullLiteral()]
]

Expand Down
4 changes: 2 additions & 2 deletions src/lang/conditionals/attempt.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ describe:: 'attempt', fn:
expect::
fink2js`
foo1 = fn:
[item, err] = attempt:
[err, item] = attempt:
bar = shrub()
bar + ni()
[item, err]

foo2 = fn: attempt: 1/0
foo2 = fn: attempt: throw new Error:: 'foobar'
`
to_match_snapshot

Expand Down
4 changes: 2 additions & 2 deletions src/lang/conditionals/attempt.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ exports[`attempt compiles 1`] = `
_do_result = [ˆerror_1, null];
}
const [item, err] = _do_result;
const [err, item] = _do_result;
_do_result = undefined;
return [item, err];
};
const foo2 = () => try {
return [null, 1 / 0];
return [null, throw new Error(\`foobar\`)];
} catch (ˆerror_2) {
returnerror_2, null];
};
Expand Down
2 changes: 1 addition & 1 deletion src/lang/literals/array.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ transform_array = fn node, {transform}:
map elem:
match elem:
null: null
{type: 'empty'}: null
else: transform:: elem

arrayExpression:: elems

4 changes: 2 additions & 2 deletions src/lang/literals/object.fnk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{objectExpression, objectProperty, stringLiteral, assignmentPattern} = import '@babel/types'


transform_object = fn node, ctx:
transform_object = fn node, {transform}:
[...props] = pipe node.exprs:
map expr: ctx.transform:: expr
map prop: transform:: prop

objectExpression:: props

Expand Down

0 comments on commit 19aaf58

Please sign in to comment.