Sha256: 7bf323ae8de5c5921da5f90ae4360f956ef32b5da8510507f9dd0721df26b12d
Contents?: true
Size: 1.14 KB
Versions: 4
Compression:
Stored size: 1.14 KB
Contents
var esprima = require('esprima'); module.exports = function (src, file) { if (typeof src !== 'string') src = String(src); try { Function(src); return; } catch (err) { if (err.constructor.name !== 'SyntaxError') throw err; return errorInfo(src, file); } }; function errorInfo (src, file) { try { esprima.parse(src); return; } catch (err) { return new ParseError(err, src, file); } } function ParseError (err, src, file) { SyntaxError.call(this); this.message = err.message.replace(/^Line \d+: /, ''); this.line = err.lineNumber; this.column = err.column; this.annotated = '\n' + (file || '(anonymous file)') + ':' + this.line + '\n' + src.split('\n')[this.line - 1] + '\n' + Array(this.column).join(' ') + '^' + '\n' + 'ParseError: ' + this.message ; } ParseError.prototype = Object.create(SyntaxError.prototype); ParseError.prototype.toString = function () { return this.annotated; }; ParseError.prototype.inspect = function () { return this.annotated; };
Version data entries
4 entries across 4 versions & 2 rubygems