diff --git a/src/lang/conditionals/attempt.fnk b/src/lang/conditionals/attempt.fnk index 075b5ec..8805e5f 100644 --- a/src/lang/conditionals/attempt.fnk +++ b/src/lang/conditionals/attempt.fnk @@ -25,6 +25,7 @@ transform_attempt = fn node, ctx: err, blockStatement:: [ expressionStatement:: + # TODO: should return undef arrayExpression:: [err, nullLiteral()] ] diff --git a/src/lang/conditionals/attempt.test.fnk b/src/lang/conditionals/attempt.test.fnk index 0f03473..d13ae76 100644 --- a/src/lang/conditionals/attempt.test.fnk +++ b/src/lang/conditionals/attempt.test.fnk @@ -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 diff --git a/src/lang/conditionals/attempt.test.fnk.snap b/src/lang/conditionals/attempt.test.fnk.snap index 9e8bf4b..3a7de60 100644 --- a/src/lang/conditionals/attempt.test.fnk.snap +++ b/src/lang/conditionals/attempt.test.fnk.snap @@ -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) { return [ˆerror_2, null]; }; diff --git a/src/lang/literals/array.fnk b/src/lang/literals/array.fnk index 102cf55..5f561f1 100644 --- a/src/lang/literals/array.fnk +++ b/src/lang/literals/array.fnk @@ -6,7 +6,7 @@ transform_array = fn node, {transform}: map elem: match elem: null: null + {type: 'empty'}: null else: transform:: elem arrayExpression:: elems - diff --git a/src/lang/literals/object.fnk b/src/lang/literals/object.fnk index efd0ef5..f5c9946 100644 --- a/src/lang/literals/object.fnk +++ b/src/lang/literals/object.fnk @@ -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