Skip to content

Commit

Permalink
Improve error output.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Feb 15, 2017
1 parent 02088a6 commit a62da66
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
18 changes: 10 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ const warns = {
};

const prettySyntaxError = (err) => {
if (err._babel && err instanceof SyntaxError) {
return new Error(`${err.name}: ${err.message}\n${err.codeFrame}`);
} else {
return err;
}
if (!(err._babel && err instanceof SyntaxError)) return err;
const msg = err.message.replace(/\(\d+:\d+\)$/, '').replace(/^([\./\w]+\:\s)/, '');
const error = new Error(`L${err.loc.line}:${err.loc.column} ${msg}\n${err.codeFrame}`);
error.name = '';
error.stack = err.stack;
return error;
};

class BabelCompiler {
constructor(config) {
if (!config) config = {};
const options = config.plugins &&
(config.plugins.babel || config.plugins.ES6to5) || {};
if (options && !config.plugins.babel && config.plugins.ES6to5) {
const pl = config.plugins;
const options = pl && (pl.babel || pl.ES6to5) || {};

if (pl && !pl.babel && pl.ES6to5) {
logger.warn(warns.ES6to5);
}

Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@
"scripts": {
"test": "eslint index.js && mocha"
},
"files": ["index.js"],
"files": [
"index.js"
],
"dependencies": {
"babel-core": "^6.0.0",
"anymatch": "^1.0.0",
"loggy": "~1.0.1",
"babel-preset-env": "^1.1.8"
"babel-core": "^6.0.0",
"babel-preset-env": "^1.1.8",
"loggy": "~1.0.1"
},
"devDependencies": {
"babel-plugin-transform-es2015-template-literals": "^6.8.0",
"babel-plugin-transform-node-env-inline": "^6.1.18",
"babel-preset-es2015": "^6.22.0",
"mocha": "^2.0.0",
"eslint": "^2.0.0"
}
Expand Down
10 changes: 8 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ describe('Plugin', function() {
plugin.compile({data: content, path: 'file.js'}).then(result => {
assert(result.data.indexOf(expected) !== -1);
done();
}, error => assert(!error));
}, error => {
console.log(error);
assert(!error);
});
});

it('should load indicated presets', function(done) {
Expand All @@ -48,7 +51,10 @@ describe('Plugin', function() {
plugin.compile({data: content, path: 'file.js'}).then(result => {
assert(result.data.indexOf(expected) !== -1);
done();
}, error => assert(!error));
}, error => {
console.log(error);
assert(!error);
});
});

it('should load indicated presets with options', function(done) {
Expand Down

0 comments on commit a62da66

Please sign in to comment.