react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / syntax-error / index.js
80713 viewsvar aparse = require('acorn').parse;1function parse (src) { return aparse(src, { ecmaVersion: 6 }) }23module.exports = function (src, file) {4if (typeof src !== 'string') src = String(src);56try {7eval('throw "STOP"; (function () { ' + src + '})()');8return;9}10catch (err) {11if (err === 'STOP') return undefined;12if (err.constructor.name !== 'SyntaxError') throw err;13return errorInfo(src, file);14}15};1617function errorInfo (src, file) {18try { parse(src) }19catch (err) {20return new ParseError(err, src, file);21}22return undefined;23}2425function ParseError (err, src, file) {26SyntaxError.call(this);2728this.message = err.message.replace(/\s+\(\d+:\d+\)$/, '');2930this.line = err.loc.line;31this.column = err.loc.column + 1;3233this.annotated = '\n'34+ (file || '(anonymous file)')35+ ':' + this.line36+ '\n'37+ src.split('\n')[this.line - 1]38+ '\n'39+ Array(this.column).join(' ') + '^'40+ '\n'41+ 'ParseError: ' + this.message42;43}4445ParseError.prototype = Object.create(SyntaxError.prototype);4647ParseError.prototype.toString = function () {48return this.annotated;49};5051ParseError.prototype.inspect = function () {52return this.annotated;53};545556