From 72f0b085f39d79e2f87a38c4d714b027c3234c9d Mon Sep 17 00:00:00 2001 From: Jan Klaas Kollhof Date: Sun, 12 Apr 2020 08:56:10 +0200 Subject: [PATCH 1/4] refactor(style): remove the use of Array.map, use parens-less calls --- package-lock.json | 6 ++--- package.json | 2 +- src/index.test.fnk | 4 ++-- src/js/do-expression.fnk | 2 +- src/js/types.fnk | 12 ++++------ src/lang/assignment/index.fnk | 19 +++++++++------ src/lang/assignment/index.test.fnk | 12 +++++----- src/lang/async/index.test.fnk | 4 ++-- src/lang/block/index.fnk | 11 +++++---- src/lang/call/call.fnk | 2 +- src/lang/call/call.test.fnk | 4 ++-- src/lang/call/pipe.test.fnk | 4 ++-- src/lang/comments/index.test.fnk | 4 ++-- src/lang/conditionals/attempt.fnk | 5 ++-- src/lang/conditionals/attempt.test.fnk | 4 ++-- src/lang/conditionals/match.fnk | 28 +++++++++++----------- src/lang/conditionals/match.test.fnk | 28 +++++++++++----------- src/lang/func/index.fnk | 5 +++- src/lang/func/index.test.fnk | 4 ++-- src/lang/generic/binary.fnk | 10 ++++---- src/lang/generic/binary.test.fnk | 4 ++-- src/lang/generic/infix.test.fnk | 4 ++-- src/lang/generic/left.fnk | 11 ++++++--- src/lang/identifier/index.test.fnk | 12 +++++----- src/lang/iterable/filter.fnk | 7 +++--- src/lang/iterable/filter.test.fnk | 4 ++-- src/lang/iterable/find.fnk | 7 +++--- src/lang/iterable/find.test.fnk | 8 +++---- src/lang/iterable/fold.fnk | 7 +++--- src/lang/iterable/fold.test.fnk | 12 +++++----- src/lang/iterable/map.fnk | 7 +++--- src/lang/iterable/map.test.fnk | 32 +++++++++++++------------- src/lang/iterable/unfold.fnk | 7 +++--- src/lang/iterable/unfold.test.fnk | 24 +++++++++---------- src/lang/iterable/while.fnk | 7 +++--- src/lang/iterable/while.test.fnk | 8 +++---- src/lang/js-compat/new.test.fnk | 4 ++-- src/lang/js-compat/throw.test.fnk | 4 ++-- src/lang/jsx/index.fnk | 7 ++++-- src/lang/jsx/index.test.fnk | 4 ++-- src/lang/literals/array.fnk | 9 ++++---- src/lang/literals/array.test.fnk | 8 +++---- src/lang/literals/number.test.fnk | 12 +++++----- src/lang/literals/object.fnk | 12 ++++++---- src/lang/literals/object.test.fnk | 30 ++++++++++++------------ src/lang/literals/regex.test.fnk | 12 +++++----- src/lang/literals/string.fnk | 15 +++++------- src/lang/literals/string.test.fnk | 20 ++++++++-------- src/lang/logical/index.test.fnk | 4 ++-- src/lang/module/import.test.fnk | 4 ++-- src/lang/module/index.fnk | 6 ++--- src/lang/module/index.test.fnk | 4 ++-- src/lang/partial/index.test.fnk | 4 ++-- src/lang/prop-access/index.fnk | 17 ++++++-------- src/lang/prop-access/index.test.fnk | 4 ++-- src/testing/index.fnk | 3 ++- src/testing/jest.fnk | 16 ++++++------- 57 files changed, 273 insertions(+), 257 deletions(-) diff --git a/package-lock.json b/package-lock.json index e706190..a8d69e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -400,9 +400,9 @@ } }, "@fink/loxia": { - "version": "4.9.0", - "resolved": "https://registry.npmjs.org/@fink/loxia/-/loxia-4.9.0.tgz", - "integrity": "sha512-apJpO935A4GK8UW/SrP4J08LY9W5+KnYcYF1DRKt2gkP/Z0pBMQVGhzdXU4aEnkiuKinG0tGseCq+eXPJSfaTg==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@fink/loxia/-/loxia-4.10.0.tgz", + "integrity": "sha512-OhhBp7eyj0ejhkg4gRSTO4IAtvdBEWieoVG/mlz0n1ChJ3gEG6wxnvyomNIhSEvQLA85TdcSHXPil+4MgWsFUg==", "dev": true, "requires": { "@babel/generator": "^7.9.5", diff --git a/package.json b/package.json index b7583df..1247443 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@fink/cli": "^2.3.0", "@fink/jest": "^1.1.0", "@fink/larix": "^4.10.0", - "@fink/loxia": "^4.9.0", + "@fink/loxia": "^4.10.0", "commitizen": "^4.0.4", "cz-conventional-changelog": "^3.1.0", "jest-cli": "^25.3.0", diff --git a/src/index.test.fnk b/src/index.test.fnk index d1a7d28..5f6b362 100644 --- a/src/index.test.fnk +++ b/src/index.test.fnk @@ -6,9 +6,9 @@ describe:: 'errors', fn: it:: 'throws with code snippet', fn: ( - fn: fink2js(` + fn: fink2js` 123 = foo` - ) + ) to_throw ` test.fnk:1:0 1| 123 = foo diff --git a/src/js/do-expression.fnk b/src/js/do-expression.fnk index e5ab3b0..501d254 100644 --- a/src/js/do-expression.fnk +++ b/src/js/do-expression.fnk @@ -23,7 +23,7 @@ last_expressions = fn path: isBlockStatement:: ?: body = get_body:: path - last = body.(body.length - 1) + [..., last] = body match last: isExpressionStatement:: ?: [last] diff --git a/src/js/types.fnk b/src/js/types.fnk index 768138c..9458858 100644 --- a/src/js/types.fnk +++ b/src/js/types.fnk @@ -20,18 +20,16 @@ expr_block = fn ...exprs: ...pipe exprs: map node: match node: - {type: ?.endsWith:: 'Expression'}: expressionStatement:: node - isIdentifier:: ?: expressionStatement:: node + {type: ?.endsWith:: 'Expression'}: + expressionStatement:: node + isIdentifier:: ?: + expressionStatement:: node else: node ] typof = fn value: unaryExpression:: 'typeof', value -split_last = fn [...items]: - [items.slice(0, -1), items.(items.length - 1)] - - and = fn left, ...rest: match rest: {length: ? > 0}: @@ -59,7 +57,7 @@ not_nullish = fn value: ident = fn name: match name: - # TODO: typeof name == 'string': identifier(escape_ident(name)) or + # TODO: typeof name == 'string': identifier:: escape_ident:: name or {constructor: String}: identifier:: escape_ident:: name else: # {type: 'Identifier'} diff --git a/src/lang/assignment/index.fnk b/src/lang/assignment/index.fnk index 5a6fad6..623f39f 100644 --- a/src/lang/assignment/index.fnk +++ b/src/lang/assignment/index.fnk @@ -43,9 +43,14 @@ transform_spread_left = fn {left}, {transform}: slice = fn items, start, end=null: + start_num = numericLiteral:: start + start_end = match end: - null: [numericLiteral(start)] - else: [numericLiteral(start), numericLiteral(end)] + null: + [start_num] + else: + end_num = numericLiteral:: end + [start_num, end_num] callExpression:: memberExpression:: @@ -54,18 +59,18 @@ slice = fn items, start, end=null: start_end -transform_spread_right = fn node, ctx: +transform_spread_right = fn {left, right}, ctx: items = ctx.unique_ident:: 'items' items_init = variableDeclaration:: 'const' [ variableDeclarator:: arrayPattern:: [restElement:: items] - transform_value:: node.right, ctx + transform_value:: right, ctx ] - len = node.left.exprs.length - 1 - idx = node.left.exprs.findIndex:: fn expr: + len = left.exprs.length - 1 + idx = left.exprs.findIndex:: fn expr: match expr: {type: 'spread'}: true else: false @@ -98,7 +103,7 @@ transform_assign = fn node, ctx: else: left = transform_left:: ctx.transform:: node.left right = transform_value:: node.right, ctx - # wrap(node, assignmentExpression('=', left, right)) + # wrap with loc and comment? assignmentExpression:: '=', left, right diff --git a/src/lang/assignment/index.test.fnk b/src/lang/assignment/index.test.fnk index 15e5242..0f960f5 100644 --- a/src/lang/assignment/index.test.fnk +++ b/src/lang/assignment/index.test.fnk @@ -4,7 +4,7 @@ describe:: 'assignment', fn: it:: 'compiles', fn: - fink2js(` + fink2js` assign = 1 # simple assign2 = assign @@ -18,19 +18,19 @@ describe:: 'assignment', fn: + 234 + -567 - 1111 - `) eq snapshot + ` eq snapshot it:: 'compiles destructuring', fn: - fink2js(` + fink2js` # standard JS destructuring [...head, last] = '1234' - `) eq snapshot + ` eq snapshot - fink2js(` + fink2js` # enhanced destructuring [foo, bar, ...spam, ni, shrub] = '123' [a, , ..., b, c] = '123' - `) eq snapshot + ` eq snapshot diff --git a/src/lang/async/index.test.fnk b/src/lang/async/index.test.fnk index b83c6c6..ea13231 100644 --- a/src/lang/async/index.test.fnk +++ b/src/lang/async/index.test.fnk @@ -5,7 +5,7 @@ describe:: 'await', fn: it:: 'compiles', fn: - fink2js(` + fink2js` task1 = fn foo: - await foo task2 = fn foo: await (foo + 4) @@ -20,7 +20,7 @@ describe:: 'await', fn: else : curr + 1 await ni - `) eq snapshot + ` eq snapshot diff --git a/src/lang/block/index.fnk b/src/lang/block/index.fnk index e7df23b..02c6198 100644 --- a/src/lang/block/index.fnk +++ b/src/lang/block/index.fnk @@ -5,7 +5,7 @@ {consts} = import '../../js/types' -block_statement = fn {transform}: fn expr: +block_statement = fn expr, {transform}: st = transform:: expr match st: @@ -13,7 +13,7 @@ block_statement = fn {transform}: fn expr: decl = consts:: st.left, st.right {...decl, leadingComments: st.leadingComments} else: - # TODO: check if (isExpression(st)) ... + # TODO: check if isExpression:: ?: ... expressionStatement:: st @@ -26,6 +26,7 @@ transform_block = fn node, ctx: ctx.transform:: expr else: doExpression:: - blockStatement:: - exprs.map:: block_statement:: ctx - + blockStatement:: [ + ...pipe exprs: + map expr: block_statement:: expr, ctx + ] diff --git a/src/lang/call/call.fnk b/src/lang/call/call.fnk index 67dd94f..593745f 100644 --- a/src/lang/call/call.fnk +++ b/src/lang/call/call.fnk @@ -8,4 +8,4 @@ transform_call = fn node, ctx: map expr: ctx.transform:: expr - {...callExpression(callee, args)} + {...callExpression:: callee, args} diff --git a/src/lang/call/call.test.fnk b/src/lang/call/call.test.fnk index d0f091a..6f4c33b 100644 --- a/src/lang/call/call.test.fnk +++ b/src/lang/call/call.test.fnk @@ -5,12 +5,12 @@ describe:: 'call', fn: it:: 'compiles', fn: - fink2js(` + fink2js` call1 = a(ni, x=123, ...x) call2 = a(ni) call3 = a () call4 = a(fn x: x*2) - `) eq snapshot + ` eq snapshot diff --git a/src/lang/call/pipe.test.fnk b/src/lang/call/pipe.test.fnk index 3006d96..5555bfa 100644 --- a/src/lang/call/pipe.test.fnk +++ b/src/lang/call/pipe.test.fnk @@ -5,7 +5,7 @@ describe:: 'pipe', fn: it:: 'compiles', fn: - fink2js(` + fink2js` pipe: foo bar @@ -13,5 +13,5 @@ describe:: 'pipe', fn: pipe [1, 2, 3]: map item: item * 2 - `) eq snapshot + ` eq snapshot diff --git a/src/lang/comments/index.test.fnk b/src/lang/comments/index.test.fnk index 191fb5a..6577b4d 100644 --- a/src/lang/comments/index.test.fnk +++ b/src/lang/comments/index.test.fnk @@ -5,7 +5,7 @@ describe:: 'comment', fn: it:: 'compiles', fn: - fink2js(` + fink2js` # leading expression spam = ni @@ -17,5 +17,5 @@ describe:: 'comment', fn: spam # trailing module - `) eq snapshot + ` eq snapshot diff --git a/src/lang/conditionals/attempt.fnk b/src/lang/conditionals/attempt.fnk index 96730f0..075b5ec 100644 --- a/src/lang/conditionals/attempt.fnk +++ b/src/lang/conditionals/attempt.fnk @@ -3,17 +3,16 @@ expressionStatement, doExpression, nullLiteral, isDoExpression } = import '@babel/types' -{split_last} = import '../../js/types' {transform_block} = import '../block' transform_attempt = fn node, ctx: - block = transform_block(node, ctx) + block = transform_block:: node, ctx body = match block: isDoExpression:: ?: block.body.body else: [block] - [expressions, last_expr] = split_last:: body + [...expressions, last_expr] = body err = ctx.unique_ident:: 'error' try_block = blockStatement:: [ diff --git a/src/lang/conditionals/attempt.test.fnk b/src/lang/conditionals/attempt.test.fnk index 710cb08..e43703d 100644 --- a/src/lang/conditionals/attempt.test.fnk +++ b/src/lang/conditionals/attempt.test.fnk @@ -5,7 +5,7 @@ describe:: 'attempt', fn: it:: 'compiles', fn: - fink2js(` + fink2js` foo1 = fn: [item, err] = attempt: bar = shrub() @@ -13,7 +13,7 @@ describe:: 'attempt', fn: [item, err] foo2 = fn: attempt: 1/0 - `) eq snapshot + ` eq snapshot diff --git a/src/lang/conditionals/match.fnk b/src/lang/conditionals/match.fnk index 379b96d..8352683 100644 --- a/src/lang/conditionals/match.fnk +++ b/src/lang/conditionals/match.fnk @@ -62,14 +62,16 @@ match_obj = fn value, obj, emit_result, ctx, cond: id = ctx.unique_ident:: 'p' {id, prop} - decl = objectPattern:: - id_props.map:: fn {id, prop}: - match prop: - {key: {type: 'spread'}}: - restElement:: id - else: - [key, computed] = get_key:: prop, ctx - objectProperty:: key, id, computed + decl = objectPattern:: [ + ... pipe id_props: + map {id, prop}: + match prop: + {key: {type: 'spread'}}: + restElement:: id + else: + [computed, key] = get_key:: prop, ctx + objectProperty:: key, id, computed + ] ifStatement:: not_nullish:: value @@ -94,9 +96,8 @@ match_elems = fn elems, emit_result, ctx, cond: get_array_decl = fn arr, id_elems, right, ctx: - left = { - type: 'array', - exprs: id_elems.map(fn {id, value}: + [...exprs] = pipe id_elems: + map {id, value}: match value: # e.g. empty elems in [,, foo, bar] null: null @@ -109,9 +110,8 @@ get_array_decl = fn arr, id_elems, right, ctx: {...value, right: ident} else: {type: 'ident', value: id.name} - ), - loc: arr.loc - } + + left = {type: 'array', exprs, loc: arr.loc} decl = ctx.transform:: { type: 'assign', diff --git a/src/lang/conditionals/match.test.fnk b/src/lang/conditionals/match.test.fnk index 39aa322..340a48c 100644 --- a/src/lang/conditionals/match.test.fnk +++ b/src/lang/conditionals/match.test.fnk @@ -4,7 +4,7 @@ describe:: 'match', fn: it:: 'compiles', fn: - fink2js(` + fink2js` match shrub: # simple value 123: @@ -22,19 +22,19 @@ describe:: 'match', fn: # fallback if none of above match else: shrub - `) eq snapshot + ` eq snapshot it:: 'compiles without else', fn: - fink2js(` + fink2js` match shrub: {foo: 4, ni}: spam + ni 123: spam - `) eq snapshot + ` eq snapshot it:: 'compiles nested pattern', fn: - fink2js(` + fink2js` match shrub: # deep obj comparison {foo: {}}: spam + ni @@ -46,40 +46,40 @@ describe:: 'match', fn: {(a): {b, c}}: ni # spread {(foo): {}, ...{bar, spam}}: ni - `) eq snapshot + ` eq snapshot - fink2js(` + fink2js` match shrub: # deep array comparison [1, 2, [ni]]: ni [1, 2, [], {}]: foo [1, [2, 3], 4]: bar [1, [2, [3, 4]], [5, 6], 7]: spam - `) eq snapshot + ` eq snapshot - fink2js(` + fink2js` # spread and ignored elems match shrub: [1, ,2]: foo [1, ...{length: 0}]: foo [1, ..., 3]: foo [1, ...{length: 0}, 3]: foo - `) eq snapshot + ` eq snapshot it:: 'compiles nested match', fn: - fink2js(` + fink2js` test = fn: match foo: bar: match spam: shrub: ni bar - `) eq snapshot + ` eq snapshot it:: 'compiles patial application', fn: - fink2js(` + fink2js` match {spam: 123}: # simple unary !?: ni @@ -124,4 +124,4 @@ describe:: 'match', fn: # nested as call arg [is_foo(?)]: ni - `) eq snapshot + ` eq snapshot diff --git a/src/lang/func/index.fnk b/src/lang/func/index.fnk index 07a4af8..c945d8c 100644 --- a/src/lang/func/index.fnk +++ b/src/lang/func/index.fnk @@ -6,7 +6,10 @@ transform_func = fn node, ctx: - params = node.args.map:: fn arg: transform_left:: ctx.transform:: arg + [...params] = pipe node.args: + map arg: + transform_left:: ctx.transform:: arg + body = transform_block:: node, ctx arrowFunctionExpression:: params, body diff --git a/src/lang/func/index.test.fnk b/src/lang/func/index.test.fnk index d5fbc78..39adf9f 100644 --- a/src/lang/func/index.test.fnk +++ b/src/lang/func/index.test.fnk @@ -4,7 +4,7 @@ describe:: 'func', fn: it:: 'compiles', fn: - fink2js(` + fink2js` fun1 = fn a, b=12, ...d: a + b + c fun2 = fn b: @@ -29,7 +29,7 @@ describe:: 'func', fn: shrub(...a) foo() bar() - `) eq snapshot + ` eq snapshot diff --git a/src/lang/generic/binary.fnk b/src/lang/generic/binary.fnk index 13bec6d..b4621ce 100644 --- a/src/lang/generic/binary.fnk +++ b/src/lang/generic/binary.fnk @@ -8,10 +8,10 @@ transform_op = { } -transform_binary = fn node, {transform}: - left = transform:: node.left - right = transform:: node.right +transform_binary = fn {op, left, right}, {transform}: + {(op): operator=op} = transform_op - op = transform_op.(node.op) || node.op + bin_left = transform:: left + bin_right = transform:: right - binaryExpression:: op, left, right + binaryExpression:: operator, bin_left, bin_right diff --git a/src/lang/generic/binary.test.fnk b/src/lang/generic/binary.test.fnk index 745ec71..3741f27 100644 --- a/src/lang/generic/binary.test.fnk +++ b/src/lang/generic/binary.test.fnk @@ -4,7 +4,7 @@ describe:: 'binary', fn: it:: 'compiles', fn: - fink2js(` + fink2js` math_precedence1 = -1 + 0 + 1 + 2 * 3 % 1 math_precedence2 = -1 + 0 + (1 + 2) * 3 / 2 @@ -15,5 +15,5 @@ describe:: 'binary', fn: group1 = (1 + 2) * 3 group2 = (34234^-34234) + 1 - `) eq snapshot + ` eq snapshot diff --git a/src/lang/generic/infix.test.fnk b/src/lang/generic/infix.test.fnk index cbe001e..882a788 100644 --- a/src/lang/generic/infix.test.fnk +++ b/src/lang/generic/infix.test.fnk @@ -5,8 +5,8 @@ describe:: 'infix operators', fn: it:: 'compiles', fn: - fink2js(` + fink2js` add = fn a, b: a + b foo = 123 add 456 - `) eq snapshot + ` eq snapshot diff --git a/src/lang/generic/left.fnk b/src/lang/generic/left.fnk index 3a32060..d0ea769 100644 --- a/src/lang/generic/left.fnk +++ b/src/lang/generic/left.fnk @@ -13,9 +13,14 @@ transform_left = fn val: restElement:: val.argument isArrayExpression:: ?: - arrayPattern:: val.elements.map:: transform_left + arrayPattern:: [ + ... pipe val.elements: + map item: transform_left:: item + ] isObjectExpression:: ?: - objectPattern:: val.properties.map:: transform_left - + objectPattern:: [ + ... pipe val.properties: + map prop: transform_left:: prop + ] else: val diff --git a/src/lang/identifier/index.test.fnk b/src/lang/identifier/index.test.fnk index 9615b77..5a31ef2 100644 --- a/src/lang/identifier/index.test.fnk +++ b/src/lang/identifier/index.test.fnk @@ -4,25 +4,25 @@ describe:: 'identifiers', fn: it:: 'escapes reserved JS identifiers', fn: - fink2js(` + fink2js` {do, if, in, for, let, new, try, var, case, enum, void} = foobar {with, break, catch, class, const, super, while, yield, delete} = spam {export, import, public, return, static, switch, typeof, default} = ham {extends, finally, package, private, continue, debugger, function} = ni {arguments, interface, protected, implements, instanceof} = nu - `) eq snapshot + ` eq snapshot it:: 'does not escape true, false, null', fn: - fink2js(` + fink2js` foo = [true, false, null] - `) eq snapshot + ` eq snapshot it:: 'escapes identifiers incompatible with JS', fn: - fink2js(` + fink2js` @ = spam ∂ = shrub - `) eq snapshot + ` eq snapshot diff --git a/src/lang/iterable/filter.fnk b/src/lang/iterable/filter.fnk index a2a2a00..e568e8c 100644 --- a/src/lang/iterable/filter.fnk +++ b/src/lang/iterable/filter.fnk @@ -1,6 +1,6 @@ {returnStatement, ifStatement, expressionStatement} = import'@babel/types' -{generator, for_of, split_last, yields, consts} = import '../../js/types' +{generator, for_of, yields, consts} = import '../../js/types' {block_statement} = import '../block' {transform_init} = import './init' @@ -16,13 +16,14 @@ transform_filter = fn node, ctx: items = unique_ident:: 'items' result = unique_ident:: 'result' - [expressions, last_expr] = split_last:: node.exprs + [...expressions, last_expr] = node.exprs generator('filter')(items):: for_of(item, items):: item_init - ...expressions.map:: block_statement:: {transform} + ...pipe expressions: + map expr: block_statement:: expr, ctx consts:: result, transform:: last_expr diff --git a/src/lang/iterable/filter.test.fnk b/src/lang/iterable/filter.test.fnk index 28240df..bbc9da2 100644 --- a/src/lang/iterable/filter.test.fnk +++ b/src/lang/iterable/filter.test.fnk @@ -4,7 +4,7 @@ describe:: 'filter', fn: it:: 'compiles', fn: - fink2js(` + fink2js` filter item: item % 2 == 0 @@ -13,5 +13,5 @@ describe:: 'filter', fn: filter [...a, b]: b && a.length == 0 - `) eq snapshot + ` eq snapshot diff --git a/src/lang/iterable/find.fnk b/src/lang/iterable/find.fnk index 372e7f8..05b5337 100644 --- a/src/lang/iterable/find.fnk +++ b/src/lang/iterable/find.fnk @@ -1,6 +1,6 @@ {returnStatement, ifStatement} = import'@babel/types' -{for_of, split_last, func, consts, undef} = import '../../js/types' +{for_of, func, consts, undef} = import '../../js/types' {block_statement} = import '../block' {transform_init} = import './init' @@ -15,14 +15,15 @@ transform_find = fn node, ctx: items = unique_ident:: 'items' found = unique_ident:: 'found' - [expressions, last_expr] = split_last:: node.exprs + [...expressions, last_expr] = node.exprs func(items):: for_of(item, items):: item_init - ...expressions.map:: block_statement:: {transform} + ...pipe expressions: + map expr: block_statement:: expr, ctx consts:: found, transform:: last_expr diff --git a/src/lang/iterable/find.test.fnk b/src/lang/iterable/find.test.fnk index ed136af..d6a7a97 100644 --- a/src/lang/iterable/find.test.fnk +++ b/src/lang/iterable/find.test.fnk @@ -4,14 +4,14 @@ describe:: 'find', fn: it:: 'compiles simple find', fn: - fink2js(` + fink2js` find item: item > 3 - `) eq snapshot + ` eq snapshot it:: 'compiles complex find', fn: - fink2js(` + fink2js` find {item}: match item: {spam}: shrub @@ -22,7 +22,7 @@ describe:: 'find', fn: find [...foo , bar]: bar && foo.length == 0 - `) eq snapshot + ` eq snapshot diff --git a/src/lang/iterable/fold.fnk b/src/lang/iterable/fold.fnk index b2982b3..aac4968 100644 --- a/src/lang/iterable/fold.fnk +++ b/src/lang/iterable/fold.fnk @@ -1,6 +1,6 @@ {expressionStatement} = import '@babel/types' -{assign, params, for_of, split_last, func, consts, lets} = import '../../js/types' +{assign, params, for_of, func, consts, lets} = import '../../js/types' {block_statement} = import '../block' {transform_init} = import './init' @@ -24,7 +24,7 @@ transform_fold = fn node, ctx: } items = unique_ident:: 'items' - [expressions, last_expr] = split_last(node.exprs) + [...expressions, last_expr] = node.exprs func(items):: lets:: acc, transform:: acc_arg.right @@ -33,7 +33,8 @@ transform_fold = fn node, ctx: consts:: acc_assign.left, acc_assign.right item_init - ...expressions.map:: block_statement:: {transform} + ...pipe expressions: + map expr: block_statement:: expr, ctx assign:: acc, transform:: last_expr acc diff --git a/src/lang/iterable/fold.test.fnk b/src/lang/iterable/fold.test.fnk index 2c346f0..426fd66 100644 --- a/src/lang/iterable/fold.test.fnk +++ b/src/lang/iterable/fold.test.fnk @@ -4,30 +4,30 @@ describe:: 'fold', fn: it:: 'compiles', fn: - fink2js(` + fink2js` fold item, acc=0: ni = item + acc item * acc - `) eq snapshot + ` eq snapshot it:: 'destructuring item', fn: - fink2js(` + fink2js` fold [foo, ...bar], acc=[]: [[foo, bar], ...acc] fold [...foo, bar], acc=[]: [[foo, bar], ...acc] - `) eq snapshot + ` eq snapshot it:: 'destructuring accu', fn: - fink2js(` + fink2js` fold item, [foo, ...bar]=[]: [item, bar, foo] fold item, [...foo, bar]=[]: [item, bar, foo] - `) eq snapshot + ` eq snapshot diff --git a/src/lang/iterable/map.fnk b/src/lang/iterable/map.fnk index 9820476..349b64a 100644 --- a/src/lang/iterable/map.fnk +++ b/src/lang/iterable/map.fnk @@ -1,4 +1,4 @@ -{generator, for_of, yields, split_last} = import '../../js/types' +{generator, for_of, yields} = import '../../js/types' {block_statement} = import '../block' {transform_init} = import './init' @@ -14,7 +14,7 @@ transform_any = fn flatten: fn node, ctx: items = unique_ident:: 'items' - [expressions, last_expr] = split_last:: node.exprs + [...expressions, last_expr] = node.exprs last_is_spread = last_expr.type == 'spread' yield_value = match last_is_spread: @@ -26,7 +26,8 @@ transform_any = fn flatten: fn node, ctx: for_of(item, items):: item_init - ...expressions.map:: block_statement:: {transform} + ...pipe expressions: + map expr: block_statement:: expr, ctx yields:: transform:: yield_value diff --git a/src/lang/iterable/map.test.fnk b/src/lang/iterable/map.test.fnk index 29044ed..2da93b5 100644 --- a/src/lang/iterable/map.test.fnk +++ b/src/lang/iterable/map.test.fnk @@ -4,60 +4,60 @@ describe:: 'map', fn: it:: 'compiles single line', fn: - fink2js(` + fink2js` map item: item * 2 - `) eq snapshot + ` eq snapshot it:: 'compiles multi line', fn: - fink2js(` + fink2js` map item: item * 2 - `) eq snapshot + ` eq snapshot it:: 'compiles single line with default value', fn: - fink2js(` + fink2js` map item=123: item * 2 - `) eq snapshot + ` eq snapshot it:: 'compiles single line with destructured obj', fn: - fink2js(` + fink2js` map {item}: item * 2 - `) eq snapshot + ` eq snapshot it:: 'compiles single line with destructured array', fn: - fink2js(` + fink2js` map [x, y]: x + y - `) eq snapshot + ` eq snapshot it:: 'compiles as flat map', fn: - fink2js(` + fink2js` map [x, y]: ...[x, y] - `) eq snapshot + ` eq snapshot it:: 'compiles destructuring', fn: - fink2js(` + fink2js` map [x, ...rest]: rest map [...ignored, last]: last - `) eq snapshot + ` eq snapshot describe:: 'flat_map', fn: it:: 'compiles', fn: - fink2js(` + fink2js` flat_map item: [spam + item] flat_map item: [spam] - `) eq snapshot + ` eq snapshot diff --git a/src/lang/iterable/unfold.fnk b/src/lang/iterable/unfold.fnk index 3cde14b..1b47963 100644 --- a/src/lang/iterable/unfold.fnk +++ b/src/lang/iterable/unfold.fnk @@ -1,5 +1,5 @@ {whileStatement, blockStatement, assignmentPattern} = import '@babel/types' -{assign, generator, split_last, consts, yields, true_} = import '../../js/types' +{assign, generator, consts, yields, true_} = import '../../js/types' {block_statement} = import '../block' {transform_init} = import './init' @@ -45,7 +45,7 @@ get_accs = fn node, next_value, ctx: transform_unfold = fn node, ctx: {transform, unique_ident} = ctx - [expressions, last_expr] = split_last:: node.exprs + [...expressions, last_expr] = node.exprs result_id = unique_ident:: 'result' @@ -62,7 +62,8 @@ transform_unfold = fn node, ctx: loop:: ...acc_assign - ...expressions.map:: block_statement:: {transform} + ...pipe expressions: + map expr: block_statement:: expr, ctx consts:: result_id, result yields:: result_id diff --git a/src/lang/iterable/unfold.test.fnk b/src/lang/iterable/unfold.test.fnk index 3e75fe1..3a3ce7c 100644 --- a/src/lang/iterable/unfold.test.fnk +++ b/src/lang/iterable/unfold.test.fnk @@ -5,46 +5,46 @@ describe:: 'unfold', fn: it:: 'compiles item is accu', fn: - fink2js(` + fink2js` unfold prev=0: prev + 1 - `) eq snapshot + ` eq snapshot it:: 'compiles with separate item and accu result', fn: - fink2js(` + fink2js` unfold {prev=0, acc=0}={}: item = prev + accu # TODO should work without parens (item, {prev: item, accu: accu + 1}) - `) eq snapshot + ` eq snapshot it:: 'compiles without default assignment', fn: - fink2js(` + fink2js` pipe 0: unfold prev: prev + 1 - `) eq snapshot + ` eq snapshot it:: 'compiles without accus', fn: - fink2js(` + fink2js` unfold: 1234 - `) eq snapshot + ` eq snapshot it:: 'compiles destructured accus', fn: - fink2js(` + fink2js` unfold [foo, ...bar]: # TODO should work without parens (foo, bar) - `) eq snapshot + ` eq snapshot - fink2js(` + fink2js` unfold [...foo, bar]: # TODO should work without parens (foo, bar) - `) eq snapshot + ` eq snapshot diff --git a/src/lang/iterable/while.fnk b/src/lang/iterable/while.fnk index 32b34cb..2de6974 100644 --- a/src/lang/iterable/while.fnk +++ b/src/lang/iterable/while.fnk @@ -1,6 +1,6 @@ {returnStatement, ifStatement} = import'@babel/types' -{generator, for_of, split_last, yields, consts, neq, true_} = import '../../js/types' +{generator, for_of, yields, consts, neq, true_} = import '../../js/types' {block_statement} = import '../block' {transform_init} = import './init' @@ -16,14 +16,15 @@ transform_while = fn node, ctx: items = unique_ident:: 'items' result = unique_ident:: 'result' - [expressions, last_expr] = split_last:: node.exprs + [...expressions, last_expr] = node.exprs generator('filter_while')(items):: for_of(item, items):: item_init - ...expressions.map:: block_statement:: {transform} + ...pipe expressions: + map expr: block_statement:: expr, ctx consts:: result, transform:: last_expr diff --git a/src/lang/iterable/while.test.fnk b/src/lang/iterable/while.test.fnk index f147282..fb7f9fa 100644 --- a/src/lang/iterable/while.test.fnk +++ b/src/lang/iterable/while.test.fnk @@ -4,18 +4,18 @@ describe:: 'while', fn: it:: 'compiles', fn: - fink2js(` + fink2js` while item: item < 10 - `) eq snapshot + ` eq snapshot it:: 'compiles destructuring', fn: - fink2js(` + fink2js` while [foo, ...bar]: foo && bar.length == 0 while [...foo, bar]: bar && foo.length == 0 - `) eq snapshot + ` eq snapshot diff --git a/src/lang/js-compat/new.test.fnk b/src/lang/js-compat/new.test.fnk index 491792e..178a463 100644 --- a/src/lang/js-compat/new.test.fnk +++ b/src/lang/js-compat/new.test.fnk @@ -4,9 +4,9 @@ describe:: 'new', fn: it:: 'compiles', fn: - fink2js(` + fink2js` foo = new Set() bar = new Set:: 'abca' - `) eq snapshot + ` eq snapshot diff --git a/src/lang/js-compat/throw.test.fnk b/src/lang/js-compat/throw.test.fnk index aaff3cf..039a1e8 100644 --- a/src/lang/js-compat/throw.test.fnk +++ b/src/lang/js-compat/throw.test.fnk @@ -4,11 +4,11 @@ describe:: 'throw', fn: it:: 'compiles', fn: - fink2js(` + fink2js` fn bar: match bar: has_err:: ?: throw err:: 'spam' else: bar - `) eq snapshot + ` eq snapshot diff --git a/src/lang/jsx/index.fnk b/src/lang/jsx/index.fnk index 9abc318..df03a04 100644 --- a/src/lang/jsx/index.fnk +++ b/src/lang/jsx/index.fnk @@ -7,8 +7,11 @@ transform_jsx_elem = fn node, {transform}: id = jsxIdentifier:: node.name - attrs = node.props.map:: fn expr: transform:: expr - children = node.children.map:: fn expr: transform:: expr + [...attrs] = pipe node.props: + map expr: transform:: expr + + [...children] = pipe node.children: + map expr: transform:: expr jsxElement:: jsxOpeningElement:: id, attrs, node.self_closing diff --git a/src/lang/jsx/index.test.fnk b/src/lang/jsx/index.test.fnk index 4c5fb15..2b0dd4d 100644 --- a/src/lang/jsx/index.test.fnk +++ b/src/lang/jsx/index.test.fnk @@ -4,7 +4,7 @@ describe:: 'jsx', fn: it:: 'compiles', fn: - fink2js(` + fink2js` jsx1 = jsx2 = jsx3 = @@ -18,7 +18,7 @@ describe:: 'jsx', fn: ni - `) eq snapshot + ` eq snapshot diff --git a/src/lang/literals/array.fnk b/src/lang/literals/array.fnk index 80877ea..102cf55 100644 --- a/src/lang/literals/array.fnk +++ b/src/lang/literals/array.fnk @@ -2,10 +2,11 @@ transform_array = fn node, {transform}: - elems = node.exprs.map:: fn elem: - match elem: - null: null - else: transform:: elem + [...elems] = pipe node.exprs: + map elem: + match elem: + null: null + else: transform:: elem arrayExpression:: elems diff --git a/src/lang/literals/array.test.fnk b/src/lang/literals/array.test.fnk index 587f9d9..f5ab283 100644 --- a/src/lang/literals/array.test.fnk +++ b/src/lang/literals/array.test.fnk @@ -4,7 +4,7 @@ describe:: 'array', fn: it:: 'compiles', fn: - fink2js(` + fink2js` array1 = [] array2 = [1] array3 = [1, 2, 4, a(), ...b] @@ -14,12 +14,12 @@ describe:: 'array', fn: [1, 2], (3 + 3) * 2 ] - `) eq snapshot + ` eq snapshot describe:: 'destructuring array', fn: it:: 'compiles', fn: - fink2js(` + fink2js` [a, b, c] = ni [,, d] = ni [head, ...tail] = ni @@ -27,7 +27,7 @@ describe:: 'destructuring array', fn: [first, second, ...middle, penultimate, end] = '123' [ni, ..., nu] = '123' [..., nuna] = '123' - `) eq snapshot + ` eq snapshot diff --git a/src/lang/literals/number.test.fnk b/src/lang/literals/number.test.fnk index 2a3a6a6..038e54e 100644 --- a/src/lang/literals/number.test.fnk +++ b/src/lang/literals/number.test.fnk @@ -4,26 +4,26 @@ describe:: 'numbers', fn: it:: 'transforms integers', fn: - fink2js(` + fink2js` x = 1234578 y = 0123 - `) eq snapshot + ` eq snapshot it:: 'transforms floats', fn: - fink2js(` + fink2js` x = 1.234578 y = 1.23e45 z = 1.23e-45 a = 1.23e+45 - `) eq snapshot + ` eq snapshot it:: 'transforms hex, octet, binary', fn: - fink2js(` + fink2js` h = 0x123456789ABCDEF0 o = 0o12345670 b = 0b01010 - `) eq snapshot + ` eq snapshot diff --git a/src/lang/literals/object.fnk b/src/lang/literals/object.fnk index 600fc4f..efd0ef5 100644 --- a/src/lang/literals/object.fnk +++ b/src/lang/literals/object.fnk @@ -2,7 +2,9 @@ transform_object = fn node, ctx: - props = node.exprs.map:: fn expr: ctx.transform:: expr + [...props] = pipe node.exprs: + map expr: ctx.transform:: expr + objectExpression:: props @@ -14,11 +16,11 @@ str_key = fn {value, loc}: get_key = fn {key}, ctx: match key: {type: 'group'}: - [ctx.transform(key), true] + [true, ctx.transform:: key] {type: 'string'}: - [ctx.transform(key), true] + [true, ctx.transform:: key] else: - [str_key(key), false] + [false, str_key:: key] transform_prop = fn node, ctx: @@ -26,7 +28,7 @@ transform_prop = fn node, ctx: {key: {type: 'spread'}}: ctx.transform:: node.key else: - [key, computed] = get_key:: node, ctx + [computed, key] = get_key:: node, ctx value = ctx.transform:: node.value shorthand = node.key == node.value diff --git a/src/lang/literals/object.test.fnk b/src/lang/literals/object.test.fnk index 5004e03..a1545c6 100644 --- a/src/lang/literals/object.test.fnk +++ b/src/lang/literals/object.test.fnk @@ -4,23 +4,23 @@ describe:: 'object', fn: it:: 'compiles simple', fn: - fink2js(`obj = {}`) eq snapshot + fink2js`obj = {}` eq snapshot it:: 'compiles shorthand', fn: - fink2js(`obj = {a}`) eq snapshot - fink2js(`obj = {a, delete, true, false}`) eq snapshot + fink2js`obj = {a}` eq snapshot + fink2js`obj = {a, delete, true, false}` eq snapshot it:: 'compiles spread', fn: - fink2js(`obj = {a, b, ...c}`) eq snapshot + fink2js`obj = {a, b, ...c}` eq snapshot it:: 'compiles key:val', fn: - fink2js(`obj = {a: 1, b: 123, 'c-d-e': cde}`) eq snapshot - fink2js(` + fink2js`obj = {a: 1, b: 123, 'c-d-e': cde}` eq snapshot + fink2js` obj7 = {a: 123, b: 123 && 123 && 1345, c: fn a, b: 134} - `) eq snapshot + ` eq snapshot it:: 'compiles multiline', fn: - fink2js(`obj = { + fink2js`obj = { a: 123, b: 123 @@ -33,31 +33,31 @@ describe:: 'object', fn: n = a+3 foo(n) } - `) eq snapshot + ` eq snapshot describe:: 'calculated props', fn: it:: 'compiles', fn: - fink2js(` + fink2js` foo = { foo, (Symbol('foo')): 123, 'spam': 456, ni } - `) eq snapshot + ` eq snapshot describe:: 'destructuring object', fn: it:: 'compiles simple', fn: - fink2js(`{a, b, c} = ni`) eq snapshot + fink2js`{a, b, c} = ni` eq snapshot it:: 'compiles spread', fn: - fink2js(`{e, ...f} = {e: 0, foo: 12, bar: 34}`) eq snapshot + fink2js`{e, ...f} = {e: 0, foo: 12, bar: 34}` eq snapshot it:: 'compiles defaults', fn: - fink2js(`{x=1, ni: {y, z}} = {ni: {y: 1, z: 2}}`) eq snapshot + fink2js`{x=1, ni: {y, z}} = {ni: {y: 1, z: 2}}` eq snapshot it:: 'compiles computed keys', fn: - fink2js(`{'n i': ni} = foo`) eq snapshot + fink2js`{'n i': ni} = foo` eq snapshot diff --git a/src/lang/literals/regex.test.fnk b/src/lang/literals/regex.test.fnk index dc02b24..0f60edd 100644 --- a/src/lang/literals/regex.test.fnk +++ b/src/lang/literals/regex.test.fnk @@ -4,24 +4,24 @@ describe:: 'regex', fn: it:: 'compiles single line', fn: - fink2js(` + fink2js` regex = rx/(?\\d{4})-(?\\d{2})-(?\\d{2})/ - `) eq snapshot + ` eq snapshot it:: 'compiles multiline', fn: - fink2js(` + fink2js` regex = rx/ (?\\d{4})- # year part of a date (?\\d{2})- # month part of a date (?\\d{2}) # day part of a date /gm - `) eq snapshot + ` eq snapshot it:: 'compiles escape char', fn: - fink2js(` + fink2js` regex = rx/.+\\/.+\\\\/ - `) eq snapshot + ` eq snapshot diff --git a/src/lang/literals/string.fnk b/src/lang/literals/string.fnk index cda0fdf..e43850b 100644 --- a/src/lang/literals/string.fnk +++ b/src/lang/literals/string.fnk @@ -2,15 +2,13 @@ transform_string = fn node, {transform}: - quasies = node.parts - .filter(fn part, idx: idx % 2 == 0) - .map(fn part: templateElement({ - raw: part.value.replace(rx/\\([\s\S])|(`)/g, '\\$1$2') - })) + [...quasies] = pipe node.parts.filter:: fn part, idx: idx % 2 == 0: + map part: templateElement:: + {raw: part.value.replace(rx/\\([\s\S])|(`)/g, '\\$1$2')} - expressions = node.parts - .filter(fn part, idx: idx % 2 == 1) - .map(fn part:transform(part)) + + [...expressions] = pipe node.parts.filter:: fn part, idx: idx % 2 == 1: + map part:transform:: part templ_str = templateLiteral:: quasies, expressions {tag=null} = node @@ -22,4 +20,3 @@ transform_string = fn node, {transform}: transform:: node.tag templ_str - diff --git a/src/lang/literals/string.test.fnk b/src/lang/literals/string.test.fnk index 65b3ddd..3302dd8 100644 --- a/src/lang/literals/string.test.fnk +++ b/src/lang/literals/string.test.fnk @@ -5,41 +5,41 @@ describe:: 'string', fn: it:: 'compiles simple', fn: - fink2js(` + fink2js` str = 'ab' - `) eq snapshot + ` eq snapshot it:: 'compiles multiline', fn: - fink2js(` + fink2js` str = ' line 1 line 2 with leading space line 3' - `) eq snapshot + ` eq snapshot it:: 'compiles escape chars', fn: - fink2js(` + fink2js` str1 = 'foo\`bar\\nspam\\\`ni' str2 = \`foo\\\`bar\` str3 = "foo\\\\" - `) eq snapshot + ` eq snapshot it:: 'compiles tagged template string', fn: - fink2js(` + fink2js` str = foo'bar \${spam ni shrub} na' - `) eq snapshot + ` eq snapshot it:: 'compiles multiline with expressions', fn: - fink2js(` + fink2js` str = ' bar spam \${shrub + ni}\${foo} ni ' - `) eq snapshot + ` eq snapshot diff --git a/src/lang/logical/index.test.fnk b/src/lang/logical/index.test.fnk index 3760c80..c4f5632 100644 --- a/src/lang/logical/index.test.fnk +++ b/src/lang/logical/index.test.fnk @@ -5,9 +5,9 @@ describe:: 'logical', fn: it:: 'compiles operators', fn: - fink2js(` + fink2js` logical = a || b || c && d < 1 <= s - `) eq snapshot + ` eq snapshot diff --git a/src/lang/module/import.test.fnk b/src/lang/module/import.test.fnk index 8f17a2b..948f3d5 100644 --- a/src/lang/module/import.test.fnk +++ b/src/lang/module/import.test.fnk @@ -5,10 +5,10 @@ describe:: 'import', fn: it:: 'compiles', fn: - fink2js(` + fink2js` {foo} = import './spam' {foo: bar} = import './shrub' - `) eq snapshot + ` eq snapshot diff --git a/src/lang/module/index.fnk b/src/lang/module/index.fnk index 64c4640..9a94bf4 100644 --- a/src/lang/module/index.fnk +++ b/src/lang/module/index.fnk @@ -23,10 +23,8 @@ transform_module = fn node, ctx: id = ident:: value objectProperty:: id, id, false, true - body = pipe node.exprs: - map expr: - block_statement(ctx):: expr - + [...body] = pipe node.exprs: + map expr: block_statement:: expr, ctx # TODO: use individual exports? obj = identifier:: 'Object' diff --git a/src/lang/module/index.test.fnk b/src/lang/module/index.test.fnk index 92e500d..0af0e3f 100644 --- a/src/lang/module/index.test.fnk +++ b/src/lang/module/index.test.fnk @@ -5,14 +5,14 @@ describe:: 'module', fn: it:: 'handles comments', fn: - fink2js(` + fink2js` # leading comment # expr comment foo = bar # trailing comment - `) eq snapshot + ` eq snapshot diff --git a/src/lang/partial/index.test.fnk b/src/lang/partial/index.test.fnk index 95c4eab..56f75fc 100644 --- a/src/lang/partial/index.test.fnk +++ b/src/lang/partial/index.test.fnk @@ -4,12 +4,12 @@ describe:: 'partial', fn: it:: 'compiles assignment', fn: - fink2js(` + fink2js` foo1 = a * ? + 1 foo2 = bar(?) foo3 = ?.bar() foo4 = ?() - `) eq snapshot + ` eq snapshot diff --git a/src/lang/prop-access/index.fnk b/src/lang/prop-access/index.fnk index 38b38c3..d829754 100644 --- a/src/lang/prop-access/index.fnk +++ b/src/lang/prop-access/index.fnk @@ -2,19 +2,16 @@ {add, any} = import '../context' -transform_member = fn node, {transform}: - left = transform:: node.left +transform_member = fn {left, right}, {transform}: + memb_left = transform:: left - right = match node.right: - {type: 'ident'}: identifier:: node.right.value - else: transform:: node.right + memb_right = match right: + {type: 'ident'}: identifier:: right.value + else: transform:: right - computed = ( - node.right.type == 'string' - || node.right.type == 'group' - ) + computed = (right.type == 'string' || right.type == 'group') - memberExpression:: left, right, computed + memberExpression:: memb_left, memb_right, computed add_member = fn ctx: diff --git a/src/lang/prop-access/index.test.fnk b/src/lang/prop-access/index.test.fnk index 092e888..a504586 100644 --- a/src/lang/prop-access/index.test.fnk +++ b/src/lang/prop-access/index.test.fnk @@ -5,10 +5,10 @@ describe:: 'member', fn: it:: 'compiles', fn: - fink2js(` + fink2js` foo = spam.shrub computed_member = item.'bar spam' computed_member2 = item.(Symbol.iterator) reserved_prop = item.arguments - `) eq snapshot + ` eq snapshot diff --git a/src/testing/index.fnk b/src/testing/index.fnk index af0084b..adff330 100644 --- a/src/testing/index.fnk +++ b/src/testing/index.fnk @@ -2,7 +2,8 @@ {generate} = import '..' -fink2js = fn source: +fink2js = fn strings, ...exprs: + source = String.raw:: {raw: strings}, ...exprs filename = 'test.fnk' ast = parse:: source, filename {code} = generate:: ast, filename, source diff --git a/src/testing/jest.fnk b/src/testing/jest.fnk index cad86ac..5ca3ac5 100644 --- a/src/testing/jest.fnk +++ b/src/testing/jest.fnk @@ -1,30 +1,30 @@ -anything = Symbol(`anything`) +anything = Symbol:: `anything` -snapshot = Symbol(`snapshot`) +snapshot = Symbol:: `snapshot` describe = fn descr, tests: - global.describe(descr, tests) + global.describe:: descr, tests undefined it = fn descr, test: - global.it(descr, test) + global.it:: descr, test undefined + eq = fn result, expected: match expected: # istanbul ignore else snapshot: expect(result).toMatchSnapshot() # istanbul ignore next - else: expect(result).toEqual(expected) + else: expect(result).toEqual:: expected # istanbul ignore next is = fn result, expected: - expect(result).toBe(expected) + expect(result).toBe:: expected to_throw = fn func, err: - expect(func).toThrow(err) - + expect(func).toThrow:: err From bd3e55e56f80a8daf85c50940957bd3f1d805aca Mon Sep 17 00:00:00 2001 From: Jan Klaas Kollhof Date: Sun, 12 Apr 2020 12:35:08 +0200 Subject: [PATCH 2/4] refactor(tests): use non infix snapshot and throw matching --- src/index.test.fnk | 60 ++++---- src/lang/assignment/index.test.fnk | 56 +++---- src/lang/async/index.test.fnk | 28 ++-- src/lang/call/call.test.fnk | 16 +- src/lang/call/pipe.test.fnk | 20 +-- src/lang/comments/index.test.fnk | 26 ++-- src/lang/conditionals/attempt.test.fnk | 20 +-- src/lang/conditionals/match.test.fnk | 198 +++++++++++++------------ src/lang/func/index.test.fnk | 56 +++---- src/lang/generic/binary.test.fnk | 24 +-- src/lang/generic/infix.test.fnk | 12 +- src/lang/identifier/index.test.fnk | 36 +++-- src/lang/iterable/filter.test.fnk | 20 +-- src/lang/iterable/find.test.fnk | 38 ++--- src/lang/iterable/fold.test.fnk | 44 +++--- src/lang/iterable/map.test.fnk | 78 ++++++---- src/lang/iterable/unfold.test.fnk | 74 +++++---- src/lang/iterable/while.test.fnk | 26 ++-- src/lang/js-compat/new.test.fnk | 12 +- src/lang/js-compat/throw.test.fnk | 16 +- src/lang/jsx/index.test.fnk | 34 +++-- src/lang/literals/array.test.fnk | 46 +++--- src/lang/literals/number.test.fnk | 38 +++-- src/lang/literals/object.test.fnk | 88 +++++++---- src/lang/literals/regex.test.fnk | 34 +++-- src/lang/literals/string.test.fnk | 60 ++++---- src/lang/logical/index.test.fnk | 10 +- src/lang/module/import.test.fnk | 13 +- src/lang/module/index.test.fnk | 16 +- src/lang/partial/index.test.fnk | 16 +- src/lang/prop-access/index.test.fnk | 16 +- src/testing/jest.fnk | 21 +-- 32 files changed, 697 insertions(+), 555 deletions(-) diff --git a/src/index.test.fnk b/src/index.test.fnk index 5f6b362..3ff28b5 100644 --- a/src/index.test.fnk +++ b/src/index.test.fnk @@ -1,36 +1,36 @@ {generate} = import '.' {fink2js} = import './testing' -{describe, it, to_throw} = import './testing/jest' +{describe, it, expect, to_throw} = import './testing/jest' describe:: 'errors', fn: it:: 'throws with code snippet', fn: - ( - fn: fink2js` - 123 = foo` - - ) to_throw ` - test.fnk:1:0 - 1| 123 = foo - ^ - - Unable to transform 'assign ='.` - - ( - fn: generate({ - type: 'test', - op: null, - loc: { - start: {pos: 0, line: 1, column: 0}, - end: {pos: 9, line: 1, column: 9} - } - }, 'test.fnk', 'foobar') - - ) to_throw ` - test.fnk:1:0 - 1| foobar - ^ - - Unable to transform 'test'. - - Unknown expression` + expect:: + fn: fink2js` + 123 = foo` + + to_throw:: ` + test.fnk:1:0 + 1| 123 = foo + ^ + + Unable to transform 'assign ='.` + + expect:: + fn: generate({ + type: 'test', + op: null, + loc: { + start: {pos: 0, line: 1, column: 0}, + end: {pos: 9, line: 1, column: 9} + } + }, 'test.fnk', 'foobar') + + to_throw:: ` + test.fnk:1:0 + 1| foobar + ^ + + Unable to transform 'test'. + + Unknown expression` diff --git a/src/lang/assignment/index.test.fnk b/src/lang/assignment/index.test.fnk index 0f960f5..5dbb90d 100644 --- a/src/lang/assignment/index.test.fnk +++ b/src/lang/assignment/index.test.fnk @@ -1,36 +1,42 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'assignment', fn: it:: 'compiles', fn: - fink2js` - assign = 1 - # simple - assign2 = assign + expect:: + fink2js` + assign = 1 + # simple + assign2 = assign - no_clash_with_await = 13 + no_clash_with_await = 13 - assign_lang_const1 = true - assign_lang_const2 = false + assign_lang_const1 = true + assign_lang_const2 = false - multi_line_assign = 123 - + 234 + - -567 - - 1111 - ` eq snapshot + multi_line_assign = 123 + + 234 + + -567 + - 1111 + ` + to_match_snapshot it:: 'compiles destructuring', fn: - fink2js` - # standard JS destructuring - [...head, last] = '1234' - ` eq snapshot - - - fink2js` - # enhanced destructuring - [foo, bar, ...spam, ni, shrub] = '123' - - [a, , ..., b, c] = '123' - ` eq snapshot + expect:: + fink2js` + # standard JS destructuring + [...head, last] = '1234' + ` + to_match_snapshot + + + expect:: + fink2js` + # enhanced destructuring + [foo, bar, ...spam, ni, shrub] = '123' + + [a, , ..., b, c] = '123' + ` + to_match_snapshot diff --git a/src/lang/async/index.test.fnk b/src/lang/async/index.test.fnk index ea13231..68ca263 100644 --- a/src/lang/async/index.test.fnk +++ b/src/lang/async/index.test.fnk @@ -1,26 +1,28 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'await', fn: it:: 'compiles', fn: - fink2js` - task1 = fn foo: - await foo + expect:: + fink2js` + task1 = fn foo: - await foo - task2 = fn foo: await (foo + 4) + task2 = fn foo: await (foo + 4) - task3 = fn foo: - bar = await foo() - bar + 123 + task3 = fn foo: + bar = await foo() + bar + 123 - a_gen = unfold curr=0: - match shrub: - spam: await ni(curr) - else : curr + 1 + a_gen = unfold curr=0: + match shrub: + spam: await ni(curr) + else : curr + 1 - await ni - ` eq snapshot + await ni + ` + to_match_snapshot diff --git a/src/lang/call/call.test.fnk b/src/lang/call/call.test.fnk index 6f4c33b..5a7d45b 100644 --- a/src/lang/call/call.test.fnk +++ b/src/lang/call/call.test.fnk @@ -1,16 +1,18 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'call', fn: it:: 'compiles', fn: - fink2js` - call1 = a(ni, x=123, ...x) - call2 = a(ni) - call3 = a () - call4 = a(fn x: x*2) - ` eq snapshot + expect:: + fink2js` + call1 = a(ni, x=123, ...x) + call2 = a(ni) + call3 = a () + call4 = a(fn x: x*2) + ` + to_match_snapshot diff --git a/src/lang/call/pipe.test.fnk b/src/lang/call/pipe.test.fnk index 5555bfa..4693e4c 100644 --- a/src/lang/call/pipe.test.fnk +++ b/src/lang/call/pipe.test.fnk @@ -1,17 +1,19 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'pipe', fn: it:: 'compiles', fn: - fink2js` - pipe: - foo - bar - spam + expect:: + fink2js` + pipe: + foo + bar + spam - pipe [1, 2, 3]: - map item: item * 2 - ` eq snapshot + pipe [1, 2, 3]: + map item: item * 2 + ` + to_match_snapshot diff --git a/src/lang/comments/index.test.fnk b/src/lang/comments/index.test.fnk index 6577b4d..1519a0e 100644 --- a/src/lang/comments/index.test.fnk +++ b/src/lang/comments/index.test.fnk @@ -1,21 +1,23 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'comment', fn: it:: 'compiles', fn: - fink2js` - # leading expression - spam = ni + expect:: + fink2js` + # leading expression + spam = ni - --- - Shrub ni. - --- - bar = fn: - --- single line block --- - spam + --- + Shrub ni. + --- + bar = fn: + --- single line block --- + spam - # trailing module - ` eq snapshot + # trailing module + ` + to_match_snapshot diff --git a/src/lang/conditionals/attempt.test.fnk b/src/lang/conditionals/attempt.test.fnk index e43703d..0f03473 100644 --- a/src/lang/conditionals/attempt.test.fnk +++ b/src/lang/conditionals/attempt.test.fnk @@ -1,19 +1,21 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'attempt', fn: it:: 'compiles', fn: - fink2js` - foo1 = fn: - [item, err] = attempt: - bar = shrub() - bar + ni() - [item, err] + expect:: + fink2js` + foo1 = fn: + [item, err] = attempt: + bar = shrub() + bar + ni() + [item, err] - foo2 = fn: attempt: 1/0 - ` eq snapshot + foo2 = fn: attempt: 1/0 + ` + to_match_snapshot diff --git a/src/lang/conditionals/match.test.fnk b/src/lang/conditionals/match.test.fnk index 340a48c..a3678aa 100644 --- a/src/lang/conditionals/match.test.fnk +++ b/src/lang/conditionals/match.test.fnk @@ -1,127 +1,141 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'match', fn: it:: 'compiles', fn: - fink2js` - match shrub: - # simple value - 123: - # result - spam + expect:: + fink2js` + match shrub: + # simple value + 123: + # result + spam - # object matching - {foo: 4, ni}: - spam + ni + # object matching + {foo: 4, ni}: + spam + ni - # array matching - [1, 2, ni]: - ni + # array matching + [1, 2, ni]: + ni - # fallback if none of above match - else: - shrub - ` eq snapshot + # fallback if none of above match + else: + shrub + ` + to_match_snapshot it:: 'compiles without else', fn: - fink2js` - match shrub: - {foo: 4, ni}: spam + ni - 123: spam - ` eq snapshot + expect:: + fink2js` + match shrub: + {foo: 4, ni}: spam + ni + 123: spam + ` + to_match_snapshot it:: 'compiles nested pattern', fn: - fink2js` - match shrub: - # deep obj comparison - {foo: {}}: spam + ni - {foo: []}: spam + ni - {foo: 4, ni: {na, nu}}: spam + ni - {xx: 1, foo: {bar: 'spam'}, shrub: {na: 'nu'}}: ni - {ni: {len: 1}, na: {len: 1}}: na - # calculated props - {(a): {b, c}}: ni - # spread - {(foo): {}, ...{bar, spam}}: ni - ` eq snapshot - - fink2js` - match shrub: - # deep array comparison - [1, 2, [ni]]: ni - [1, 2, [], {}]: foo - [1, [2, 3], 4]: bar - [1, [2, [3, 4]], [5, 6], 7]: spam - ` eq snapshot - - fink2js` - # spread and ignored elems - match shrub: - [1, ,2]: foo - [1, ...{length: 0}]: foo - [1, ..., 3]: foo - [1, ...{length: 0}, 3]: foo - ` eq snapshot + expect:: + fink2js` + match shrub: + # deep obj comparison + {foo: {}}: spam + ni + {foo: []}: spam + ni + {foo: 4, ni: {na, nu}}: spam + ni + {xx: 1, foo: {bar: 'spam'}, shrub: {na: 'nu'}}: ni + {ni: {len: 1}, na: {len: 1}}: na + # calculated props + {(a): {b, c}}: ni + # spread + {(foo): {}, ...{bar, spam}}: ni + ` + to_match_snapshot + + expect:: + fink2js` + match shrub: + # deep array comparison + [1, 2, [ni]]: ni + [1, 2, [], {}]: foo + [1, [2, 3], 4]: bar + [1, [2, [3, 4]], [5, 6], 7]: spam + ` + to_match_snapshot + + expect:: + fink2js` + # spread and ignored elems + match shrub: + [1, ,2]: foo + [1, ...{length: 0}]: foo + [1, ..., 3]: foo + [1, ...{length: 0}, 3]: foo + ` + to_match_snapshot it:: 'compiles nested match', fn: - fink2js` - test = fn: - match foo: - bar: - match spam: - shrub: ni - bar - ` eq snapshot + expect:: + fink2js` + test = fn: + match foo: + bar: + match spam: + shrub: ni + bar + ` + to_match_snapshot it:: 'compiles patial application', fn: - fink2js` - match {spam: 123}: - # simple unary - !?: ni + expect:: + fink2js` + match {spam: 123}: + # simple unary + !?: ni - # simple binary - ? > 123: ni + # simple binary + ? > 123: ni - # simple call - ?(): ni + # simple call + ?(): ni - # simple as call arg - shrub:: ?: ni + # simple as call arg + shrub:: ?: ni - # nested unary - {spam: !?}: ni + # nested unary + {spam: !?}: ni - # nested binary - {spam: ? > 123}: ni + # nested binary + {spam: ? > 123}: ni - # nested call - {spam: ?()}: ni + # nested call + {spam: ?()}: ni - # nested member call - {spam: ?.is_foo()}: ni + # nested member call + {spam: ?.is_foo()}: ni - # nested as call arg - {spam: is_foo(?)}: ni + # nested as call arg + {spam: is_foo(?)}: ni - # nested unary - [!?]: ni + # nested unary + [!?]: ni - # nested binary - [? > 123]: ni + # nested binary + [? > 123]: ni - # nested call - [?()]: ni + # nested call + [?()]: ni - # nested member call - [?.is_foo()]: ni + # nested member call + [?.is_foo()]: ni - # nested as call arg - [is_foo(?)]: ni - ` eq snapshot + # nested as call arg + [is_foo(?)]: ni + ` + to_match_snapshot diff --git a/src/lang/func/index.test.fnk b/src/lang/func/index.test.fnk index 39adf9f..e626fdf 100644 --- a/src/lang/func/index.test.fnk +++ b/src/lang/func/index.test.fnk @@ -1,35 +1,37 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'func', fn: it:: 'compiles', fn: - fink2js` - fun1 = fn a, b=12, ...d: a + b + c - - fun2 = fn b: - b * 2 - - fun3 = fn: 'shrub' - fun4 = fn: - 'shrub' - - fun5 = fn c: fn d, e: - match [d, e]: - [1, 2]: c - [2, 1]: 1/c - - fun6 = fn c, d: - x = 123 - match ni: - c + x: d - c + 1: d + 1 - - fun7 = fn a, b=12, c: - shrub(...a) - foo() - bar() - ` eq snapshot + expect:: + fink2js` + fun1 = fn a, b=12, ...d: a + b + c + + fun2 = fn b: + b * 2 + + fun3 = fn: 'shrub' + fun4 = fn: + 'shrub' + + fun5 = fn c: fn d, e: + match [d, e]: + [1, 2]: c + [2, 1]: 1/c + + fun6 = fn c, d: + x = 123 + match ni: + c + x: d + c + 1: d + 1 + + fun7 = fn a, b=12, c: + shrub(...a) + foo() + bar() + ` + to_match_snapshot diff --git a/src/lang/generic/binary.test.fnk b/src/lang/generic/binary.test.fnk index 3741f27..54cb9b6 100644 --- a/src/lang/generic/binary.test.fnk +++ b/src/lang/generic/binary.test.fnk @@ -1,19 +1,21 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'binary', fn: it:: 'compiles', fn: - fink2js` - math_precedence1 = -1 + 0 + 1 + 2 * 3 % 1 - math_precedence2 = -1 + 0 + (1 + 2) * 3 / 2 + expect:: + fink2js` + math_precedence1 = -1 + 0 + 1 + 2 * 3 % 1 + math_precedence2 = -1 + 0 + (1 + 2) * 3 / 2 - multi_line_assign = 123 - + 234 + - -567 - - 1111 + multi_line_assign = 123 + + 234 + + -567 + - 1111 - group1 = (1 + 2) * 3 - group2 = (34234^-34234) + 1 - ` eq snapshot + group1 = (1 + 2) * 3 + group2 = (34234^-34234) + 1 + ` + to_match_snapshot diff --git a/src/lang/generic/infix.test.fnk b/src/lang/generic/infix.test.fnk index 882a788..5ef27e9 100644 --- a/src/lang/generic/infix.test.fnk +++ b/src/lang/generic/infix.test.fnk @@ -1,12 +1,14 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'infix operators', fn: it:: 'compiles', fn: - fink2js` - add = fn a, b: a + b - foo = 123 add 456 - ` eq snapshot + expect:: + fink2js` + add = fn a, b: a + b + foo = 123 add 456 + ` + to_match_snapshot diff --git a/src/lang/identifier/index.test.fnk b/src/lang/identifier/index.test.fnk index 5a31ef2..584c75c 100644 --- a/src/lang/identifier/index.test.fnk +++ b/src/lang/identifier/index.test.fnk @@ -1,28 +1,34 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'identifiers', fn: it:: 'escapes reserved JS identifiers', fn: - fink2js` - {do, if, in, for, let, new, try, var, case, enum, void} = foobar - {with, break, catch, class, const, super, while, yield, delete} = spam - {export, import, public, return, static, switch, typeof, default} = ham - {extends, finally, package, private, continue, debugger, function} = ni - {arguments, interface, protected, implements, instanceof} = nu - ` eq snapshot + expect:: + fink2js` + {do, if, in, for, let, new, try, var, case, enum, void} = foobar + {with, break, catch, class, const, super, while, yield, delete} = spam + {export, import, public, return, static, switch, typeof, default} = ham + {extends, finally, package, private, continue, debugger, function} = ni + {arguments, interface, protected, implements, instanceof} = nu + ` + to_match_snapshot it:: 'does not escape true, false, null', fn: - fink2js` - foo = [true, false, null] - ` eq snapshot + expect:: + fink2js` + foo = [true, false, null] + ` + to_match_snapshot it:: 'escapes identifiers incompatible with JS', fn: - fink2js` - @ = spam - ∂ = shrub - ` eq snapshot + expect:: + fink2js` + @ = spam + ∂ = shrub + ` + to_match_snapshot diff --git a/src/lang/iterable/filter.test.fnk b/src/lang/iterable/filter.test.fnk index bbc9da2..61df0fd 100644 --- a/src/lang/iterable/filter.test.fnk +++ b/src/lang/iterable/filter.test.fnk @@ -1,17 +1,19 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'filter', fn: it:: 'compiles', fn: - fink2js` - filter item: - item % 2 == 0 + expect:: + fink2js` + filter item: + item % 2 == 0 - filter [a, ...b]: - a && b.length == 0 + filter [a, ...b]: + a && b.length == 0 - filter [...a, b]: - b && a.length == 0 - ` eq snapshot + filter [...a, b]: + b && a.length == 0 + ` + to_match_snapshot diff --git a/src/lang/iterable/find.test.fnk b/src/lang/iterable/find.test.fnk index d6a7a97..3a85dbf 100644 --- a/src/lang/iterable/find.test.fnk +++ b/src/lang/iterable/find.test.fnk @@ -1,28 +1,32 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'find', fn: it:: 'compiles simple find', fn: - fink2js` - find item: - item > 3 - ` eq snapshot + expect:: + fink2js` + find item: + item > 3 + ` + to_match_snapshot it:: 'compiles complex find', fn: - fink2js` - find {item}: - match item: - {spam}: shrub - else: ni - - find [foo , ...bar]: - foo && bar.length == 0 - - find [...foo , bar]: - bar && foo.length == 0 - ` eq snapshot + expect:: + fink2js` + find {item}: + match item: + {spam}: shrub + else: ni + + find [foo , ...bar]: + foo && bar.length == 0 + + find [...foo , bar]: + bar && foo.length == 0 + ` + to_match_snapshot diff --git a/src/lang/iterable/fold.test.fnk b/src/lang/iterable/fold.test.fnk index 426fd66..3544b8f 100644 --- a/src/lang/iterable/fold.test.fnk +++ b/src/lang/iterable/fold.test.fnk @@ -1,33 +1,39 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'fold', fn: it:: 'compiles', fn: - fink2js` - fold item, acc=0: - ni = item + acc - item * acc - ` eq snapshot + expect:: + fink2js` + fold item, acc=0: + ni = item + acc + item * acc + ` + to_match_snapshot it:: 'destructuring item', fn: - fink2js` - fold [foo, ...bar], acc=[]: - [[foo, bar], ...acc] + expect:: + fink2js` + fold [foo, ...bar], acc=[]: + [[foo, bar], ...acc] - fold [...foo, bar], acc=[]: - [[foo, bar], ...acc] - ` eq snapshot + fold [...foo, bar], acc=[]: + [[foo, bar], ...acc] + ` + to_match_snapshot it:: 'destructuring accu', fn: - fink2js` - fold item, [foo, ...bar]=[]: - [item, bar, foo] - - fold item, [...foo, bar]=[]: - [item, bar, foo] - ` eq snapshot + expect:: + fink2js` + fold item, [foo, ...bar]=[]: + [item, bar, foo] + + fold item, [...foo, bar]=[]: + [item, bar, foo] + ` + to_match_snapshot diff --git a/src/lang/iterable/map.test.fnk b/src/lang/iterable/map.test.fnk index 2da93b5..a08baf3 100644 --- a/src/lang/iterable/map.test.fnk +++ b/src/lang/iterable/map.test.fnk @@ -1,63 +1,79 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'map', fn: it:: 'compiles single line', fn: - fink2js` - map item: item * 2 - ` eq snapshot + expect:: + fink2js` + map item: item * 2 + ` + to_match_snapshot it:: 'compiles multi line', fn: - fink2js` - map item: - item * 2 - ` eq snapshot + expect:: + fink2js` + map item: + item * 2 + ` + to_match_snapshot it:: 'compiles single line with default value', fn: - fink2js` - map item=123: item * 2 - ` eq snapshot + expect:: + fink2js` + map item=123: item * 2 + ` + to_match_snapshot it:: 'compiles single line with destructured obj', fn: - fink2js` - map {item}: item * 2 - ` eq snapshot + expect:: + fink2js` + map {item}: item * 2 + ` + to_match_snapshot it:: 'compiles single line with destructured array', fn: - fink2js` - map [x, y]: x + y - ` eq snapshot + expect:: + fink2js` + map [x, y]: x + y + ` + to_match_snapshot it:: 'compiles as flat map', fn: - fink2js` - map [x, y]: - ...[x, y] - ` eq snapshot + expect:: + fink2js` + map [x, y]: + ...[x, y] + ` + to_match_snapshot it:: 'compiles destructuring', fn: - fink2js` - map [x, ...rest]: - rest + expect:: + fink2js` + map [x, ...rest]: + rest - map [...ignored, last]: - last + map [...ignored, last]: + last - ` eq snapshot + ` + to_match_snapshot describe:: 'flat_map', fn: it:: 'compiles', fn: - fink2js` - flat_map item: [spam + item] + expect:: + fink2js` + flat_map item: [spam + item] - flat_map item: [spam] - ` eq snapshot + flat_map item: [spam] + ` + to_match_snapshot diff --git a/src/lang/iterable/unfold.test.fnk b/src/lang/iterable/unfold.test.fnk index 3a3ce7c..a838848 100644 --- a/src/lang/iterable/unfold.test.fnk +++ b/src/lang/iterable/unfold.test.fnk @@ -1,50 +1,62 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'unfold', fn: it:: 'compiles item is accu', fn: - fink2js` - unfold prev=0: - prev + 1 - ` eq snapshot + expect:: + fink2js` + unfold prev=0: + prev + 1 + ` + to_match_snapshot it:: 'compiles with separate item and accu result', fn: - fink2js` - unfold {prev=0, acc=0}={}: - item = prev + accu - # TODO should work without parens - (item, {prev: item, accu: accu + 1}) - ` eq snapshot + expect:: + fink2js` + unfold {prev=0, acc=0}={}: + item = prev + accu + # TODO should work without parens + (item, {prev: item, accu: accu + 1}) + ` + to_match_snapshot it:: 'compiles without default assignment', fn: - fink2js` - pipe 0: - unfold prev: - prev + 1 - ` eq snapshot + expect:: + fink2js` + pipe 0: + unfold prev: + prev + 1 + ` + to_match_snapshot it:: 'compiles without accus', fn: - fink2js` - unfold: - 1234 - ` eq snapshot + expect:: + fink2js` + unfold: + 1234 + ` + to_match_snapshot it:: 'compiles destructured accus', fn: - fink2js` - unfold [foo, ...bar]: - # TODO should work without parens - (foo, bar) - ` eq snapshot - - fink2js` - unfold [...foo, bar]: - # TODO should work without parens - (foo, bar) - ` eq snapshot + expect:: + fink2js` + unfold [foo, ...bar]: + # TODO should work without parens + (foo, bar) + ` + to_match_snapshot + + expect:: + fink2js` + unfold [...foo, bar]: + # TODO should work without parens + (foo, bar) + ` + to_match_snapshot diff --git a/src/lang/iterable/while.test.fnk b/src/lang/iterable/while.test.fnk index fb7f9fa..2c13d51 100644 --- a/src/lang/iterable/while.test.fnk +++ b/src/lang/iterable/while.test.fnk @@ -1,21 +1,25 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'while', fn: it:: 'compiles', fn: - fink2js` - while item: - item < 10 - ` eq snapshot + expect:: + fink2js` + while item: + item < 10 + ` + to_match_snapshot it:: 'compiles destructuring', fn: - fink2js` - while [foo, ...bar]: - foo && bar.length == 0 + expect:: + fink2js` + while [foo, ...bar]: + foo && bar.length == 0 - while [...foo, bar]: - bar && foo.length == 0 - ` eq snapshot + while [...foo, bar]: + bar && foo.length == 0 + ` + to_match_snapshot diff --git a/src/lang/js-compat/new.test.fnk b/src/lang/js-compat/new.test.fnk index 178a463..01fd676 100644 --- a/src/lang/js-compat/new.test.fnk +++ b/src/lang/js-compat/new.test.fnk @@ -1,12 +1,14 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'new', fn: it:: 'compiles', fn: - fink2js` - foo = new Set() - bar = new Set:: 'abca' - ` eq snapshot + expect:: + fink2js` + foo = new Set() + bar = new Set:: 'abca' + ` + to_match_snapshot diff --git a/src/lang/js-compat/throw.test.fnk b/src/lang/js-compat/throw.test.fnk index 039a1e8..cc8695f 100644 --- a/src/lang/js-compat/throw.test.fnk +++ b/src/lang/js-compat/throw.test.fnk @@ -1,14 +1,16 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'throw', fn: it:: 'compiles', fn: - fink2js` - fn bar: - match bar: - has_err:: ?: throw err:: 'spam' - else: bar - ` eq snapshot + expect:: + fink2js` + fn bar: + match bar: + has_err:: ?: throw err:: 'spam' + else: bar + ` + to_match_snapshot diff --git a/src/lang/jsx/index.test.fnk b/src/lang/jsx/index.test.fnk index 2b0dd4d..61c7b05 100644 --- a/src/lang/jsx/index.test.fnk +++ b/src/lang/jsx/index.test.fnk @@ -1,24 +1,26 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'jsx', fn: it:: 'compiles', fn: - fink2js` - jsx1 = - jsx2 = - jsx3 = - jsx4 = - jsx5 = - jsx6 = - - foo {ni} - ham - spam - - ni - - ` eq snapshot + expect:: + fink2js` + jsx1 = + jsx2 = + jsx3 = + jsx4 = + jsx5 = + jsx6 = + + foo {ni} + ham + spam + + ni + + ` + to_match_snapshot diff --git a/src/lang/literals/array.test.fnk b/src/lang/literals/array.test.fnk index f5ab283..8d71bc6 100644 --- a/src/lang/literals/array.test.fnk +++ b/src/lang/literals/array.test.fnk @@ -1,33 +1,37 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'array', fn: it:: 'compiles', fn: - fink2js` - array1 = [] - array2 = [1] - array3 = [1, 2, 4, a(), ...b] - array4 = [ - a + 1 + 45+ - b + c, - [1, 2], - (3 + 3) * 2 - ] - ` eq snapshot + expect:: + fink2js` + array1 = [] + array2 = [1] + array3 = [1, 2, 4, a(), ...b] + array4 = [ + a + 1 + 45+ + b + c, + [1, 2], + (3 + 3) * 2 + ] + ` + to_match_snapshot describe:: 'destructuring array', fn: it:: 'compiles', fn: - fink2js` - [a, b, c] = ni - [,, d] = ni - [head, ...tail] = ni - [...items, last] = '1234' - [first, second, ...middle, penultimate, end] = '123' - [ni, ..., nu] = '123' - [..., nuna] = '123' - ` eq snapshot + expect:: + fink2js` + [a, b, c] = ni + [,, d] = ni + [head, ...tail] = ni + [...items, last] = '1234' + [first, second, ...middle, penultimate, end] = '123' + [ni, ..., nu] = '123' + [..., nuna] = '123' + ` + to_match_snapshot diff --git a/src/lang/literals/number.test.fnk b/src/lang/literals/number.test.fnk index 038e54e..d5c8b76 100644 --- a/src/lang/literals/number.test.fnk +++ b/src/lang/literals/number.test.fnk @@ -1,29 +1,35 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'numbers', fn: it:: 'transforms integers', fn: - fink2js` - x = 1234578 - y = 0123 - ` eq snapshot + expect:: + fink2js` + x = 1234578 + y = 0123 + ` + to_match_snapshot it:: 'transforms floats', fn: - fink2js` - x = 1.234578 - y = 1.23e45 - z = 1.23e-45 - a = 1.23e+45 - ` eq snapshot + expect:: + fink2js` + x = 1.234578 + y = 1.23e45 + z = 1.23e-45 + a = 1.23e+45 + ` + to_match_snapshot it:: 'transforms hex, octet, binary', fn: - fink2js` - h = 0x123456789ABCDEF0 - o = 0o12345670 - b = 0b01010 - ` eq snapshot + expect:: + fink2js` + h = 0x123456789ABCDEF0 + o = 0o12345670 + b = 0b01010 + ` + to_match_snapshot diff --git a/src/lang/literals/object.test.fnk b/src/lang/literals/object.test.fnk index a1545c6..952478a 100644 --- a/src/lang/literals/object.test.fnk +++ b/src/lang/literals/object.test.fnk @@ -1,63 +1,87 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'object', fn: it:: 'compiles simple', fn: - fink2js`obj = {}` eq snapshot + expect:: + fink2js`obj = {}` + to_match_snapshot it:: 'compiles shorthand', fn: - fink2js`obj = {a}` eq snapshot - fink2js`obj = {a, delete, true, false}` eq snapshot + expect:: + fink2js`obj = {a}` + to_match_snapshot + expect:: + fink2js`obj = {a, delete, true, false}` + to_match_snapshot it:: 'compiles spread', fn: - fink2js`obj = {a, b, ...c}` eq snapshot + expect:: + fink2js`obj = {a, b, ...c}` + to_match_snapshot it:: 'compiles key:val', fn: - fink2js`obj = {a: 1, b: 123, 'c-d-e': cde}` eq snapshot - fink2js` - obj7 = {a: 123, b: 123 && 123 && 1345, c: fn a, b: 134} - ` eq snapshot + expect:: + fink2js`obj = {a: 1, b: 123, 'c-d-e': cde}` + to_match_snapshot + expect:: + fink2js` + obj7 = {a: 123, b: 123 && 123 && 1345, c: fn a, b: 134} + ` + to_match_snapshot it:: 'compiles multiline', fn: - fink2js`obj = { - a: 123, + expect:: + fink2js`obj = { + a: 123, - b: 123 - && 123 - && 1345, + b: 123 + && 123 + && 1345, - c: fn a, b: 134, + c: fn a, b: 134, - d: - n = a+3 - foo(n) - } - ` eq snapshot + d: + n = a+3 + foo(n) + } + ` + to_match_snapshot describe:: 'calculated props', fn: it:: 'compiles', fn: - fink2js` - foo = { - foo, - (Symbol('foo')): 123, - 'spam': 456, - ni - } - ` eq snapshot + expect:: + fink2js` + foo = { + foo, + (Symbol('foo')): 123, + 'spam': 456, + ni + } + ` + to_match_snapshot describe:: 'destructuring object', fn: it:: 'compiles simple', fn: - fink2js`{a, b, c} = ni` eq snapshot + expect:: + fink2js`{a, b, c} = ni` + to_match_snapshot it:: 'compiles spread', fn: - fink2js`{e, ...f} = {e: 0, foo: 12, bar: 34}` eq snapshot + expect:: + fink2js`{e, ...f} = {e: 0, foo: 12, bar: 34}` + to_match_snapshot it:: 'compiles defaults', fn: - fink2js`{x=1, ni: {y, z}} = {ni: {y: 1, z: 2}}` eq snapshot + expect:: + fink2js`{x=1, ni: {y, z}} = {ni: {y: 1, z: 2}}` + to_match_snapshot it:: 'compiles computed keys', fn: - fink2js`{'n i': ni} = foo` eq snapshot + expect:: + fink2js`{'n i': ni} = foo` + to_match_snapshot diff --git a/src/lang/literals/regex.test.fnk b/src/lang/literals/regex.test.fnk index 0f60edd..310dc14 100644 --- a/src/lang/literals/regex.test.fnk +++ b/src/lang/literals/regex.test.fnk @@ -1,27 +1,33 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'regex', fn: it:: 'compiles single line', fn: - fink2js` - regex = rx/(?\\d{4})-(?\\d{2})-(?\\d{2})/ - ` eq snapshot + expect:: + fink2js` + regex = rx/(?\\d{4})-(?\\d{2})-(?\\d{2})/ + ` + to_match_snapshot it:: 'compiles multiline', fn: - fink2js` - regex = rx/ - (?\\d{4})- # year part of a date - (?\\d{2})- # month part of a date - (?\\d{2}) # day part of a date - /gm - ` eq snapshot + expect:: + fink2js` + regex = rx/ + (?\\d{4})- # year part of a date + (?\\d{2})- # month part of a date + (?\\d{2}) # day part of a date + /gm + ` + to_match_snapshot it:: 'compiles escape char', fn: - fink2js` - regex = rx/.+\\/.+\\\\/ - ` eq snapshot + expect:: + fink2js` + regex = rx/.+\\/.+\\\\/ + ` + to_match_snapshot diff --git a/src/lang/literals/string.test.fnk b/src/lang/literals/string.test.fnk index 3302dd8..d41a309 100644 --- a/src/lang/literals/string.test.fnk +++ b/src/lang/literals/string.test.fnk @@ -1,45 +1,55 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'string', fn: it:: 'compiles simple', fn: - fink2js` - str = 'ab' - ` eq snapshot + expect:: + fink2js` + str = 'ab' + ` + to_match_snapshot it:: 'compiles multiline', fn: - fink2js` - str = ' - line 1 - line 2 with leading space - line 3' - ` eq snapshot + expect:: + fink2js` + str = ' + line 1 + line 2 with leading space + line 3' + ` + to_match_snapshot it:: 'compiles escape chars', fn: - fink2js` - str1 = 'foo\`bar\\nspam\\\`ni' - str2 = \`foo\\\`bar\` - str3 = "foo\\\\" - ` eq snapshot + expect:: + fink2js` + str1 = 'foo\`bar\\nspam\\\`ni' + str2 = \`foo\\\`bar\` + str3 = "foo\\\\" + ` + to_match_snapshot it:: 'compiles tagged template string', fn: - fink2js` - str = foo'bar \${spam ni shrub} na' - ` eq snapshot + expect:: + fink2js` + str = foo'bar \${spam ni shrub} na' + ` + to_match_snapshot it:: 'compiles multiline with expressions', fn: - fink2js` - str = ' - bar - spam \${shrub + ni}\${foo} - ni - ' - ` eq snapshot + expect:: + fink2js` + str = ' + bar + spam \${shrub + ni}\${foo} + ni + ' + ` + to_match_snapshot diff --git a/src/lang/logical/index.test.fnk b/src/lang/logical/index.test.fnk index c4f5632..ccbbd30 100644 --- a/src/lang/logical/index.test.fnk +++ b/src/lang/logical/index.test.fnk @@ -1,13 +1,15 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'logical', fn: it:: 'compiles operators', fn: - fink2js` - logical = a || b || c && d < 1 <= s - ` eq snapshot + expect:: + fink2js` + logical = a || b || c && d < 1 <= s + ` + to_match_snapshot diff --git a/src/lang/module/import.test.fnk b/src/lang/module/import.test.fnk index 948f3d5..2f40b2e 100644 --- a/src/lang/module/import.test.fnk +++ b/src/lang/module/import.test.fnk @@ -1,14 +1,15 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'import', fn: it:: 'compiles', fn: - - fink2js` - {foo} = import './spam' - {foo: bar} = import './shrub' - ` eq snapshot + expect:: + fink2js` + {foo} = import './spam' + {foo: bar} = import './shrub' + ` + to_match_snapshot diff --git a/src/lang/module/index.test.fnk b/src/lang/module/index.test.fnk index 0af0e3f..f0267bd 100644 --- a/src/lang/module/index.test.fnk +++ b/src/lang/module/index.test.fnk @@ -1,18 +1,20 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'module', fn: it:: 'handles comments', fn: - fink2js` - # leading comment + expect:: + fink2js` + # leading comment - # expr comment - foo = bar + # expr comment + foo = bar - # trailing comment - ` eq snapshot + # trailing comment + ` + to_match_snapshot diff --git a/src/lang/partial/index.test.fnk b/src/lang/partial/index.test.fnk index 56f75fc..87eaf8a 100644 --- a/src/lang/partial/index.test.fnk +++ b/src/lang/partial/index.test.fnk @@ -1,15 +1,17 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'partial', fn: it:: 'compiles assignment', fn: - fink2js` - foo1 = a * ? + 1 - foo2 = bar(?) - foo3 = ?.bar() - foo4 = ?() - ` eq snapshot + expect:: + fink2js` + foo1 = a * ? + 1 + foo2 = bar(?) + foo3 = ?.bar() + foo4 = ?() + ` + to_match_snapshot diff --git a/src/lang/prop-access/index.test.fnk b/src/lang/prop-access/index.test.fnk index a504586..09b11e1 100644 --- a/src/lang/prop-access/index.test.fnk +++ b/src/lang/prop-access/index.test.fnk @@ -1,14 +1,16 @@ {fink2js} = import '../../testing' -{describe, it, eq, snapshot} = import '../../testing/jest' +{describe, it, expect, to_match_snapshot} = import '../../testing/jest' describe:: 'member', fn: it:: 'compiles', fn: - fink2js` - foo = spam.shrub - computed_member = item.'bar spam' - computed_member2 = item.(Symbol.iterator) - reserved_prop = item.arguments - ` eq snapshot + expect:: + fink2js` + foo = spam.shrub + computed_member = item.'bar spam' + computed_member2 = item.(Symbol.iterator) + reserved_prop = item.arguments + ` + to_match_snapshot diff --git a/src/testing/jest.fnk b/src/testing/jest.fnk index 5ca3ac5..c719d98 100644 --- a/src/testing/jest.fnk +++ b/src/testing/jest.fnk @@ -1,7 +1,3 @@ -anything = Symbol:: `anything` - -snapshot = Symbol:: `snapshot` - describe = fn descr, tests: global.describe:: descr, tests @@ -13,18 +9,13 @@ it = fn descr, test: undefined -eq = fn result, expected: - match expected: - # istanbul ignore else - snapshot: expect(result).toMatchSnapshot() - # istanbul ignore next - else: expect(result).toEqual:: expected +to_match_snapshot = fn expect_actual: + expect_actual.toMatchSnapshot() -# istanbul ignore next -is = fn result, expected: - expect(result).toBe:: expected +to_throw = fn expected: fn expect_actual: + expect_actual.toThrow:: expected -to_throw = fn func, err: - expect(func).toThrow:: err +expect = fn actual, expectation: + expectation:: global.expect:: actual From f79918aa0160bea9f012e777182bf28b5bfe6a6b Mon Sep 17 00:00:00 2001 From: Jan Klaas Kollhof Date: Sun, 12 Apr 2020 12:54:03 +0200 Subject: [PATCH 3/4] test(cov): add missing tests for blocks with multiple exprs --- src/lang/iterable/filter.test.fnk | 3 ++- src/lang/iterable/filter.test.fnk.snap | 3 ++- src/lang/iterable/find.test.fnk | 3 ++- src/lang/iterable/find.test.fnk.snap | 3 ++- src/lang/iterable/map.test.fnk | 3 ++- src/lang/iterable/map.test.fnk.snap | 3 ++- src/lang/iterable/while.test.fnk | 3 ++- src/lang/iterable/while.test.fnk.snap | 3 ++- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/lang/iterable/filter.test.fnk b/src/lang/iterable/filter.test.fnk index 61df0fd..1d54c88 100644 --- a/src/lang/iterable/filter.test.fnk +++ b/src/lang/iterable/filter.test.fnk @@ -10,7 +10,8 @@ describe:: 'filter', fn: item % 2 == 0 filter [a, ...b]: - a && b.length == 0 + a_alone = a && b.length == 0 + a_alone filter [...a, b]: b && a.length == 0 diff --git a/src/lang/iterable/filter.test.fnk.snap b/src/lang/iterable/filter.test.fnk.snap index a540616..cbefc9d 100644 --- a/src/lang/iterable/filter.test.fnk.snap +++ b/src/lang/iterable/filter.test.fnk.snap @@ -12,7 +12,8 @@ exports[`filter compiles 1`] = ` (function* filter(ˆitems_5) { for (const ˆitem_4 of ˆitems_5) { const [a, ...b] = ˆitem_4; - const ˆresult_6 = a && b.length === 0; + const a_alone = a && b.length === 0; + const ˆresult_6 = a_alone; if (ˆresult_6) yield ˆitem_4; } }); diff --git a/src/lang/iterable/find.test.fnk b/src/lang/iterable/find.test.fnk index 3a85dbf..d821557 100644 --- a/src/lang/iterable/find.test.fnk +++ b/src/lang/iterable/find.test.fnk @@ -21,7 +21,8 @@ describe:: 'find', fn: else: ni find [foo , ...bar]: - foo && bar.length == 0 + foo_alone = foo && bar.length == 0 + foo_alone find [...foo , bar]: bar && foo.length == 0 diff --git a/src/lang/iterable/find.test.fnk.snap b/src/lang/iterable/find.test.fnk.snap index 70c4dec..a0e1cbc 100644 --- a/src/lang/iterable/find.test.fnk.snap +++ b/src/lang/iterable/find.test.fnk.snap @@ -40,7 +40,8 @@ exports[`find compiles complex find 1`] = ` ˆitems_8 => { for (const ˆitem_7 of ˆitems_8) { const [foo, ...bar] = ˆitem_7; - const ˆfound_9 = foo && bar.length === 0; + const foo_alone = foo && bar.length === 0; + const ˆfound_9 = foo_alone; if (ˆfound_9) return ˆitem_7; } diff --git a/src/lang/iterable/map.test.fnk b/src/lang/iterable/map.test.fnk index a08baf3..ac471c9 100644 --- a/src/lang/iterable/map.test.fnk +++ b/src/lang/iterable/map.test.fnk @@ -15,7 +15,8 @@ describe:: 'map', fn: expect:: fink2js` map item: - item * 2 + ni = foo:: item + ni + 2 ` to_match_snapshot diff --git a/src/lang/iterable/map.test.fnk.snap b/src/lang/iterable/map.test.fnk.snap index 906cbf6..4bb0daf 100644 --- a/src/lang/iterable/map.test.fnk.snap +++ b/src/lang/iterable/map.test.fnk.snap @@ -58,7 +58,8 @@ exports[`map compiles multi line 1`] = ` "(function* map(ˆitems_2) { for (const ˆitem_1 of ˆitems_2) { const item = ˆitem_1; - yield item * 2; + const ni = foo(item); + yield ni + 2; } }); diff --git a/src/lang/iterable/while.test.fnk b/src/lang/iterable/while.test.fnk index 2c13d51..e39a4f3 100644 --- a/src/lang/iterable/while.test.fnk +++ b/src/lang/iterable/while.test.fnk @@ -16,7 +16,8 @@ describe:: 'while', fn: expect:: fink2js` while [foo, ...bar]: - foo && bar.length == 0 + foo_alone = foo && bar.length == 0 + foo_alone while [...foo, bar]: bar && foo.length == 0 diff --git a/src/lang/iterable/while.test.fnk.snap b/src/lang/iterable/while.test.fnk.snap index 2a3e845..32d8d03 100644 --- a/src/lang/iterable/while.test.fnk.snap +++ b/src/lang/iterable/while.test.fnk.snap @@ -17,7 +17,8 @@ exports[`while compiles destructuring 1`] = ` "(function* filter_while(ˆitems_2) { for (const ˆitem_1 of ˆitems_2) { const [foo, ...bar] = ˆitem_1; - const ˆresult_3 = foo && bar.length === 0; + const foo_alone = foo && bar.length === 0; + const ˆresult_3 = foo_alone; if (ˆresult_3 !== true) return; yield ˆitem_1; } From b238a19512a33bc757f07d7a2b1334e9026ba527 Mon Sep 17 00:00:00 2001 From: Jan Klaas Kollhof Date: Mon, 13 Apr 2020 08:23:08 +0200 Subject: [PATCH 4/4] refactor(style): use call without parens, remove infix calls --- src/js/async.fnk | 7 ++----- src/lang/literals/string.test.fnk | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/js/async.fnk b/src/js/async.fnk index e3bf8a9..65a4bd0 100644 --- a/src/js/async.fnk +++ b/src/js/async.fnk @@ -2,17 +2,14 @@ {isArrowFunctionExpression, isFunctionExpression} = import '@babel/types' -assign = Object.assign - - transform_async = fn path: # TODO: should avoid mutating nodes match path: isArrowFunctionExpression:: ?: - path.node assign {async: true} + Object.assign:: path.node, {async: true} isFunctionExpression:: ?: - path.node assign {async: true} + Object.assign:: path.node, {async: true} {parentPath: {}}: transform_async:: path.parentPath diff --git a/src/lang/literals/string.test.fnk b/src/lang/literals/string.test.fnk index d41a309..c0a911a 100644 --- a/src/lang/literals/string.test.fnk +++ b/src/lang/literals/string.test.fnk @@ -36,7 +36,7 @@ describe:: 'string', fn: it:: 'compiles tagged template string', fn: expect:: fink2js` - str = foo'bar \${spam ni shrub} na' + str = foo'bar \${ni:: spam, shrub} na' ` to_match_snapshot