1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 09:56:22 +00:00
HackMyResume/dist/utils/syntax-error-ex.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-01-27 10:29:26 +00:00
(function() {
2018-02-12 05:05:29 +00:00
/**
Definition of the SyntaxErrorEx class.
@module utils/syntax-error-ex
@license MIT. See LICENSE.md for details.
*/
2016-01-27 10:29:26 +00:00
var SyntaxErrorEx;
2018-02-12 05:05:29 +00:00
/**
Represents a SyntaxError exception with line and column info.
Collect syntax error information from the provided exception object. The
JavaScript `SyntaxError` exception isn't interpreted uniformly across environ-
ments, so we reparse on error to grab the line and column.
See: http://stackoverflow.com/q/13323356
@class SyntaxErrorEx
*/
SyntaxErrorEx = class SyntaxErrorEx {
constructor(ex, rawData) {
var JSONLint, colNum, err, lineNum, lint;
lineNum = null;
colNum = null;
JSONLint = require('json-lint');
lint = JSONLint(rawData, {
comments: false
});
if (lint.error) {
2018-02-12 05:05:29 +00:00
[this.line, this.col] = [lint.line, lint.character];
}
if (!lint.error) {
JSONLint = require('jsonlint');
try {
JSONLint.parse(rawData);
2018-02-12 05:05:29 +00:00
} catch (error) {
err = error;
this.line = (/on line (\d+)/.exec(err))[1];
}
}
}
2018-02-12 05:05:29 +00:00
};
2016-01-27 10:29:26 +00:00
2018-02-12 05:05:29 +00:00
// Return true if the supplied parameter is a JavaScript SyntaxError
2016-01-27 10:29:26 +00:00
SyntaxErrorEx.is = function(ex) {
return ex instanceof SyntaxError;
};
module.exports = SyntaxErrorEx;
}).call(this);
2016-02-02 02:14:36 +00:00
//# sourceMappingURL=syntax-error-ex.js.map