diff --git a/package-lock.json b/package-lock.json index 313b761..959d85c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -999,9 +999,9 @@ } }, "@fink/larix": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/@fink/larix/-/larix-4.1.0.tgz", - "integrity": "sha512-h1dDbPmvcJtS7ehdWG4GWndJSIbD4Gs6wzDNyj3yhU4emBwIb2z7tMHSP3wYg5OJWTkMHIDD4ZvHgBliwpErsw==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/@fink/larix/-/larix-4.2.0.tgz", + "integrity": "sha512-PWfLR8pGnd7PMEhMLeUhbnBHulsUuh5gqRhyfSI7Ux57jtK6pb2XhbRugeXGx/rZ7YF6nDSaAJk8gu5va6QoyA==", "dev": true, "requires": { "@fink/prattler": "^1.0.0" diff --git a/package.json b/package.json index 0ec27a0..cb20442 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.js b/src/index.js index 48c8a09..c134900 100644 --- a/src/index.js +++ b/src/index.js @@ -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 = { @@ -71,6 +73,8 @@ const unary_ops = { await: transform_await, '...': transform_spread, '!': transform_unary, + new: transform_new, + throw: transform_throw, import: transform_import }; diff --git a/src/transform/__snapshots__/new.test.js.snap b/src/transform/__snapshots__/new.test.js.snap new file mode 100644 index 0000000..c152b55 --- /dev/null +++ b/src/transform/__snapshots__/new.test.js.snap @@ -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 +});" +`; diff --git a/src/transform/__snapshots__/throw.test.js.snap b/src/transform/__snapshots__/throw.test.js.snap new file mode 100644 index 0000000..86febdc --- /dev/null +++ b/src/transform/__snapshots__/throw.test.js.snap @@ -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 +});" +`; diff --git a/src/transform/new.js b/src/transform/new.js new file mode 100644 index 0000000..c6f51ee --- /dev/null +++ b/src/transform/new.js @@ -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)); +}; + diff --git a/src/transform/new.test.js b/src/transform/new.test.js new file mode 100644 index 0000000..8644868 --- /dev/null +++ b/src/transform/new.test.js @@ -0,0 +1,12 @@ +import {fink2js} from '../testing'; + + +describe('new', ()=> { + it('transforms new', ()=> { + expect( + fink2js(` + foo = new Set() + `) + ).toMatchSnapshot(); + }); +}); diff --git a/src/transform/throw.js b/src/transform/throw.js new file mode 100644 index 0000000..8d9f4fd --- /dev/null +++ b/src/transform/throw.js @@ -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)); +}; + diff --git a/src/transform/throw.test.js b/src/transform/throw.test.js new file mode 100644 index 0000000..2520eb3 --- /dev/null +++ b/src/transform/throw.test.js @@ -0,0 +1,12 @@ +import {fink2js} from '../testing'; + + +describe('throw', ()=> { + it('transforms throw', ()=> { + expect( + fink2js(` + foo = bar || throw err('spam') + `) + ).toMatchSnapshot(); + }); +});