Skip to content

Commit

Permalink
feature: goldstein: async
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Aug 28, 2023
1 parent 901a4fa commit 37f9e82
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .madrun.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {run} from 'madrun';
export default {
'test': () => `tape packages/**/*.spec.js`,
'coverage': async () => `escover ${await run('test')}`,
'lint': () => `putout . --rulesdir rules`,
'lint': () => `putout .`,
'fix:lint': () => run('lint', '--fix'),
'build': () => 'node .build.js',
'wisdom': () => run(['lint', 'coverage', 'build']),
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const source = `

const {keywordFn} = keywords;

compile(source, {
await compile(source, {
keywords: [
keywordFn,
function id(Parser) {
Expand Down
6 changes: 3 additions & 3 deletions packages/goldstein/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {transform} from 'putout';
import {transformAsync} from 'putout';
import {print} from '@putout/printer';
import {parse} from './parser.js';
import estreeToBabel from 'estree-to-babel';

export * from './parser.js';
export const compile = (source, options = {}) => {
export const compile = async (source, options = {}) => {
const ast = estreeToBabel(parse(source, options));

transform(ast, source, {
await transformAsync(ast, source, {
rules: {
...options.rules,
},
Expand Down
50 changes: 26 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', (t) => {
const result = compile(`
test('goldstein: compile', async (t) => {
const result = await compile(`
fn hello() {
}
`);
Expand All @@ -18,8 +18,8 @@ test('goldstein: compile', (t) => {
t.end();
});

test('goldstein: compile: guard', (t) => {
const result = compile(montag`
test('goldstein: compile: guard', async (t) => {
const result = await compile(montag`
fn hello() {
guard (text !== 'world') else {
return ''
Expand All @@ -34,6 +34,7 @@ test('goldstein: compile: guard', (t) => {
if (text === 'world') {
return '';
}
return 'Hello ' + text;
}
Expand All @@ -43,8 +44,8 @@ test('goldstein: compile: guard', (t) => {
t.end();
});

test('goldstein: compile: try', (t) => {
const result = compile(montag`
test('goldstein: compile: try', async (t) => {
const result = await compile(montag`
try hello(a, b, c);
`);

Expand All @@ -59,8 +60,8 @@ test('goldstein: compile: try', (t) => {
t.end();
});

test('goldstein: compile: should', (t) => {
const result = compile(montag`
test('goldstein: compile: should', async (t) => {
const result = await compile(montag`
should hello(a, b, c);
`);

Expand All @@ -75,8 +76,8 @@ test('goldstein: compile: should', (t) => {
t.end();
});

test('goldstein: compile: freeze', (t) => {
const result = compile(montag`
test('goldstein: compile: freeze', async (t) => {
const result = await compile(montag`
freeze {
example: true
}
Expand All @@ -94,8 +95,8 @@ test('goldstein: compile: freeze', (t) => {
t.end();
});

test('goldstein: compile: sourceType', (t) => {
const result = compile(montag`
test('goldstein: compile: sourceType', async (t) => {
const result = await compile(montag`
export fn hello() {};
`);

Expand All @@ -108,8 +109,8 @@ test('goldstein: compile: sourceType', (t) => {
t.end();
});

test('goldstein: compile: throw expression', (t) => {
const result = compile(montag`
test('goldstein: compile: throw expression', async (t) => {
const result = await compile(montag`
const a = () => throw 'hello';
`);

Expand All @@ -124,8 +125,8 @@ test('goldstein: compile: throw expression', (t) => {
t.end();
});

test('goldstein: compile: curry', (t) => {
const result = compile(montag`
test('goldstein: compile: curry', async (t) => {
const result = await compile(montag`
sum~(5);
`);

Expand All @@ -140,8 +141,8 @@ test('goldstein: compile: curry', (t) => {
t.end();
});

test('goldstein: compile: arrow', (t) => {
const result = compile(montag`
test('goldstein: compile: arrow', async (t) => {
const result = await compile(montag`
function hello() => {
}
`);
Expand All @@ -154,15 +155,15 @@ test('goldstein: compile: arrow', (t) => {
t.end();
});

test('goldstein: compile: options', (t) => {
test('goldstein: compile: options', async (t) => {
const source = montag`
fn hello() {
return id('hello');
}
`;

const {keywordFn} = keywords;
const result = compile(source, {
const result = await compile(source, {
keywords: [keywordFn],
rules: {
declare: ['on', {
Expand Down Expand Up @@ -196,8 +197,8 @@ test('goldstein: parse: curry', (t) => {
t.end();
});

test('goldstein: parse: if', (t) => {
const result = compile(montag`
test('goldstein: parse: if', async (t) => {
const result = await compile(montag`
if a > 3 {
log('hello');
}
Expand All @@ -213,8 +214,8 @@ test('goldstein: parse: if', (t) => {
t.end();
});

test('goldstein: parse: import', (t) => {
const result = compile(montag`
test('goldstein: parse: import', async (t) => {
const result = await compile(montag`
import hello from './hello.gs';
`);

Expand All @@ -225,3 +226,4 @@ test('goldstein: parse: import', (t) => {
t.equal(result, expected);
t.end();
});

1 change: 1 addition & 0 deletions packages/keyword-guard/fixture/guard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ function hello() {
if (!text !== "world") {
return "";
}

return "Hello " + text;
}
1 change: 1 addition & 0 deletions packages/keyword-guard/fixture/no-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ function hello() {
if (!text !== "world") {
return "";
}

return "Hello " + text;
}

0 comments on commit 37f9e82

Please sign in to comment.