Skip to content

Commit

Permalink
feature: goldstein: export print, convert
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Oct 3, 2023
1 parent fb66b8d commit 7c33a12
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,30 @@ parse(`
`, options);
```

### `print(ast)`

You can make any modifications to **Goldstein AST** and then `print` back to **Goldstein**:

```
import {parse, print} from 'goldstein';
const ast = parse(`const t = try f('hello')`);
const source = print(ast);
```

### `convert(source)`

You can even convert **JavaScript** to **Goldstein** with:

```
import {convert} from 'goldstein';
const ast = convert(`const t = tryCatch(f, 'hello');`;
// returns
`const t = try f('hello')`)
```

## Keywords

**Goldstein** is absolutely compatible with JavaScript, and it has extensions.
Expand Down
2 changes: 1 addition & 1 deletion packages/convert/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {test} from 'supertape';
import montag from 'montag';
import {convert} from './index.js';

test('goldstein: convert', (t) => {
test('goldstein: convert: tryCatch', (t) => {
const source = `const a = await tryToCatch(f, 'hello')`;
const result = convert(source);

Expand Down
1 change: 1 addition & 0 deletions packages/goldstein/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {parse} from './parser.js';

export * from './parser.js';
export {print} from '../printer/index.js';
export {convert} from '../convert/index.js';
export const compile = (source, options = {}) => {
const ast = parse(source, options);

Expand Down
11 changes: 11 additions & 0 deletions packages/goldstein/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
keywords,
parse,
print,
convert,
} from './index.js';

test('goldstein: compile', (t) => {
Expand Down Expand Up @@ -254,3 +255,13 @@ test('goldstein: print', (t) => {
t.equal(result, `${source}\n`);
t.end();
});

test('goldstein: convert', (t) => {
const source = `const a = tryCatch(f, 'hello');`;
const result = convert(source);

const expected = `const a = try f('hello');\n`;

t.equal(result, expected);
t.end();
});

0 comments on commit 7c33a12

Please sign in to comment.