Skip to content

Commit

Permalink
Merge pull request #90 from fink-lang/features
Browse files Browse the repository at this point in the history
features
  • Loading branch information
kollhof authored Oct 21, 2020
2 parents b676e26 + 1b2511c commit fdbbdd5
Show file tree
Hide file tree
Showing 10 changed files with 19,829 additions and 1,565 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: setup nodejs
uses: actions/setup-node@v1
with:
node-version: 14.x
node-version: 15.x

- name: install dependencies
env:
Expand Down
21,241 changes: 19,713 additions & 1,528 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{
"name": "@fink/loxia",
"version": "0.0.0-semantically-released",
"keywords": [
"fink",
"fink-lang",
"compiler"
],
"license": "MIT",
"engines": {
"node": ">=14.0.0"
},
"type": "module",
"exports": {
".": {
"import": "./generate.js",
"require": "./cjs/generate.js"
},
"./": {
"import": "./",
"require": "./cjs/"
}
},
"version": "0.0.0-semantically-released",
"private": false,
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -43,15 +44,10 @@
"sm:build": "fnk --src ../foo.fnk --out-dir ../ --source-maps inline --module-type 'mjs'",
"sm:view": "npx source-map-visualize ../foo.js"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"devDependencies": {
"@fink/cli": "^8.0.0",
"@fink/jest": "^7.0.0",
"@fink/larix": "^13.1.0",
"@fink/larix": "^14.0.0",
"@fink/loxia": "^14.0.2",
"commitizen": "^4.1.2",
"cz-conventional-changelog": "^3.1.0",
Expand All @@ -66,5 +62,10 @@
"@fink/js-interop": "^2.0.1",
"@fink/snippet": "^2.0.1",
"@fink/std-lib": "^5.0.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
18 changes: 9 additions & 9 deletions src/generate.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ describe 'errors', fn:

expect
error
to_equal "
to_equal '
test.fnk:1:7
1| foo = [
^

Expected ',' or indented(>=1) new line or ']'.
"
Expected `,` or indented(>=1) new line or `]`.
'

it 'errors with code snippet', fn:
{errors: [{error}]} = fink2js '
Expand All @@ -58,15 +58,15 @@ describe 'errors', fn:

expect
error
to_equal "
to_equal '
test.fnk:2:0
1| foo = bar
2| 123 = foo
^
3| shrub = ni

Unable to transform 'assign ='.
"
Unable to transform `assign =`.
'

it 'errors with bad babel options', fn:
{errors: [{message}]} = fink2js
Expand All @@ -91,10 +91,10 @@ describe 'errors', fn:

expect
error
to_equal "
to_equal '
test.fnk:1:0
1| foobar
^

Unable to transform 'test foobar'.
"
Unable to transform `test foobar`.
'
16 changes: 16 additions & 0 deletions src/lang/call/pipe.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@ describe 'pipe', fn:
'
to_match_snapshot


describe 'small pipe |', fn:
it 'pipes', fn:
expect
fink2js '
foo = 134 | is_int
'
to_match_snapshot

it 'handles precedence', fn:
expect
fink2js '
foo = "foo" | matches rx"[a-z]", ?
bar = [spam | ham, shrub | ni]
'
to_match_snapshot
7 changes: 7 additions & 0 deletions src/lang/call/pipe.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ exports[`pipe compiles 1`] = `
}(ˆpipe_result_2);
}"
`;

exports[`small pipe | handles precedence 1`] = `
"export const foo = (ˆ1r) => matches(rx\`[a-z]\`, ˆ1r)(\`foo\`);
export const bar = [ham(spam), ni(shrub)];"
`;

exports[`small pipe | pipes 1`] = `"export const foo = is_int(134);"`;
6 changes: 3 additions & 3 deletions src/lang/errors.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ transform_error = fn {message}, expr, {code, filename}:
type_op = '${expr.type} ${expr.op}'

error = dict:
error: "
error: '
${filename}:${line}:${column}
${highlight_code_loc code, expr.loc}

Unable to transform '${type_op}'.
"
Unable to transform `${type_op}`.
'
expr
message
stack: stack_trace transform_error
Expand Down
32 changes: 23 additions & 9 deletions src/lang/jsx/init.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@ babel_types = import '@babel/types'
{
jsxElement, jsxOpeningElement, jsxIdentifier, jsxClosingElement, jsxAttribute
stringLiteral, jsxExpressionContainer, jsxText, jsxFragment, jsxOpeningFragment
jsxClosingFragment
jsxClosingFragment, jsxSpreadAttribute
} = babel_types

{length} = import '@fink/std-lib/iter.fnk'

{add, any} = import '../context.fnk'



transform_jsx_elem = fn node, {transform}:
id = jsxIdentifier node.name

[...attrs] = pipe node.props:
map expr: transform expr
map expr:
match expr:
{type: 'spread'}:
jsxSpreadAttribute transform expr.right
else:
transform expr

[...children] = pipe node.children:
map expr: transform expr
Expand All @@ -35,18 +44,24 @@ transform_jsx_frag = fn node, {transform}:


transform_jsx_attr = fn node, {transform}:
id = jsxIdentifier node.name
{loc, name} = node

value = match node:
{value: {}}: [transform node.value]
else: []
{value: {type: 'string', exprs: 1 == length ?}}:
{exprs: [str]} = node.value
[stringLiteral str.value]

jsxAttribute id, ...value
{value: {type: 'jsx:expr'}}:
[transform node.value]

{value: {}}:
[jsxExpressionContainer transform node.value]

else:
[jsxExpressionContainer transform {type: 'ident', value: name, loc}]

transform_jsx_str = fn node:
stringLiteral node.value
id = jsxIdentifier name
jsxAttribute id, ...value



Expand All @@ -65,7 +80,6 @@ add_jsx = fn ctx:
add 'jsx:frag', any, transform_jsx_frag
add 'jsx:elem', any, transform_jsx_elem
add 'jsx:attr', any, transform_jsx_attr
add 'jsx:string', any, transform_jsx_str
add 'jsx:text', any, transform_jsx_text
add 'jsx:expr', any, transform_jsx_expr_container

31 changes: 31 additions & 0 deletions src/lang/jsx/init.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,34 @@ describe 'jsx', fn:
to_match_snapshot



describe 'JSX extensions', fn:
it 'compiles spread', fn:
expect
fink2js '<Foobar spam ...ham shrub />'
to_match_snapshot


it "compiles template str attr", fn:
expect
fink2js "<Foobar spam='ni: \${1 + 2}' />"
to_match_snapshot


it "compiles fink expr as attr values", fn:
expect
fink2js "<Foobar spam=ham shrub=1234 ni=-123> foo </Foobar>"
to_match_snapshot


it "compiles fink expr with gt comparison", fn:
expect
fink2js "<Foobar spam=(foo > 123) shrub=1234> ni </Foobar>"
to_match_snapshot


it "compiles expr group with call for attr value", fn:
expect
fink2js "<Foobar spam=(ham ni) shrub=1234 />"
to_match_snapshot

18 changes: 14 additions & 4 deletions src/lang/jsx/init.test.fnk.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`JSX extensions compiles expr group with call for attr value 1`] = `"<Foobar spam={ham(ni)} shrub={1234} />;"`;

exports[`JSX extensions compiles fink expr as attr values 1`] = `"<Foobar spam={ham} shrub={1234} ni={-123}> foo </Foobar>;"`;

exports[`JSX extensions compiles fink expr with gt comparison 1`] = `"<Foobar spam={foo > 123} shrub={1234}> ni </Foobar>;"`;

exports[`JSX extensions compiles spread 1`] = `"<Foobar spam={spam} {...ham} shrub={shrub} />;"`;

exports[`JSX extensions compiles template str attr 1`] = `"<Foobar spam={\`ni: \${1 + 2}\`} />;"`;
exports[`jsx compiles empty elem 1`] = `"export const elem = <b></b>;"`;
exports[`jsx compiles fragment 1`] = `"export const elem = <></>;"`;
Expand All @@ -23,10 +33,10 @@ exports[`jsx compiles with children and expr 1`] = `
</a>;"
`;
exports[`jsx compiles with expr params 1`] = `"export const elem = <a foo bar={1234} />;"`;
exports[`jsx compiles with expr params 1`] = `"export const elem = <a foo={foo} bar={1234} />;"`;
exports[`jsx compiles with expr params 2`] = `"export const elem = <a foo bar=\\"ni\\" />;"`;
exports[`jsx compiles with expr params 2`] = `"export const elem = <a foo={foo} bar=\\"ni\\" />;"`;
exports[`jsx compiles with str params 1`] = `"export const elem = <a foo bar=\\"ni\\" />;"`;
exports[`jsx compiles with str params 1`] = `"export const elem = <a foo={foo} bar=\\"ni\\" />;"`;
exports[`jsx compiles with str params 2`] = `"export const elem = <a foo bar=\\"ni\\" />;"`;
exports[`jsx compiles with str params 2`] = `"export const elem = <a foo={foo} bar=\\"ni\\" />;"`;

0 comments on commit fdbbdd5

Please sign in to comment.