diff --git a/package-lock.json b/package-lock.json index d581735..5f2af2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -319,18 +319,18 @@ } }, "@fink/larix": { - "version": "4.8.0", - "resolved": "https://registry.npmjs.org/@fink/larix/-/larix-4.8.0.tgz", - "integrity": "sha512-1dWSekCYW4xaNQhFfj/0StdwYcmmP91n/VxG2/WPHJusN7nBAUrPFZqNXkRuepUuADNj3chr5l45LpsRSXHA6w==", + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/@fink/larix/-/larix-4.8.1.tgz", + "integrity": "sha512-x8iwRdctzytqWrx2YjGlFD70veAltKP5KJdL3yrU5oKJj7x/EdnLFl9b2hFb+Yhs1hTP75/l53M9+9TqJTt2Ug==", "dev": true, "requires": { "@fink/prattler": "^2.0.0" } }, "@fink/loxia": { - "version": "4.6.4", - "resolved": "https://registry.npmjs.org/@fink/loxia/-/loxia-4.6.4.tgz", - "integrity": "sha512-AZo+NamBxtmQc3Olyd2LexRjc2C5CN9GOFnATjGUj5Qly+XReGIXSx2J1bECrNH0aoWtOpvahf6blPFV9NjEew==", + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/@fink/loxia/-/loxia-4.7.0.tgz", + "integrity": "sha512-qhqk6nGW8eSHpZ42/Jdl8FpsD1b0MexxlCxgHYf00HjFT+XsyuVKnOa6oe0xToVAUX5/OsujWeVzuxfryFHCdw==", "dev": true, "requires": { "@babel/generator": "^7.8.6", @@ -1252,9 +1252,9 @@ }, "dependencies": { "cross-spawn": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.1.tgz", - "integrity": "sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg==", + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.2.tgz", + "integrity": "sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw==", "dev": true, "requires": { "path-key": "^3.1.0", @@ -1380,9 +1380,9 @@ } }, "semver": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.1.3.tgz", - "integrity": "sha512-ekM0zfiA9SCBlsKa2X1hxyxiI4L3B6EbVJkkdgQXnSEEaHlGdvyodMruTiulSRWMMB4NeIuYNMC9rTKTz97GxA==", + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.2.1.tgz", + "integrity": "sha512-aHhm1pD02jXXkyIpq25qBZjr3CQgg8KST8uX0OWXch3xE6jw+1bfbWnCjzMwojsTquroUmKFHNzU6x26mEiRxw==", "dev": true }, "shebang-command": { @@ -1500,9 +1500,9 @@ } }, "@types/babel__traverse": { - "version": "7.0.9", - "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.0.9.tgz", - "integrity": "sha512-jEFQ8L1tuvPjOI8lnpaf73oCJe+aoxL6ygqSy6c8LcW98zaC+4mzWuQIRCEvKeCOu+lbqdXcg4Uqmm1S8AP1tw==", + "version": "7.0.10", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.0.10.tgz", + "integrity": "sha512-74fNdUGrWsgIB/V9kTO5FGHPWYY6Eqn+3Z7L6Hc4e/BxjYV7puvBqp5HwsVYYfLm6iURYBNCx4Ut37OF9yitCw==", "dev": true, "requires": { "@babel/types": "^7.3.0" @@ -1540,9 +1540,9 @@ } }, "@types/node": { - "version": "13.9.8", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.9.8.tgz", - "integrity": "sha512-1WgO8hsyHynlx7nhP1kr0OFzsgKz5XDQL+Lfc3b1Q3qIln/n8cKD4m09NJ0+P1Rq7Zgnc7N0+SsMnoD1rEb0kA==", + "version": "13.11.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.11.0.tgz", + "integrity": "sha512-uM4mnmsIIPK/yeO+42F2RQhGUIs39K2RFmugcJANppXe6J1nvH87PvzPZYpza7Xhhs8Yn9yIAVdLZ84z61+0xQ==", "dev": true }, "@types/normalize-package-data": { @@ -3062,9 +3062,9 @@ }, "dependencies": { "cross-spawn": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.1.tgz", - "integrity": "sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg==", + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.2.tgz", + "integrity": "sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw==", "dev": true, "requires": { "path-key": "^3.1.0", @@ -3528,9 +3528,9 @@ "dev": true }, "fastq": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.6.1.tgz", - "integrity": "sha512-mpIH5sKYueh3YyeJwqtVo8sORi0CgtmkVbK6kZStpQlZBYQuTzG2CZ7idSiJuA7bY0SFCWUc5WIs+oYumGCQNw==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.7.0.tgz", + "integrity": "sha512-YOadQRnHd5q6PogvAR/x62BGituF2ufiEA6s8aavQANw5YKHERI4AREboX6KotzP8oX2klxYF2wcV/7bn1clfQ==", "dev": true, "requires": { "reusify": "^1.0.4" @@ -6089,9 +6089,9 @@ "dev": true }, "json5": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.1.2.tgz", - "integrity": "sha512-MoUOQ4WdiN3yxhm7NEVJSJrieAo5hNSLQ5sj05OTRHPL9HOBy8u4Bu88jsC1jvqAdN+E1bJmsUcZH+1HQxliqQ==", + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.1.3.tgz", + "integrity": "sha512-KXPvOm8K9IJKFM0bmdn8QXh7udDh1g/giieX0NLCaMnb4hEiVFqnop2ImTXCc5e0/oHz3LTqmHGtExn5hfMkOA==", "dev": true, "requires": { "minimist": "^1.2.5" @@ -10775,9 +10775,9 @@ "dev": true }, "p-limit": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.2.tgz", - "integrity": "sha512-WGR+xHecKTr7EbUEhyLSh5Dube9JtdiG78ufaeLxTgpudf/20KqyMioIUZJAezlTIi6evxuoUs9YXc11cU+yzQ==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", "dev": true, "requires": { "p-try": "^2.0.0" @@ -11520,9 +11520,9 @@ "dev": true }, "rxjs": { - "version": "6.5.4", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.4.tgz", - "integrity": "sha512-naMQXcgEo3csAEGvw/NydRA0fuS2nDZJiw1YUWFKU7aPPAPGZEsD4Iimit96qwCieH6y614MCLYwdkrWx7z/7Q==", + "version": "6.5.5", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.5.tgz", + "integrity": "sha512-WfQI+1gohdf0Dai/Bbmk5L5ItH5tYqm3ki2c5GdWhKjalzjg93N3avFjVStyZZz+A2Em+ZxKH5bNghw9UeylGQ==", "dev": true, "requires": { "tslib": "^1.9.0" @@ -11655,9 +11655,9 @@ } }, "cross-spawn": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.1.tgz", - "integrity": "sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg==", + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.2.tgz", + "integrity": "sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw==", "dev": true, "requires": { "path-key": "^3.1.0", @@ -11798,9 +11798,9 @@ "dev": true }, "semver": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.1.3.tgz", - "integrity": "sha512-ekM0zfiA9SCBlsKa2X1hxyxiI4L3B6EbVJkkdgQXnSEEaHlGdvyodMruTiulSRWMMB4NeIuYNMC9rTKTz97GxA==", + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.2.1.tgz", + "integrity": "sha512-aHhm1pD02jXXkyIpq25qBZjr3CQgg8KST8uX0OWXch3xE6jw+1bfbWnCjzMwojsTquroUmKFHNzU6x26mEiRxw==", "dev": true }, "semver-diff": { @@ -13072,9 +13072,9 @@ } }, "windows-release": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/windows-release/-/windows-release-3.2.0.tgz", - "integrity": "sha512-QTlz2hKLrdqukrsapKsINzqMgOUpQW268eJ0OaOpJN32h272waxR9fkB9VoWRtK7uKHG5EHJcTXQBD8XZVJkFA==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/windows-release/-/windows-release-3.3.0.tgz", + "integrity": "sha512-2HetyTg1Y+R+rUgrKeUEhAG/ZuOmTrI1NBb3ZyAGQMYmOJjBBPe4MTodghRkmLJZHwkuPi02anbeGP+Zf401LQ==", "dev": true, "requires": { "execa": "^1.0.0" diff --git a/package.json b/package.json index fcc0e71..ea4abe4 100644 --- a/package.json +++ b/package.json @@ -36,10 +36,10 @@ "devDependencies": { "@fink/cli": "^2.3.0", "@fink/jest": "^1.1.0", - "@fink/larix": "^4.8.0", + "@fink/larix": "^4.8.1", "commitizen": "^4.0.3", "cz-conventional-changelog": "^3.1.0", - "jest-cli": "^25.2.7", + "jest-cli": "^25.2.4", "npx-run": "^2.1.2", "semantic-release": "^17.0.4" }, diff --git a/src/index.test.fnk b/src/index.test.fnk index fdd4fa2..d1a7d28 100644 --- a/src/index.test.fnk +++ b/src/index.test.fnk @@ -34,5 +34,3 @@ describe:: 'errors', fn: Unable to transform 'test'. Unknown expression` - - diff --git a/src/js/async.fnk b/src/js/async.fnk index 1163b86..1c0d257 100644 --- a/src/js/async.fnk +++ b/src/js/async.fnk @@ -1,16 +1,16 @@ assign = Object.assign + transform_async = fn path: # TODO: should avoid mutating nodes - match true: - path.isArrowFunctionExpression(): + match path: + ?.isArrowFunctionExpression(): path.node assign {async: true} - path.isFunctionExpression(): + ?.isFunctionExpression(): path.node assign {async: true} - !!path.parentPath: - transform_async(path.parentPath) - + {parentPath: {}}: + transform_async:: path.parentPath null diff --git a/src/js/do-expression.fnk b/src/js/do-expression.fnk index 1b51eb5..e5ab3b0 100644 --- a/src/js/do-expression.fnk +++ b/src/js/do-expression.fnk @@ -1,99 +1,102 @@ { assignmentExpression, returnStatement, callExpression, - arrowFunctionExpression, expressionStatement + arrowFunctionExpression, expressionStatement, + isDoExpression, isBlockStatement, isLabeledStatement, isTryStatement, + isVariableDeclarator, isArrowFunctionExpression, isExpressionStatement, + isReturnStatement, isProgram, isIfStatement } = import '@babel/types' + {lets, assign, undef} = import './types' +get_body = fn path: path.get:: 'body' + +consume_all = fold item, acc=null: null + + last_expressions = fn path: - match true: - path.isDoExpression(): - body = path.get('body') - [...last_expressions(body)] + match path: + isDoExpression:: ?: + body = get_body:: path + [...last_expressions:: body] - path.isBlockStatement(): - body = path.get('body') + isBlockStatement:: ?: + body = get_body:: path last = body.(body.length - 1) - match true: - last.isExpressionStatement(): + match last: + isExpressionStatement:: ?: [last] else: - [...last_expressions(last)] + [...last_expressions:: last] - path.isLabeledStatement(): - body = path.get('body') + isLabeledStatement:: ?: + body = get_body:: path items = [] - body.traverse( + body.traverse:: { LabeledStatement: fn nested_match: nested_match.skip() , BreakStatement: fn brk: - last = brk.getSibling(brk.key - 1) + last = brk.getSibling:: brk.key - 1 # TODO: don't use mutation - items.push(last) + items.push:: last null } - ) items - # istanbul ignore else - path.isTryStatement(): + # TODO: isTryStatement:: ?: + else: + block = path.get::'block' + handler = path.get:: 'handler' + body = get_body:: handler [ - ...last_expressions(path.get('block')), - ...last_expressions(path.get('handler').get('body')) + ...last_expressions(block), + ...last_expressions(body) ] - else: - # istanbul ignore next - throw path.buildCodeFrameError(`Can't convert do-expression`) - - -consume_all = fold item, acc=null: null replace_with_return = fn path: - pipe last_expressions(path): + pipe last_expressions:: path: map expr: - match true: - expr.node.expression.operator == 'throw': + match expr: + {node: {expression: {operator:'throw'}}}: # no return throw ... - expr.replaceWith( - expressionStatement(expr.node.expression) - ) + expr.replaceWith:: + expressionStatement:: expr.node.expression + else: - expr.replaceWith( - returnStatement(expr.node.expression) - ) + expr.replaceWith:: + returnStatement:: expr.node.expression # TODO: no need for e.g. breaks after a return - sibl = expr.getSibling(expr.key+1) - match true: + sibl = expr.getSibling:: expr.key + 1 + match {sibl}: # istanbul ignore else - !!sibl: + {sibl: {}}: sibl.remove() consume_all simple = fn body, sl=false: - match true: - body.isBlockStatement(): - [stmnt, ...rest] = body.get('body') + match body: + isBlockStatement:: ?: + [stmnt, ...rest] = get_body:: body match rest: {length: 0}: # e.g. fn arg: match ...: ... - match true: - (sl && stmnt.isLabeledStatement()): + match {sl, stmnt}: + {sl: true, stmnt: isLabeledStatement:: ?}: stmnt.node.body + # TODO: + # {sl: true, stmnt: isIfStatement:: ?}: + # body.node else: - # TODO: - # if (sl && stmnt.isIfStatement()) { - # return body.node - # } - simple(stmnt) + simple:: stmnt else: body.node else: @@ -101,19 +104,18 @@ simple = fn body, sl=false: replace_with_assign = fn target, path: - id = path.parentPath.scope.generateUidIdentifier('do_result') - #TODO: - Object.assign(target.node, {init: id}) + id = path.parentPath.scope.generateUidIdentifier:: 'do_result' + #TODO: don't mutate + Object.assign:: target.node, {init: id} - target.parentPath.insertBefore(lets(id)) - target.parentPath.insertBefore(simple(path.get('body'))) - target.parentPath.insertAfter(assign(id, undef())) + target.parentPath.insertBefore:: lets:: id + target.parentPath.insertBefore:: simple:: get_body:: path + target.parentPath.insertAfter:: assign:: id, undef() - pipe last_expressions(path): + pipe last_expressions:: path: map expr: - expr.replaceWith( - assignmentExpression('=', id, expr.node.expression) - ) + expr.replaceWith:: + assignmentExpression:: '=', id, expr.node.expression consume_all @@ -121,42 +123,41 @@ replace_with_assign = fn target, path: transform_do_expr = fn path: {parentPath: parent} = path - match true: - parent.isVariableDeclarator(): - replace_with_assign(parent, path) + match parent: + isVariableDeclarator:: ?: + replace_with_assign:: parent, path + + isArrowFunctionExpression:: ?: + body = get_body:: path - parent.isArrowFunctionExpression(): - # console.log(dbg(parent.node)) - Object.assign(parent.node, {body: simple(path.get('body'), true)}) - replace_with_return(path) + Object.assign:: + parent.node, + {body: simple:: body, true} - parent.isExpressionStatement(): + replace_with_return:: path + + isExpressionStatement:: ?: # this is used e.g. for conditional at the module level - parent.replaceWith(path.get('body').node) + parent.replaceWith:: + get_body:: path + + isReturnStatement:: ?: + body = get_body:: path - parent.isReturnStatement(): - parent.replaceWith(simple(path.get('body'), true)) - replace_with_return(path) + parent.replaceWith:: + simple:: body, true - # istanbul ignore else - !parent.isProgram(): + replace_with_return:: path + else: # e.g. # { # foo: # x = spam # x + 3 # } - path.replaceWith( - callExpression(arrowFunctionExpression([], path.node), []) - ) - # parent.insertBefore(expressionStatement(identifier('ret_st'))) - # throw parent.buildCodeFrameError(`Can't convert do-expression`) - null - else: - # istanbul ignore next - throw parent.buildCodeFrameError(`Can't convert do-expression`) - # istanbul ignore next - null + arrow = arrowFunctionExpression:: [], path.node + path.replaceWith:: + callExpression:: arrow, [] null diff --git a/src/js/types.fnk b/src/js/types.fnk index a55b4f9..c4dc435 100644 --- a/src/js/types.fnk +++ b/src/js/types.fnk @@ -16,31 +16,30 @@ wrap = fn larix_node, js_node: - {...js_node, ...get_comment(larix_node), loc: larix_node.loc} + comment = get_comment:: larix_node + {...js_node, ...comment, loc: larix_node.loc} expr_block = fn ...exprs: - doExpression( - blockStatement([ + doExpression:: + blockStatement:: [ ...pipe exprs: map node: - match true: - (node.type.endsWith('Expression') || isIdentifier(node)): - expressionStatement(node) - else: - node - ]) - ) + match node: + {type: ?.endsWith('Expression')}: expressionStatement:: node + isIdentifier(?): expressionStatement:: node + else: node + ] member = fn obj: fn key, computed: - memberExpression(obj, key, computed) + memberExpression:: obj, key, computed -str = fn txt: stringLiteral(txt) +str = fn txt: stringLiteral:: txt -typof = fn value: unaryExpression('typeof', value) +typof = fn value: unaryExpression:: 'typeof', value split_last = fn [...items]: @@ -48,35 +47,34 @@ split_last = fn [...items]: and = fn left, ...rest: - match true: - rest.length > 0: - logicalExpression('&&', left, and(...rest)) + match rest: + {length: ? > 0}: + logicalExpression:: '&&', left, and:: ...rest else: left -neq = fn left, right: binaryExpression('!==', left, right) +neq = fn left, right: binaryExpression:: '!==', left, right -eq = fn left, right: binaryExpression('===', left, right) +eq = fn left, right: binaryExpression:: '===', left, right -undef = fn: identifier('undefined') +undef = fn: identifier:: 'undefined' -nul = fn: identifier('null') +nul = fn: identifier:: 'null' -true_ = fn: identifier('true') +true_ = fn: identifier:: 'true' not_nullish = fn value: - and( - neq(value, undef()), - neq(value, nul()) - ) + not_null = neq:: value, nul() + not_undef = neq:: value, undef() + and:: not_undef, not_null ident = fn name: match name: # TODO: typeof name == 'string': identifier(escape_ident(name)) or - {constructor: String}: identifier(escape_ident(name)) + {constructor: String}: identifier:: escape_ident:: name else: # {type: 'Identifier'} # {type: 'ObjectPattern'} @@ -85,36 +83,47 @@ ident = fn name: name +declarator = fn id, init: + decl_id = ident:: id + variableDeclarator:: decl_id, init + + consts = fn id, init: - variableDeclaration('const', [variableDeclarator(ident(id), init)]) + variableDeclaration:: + 'const', + [declarator:: id, init] lets = fn id, init: - variableDeclaration('let', [variableDeclarator(ident(id), init)]) + variableDeclaration:: + 'let', + [declarator:: id, init] call = fn callee: fn ...args: - callExpression(callee, args) + callExpression:: callee, args assign = fn left, right: - expressionStatement(assignmentExpression('=', left, right)) + expressionStatement:: + assignmentExpression:: '=', left, right yields = fn expr, delegate: - expressionStatement(yieldExpression(expr, delegate)) + expressionStatement:: + yieldExpression:: expr, delegate iff = fn test: fn consequent: ifStatement(test, consequent) -returns = fn expr: returnStatement(expr) +returns = fn expr: + returnStatement:: expr yield_or_stop = fn expr, unique_ident, delegate: - result = unique_ident('result') - + result = unique_ident:: 'result' [ consts(result, expr), yields(result, delegate) @@ -122,40 +131,36 @@ yield_or_stop = fn expr, unique_ident, delegate: func = fn ...args: fn expr, ...expressions: - arrowFunctionExpression( + arrowFunctionExpression:: args, - expr_block(expr, ...expressions) - ) + expr_block:: expr, ...expressions generator = fn name: fn ...args: fn ...statements: - functionExpression( - ident(name), - args, - blockStatement(statements), - true - ) + func_name = ident:: name + body = blockStatement:: statements + functionExpression:: func_name, args, body, true for_of = fn item, items: fn ...expressions: - forOfStatement( - consts(item), items, - blockStatement(expressions) - ) + forOfStatement:: + consts(item), + items, + blockStatement:: expressions params = fn exprs: [...args] = pipe exprs: map expr: - match true: - isAssignmentExpression(expr): - assignmentPattern(expr.left, expr.right) + match expr: + isAssignmentExpression:: ?: + assignmentPattern:: expr.left, expr.right - isObjectExpression(expr): - objectPattern(params(expr.properties)) + isObjectExpression:: ?: + objectPattern:: params:: expr.properties - isArrayExpression(expr): - arrayPattern(params(expr.elements)) + isArrayExpression:: ?: + arrayPattern:: params:: expr.elements # TODO: was previously used. # (isSpreadElement(expr): diff --git a/src/lang/assignment/index.fnk b/src/lang/assignment/index.fnk index f769bf1..899000e 100644 --- a/src/lang/assignment/index.fnk +++ b/src/lang/assignment/index.fnk @@ -2,11 +2,12 @@ {add, any} = import '../context' {transform_left} = import '../generic/left' +{transform_value} = import '../partial' transform_assign = fn node, ctx: left = transform_left(ctx.transform(node.left)) - right = ctx.transform(node.right) + right = transform_value(node.right, ctx) # wrap(node, assignmentExpression('=', left, right)) assignmentExpression('=', left, right) diff --git a/src/lang/block/index.fnk b/src/lang/block/index.fnk index 2e182c2..4c2ad20 100644 --- a/src/lang/block/index.fnk +++ b/src/lang/block/index.fnk @@ -3,19 +3,19 @@ expressionStatement, variableDeclaration, variableDeclarator } = import '@babel/types' +{consts} = import '../../js/types' + block_statement = fn {transform}: fn expr: - st = transform(expr) + st = transform:: expr - match true: - isAssignmentExpression(st): - decl = variableDeclaration( - 'const', [variableDeclarator(st.left, st.right)] - ) + match st: + isAssignmentExpression:: ?: + decl = consts:: st.left, st.right {...decl, leadingComments: st.leadingComments} else: # TODO: check if (isExpression(st)) ... - expressionStatement(st) + expressionStatement:: st transform_block = fn node, ctx: @@ -24,10 +24,10 @@ transform_block = fn node, ctx: match exprs: {length: 1}: [expr] = exprs - ctx.transform(expr) + ctx.transform:: expr else: - doExpression( - blockStatement( - exprs.map(block_statement(ctx)) - ) - ) + doExpression:: + blockStatement:: + # TODO: why map:: block_statement? + exprs.map:: block_statement:: ctx + diff --git a/src/lang/conditionals/attempt.fnk b/src/lang/conditionals/attempt.fnk index 6dc01cc..96730f0 100644 --- a/src/lang/conditionals/attempt.fnk +++ b/src/lang/conditionals/attempt.fnk @@ -9,30 +9,30 @@ transform_attempt = fn node, ctx: block = transform_block(node, ctx) - body = match true: - isDoExpression(block): block.body.body + body = match block: + isDoExpression:: ?: block.body.body else: [block] - [expressions, last_expr] = split_last(body) - err = ctx.unique_ident('error') - - doExpression( - blockStatement([ - tryStatement( - blockStatement([ - ...expressions, - expressionStatement( - arrayExpression([nullLiteral(), last_expr.expression || last_expr]) - ) - ]), - catchClause( - err, - blockStatement([ - expressionStatement( - arrayExpression([err, nullLiteral()]) - ) - ]) - ) - ) - ]) - ) + [expressions, last_expr] = split_last:: body + err = ctx.unique_ident:: 'error' + + try_block = blockStatement:: [ + ...expressions, + expressionStatement:: + arrayExpression:: [nullLiteral(), last_expr.expression || last_expr] + ] + + catch_block = catchClause:: + err, + blockStatement:: [ + expressionStatement:: + arrayExpression:: [err, nullLiteral()] + ] + + doExpression:: + blockStatement:: [ + tryStatement:: + try_block, + catch_block + ] + diff --git a/src/lang/conditionals/match.fnk b/src/lang/conditionals/match.fnk index b0da8b2..12c2a7f 100644 --- a/src/lang/conditionals/match.fnk +++ b/src/lang/conditionals/match.fnk @@ -11,6 +11,7 @@ {get_key} = import '../literals/object' {is_array} = import '../literals/array' +{is_partial} = import '../partial' iter = fn value: @@ -26,52 +27,26 @@ is_iterable = fn value: ) -args_has_partial = fn {args}: - pipe args: - map arg: is_partial:: arg - find partial: partial - - -is_partial = fn node: - match node: - {type: 'partial'}: true - {left: {type: 'partial'}}: true - {right: {type: 'partial'}}: true - {type: 'call', callee: {type: 'partial'}}: true - {type: 'call', callee: {left: {type: 'partial'}}}: true - {type: 'call'}: args_has_partial:: node - else: false - - -transform_with_partials = fn id, node, {partial_ident, transform, ...ctx}: - partial = is_partial:: node - +comp = fn id, expected, {partial_ident, transform, ...ctx}: value_ctx = {...ctx, partial_ident: id} + value = transform:: expected, value_ctx - # TODO: should get partial info from transforming node? - [partial, transform(node, value_ctx)] + match expected: + is_partial:: ?: value + else: eq:: id, value -comp = fn id, expected, ctx: - [partial, value] = transform_with_partials(id, expected, ctx) - - match true: - partial: value - else: eq(id, value) - - -split_simple_nested = fn id_props, use_val, ctx: +split_simple_nested = fn id_props, ctx: pipe id_props: fold [id, item], [simple, nested]=[[], []]: - elem = match true: - use_val: - match item.value: - {type: 'block', exprs: {length: 1}}: - {exprs: [expr]} = item.value - expr - else: - item.value - else: item + elem = match item: + {type: 'prop', value: {type: 'block', exprs: {length: 1}}}: + {exprs: [expr]} = item.value + expr + {type: 'prop'}: + item.value + else: + item match elem: {type: 'array'}: @@ -95,7 +70,7 @@ match_props = fn value, props, emit_result, ctx: ) ) - [simple, nested] = split_simple_nested(id_props, true, ctx) + [simple, nested] = split_simple_nested(id_props, ctx) nested_block = match nested: {length: 0}: @@ -133,7 +108,7 @@ match_elems = fn value, elems, emit_result, ctx: decl = arrayPattern(id_elems.map(fn [id]: id)) - [simple, nested] = split_simple_nested(id_elems, false, ctx) + [simple, nested] = split_simple_nested(id_elems, ctx) blockStatement([ consts(decl, value), diff --git a/src/lang/conditionals/match.test.fnk b/src/lang/conditionals/match.test.fnk index 0fe9bb0..4fd3dc4 100644 --- a/src/lang/conditionals/match.test.fnk +++ b/src/lang/conditionals/match.test.fnk @@ -49,6 +49,7 @@ describe:: 'match', fn: ? > 123: ni !?: ni ?(): ni + shrub:: ?: ni {spam: ? > 123}: ni {spam: ?()}: ni diff --git a/src/lang/conditionals/match.test.fnk.snap b/src/lang/conditionals/match.test.fnk.snap index 80e64cd..ffc7558 100644 --- a/src/lang/conditionals/match.test.fnk.snap +++ b/src/lang/conditionals/match.test.fnk.snap @@ -156,6 +156,11 @@ exports[`match compiles patial application 1`] = ` break ˆmatch_2; } + if (shrub(ˆvalue_1)) { + ni; + break ˆmatch_2; + } + if (ˆvalue_1 !== undefined && ˆvalue_1 !== null) { const { \\"spam\\": ˆp_3 diff --git a/src/lang/context.fnk b/src/lang/context.fnk index 6941333..ccb8755 100644 --- a/src/lang/context.fnk +++ b/src/lang/context.fnk @@ -1,5 +1,6 @@ -any = false +{code_frame_err} = import './errors' +any = false add = fn type, op, transformer: fn {transformers, ...ctx}: next_transformers = { @@ -12,10 +13,14 @@ add = fn type, op, transformer: fn {transformers, ...ctx}: obj_has = fn obj, key: Object.prototype.hasOwnProperty.call(obj, key) -get_transformer = fn op, type, {transformers}: - match true: - obj_has(transformers, op): +get_transformer = fn {op, type}, {transformers}: + match transformers: + obj_has:: ?, op: transformers.(op) - obj_has(transformers, type): + obj_has:: ?, type: transformers.(type) + + else: fn node, ctx: + err = new Error:: 'Unknown expression' + throw code_frame_err:: err, node, ctx diff --git a/src/lang/errors.fnk b/src/lang/errors.fnk index 74747d1..eaa3f2f 100644 --- a/src/lang/errors.fnk +++ b/src/lang/errors.fnk @@ -4,21 +4,21 @@ transform_error = fn {message}, node, {code, filename}: {start: {line, column}} = node.loc - type_op = match true: - !!node.op: `${node.type} ${node.op}` + type_op = match node: + {op: {}}: `${node.type} ${node.op}` else: node.type # TODO: add filename and line to constructor? - err = new Error( + err = new Error:: `${filename}:${line}:${column}\n${ highlight_code_loc(code, node.loc) }\n\nUnable to transform '${type_op}'.\n\n${message}` - ) - Object.assign(err, {is_transform_err: true}) + + Object.assign:: err, {is_transform_err: true} err code_frame_err = fn err, node, code: match err: {is_transform_err: true}: err - else: transform_error(err, node, code) + else: transform_error:: err, node, code diff --git a/src/lang/generic/left.fnk b/src/lang/generic/left.fnk index adbb981..3a32060 100644 --- a/src/lang/generic/left.fnk +++ b/src/lang/generic/left.fnk @@ -5,17 +5,17 @@ transform_left = fn val: - match true: - isAssignmentExpression(val): - assignmentPattern(val.left, val.right) + match val: + isAssignmentExpression:: ?: + assignmentPattern:: val.left, val.right - isSpreadElement(val): - restElement(val.argument) + isSpreadElement:: ?: + restElement:: val.argument - isArrayExpression(val): - arrayPattern(val.elements.map(transform_left)) + isArrayExpression:: ?: + arrayPattern:: val.elements.map:: transform_left - isObjectExpression(val): - objectPattern(val.properties.map(transform_left)) + isObjectExpression:: ?: + objectPattern:: val.properties.map:: transform_left else: val diff --git a/src/lang/index.fnk b/src/lang/index.fnk index 940058f..e380b13 100644 --- a/src/lang/index.fnk +++ b/src/lang/index.fnk @@ -50,24 +50,22 @@ add_transformers = fn ctx: transform_expr = fn node, ctx: - transform = get_transformer(node.op, node.type, ctx) || null - - match transform: - null: throw code_frame_err(new Error('Unknown expression'), node, ctx) - transform_ctx = { ...ctx, - transform: fn nde, foo_ctx: transform_expr(nde, foo_ctx || transform_ctx) + transform: fn nde, foo_ctx: + transform_expr:: nde, foo_ctx || transform_ctx } + transform = get_transformer:: node, ctx + [err, ast] = attempt: - transformed_node = transform(node, transform_ctx) + transformed_node = transform:: node, transform_ctx # TODO: some nodes have location data - wrap(node, transformed_node) + wrap:: node, transformed_node match err: null: ast - else: throw code_frame_err(err, node, ctx) + else: throw code_frame_err:: err, node, ctx init_ctx = fn code, filename: @@ -81,7 +79,7 @@ init_ctx = fn code, filename: unique_ident: fn name: # TODO: return ident and new ctx to make it not stateful {value} = id_cntr.next() - ident(`${var_prefix}${name}_${value}`) + ident:: `${var_prefix}${name}_${value}` } pipe ctx: @@ -89,8 +87,8 @@ init_ctx = fn code, filename: transform_ast = fn node, code, filename: - ctx = init_ctx(code, filename) - js_ast = transform_expr(node, ctx) + ctx = init_ctx:: code, filename + js_ast = transform_expr:: node, ctx js_ast diff --git a/src/lang/iterable/map.fnk b/src/lang/iterable/map.fnk index de736a8..7b6e00a 100644 --- a/src/lang/iterable/map.fnk +++ b/src/lang/iterable/map.fnk @@ -5,32 +5,32 @@ transform_any = fn flatten: fn node, {transform, unique_ident}: - [item_param] = node.args.map(fn expr: transform(expr)) + [item_param] = node.args.map:: fn expr: transform:: expr - [item] = params([item_param]) - [expressions, last_expr] = split_last(node.exprs) + [item] = params:: [item_param] + [expressions, last_expr] = split_last:: node.exprs - last_is_spread = (last_expr.type == 'spread') + last_is_spread = last_expr.type == 'spread' - yield_value = match true: - last_is_spread: last_expr.right + yield_value = match last_is_spread: + true: last_expr.right else: last_expr - items = unique_ident('items') + items = unique_ident:: 'items' generator('map')(items)( for_of(item, items)( - ...expressions.map(block_statement({transform})), + ...expressions.map(block_statement:: {transform}), - ...yield_or_stop( + ...yield_or_stop:: transform(yield_value), - unique_ident, flatten || last_is_spread - ) + unique_ident, + flatten || last_is_spread ) ) -transform_map = transform_any(false) +transform_map = transform_any:: false -transform_flat_map = transform_any(true) +transform_flat_map = transform_any:: true diff --git a/src/lang/iterable/unfold.fnk b/src/lang/iterable/unfold.fnk index 2ceaf96..8ec7e87 100644 --- a/src/lang/iterable/unfold.fnk +++ b/src/lang/iterable/unfold.fnk @@ -8,13 +8,13 @@ loop = fn ...body: - whileStatement(true_(), blockStatement(body)) + whileStatement:: true_(), blockStatement:: body get_acc = fn inputs: - [acc_init] = params(inputs) - match true: - !!acc_init: + match inputs: + {length: ? > 0}: + [acc_init] = params:: inputs acc_id = acc_init.left || acc_init [acc_id, [acc_init]] else: @@ -22,34 +22,34 @@ get_acc = fn inputs: transform_unfold = fn node, {transform, unique_ident}: - [acc_id, acc_init] = get_acc( - node.args.map(fn arg: transform_left(transform(arg))) - ) + [acc_id, acc_init] = get_acc:: + node.args.map(fn arg: transform_left:: transform:: arg) - [expressions, last_expr] = split_last(node.exprs) + [expressions, last_expr] = split_last:: node.exprs [result, next_value] = match last_expr: {type: 'group'}: last_expr.exprs - else: [last_expr, false] + else: [last_expr, null] - result_id = unique_ident('result') + result_id = unique_ident:: 'result' + + acc_assign = match {acc_id, next_value}: + {acc_id: null, next_value: null}: [] + {next_value: null}: + acca = assign:: acc_id, result_id + [acca] + else: + acca = assign:: acc_id, transform:: next_value + [acca] - acc_assign = acc_id && ( - match true: - !!next_value: assign(acc_id, transform(next_value)) - else: assign(acc_id, result_id) - ) generator('unfold')(...acc_init)( - loop( - ...expressions.map(block_statement({transform})), + loop:: + ...expressions.map(block_statement:: {transform}), - consts(result_id, transform(result)), + consts(result_id, transform:: result), yields(result_id), - ...match true: - !!acc_assign: [acc_assign] - else: [] - ) + ...acc_assign ) diff --git a/src/lang/js-compat/new.test.fnk b/src/lang/js-compat/new.test.fnk index 15219b5..491792e 100644 --- a/src/lang/js-compat/new.test.fnk +++ b/src/lang/js-compat/new.test.fnk @@ -6,6 +6,7 @@ describe:: 'new', fn: it:: 'compiles', fn: fink2js(` foo = new Set() + bar = new Set:: 'abca' `) eq snapshot diff --git a/src/lang/js-compat/new.test.fnk.snap b/src/lang/js-compat/new.test.fnk.snap index c6c40b4..ceae345 100644 --- a/src/lang/js-compat/new.test.fnk.snap +++ b/src/lang/js-compat/new.test.fnk.snap @@ -2,7 +2,9 @@ exports[`new compiles 1`] = ` "const foo = new Set(); +const bar = new Set(\`abca\`); Object.assign(module.exports, { - foo + foo, + bar });" `; diff --git a/src/lang/js-compat/throw.test.fnk b/src/lang/js-compat/throw.test.fnk index ad33a8b..aaff3cf 100644 --- a/src/lang/js-compat/throw.test.fnk +++ b/src/lang/js-compat/throw.test.fnk @@ -6,8 +6,8 @@ describe:: 'throw', fn: it:: 'compiles', fn: fink2js(` fn bar: - match true: - has_err(bar): throw err('spam') + match bar: + has_err:: ?: throw err:: 'spam' else: bar `) eq snapshot diff --git a/src/lang/js-compat/throw.test.fnk.snap b/src/lang/js-compat/throw.test.fnk.snap index e49de4b..8fc510a 100644 --- a/src/lang/js-compat/throw.test.fnk.snap +++ b/src/lang/js-compat/throw.test.fnk.snap @@ -2,9 +2,9 @@ exports[`throw compiles 1`] = ` "bar => { - const ˆvalue_1 = true; + const ˆvalue_1 = bar; - if (ˆvalue_1 === has_err(bar)) { + if (has_err(ˆvalue_1)) { throw err(\`spam\`); } diff --git a/src/lang/literals/object.fnk b/src/lang/literals/object.fnk index 482a59d..8beffeb 100644 --- a/src/lang/literals/object.fnk +++ b/src/lang/literals/object.fnk @@ -7,34 +7,36 @@ transform_object = fn node, ctx: str_key = fn {value, loc}: - {...stringLiteral(value), loc} + str = stringLiteral:: value + {...str, loc} get_key = fn {key}, ctx: - match true: - (key.type == 'group' || key.type == 'string'): + match key: + {type: 'group'}: + [ctx.transform(key), true] + {type: 'string'}: [ctx.transform(key), true] else: [str_key(key), false] transform_prop = fn node, ctx: - match true: - node.key.type == 'spread': - ctx.transform(node.key) + match node: + {key: {type: 'spread'}}: + ctx.transform:: node.key else: - [key, computed] = get_key(node, ctx) - value = ctx.transform(node.value) + [key, computed] = get_key:: node, ctx + value = ctx.transform:: node.value - shorthand = (node.key == node.value) - is_default_assignment = (node.value.type == 'assign') + shorthand = node.key == node.value - final_value = match true: - is_default_assignment: - assignmentPattern(value.left, value.right) + final_value = match node: + {value: {type: 'assign'}}: + assignmentPattern:: value.left, value.right else: value - objectProperty(key, final_value, computed, shorthand) + objectProperty:: key, final_value, computed, shorthand diff --git a/src/lang/literals/object.test.fnk b/src/lang/literals/object.test.fnk index a4c4244..5004e03 100644 --- a/src/lang/literals/object.test.fnk +++ b/src/lang/literals/object.test.fnk @@ -3,29 +3,36 @@ describe:: 'object', fn: - it:: 'compiles', fn: + it:: 'compiles simple', fn: + fink2js(`obj = {}`) eq snapshot + + it:: 'compiles shorthand', fn: + fink2js(`obj = {a}`) eq snapshot + fink2js(`obj = {a, delete, true, false}`) eq snapshot + + it:: 'compiles spread', fn: + 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(` - obj1 = {} - obj2 = {a} - obj3 = {a, delete, true, false} - obj4 = {a, b, ...c} - obj5 = {a: 1, b: 123, 'c-d-e': cde } - obj6 = {a=123, b: c=456} obj7 = {a: 123, b: 123 && 123 && 1345, c: fn a, b: 134} - obj8 = { + `) eq snapshot + + it:: 'compiles multiline', fn: + fink2js(`obj = { a: 123, b: 123 && 123 && 1345, + c: fn a, b: 134, d: n = a+3 foo(n) } - - {a, b, c} `) eq snapshot @@ -42,11 +49,15 @@ describe:: 'calculated props', fn: describe:: 'destructuring object', fn: - it:: 'compiles', fn: - fink2js(` - {a, b, c} = ni - {e, ...f} = {e: 0, foo: 12, bar: 34} - {x=1, ni: {y, z}} = {ni: {y: 1, z: 2}} - {'n i': ni} = foo - `) eq snapshot + it:: 'compiles simple', fn: + fink2js(`{a, b, c} = ni`) eq snapshot + + it:: 'compiles spread', fn: + 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 + + it:: 'compiles computed keys', fn: + fink2js(`{'n i': ni} = foo`) eq snapshot diff --git a/src/lang/literals/object.test.fnk.snap b/src/lang/literals/object.test.fnk.snap index 4a0bcdc..17ba8e3 100644 --- a/src/lang/literals/object.test.fnk.snap +++ b/src/lang/literals/object.test.fnk.snap @@ -12,21 +12,15 @@ Object.assign(module.exports, { });" `; -exports[`destructuring object compiles 1`] = ` +exports[`destructuring object compiles computed keys 1`] = ` +"const { + [\`n i\`]: ni +} = foo; +Object.assign(module.exports, {});" +`; + +exports[`destructuring object compiles defaults 1`] = ` "const { - \\"a\\": a, - \\"b\\": b, - \\"c\\": c -} = ni; -const { - \\"e\\": e, - ...f -} = { - \\"e\\": 0, - \\"foo\\": 12, - \\"bar\\": 34 -}; -const { \\"x\\": x = 1, \\"ni\\": { \\"y\\": y, @@ -38,43 +32,54 @@ const { \\"z\\": 2 } }; -const { - [\`n i\`]: ni -} = foo; Object.assign(module.exports, {});" `; -exports[`object compiles 1`] = ` -"const obj1 = {}; -const obj2 = { - \\"a\\": a -}; -const obj3 = { - \\"a\\": a, - \\"delete\\": ˆdelete, - \\"true\\": true, - \\"false\\": false -}; -const obj4 = { +exports[`destructuring object compiles simple 1`] = ` +"const { \\"a\\": a, \\"b\\": b, - ...c + \\"c\\": c +} = ni; +Object.assign(module.exports, {});" +`; + +exports[`destructuring object compiles spread 1`] = ` +"const { + \\"e\\": e, + ...f +} = { + \\"e\\": 0, + \\"foo\\": 12, + \\"bar\\": 34 }; -const obj5 = { +Object.assign(module.exports, {});" +`; + +exports[`object compiles key:val 1`] = ` +"const obj = { \\"a\\": 1, \\"b\\": 123, [\`c-d-e\`]: cde }; -const obj6 = { - \\"a\\": a = 123, - \\"b\\": c = 456 -}; -const obj7 = { +Object.assign(module.exports, { + obj +});" +`; + +exports[`object compiles key:val 2`] = ` +"const obj7 = { \\"a\\": 123, \\"b\\": 123 && 123 && 1345, \\"c\\": (a, b) => 134 }; -const obj8 = { +Object.assign(module.exports, { + obj7 +});" +`; + +exports[`object compiles multiline 1`] = ` +"const obj = { \\"a\\": 123, \\"b\\": 123 && 123 && 1345, \\"c\\": (a, b) => 134, @@ -83,19 +88,46 @@ const obj8 = { return foo(n); })() }; -({ +Object.assign(module.exports, { + obj +});" +`; + +exports[`object compiles shorthand 1`] = ` +"const obj = { + \\"a\\": a +}; +Object.assign(module.exports, { + obj +});" +`; + +exports[`object compiles shorthand 2`] = ` +"const obj = { + \\"a\\": a, + \\"delete\\": ˆdelete, + \\"true\\": true, + \\"false\\": false +}; +Object.assign(module.exports, { + obj +});" +`; + +exports[`object compiles simple 1`] = ` +"const obj = {}; +Object.assign(module.exports, { + obj +});" +`; + +exports[`object compiles spread 1`] = ` +"const obj = { \\"a\\": a, \\"b\\": b, - \\"c\\": c -}); + ...c +}; Object.assign(module.exports, { - obj1, - obj2, - obj3, - obj4, - obj5, - obj6, - obj7, - obj8 + obj });" `; diff --git a/src/lang/partial/index.fnk b/src/lang/partial/index.fnk index 31ad51f..f505371 100644 --- a/src/lang/partial/index.fnk +++ b/src/lang/partial/index.fnk @@ -4,14 +4,46 @@ {add} = import '../context' +args_has_partial = fn {args}: + pipe args: + map arg: is_partial:: arg + find partial: partial + + +is_partial = fn node: + match node: + {type: 'partial'}: true + {left: is_partial:: ?}: true + {right: is_partial:: ?}: true + {type: 'call', callee: is_partial:: ?}: true + {type: 'call'}: args_has_partial:: node + else: false + + +transform_value = fn node, ctx: + partial_or_node = match node: + is_partial:: ?: + { + type: 'func', + op: 'fn', + args: [{type: 'partial', value: '?'}], + exprs: [node], + loc: node.loc + } + else: + node + + ctx.transform(partial_or_node) + + transform_partial = fn {value}, {partial_ident}: name = match partial_ident || null: - null: escape_ident(value) + null: escape_ident:: value else: partial_ident.name - identifier(name) + identifier:: name add_partial = fn ctx: pipe ctx: - add('partial', '?', transform_partial) + add:: 'partial', '?', transform_partial diff --git a/src/lang/partial/index.test.fnk b/src/lang/partial/index.test.fnk index 78514e0..95c4eab 100644 --- a/src/lang/partial/index.test.fnk +++ b/src/lang/partial/index.test.fnk @@ -3,7 +3,7 @@ describe:: 'partial', fn: - it:: 'compiles outside of match', fn: + it:: 'compiles assignment', fn: fink2js(` foo1 = a * ? + 1 foo2 = bar(?) diff --git a/src/lang/partial/index.test.fnk.snap b/src/lang/partial/index.test.fnk.snap index 9b6bc5b..d1f50ed 100644 --- a/src/lang/partial/index.test.fnk.snap +++ b/src/lang/partial/index.test.fnk.snap @@ -1,10 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`partial compiles outside of match 1`] = ` -"const foo1 = a * ˆ1r + 1; -const foo2 = bar(ˆ1r); -const foo3 = ˆ1r.bar(); -const foo4 = ˆ1r(); +exports[`partial compiles assignment 1`] = ` +"const foo1 = ˆ1r => a * ˆ1r + 1; + +const foo2 = ˆ1r => bar(ˆ1r); + +const foo3 = ˆ1r => ˆ1r.bar(); + +const foo4 = ˆ1r => ˆ1r(); + Object.assign(module.exports, { foo1, foo2, diff --git a/src/testing/jest.fnk b/src/testing/jest.fnk index b1e8859..cd6aea3 100644 --- a/src/testing/jest.fnk +++ b/src/testing/jest.fnk @@ -12,10 +12,9 @@ it = fn descr, test: global.it(descr, test) undefined - +# istanbul ignore next eq = fn result, expected: match expected: - # istanbul ignore else snapshot: expect(result).toMatchSnapshot() else: expect(result).toEqual(expected)