diff --git a/README.md b/README.md index 9781cac..7e9ffeb 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ When you need to compile **Goldstein** to **JavaScript** use: ```js import {compile} from 'goldstein'; -await compile(` +compile(` fn hello() { guard text !== "world" else { return "" @@ -117,7 +117,7 @@ const source = ` const {keywordFn} = keywords; -await compile(source, { +compile(source, { keywords: [ keywordFn, function id(Parser) { diff --git a/package.json b/package.json index 690e20c..1369046 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,9 @@ "wisdom": "madrun wisdom" }, "dependencies": { + "@putout/plugin-declare": "^2.0.1", + "@putout/plugin-logical-expressions": "^4.0.0", + "@putout/plugin-try-catch": "^3.0.0", "@putout/printer": "^3.6.0", "acorn": "^8.7.1", "esbuild": "^0.19.2", diff --git a/packages/goldstein/index.js b/packages/goldstein/index.js index 62549d0..5d9a889 100644 --- a/packages/goldstein/index.js +++ b/packages/goldstein/index.js @@ -1,20 +1,23 @@ -import {transformAsync} from 'putout'; +import {transform} from 'putout'; import {print} from '@putout/printer'; import {parse} from './parser.js'; import estreeToBabel from 'estree-to-babel'; +import tryCatchPlugin from '@putout/plugin-try-catch'; +import declarePlugin from '@putout/plugin-declare'; +import logicalExpressionsPlugin from '@putout/plugin-logical-expressions'; export * from './parser.js'; -export const compile = async (source, options = {}) => { +export const compile = (source, options = {}) => { const ast = estreeToBabel(parse(source, options)); - await transformAsync(ast, source, { + transform(ast, source, { rules: { ...options.rules, }, plugins: [ - 'try-catch', - 'declare', - 'logical-expressions', + ['try-catch', tryCatchPlugin], + ['declare', declarePlugin], + ['logical-expressions', logicalExpressionsPlugin], ], }); diff --git a/packages/goldstein/index.spec.js b/packages/goldstein/index.spec.js index b1e11db..5c0127e 100644 --- a/packages/goldstein/index.spec.js +++ b/packages/goldstein/index.spec.js @@ -6,8 +6,8 @@ import { parse, } from './index.js'; -test('goldstein: compile', async (t) => { - const result = await compile(` +test('goldstein: compile', (t) => { + const result = compile(` fn hello() { } `); @@ -18,8 +18,8 @@ test('goldstein: compile', async (t) => { t.end(); }); -test('goldstein: compile: guard', async (t) => { - const result = await compile(montag` +test('goldstein: compile: guard', (t) => { + const result = compile(montag` fn hello() { guard (text !== 'world') else { return '' @@ -44,8 +44,8 @@ test('goldstein: compile: guard', async (t) => { t.end(); }); -test('goldstein: compile: try', async (t) => { - const result = await compile(montag` +test('goldstein: compile: try', (t) => { + const result = compile(montag` try hello(a, b, c); `); @@ -60,8 +60,8 @@ test('goldstein: compile: try', async (t) => { t.end(); }); -test('goldstein: compile: should', async (t) => { - const result = await compile(montag` +test('goldstein: compile: should', (t) => { + const result = compile(montag` should hello(a, b, c); `); @@ -76,8 +76,8 @@ test('goldstein: compile: should', async (t) => { t.end(); }); -test('goldstein: compile: freeze', async (t) => { - const result = await compile(montag` +test('goldstein: compile: freeze', (t) => { + const result = compile(montag` freeze { example: true } @@ -95,8 +95,8 @@ test('goldstein: compile: freeze', async (t) => { t.end(); }); -test('goldstein: compile: sourceType', async (t) => { - const result = await compile(montag` +test('goldstein: compile: sourceType', (t) => { + const result = compile(montag` export fn hello() {}; `); @@ -109,8 +109,8 @@ test('goldstein: compile: sourceType', async (t) => { t.end(); }); -test('goldstein: compile: throw expression', async (t) => { - const result = await compile(montag` +test('goldstein: compile: throw expression', (t) => { + const result = compile(montag` const a = () => throw 'hello'; `); @@ -125,8 +125,8 @@ test('goldstein: compile: throw expression', async (t) => { t.end(); }); -test('goldstein: compile: curry', async (t) => { - const result = await compile(montag` +test('goldstein: compile: curry', (t) => { + const result = compile(montag` sum~(5); `); @@ -141,8 +141,8 @@ test('goldstein: compile: curry', async (t) => { t.end(); }); -test('goldstein: compile: arrow', async (t) => { - const result = await compile(montag` +test('goldstein: compile: arrow', (t) => { + const result = compile(montag` function hello() => { } `); @@ -155,7 +155,7 @@ test('goldstein: compile: arrow', async (t) => { t.end(); }); -test('goldstein: compile: options', async (t) => { +test('goldstein: compile: options', (t) => { const source = montag` fn hello() { return id('hello'); @@ -163,7 +163,7 @@ test('goldstein: compile: options', async (t) => { `; const {keywordFn} = keywords; - const result = await compile(source, { + const result = compile(source, { keywords: [keywordFn], rules: { declare: ['on', { @@ -197,8 +197,8 @@ test('goldstein: parse: curry', (t) => { t.end(); }); -test('goldstein: parse: if', async (t) => { - const result = await compile(montag` +test('goldstein: parse: if', (t) => { + const result = compile(montag` if a > 3 { log('hello'); } @@ -214,8 +214,8 @@ test('goldstein: parse: if', async (t) => { t.end(); }); -test('goldstein: parse: import', async (t) => { - const result = await compile(montag` +test('goldstein: parse: import', (t) => { + const result = compile(montag` import hello from './hello.gs'; `);