Skip to content

Commit

Permalink
Merge pull request #39 from fink-lang/deps
Browse files Browse the repository at this point in the history
lang upgrade
  • Loading branch information
kollhof authored Apr 23, 2020
2 parents 19aaf58 + 2ec40e2 commit 50c7ec0
Show file tree
Hide file tree
Showing 46 changed files with 546 additions and 582 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
moduleFileExtensions: ['js', 'fnk'],
transform: {
'^.+\\.js$': 'babel-jest',
'^.+\\.fnk$': ['@fink/jest']
'^.+\\.fnk$': ['@fink/jest/transform']
},
transformIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/build/'],

Expand Down
829 changes: 403 additions & 426 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
}
},
"devDependencies": {
"@fink/cli": "^2.3.0",
"@fink/jest": "^1.1.0",
"@fink/larix": "^4.10.0",
"@fink/loxia": "^4.10.0",
"@fink/cli": "^3.0.0",
"@fink/jest": "^2.0.0",
"@fink/larix": "^6.0.3",
"@fink/loxia": "^4.11.0",
"commitizen": "^4.0.4",
"cz-conventional-changelog": "^3.1.0",
"jest-cli": "^25.3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/index.test.fnk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{generate} = import '.'
{fink2js} = import './testing'
{describe, it, expect, to_throw} = import './testing/jest'
{describe, it, expect, to_throw} = import '@fink/jest'


describe:: 'errors', fn:
Expand Down
78 changes: 41 additions & 37 deletions src/js/do-expression.fnk
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
{
assignmentExpression, returnStatement, callExpression,
arrowFunctionExpression, expressionStatement,
assignmentExpression, returnStatement, expressionStatement,
isDoExpression, isBlockStatement, isLabeledStatement, isTryStatement,
isVariableDeclarator, isArrowFunctionExpression, isExpressionStatement,
isReturnStatement, isProgram, isIfStatement
isReturnStatement, isIfStatement, arrowFunctionExpression, callExpression
} = import '@babel/types'


{lets, assign, undef} = import './types'


get_body = fn path: path.get:: 'body'

consume_all = fold item, acc=null: null


simple = fn body, sl=false:
match body:
isBlockStatement:: ?:
[stmnt, ...rest] = get_body:: body

match rest:
{length: 0}:
# e.g. fn arg: match ...: ...
match {sl, stmnt}:
{sl: true, stmnt: isLabeledStatement:: ?}:
stmnt.node.body
# TODO:
# {sl: true, stmnt: isIfStatement:: ?}:
# body.node
else:
simple:: stmnt
else:
body.node
else:
body.node


last_expressions = fn path:
match path:
isDoExpression:: ?:
Expand All @@ -38,11 +58,18 @@ last_expressions = fn path:
{
LabeledStatement: fn nested_match:
nested_match.skip()
,

BreakStatement: fn brk:
last = brk.getSibling:: brk.key - 1
# TODO: don't use mutation
items.push:: last
# TODO: don't add throw expr
match last.node:
{expression: {operator: 'throw'}}:
last.replaceWith::
expressionStatement:: last.node.expression
brk.remove()
else:
# TODO: don't use mutation
items.push:: last
null
}
items
Expand All @@ -63,10 +90,8 @@ replace_with_return = fn path:
map expr:
match expr:
{node: {expression: {operator:'throw'}}}:
# no return throw ...
expr.replaceWith::
expressionStatement:: expr.node.expression

else:
expr.replaceWith::
returnStatement:: expr.node.expression
Expand All @@ -81,28 +106,6 @@ replace_with_return = fn path:
consume_all


simple = fn body, sl=false:
match body:
isBlockStatement:: ?:
[stmnt, ...rest] = get_body:: body

match rest:
{length: 0}:
# e.g. fn arg: match ...: ...
match {sl, stmnt}:
{sl: true, stmnt: isLabeledStatement:: ?}:
stmnt.node.body
# TODO:
# {sl: true, stmnt: isIfStatement:: ?}:
# body.node
else:
simple:: stmnt
else:
body.node
else:
body.node


replace_with_assign = fn target, path:
id = path.parentPath.scope.generateUidIdentifier:: 'do_result'
#TODO: don't mutate
Expand Down Expand Up @@ -148,16 +151,17 @@ transform_do_expr = fn path:
simple:: body, true

replace_with_return:: path

else:
# e.g.
# {
# foo:
# x = spam
# x + 3
# }
# fn:
# foo = match:
# spam:
# shrub
# ni
# foo
arrow = arrowFunctionExpression:: [], path.node
path.replaceWith::
callExpression:: arrow, []

null

2 changes: 1 addition & 1 deletion src/js/identifier.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
check_ident = rx/
^(?!(?:
do|if|in|for|let|new|try|var|case|enum|void|with|break|catch|class|const|super|while|yield|delete|export|import|public|return|static|switch|
typeof|default|extends|finally|package|private|continue|debugger|function|
typeof|default|extends|finally|package|private|continue|function|
arguments|interface|protected|implements|instanceof
)$)
[
Expand Down
8 changes: 6 additions & 2 deletions src/lang/assignment/index.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ transform_spread_left = fn {left}, {transform}:
else: [before, middle, [...end, expr]]

exprs = match before:
{length: 0}: [middle, {type: 'array', exprs: end}]
else: [{type: 'array', exprs: before}, middle, {type: 'array', exprs: end}]
{length: 0}:
# TODO missing loc
[middle, {type: 'array', exprs: end}]
else:
# TODO missing loc
[{type: 'array', exprs: before}, middle, {type: 'array', exprs: end}]

transform_left:: transform:: {...left, exprs}

Expand Down
2 changes: 1 addition & 1 deletion src/lang/assignment/index.test.fnk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{fink2js} = import '../../testing'
{describe, it, expect, to_match_snapshot} = import '../../testing/jest'
{describe, it, expect, to_match_snapshot} = import '@fink/jest'


describe:: 'assignment', fn:
Expand Down
4 changes: 2 additions & 2 deletions src/lang/async/index.test.fnk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{fink2js} = import '../../testing'
{describe, it, expect, to_match_snapshot} = import '../../testing/jest'
{describe, it, expect, to_match_snapshot} = import '@fink/jest'


describe:: 'await', fn:
Expand All @@ -18,7 +18,7 @@ describe:: 'await', fn:
a_gen = unfold curr=0:
match shrub:
spam: await ni(curr)
else : curr + 1
else: curr + 1

await ni
`
Expand Down
4 changes: 2 additions & 2 deletions src/lang/call/call.test.fnk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{fink2js} = import '../../testing'
{describe, it, expect, to_match_snapshot} = import '../../testing/jest'
{describe, it, expect, to_match_snapshot} = import '@fink/jest'


describe:: 'call', fn:
Expand All @@ -9,7 +9,7 @@ describe:: 'call', fn:
fink2js`
call1 = a(ni, x=123, ...x)
call2 = a(ni)
call3 = a ()
call3 = a()
call4 = a(fn x: x*2)
`
to_match_snapshot
Expand Down
2 changes: 1 addition & 1 deletion src/lang/call/pipe.test.fnk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{fink2js} = import '../../testing'
{describe, it, expect, to_match_snapshot} = import '../../testing/jest'
{describe, it, expect, to_match_snapshot} = import '@fink/jest'


describe:: 'pipe', fn:
Expand Down
2 changes: 1 addition & 1 deletion src/lang/comments/index.test.fnk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{fink2js} = import '../../testing'
{describe, it, expect, to_match_snapshot} = import '../../testing/jest'
{describe, it, expect, to_match_snapshot} = import '@fink/jest'


describe:: 'comment', fn:
Expand Down
2 changes: 1 addition & 1 deletion src/lang/conditionals/attempt.test.fnk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{fink2js} = import '../../testing'
{describe, it, expect, to_match_snapshot} = import '../../testing/jest'
{describe, it, expect, to_match_snapshot} = import '@fink/jest'


describe:: 'attempt', fn:
Expand Down
8 changes: 3 additions & 5 deletions src/lang/conditionals/match.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ match_props = fn props, emit_result, ctx, cond:
[{id, prop}, ...rest] = props

value = match prop:
{value: {type: 'block', exprs: {length: 1}}}:
{exprs: [expr]} = prop.value
expr
{key: {type: 'spread'}}:
prop.key
else:
Expand Down Expand Up @@ -100,7 +97,8 @@ get_array_decl = fn arr, id_elems, right, ctx:
map {id, value}:
match value:
# e.g. empty elems in [,, foo, bar]
null: null
{type: 'empty'}:
null
# e.g. spread in [foo, ..., bar]
{type: 'spread', right: null}:
value
Expand Down Expand Up @@ -136,7 +134,7 @@ match_array = fn value, arr, emit_result, ctx, cond:
filter {value}:
match value:
# empty elements need no matching
null: false
{type: 'empty'}: false
# empty spreads need no matching
{type: 'spread', right: null}: false
else: true
Expand Down
17 changes: 16 additions & 1 deletion src/lang/conditionals/match.test.fnk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{fink2js} = import '../../testing'
{describe, it, expect, to_match_snapshot} = import '../../testing/jest'
{describe, it, only, expect, to_match_snapshot} = import '@fink/jest'


describe:: 'match', fn:
Expand Down Expand Up @@ -139,3 +139,18 @@ describe:: 'match', fn:
[is_foo(?)]: ni
`
to_match_snapshot


it:: 'compiles do-expr', fn:
expect::
fink2js`
foo = match bar:
spam:
ni
throw foobar
else:
shrub
throw ni
`
to_match_snapshot

32 changes: 32 additions & 0 deletions src/lang/conditionals/match.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,38 @@ exports[`match compiles 1`] = `
Object.assign(module.exports, {});"
`;

exports[`match compiles do-expr 1`] = `
"let _do_result;
ˆmatch_2: {
const ˆvalue_1 = bar;
ifvalue_1 === spam) {
_do_result = (() => {
ni;
throw foobar;
})();
break ˆmatch_2;
}
{
_do_result = (() => {
shrub;
throw ni;
})();
break ˆmatch_2;
}
}
const foo = _do_result;
_do_result = undefined;
Object.assign(module.exports, {
foo
});"
`;

exports[`match compiles nested match 1`] = `
"const test = () => {
const ˆvalue_1 = foo;
Expand Down
2 changes: 1 addition & 1 deletion src/lang/func/index.test.fnk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{fink2js} = import '../../testing'
{describe, it, expect, to_match_snapshot} = import '../../testing/jest'
{describe, it, expect, to_match_snapshot} = import '@fink/jest'


describe:: 'func', fn:
Expand Down
2 changes: 1 addition & 1 deletion src/lang/generic/binary.test.fnk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{fink2js} = import '../../testing'
{describe, it, expect, to_match_snapshot} = import '../../testing/jest'
{describe, it, expect, to_match_snapshot} = import '@fink/jest'


describe:: 'binary', fn:
Expand Down
2 changes: 0 additions & 2 deletions src/lang/generic/index.fnk
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{add, any} = import '../context'
{transform_inifx} = import './infix'
{transform_block} = import '../block'


add_generic = fn ctx:
pipe ctx:
add:: 'infix', any, transform_inifx
add:: 'block', any, transform_block

12 changes: 0 additions & 12 deletions src/lang/generic/infix.fnk

This file was deleted.

14 changes: 0 additions & 14 deletions src/lang/generic/infix.test.fnk

This file was deleted.

Loading

0 comments on commit 50c7ec0

Please sign in to comment.