Skip to content

Commit

Permalink
Merge pull request #41 from fink-lang/upgrade
Browse files Browse the repository at this point in the history
upgrade to latest larix
  • Loading branch information
kollhof authored May 1, 2020
2 parents 3b417ad + faa5b68 commit 6e25684
Show file tree
Hide file tree
Showing 19 changed files with 554 additions and 462 deletions.
814 changes: 430 additions & 384 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@
}
},
"devDependencies": {
"@fink/cli": "^3.0.0",
"@fink/cli": "^3.1.0",
"@fink/jest": "^2.0.0",
"@fink/larix": "^6.0.4",
"@fink/larix": "^7.0.0",
"@fink/loxia": "^5.0.0",
"commitizen": "^4.0.4",
"commitizen": "^4.0.5",
"cz-conventional-changelog": "^3.1.0",
"jest-cli": "^25.3.0",
"jest-cli": "^25.5.3",
"npx-run": "^2.1.2",
"semantic-release": "^17.0.7"
},
"dependencies": {
"@babel/generator": "^7.9.5",
"@babel/traverse": "^7.9.5",
"@babel/types": "^7.9.5"
"@babel/generator": "^7.9.6",
"@babel/traverse": "^7.9.6",
"@babel/types": "^7.9.6"
}
}
4 changes: 2 additions & 2 deletions src/lang/arithmitic/index.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
add_arithmitic = fn ctx:
pipe ctx:
add:: 'arithm', any, transform_binary
add:: 'arithm_right', any, transform_binary
add:: 'arithm_prefix', any, transform_unary
add:: 'arithm:right', any, transform_binary
add:: 'arithm:prefix', any, transform_unary

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

value = match prop:
{key: {type: 'spread'}}:
prop.key
{left: {type: 'spread'}}:
prop.left
else:
prop.value
prop.right

emit = match props:
{length: 1}: emit_result
Expand All @@ -63,7 +63,7 @@ match_obj = fn value, obj, emit_result, ctx, cond:
... pipe id_props:
map {id, prop}:
match prop:
{key: {type: 'spread'}}:
{left: {type: 'spread'}}:
restElement:: id
else:
[computed, key] = get_key:: prop, ctx
Expand Down Expand Up @@ -184,7 +184,7 @@ match_all = fn value, matches, emit, ctx:
[condition, result] = split_condition:: expr

js_expr = match condition:
{value: 'else'}:
{type: 'literal', value: 'else'}:
js_expr = emit:: result
wrap_with_comment_loc:: js_expr, condition
else:
Expand Down
2 changes: 1 addition & 1 deletion src/lang/generic/unary.fnk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{unaryExpression} = import '@babel/types'


transform_unary= fn node, {transform}:
transform_unary = fn node, {transform}:
right = transform:: node.right
unaryExpression:: node.op, right
3 changes: 1 addition & 2 deletions src/lang/iterable/index.fnk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{add, any} = import '../context'
{transform_fold} = import './fold'
{transform_unfold} = import './unfold'
{transform_map, transform_flat_map} = import './map'
{transform_map} = import './map'
{transform_filter} = import './filter'
{transform_while} = import './while'
{transform_find} = import './find'
Expand All @@ -12,7 +12,6 @@ add_iterables = fn ctx:
add:: any, 'fold', transform_fold
add:: any, 'unfold', transform_unfold
add:: any, 'map', transform_map
add:: any, 'flat_map', transform_flat_map
add:: any, 'filter', transform_filter
add:: any, 'while', transform_while
add:: any, 'find', transform_find
10 changes: 2 additions & 8 deletions src/lang/iterable/map.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@



transform_any = fn flatten: fn node, ctx:
transform_map = fn node, ctx:
{transform, unique_ident} = ctx

item = unique_ident:: 'item'
Expand All @@ -31,10 +31,4 @@ transform_any = fn flatten: fn node, ctx:

yields::
transform:: yield_value
flatten || last_is_spread


transform_map = transform_any:: false


transform_flat_map = transform_any:: true
last_is_spread
10 changes: 0 additions & 10 deletions src/lang/iterable/map.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@ describe:: 'map', fn:
`
to_match_snapshot

describe:: 'flat_map', fn:
it:: 'compiles', fn:
expect::
fink2js`
flat_map item: [spam + item]

flat_map item: [spam]
`
to_match_snapshot




Expand Down
18 changes: 0 additions & 18 deletions src/lang/iterable/map.test.fnk.snap
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`flat_map compiles 1`] = `
"(function* map(ˆitems_2) {
for (const ˆitem_1 of ˆitems_2) {
const item = ˆitem_1;
yield* [spam + item];
}
});
(function* map(ˆitems_4) {
for (const ˆitem_3 of ˆitems_4) {
const item = ˆitem_3;
yield* [spam];
}
});
Object.assign(module.exports, {});"
`;

exports[`map compiles as flat map 1`] = `
"(function* map(ˆitems_2) {
for (const ˆitem_1 of ˆitems_2) {
Expand Down
5 changes: 4 additions & 1 deletion src/lang/literals/index.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
{transform_regex} = import './regex'
{transform_array} = import './array'
{transform_object, transform_prop} = import './object'
{transform_keyword} = import './keywords'



add_literals = fn ctx:
Expand All @@ -14,4 +16,5 @@ add_literals = fn ctx:
add:: 'regex', any, transform_regex
add:: 'array', any, transform_array
add:: 'object', any, transform_object
add:: 'prop', any, transform_prop
add:: 'object:prop', any, transform_prop
add:: 'literal', any, transform_keyword
8 changes: 8 additions & 0 deletions src/lang/literals/keywords.fnk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{booleanLiteral, nullLiteral} = import '@babel/types'


transform_keyword = fn node:
match node:
{'value': 'true'}: booleanLiteral:: true
{'value': 'false'}: booleanLiteral:: false
{'value': 'null'}: nullLiteral()
13 changes: 13 additions & 0 deletions src/lang/literals/keywords.test.fnk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{fink2js} = import '../../testing'
{describe, it, expect, to_match_snapshot} = import '@fink/jest'


describe:: 'keywords', fn:
it:: 'transforms literals', fn:
expect::
fink2js`
x = false
y = true
z = null
`
to_match_snapshot
12 changes: 12 additions & 0 deletions src/lang/literals/keywords.test.fnk.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`keywords transforms literals 1`] = `
"const x = false;
const y = true;
const z = null;
Object.assign(module.exports, {
x,
y,
z
});"
`;
12 changes: 6 additions & 6 deletions src/lang/literals/object.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ str_key = fn {value, loc}:
{...str, loc}


get_key = fn {key}, ctx:
get_key = fn {left: key}, ctx:
match key:
{type: 'group'}:
[true, ctx.transform:: key]
Expand All @@ -25,16 +25,16 @@ get_key = fn {key}, ctx:

transform_prop = fn node, ctx:
match node:
{key: {type: 'spread'}}:
ctx.transform:: node.key
{left: {type: 'spread'}}:
ctx.transform:: node.left
else:
[computed, key] = get_key:: node, ctx
value = ctx.transform:: node.value
value = ctx.transform:: node.right

shorthand = node.key == node.value
shorthand = node.left == node.right

final_value = match node:
{value: {type: 'assign'}}:
{right: {type: 'assign'}}:
assignmentPattern:: value.left, value.right
else:
value
Expand Down
2 changes: 1 addition & 1 deletion src/lang/literals/regex.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


transform_regex = fn node:
pattern = node.pattern.replace:: rx/(\#.*\n)|[\n\s]/gm, ''
pattern = node.value.replace:: rx/(\#.*\n)|[\n\s]/gm, ''

regExpLiteral:: pattern, node.flags
14 changes: 8 additions & 6 deletions src/lang/literals/string.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@


transform_string = fn node, {transform}:
[...quasies] = pipe node.parts.filter:: fn part, idx: idx % 2 == 0:
map part: templateElement::
{raw: part.value.replace(rx/\\([\s\S])|(`)/g, '\\$1$2')}
{exprs: parts, tag=null} = node

[...quasies] = pipe parts:
filter part: part.type == 'string:text'
map part:
templateElement:: {raw: part.value.replace(rx/\\([\s\S])|(`)/g, '\\$1$2')}

[...expressions] = pipe node.parts.filter:: fn part, idx: idx % 2 == 1:
map part:transform:: part
[...expressions] = pipe parts:
filter part: part.type != 'string:text'
map part: transform:: part

templ_str = templateLiteral:: quasies, expressions
{tag=null} = node

match tag:
null: templ_str
Expand Down
29 changes: 25 additions & 4 deletions src/lang/logical/index.fnk
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
{logicalExpression} = import '@babel/types'
{logicalExpression, unaryExpression} = import '@babel/types'
{add, any} = import '../context'
{transform_unary} = import '../generic/unary'


transform_op = {
'&&': '&&'
'||': '||'
'!': '!'
'and': '&&'
'or': '||'
'not': '!'
}


transform_not = fn node, {transform}:
{(node.op): op} = transform_op
right = transform:: node.right

unaryExpression:: op, right


transform_logical = fn node, {transform}:
{(node.op): op} = transform_op
left = transform:: node.left
right = transform:: node.right
logicalExpression:: node.op, left, right

logicalExpression:: op, left, right


add_logical = fn ctx:
pipe ctx:
add:: any, '&&', transform_logical
add:: any, '||', transform_logical
add:: any, '!', transform_unary
add:: any, '!', transform_not

add:: any, 'and', transform_logical
add:: any, 'or', transform_logical
add:: any, 'not', transform_not

15 changes: 11 additions & 4 deletions src/lang/logical/index.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@


describe:: 'logical', fn:
it:: 'compiles operators', fn:
it:: 'compiles', fn:

expect::
fink2js`
logical = a || b || c && d < 1 <= s
foo = a || b || c
bar = a && b && c
spam = !a
`
to_match_snapshot



expect::
fink2js`
foo = a or b or c
bar = a and b and c
spam = not a
`
to_match_snapshot
21 changes: 18 additions & 3 deletions src/lang/logical/index.test.fnk.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`logical compiles operators 1`] = `
"const logical = a || b || c && d < 1 <= s;
exports[`logical compiles 1`] = `
"const foo = a || b || c;
const bar = a && b && c;
const spam = !a;
Object.assign(module.exports, {
logical
foo,
bar,
spam
});"
`;

exports[`logical compiles 2`] = `
"const foo = a || b || c;
const bar = a && b && c;
const spam = !a;
Object.assign(module.exports, {
foo,
bar,
spam
});"
`;

0 comments on commit 6e25684

Please sign in to comment.