Skip to content

Commit

Permalink
Do not include src line if longer than 100 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstjules committed Mar 29, 2017
1 parent 9c21549 commit 1c8d47e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function _parse(src, filePath, sourceType) {
}

function getErrorContext(err, src) {
if (!err.loc || !err.loc.line) return '';
if (!err.loc || !err.loc.line || err.loc.column >= 100) return '';

var line = src.split('\n')[err.loc.line - 1];
var caret = ' '.repeat(err.loc.column) + '^';
Expand Down
8 changes: 8 additions & 0 deletions spec/parserSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,13 @@ describe('parse', function() {
expect(err.message).to.contain(`${src}\n ^`);
});
});

it('does not include the src line if longer than 100 chars', function() {
var src = ' '.repeat(100) + ']';
var fn = () => Parser.parse(src, filePath);
expect(fn).to.throwException((err) => {
expect(err.message).not.to.contain(`^`);
});
});
});
});

0 comments on commit 1c8d47e

Please sign in to comment.