From fee21a7b17fa6942c666d3c589af237919f237a7 Mon Sep 17 00:00:00 2001 From: hacksalot Date: Sun, 10 Jan 2016 05:17:28 -0500 Subject: [PATCH] Always use JSONLint for SyntaxError post-processing. Remove the check for SyntaxError's built-in line and character indicators and always re-parse on error to grab the line/column. --- src/utils/syntax-error-ex.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/utils/syntax-error-ex.js b/src/utils/syntax-error-ex.js index ff73df4..070da99 100644 --- a/src/utils/syntax-error-ex.js +++ b/src/utils/syntax-error-ex.js @@ -11,31 +11,25 @@ Definition of the SyntaxErrorEx class. 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 first check for a .lineNumber and .columnNumber and, if that's - not present, fall back to the JSONLint library, which provides that info. + ments, so we reparse on error to grab the line and column. See: http://stackoverflow.com/q/13323356 @class SyntaxErrorEx */ - module.exports = function SyntaxErrorEx( ex, rawData ) { + function SyntaxErrorEx( ex, rawData ) { var lineNum = null, colNum = null; - if( ex.lineNumber !== undefined && ex.lineNumber !== null ) { - lineNum = ex.lineNumber; - } - if( ex.columnNumber !== undefined && ex.columnNumber !== null ) { - colNum = ex.columnNumber; - } - if( lineNum === null || colNum === null ) { - var JSONLint = require('json-lint'); // TODO: json-lint or is-my-json-valid? - var lint = JSONLint( rawData, { comments: false } ); - if( lineNum === null ) lineNum = (lint.error ? lint.line : '???'); - if( colNum === null ) colNum = (lint.error ? lint.character : '???'); - } - this.line = lineNum; - this.col = colNum; + var JSONLint = require('json-lint'); + var lint = JSONLint( rawData, { comments: false } ); + this.line = (lint.error ? lint.line : '???'); + this.col = (lint.error ? lint.character : '???'); + } + + SyntaxErrorEx.is = function( ex ) { + return ex instanceof SyntaxError; }; + module.exports = SyntaxErrorEx; }());