Skip to content

Commit

Permalink
feat: add throw and new operators
Browse files Browse the repository at this point in the history
  • Loading branch information
kollhof committed Mar 2, 2020
1 parent d6d81e7 commit bfa5e9a
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 4 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
});"
`;
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();
});
});
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 bfa5e9a

Please sign in to comment.