Skip to content

Commit

Permalink
repl: move "isSyntaxError()" definition to the bottom
Browse files Browse the repository at this point in the history
fixes lint "line length too long" error
  • Loading branch information
TooTallNate committed Oct 6, 2012
1 parent f826b32 commit 59c166c
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,6 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
finish(null);
}

function isSyntaxError(e) {
// Convert error to string
e = e && (e.stack || e.toString());
return e && e.match(/^SyntaxError/) &&
// RegExp syntax error
!e.match(/^SyntaxError: Invalid regular expression/) &&
!e.match(/^SyntaxError: Invalid flags supplied to RegExp constructor/) &&
// JSON.parse() error
!(e.match(/^SyntaxError: Unexpected (token .*|end of input)/) &&
e.match(/\n at Object.parse \(native\)\n/));
}

function finish(e, ret) {

self.memory(cmd);
Expand Down Expand Up @@ -918,3 +906,21 @@ REPLServer.prototype.convertToContext = function(cmd) {

return cmd;
};


/**
* Returns `true` if "e" is a SyntaxError, `false` otherwise.
* This function filters out false positives likes JSON.parse() errors and
* RegExp syntax errors.
*/
function isSyntaxError(e) {
// Convert error to string
e = e && (e.stack || e.toString());
return e && e.match(/^SyntaxError/) &&
// RegExp syntax error
!e.match(/^SyntaxError: Invalid regular expression/) &&
!e.match(/^SyntaxError: Invalid flags supplied to RegExp constructor/) &&
// JSON.parse() error
!(e.match(/^SyntaxError: Unexpected (token .*|end of input)/) &&
e.match(/\n at Object.parse \(native\)\n/));
}

0 comments on commit 59c166c

Please sign in to comment.