Skip to content

Commit

Permalink
fix: goldstein: get back sync
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Aug 29, 2023
1 parent 12aed59 commit 999445f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down Expand Up @@ -117,7 +117,7 @@ const source = `

const {keywordFn} = keywords;

await compile(source, {
compile(source, {
keywords: [
keywordFn,
function id(Parser) {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 9 additions & 6 deletions packages/goldstein/index.js
Original file line number Diff line number Diff line change
@@ -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],
],
});

Expand Down
48 changes: 24 additions & 24 deletions packages/goldstein/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
`);
Expand All @@ -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 ''
Expand All @@ -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);
`);

Expand All @@ -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);
`);

Expand All @@ -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
}
Expand All @@ -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() {};
`);

Expand All @@ -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';
`);

Expand All @@ -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);
`);

Expand All @@ -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() => {
}
`);
Expand All @@ -155,15 +155,15 @@ 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');
}
`;

const {keywordFn} = keywords;
const result = await compile(source, {
const result = compile(source, {
keywords: [keywordFn],
rules: {
declare: ['on', {
Expand Down Expand Up @@ -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');
}
Expand All @@ -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';
`);

Expand Down

0 comments on commit 999445f

Please sign in to comment.