Skip to content

Commit

Permalink
Merge pull request #14 from fink-lang/new-features
Browse files Browse the repository at this point in the history
new features
  • Loading branch information
kollhof authored Mar 2, 2020
2 parents 911e309 + 2101be4 commit 1cbf789
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 10 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@babel/cli": "^7.2.3",
"@babel/plugin-proposal-pipeline-operator": "^7.3.2",
"@babel/preset-env": "^7.8.6",
"@fink/larix": "^4.1.0",
"@fink/larix": "^4.2.0",
"@nearmap/eslint-config-base": "^1.1.0",
"babel-eslint": "^10.1.0",
"commitizen": "^4.0.3",
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import {

import transform_do_expr from './transform/js/do-expression';
import {transform_async} from './transform/js/async';
import {transform_new} from './transform/new';
import {transform_throw} from './transform/throw';


const jsx = {
Expand Down Expand Up @@ -71,6 +73,8 @@ const unary_ops = {
await: transform_await,
'...': transform_spread,
'!': transform_unary,
new: transform_new,
throw: transform_throw,
import: transform_import
};

Expand Down
8 changes: 8 additions & 0 deletions src/transform/__snapshots__/new.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`new transforms new 1`] = `
"const foo = new Set();
Object.assign(module.exports, {
foo
});"
`;
4 changes: 3 additions & 1 deletion src/transform/__snapshots__/string.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ exports[`compiles regex 1`] = `
line 2 with leading space
line 3\`;
const str2 = \`ab\`;
const str3 = foo\`bar spam \${shrub}\`;
Object.assign(module.exports, {
str1,
str2
str2,
str3
});"
`;
8 changes: 8 additions & 0 deletions src/transform/__snapshots__/throw.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`throw transforms throw 1`] = `
"const foo = bar || throw err(\`spam\`);
Object.assign(module.exports, {
foo
});"
`;
10 changes: 10 additions & 0 deletions src/transform/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {newExpression} from '@babel/types';
import {wrap} from '../types';


export const transform_new = (node, ctx)=> {
const right = ctx.transform(node.right);

return wrap(node, newExpression(right.callee, right.arguments));
};

12 changes: 12 additions & 0 deletions src/transform/new.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {fink2js} from '../testing';


describe('new', ()=> {
it('transforms new', ()=> {
expect(
fink2js(`
foo = new Set()
`)
).toMatchSnapshot();
});
});
18 changes: 13 additions & 5 deletions src/transform/string.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import {templateElement, templateLiteral} from '@babel/types';
import {
templateElement, templateLiteral, taggedTemplateExpression
} from '@babel/types';


export const transform_string = (node)=> (
templateLiteral(
export const transform_string = (node, {transform})=> {
const templ_str = templateLiteral(
node.parts.map((part)=> templateElement({raw: part, cooked: part})),
[]
)
);
);

if (node.tag) {
return taggedTemplateExpression(transform(node.tag), templ_str);
}

return templ_str;
};

2 changes: 2 additions & 0 deletions src/transform/string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ test('compiles regex', ()=> {
line 3\`
str2 = \`ab\`
str3 = foo\`bar spam \${shrub}\`
`)
).toMatchSnapshot();
});
10 changes: 10 additions & 0 deletions src/transform/throw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {unaryExpression} from '@babel/types';
import {wrap} from '../types';


export const transform_throw = (node, ctx)=> {
const right = ctx.transform(node.right);

return wrap(node, unaryExpression('throw', right));
};

12 changes: 12 additions & 0 deletions src/transform/throw.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {fink2js} from '../testing';


describe('throw', ()=> {
it('transforms throw', ()=> {
expect(
fink2js(`
foo = bar || throw err('spam')
`)
).toMatchSnapshot();
});
});

0 comments on commit 1cbf789

Please sign in to comment.