Skip to content

Commit

Permalink
feature: goldstein: update fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jul 9, 2023
1 parent 34e8be9 commit bbe6942
Show file tree
Hide file tree
Showing 24 changed files with 50 additions and 48 deletions.
11 changes: 4 additions & 7 deletions packages/goldstein/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import {parse} from './parser.js';
import estreeToBabel from 'estree-to-babel';

export * from './parser.js';

export const compile = (source, options = {}) => {
const ast = estreeToBabel(parse(source));
const ast = estreeToBabel(parse(source, options));

transform(ast, source, {
rules: {
Expand All @@ -19,12 +18,10 @@ export const compile = (source, options = {}) => {
],
});

const {keywords} = options;

return fixEmpty(print(ast, {keywords}));
return fixEmpty(print(ast));
};

const fixEmpty = (source) => {
return source.replace(';;', ';');
export const fixEmpty = (source) => {
return source.replace(/;(\s+)?;/g, ';');
};

7 changes: 5 additions & 2 deletions packages/goldstein/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const defaultKeywords = {

export const keywords = defaultKeywords;

export const parse = (source, options, keywords = defaultKeywords) => {
const {parse} = extendParser(Object.values(keywords));
export const parse = (source, options = {}, keywords = defaultKeywords) => {
const {parse} = extendParser(Object.values({
...options.keywords,
...keywords,
}));
return parse(source);
};
3 changes: 2 additions & 1 deletion packages/keyword-arrow/fixture/arrow.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
function hello() {}
function world() {}

function world() {}
2 changes: 1 addition & 1 deletion packages/keyword-curry/fixture/curry.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const inc = currify(sum, (1, 2));
const inc = currify(sum, (1, 2));
2 changes: 1 addition & 1 deletion packages/keyword-fn/fixture/export.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export function hello() {}
export function hello() {}
2 changes: 1 addition & 1 deletion packages/keyword-fn/fixture/fn.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
function hello() {}
function hello() {}
2 changes: 1 addition & 1 deletion packages/keyword-fn/fixture/other-export.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export function hello() {}
export function hello() {}
6 changes: 3 additions & 3 deletions packages/keyword-freeze/fixture/array-freeze.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
freeze([{
'test': true
"test": true,
}, {
'example': 'Hello World!'
}]);;
"example": "Hello World!",
}]);
4 changes: 2 additions & 2 deletions packages/keyword-freeze/fixture/freeze.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
freeze({
'test': true
});;
"test": true,
});
9 changes: 4 additions & 5 deletions packages/keyword-guard/fixture/guard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function hello() {
if (!(text !== 'world')) {
return '';
if (!text !== "world") {
return "";
}

return 'Hello ' + text;
}
return "Hello " + text;
}
9 changes: 4 additions & 5 deletions packages/keyword-guard/fixture/no-parens.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function hello() {
if (!(text !== 'world')) {
return '';
if (!text !== "world") {
return "";
}

return 'Hello ' + text;
}
return "Hello " + text;
}
5 changes: 2 additions & 3 deletions packages/keyword-if/fixture/if.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
if (a > 3)
{}
if (a > 3) {}

if (a > 3)
hello();
else
world();
world();
2 changes: 1 addition & 1 deletion packages/keyword-import/fixture/import.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import f from './hello.js';
import f from './hello.js';
2 changes: 1 addition & 1 deletion packages/keyword-should/fixture/await-should.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
try {
await hello();
} catch {};
} catch {};
2 changes: 1 addition & 1 deletion packages/keyword-should/fixture/should.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
try {
hello();
} catch {};
} catch {};
2 changes: 1 addition & 1 deletion packages/keyword-throw/fixture/throw-statement.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const a = () => {
throw 'hello';
};
};
2 changes: 1 addition & 1 deletion packages/keyword-throw/fixture/throw.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const a = () => {
throw 'hello';
};
};
2 changes: 1 addition & 1 deletion packages/keyword-try/fixture/await.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
await tryToCatch(hello);
await tryToCatch(hello);
3 changes: 2 additions & 1 deletion packages/keyword-try/fixture/try-catch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ try {

try {
hello();
} catch (error) {} finally {}
} catch (error) {} finally {}

2 changes: 1 addition & 1 deletion packages/keyword-try/fixture/try.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
tryCatch(hello);
tryCatch(hello);
2 changes: 1 addition & 1 deletion packages/keyword-try/fixture/var.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const [error, result] = await tryToCatch(hello);;
const [error, result] = await tryToCatch(hello);
2 changes: 1 addition & 1 deletion packages/string-interpolation/fixture/number.gs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const x = 5;
const x = 5;
2 changes: 1 addition & 1 deletion packages/string-interpolation/fixture/simple.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
let what = 'String Interpolation';
let str = `This is a ${what.toUpperCase()}`;
let str = `This is a ${what.toUpperCase()}`;
13 changes: 8 additions & 5 deletions packages/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import {
} from 'path';

import {extend} from 'supertape';
import {extendParser} from '../parser/index.js';
import {print} from 'putout';

import tryCatch from 'try-catch';
import estreeToBabel from 'estree-to-babel';

import {extendParser} from '../parser/index.js';
import {fixEmpty} from '../goldstein/index.js';

const {stringify} = JSON;
const {UPDATE, AST} = process.env;
Expand Down Expand Up @@ -45,12 +48,12 @@ const compile = ({dir, parser}) => (t) => (name) => {
const fromData = readFileSync(from, 'utf8');
const toData = readFileSync(to, 'utf8');

const ast = parser.parse(fromData);
const ast = estreeToBabel(parser.parse(fromData));

if (AST === '1')
process.stdout.write(stringify(ast, null, 4));

const result = print(ast);
const result = fixEmpty(print(ast));

if (UPDATE === '1')
writeFileSync(to, result);
Expand All @@ -62,12 +65,12 @@ const noCompile = ({dir, parser}) => (t) => (name) => {
const from = join(dir, 'fixture', `${name}.gs`);
const fromData = readFileSync(from, 'utf8');

const ast = parser.parse(fromData);
const ast = estreeToBabel(parser.parse(fromData));

if (AST === '1')
process.stdout.write(stringify(ast, null, 4));

const result = print(ast);
const result = fixEmpty(print(ast));

return t.equal(result, fromData);
};
Expand Down

0 comments on commit bbe6942

Please sign in to comment.