Skip to content

Commit

Permalink
feat(errors): make transform errors look more like parse errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kollhof committed Mar 4, 2020
1 parent 4fbfc82 commit 6424d24
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@babel/cli": "^7.2.3",
"@babel/plugin-proposal-pipeline-operator": "^7.3.2",
"@babel/preset-env": "^7.8.6",
"@fink/larix": "^4.3.0",
"@fink/larix": "^4.4.0",
"@nearmap/eslint-config-base": "^1.1.0",
"babel-eslint": "^10.1.0",
"commitizen": "^4.0.3",
Expand Down
19 changes: 11 additions & 8 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import {unindent_text, fink2js} from './testing';
test('errors', ()=> {
expect(
()=> fink2js(`
123 = foo
`)
123 = foo`
)
).toThrow(unindent_text(`
test.fnk:1:0: Unable to transform 'assign =':
test.fnk:1:0
1| 123 = foo
^
2|`)
Unable to transform 'assign ='.`)
);


expect(
()=> generate({
type: 'test',
Expand All @@ -26,10 +27,12 @@ test('errors', ()=> {
}, 'test.fnk', 'foobar')

).toThrow(unindent_text(`
test.fnk:1:0: Unable to transform 'test':
test.fnk:1:0
1| foobar
^
`)
Unable to transform 'test'.
Unknown expression`)
);
});
4 changes: 2 additions & 2 deletions src/lang/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class TransformError extends Error {
);

super(
`${filename}:${line}:${column}: Unable to transform '${type_op}':\n\n${
`${filename}:${line}:${column}\n${
highlight_code_loc(code, node.loc)
}\n\n${err.stack}`
}\n\nUnable to transform '${type_op}'.\n\n${err.message}`
);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/testing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const unindent_text = (text)=> {

export const fink2js = (source)=> {
source = unindent_text(source);
const ast = parse(source);
const gen = generate(ast, 'test.fnk', source);
const filename = 'test.fnk';
const ast = parse(source, filename);
const gen = generate(ast, filename, source);
return gen.code;
};

0 comments on commit 6424d24

Please sign in to comment.