Fix JSHint errors in bin/pegjs

Fixes the following JSHint errors:

  bin/pegjs: line 66, col 14, 'extraOptions' used out of scope.
  bin/pegjs: line 70, col 19, 'extraOptions' used out of scope.
  bin/pegjs: line 71, col 20, 'extraOptions' used out of scope.
  bin/pegjs: line 80, col 10, Wrap the /regexp/ literal in parens to disambiguate the slash operator.
  bin/pegjs: line 128, col 43, Missing semicolon.
  bin/pegjs: line 128, col 45, Don't make functions within a loop.
  bin/pegjs: line 150, col 13, Redefinition of 'module'.
  bin/pegjs: line 217, col 34, Expected '===' and instead saw '=='.
  bin/pegjs: line 243, col 44, 'source' used out of scope.
  bin/pegjs: line 243, col 61, 'source' used out of scope.
redux
David Majda 11 years ago
parent cc3a9fde2d
commit f22d7aabb5

@ -56,8 +56,10 @@ function abort(message) {
} }
function addExtraOptions(options, json) { function addExtraOptions(options, json) {
var extraOptions;
try { try {
var extraOptions = JSON.parse(json); extraOptions = JSON.parse(json);
} catch (e) { } catch (e) {
if (!(e instanceof SyntaxError)) { throw e; } if (!(e instanceof SyntaxError)) { throw e; }
@ -72,12 +74,20 @@ function addExtraOptions(options, json) {
} }
} }
/*
* Extracted into a function just to silence JSHint complaining about creating
* functions in a loop.
*/
function trim(s) {
return s.trim();
}
/* Arguments */ /* Arguments */
var args = process.argv.slice(2); // Trim "node" and the script path. var args = process.argv.slice(2); // Trim "node" and the script path.
function isOption(arg) { function isOption(arg) {
return /^-/.test(arg); return (/^-/).test(arg);
} }
function nextArg() { function nextArg() {
@ -125,7 +135,7 @@ while (args.length > 0 && isOption(args[0])) {
} }
options.allowedStartRules = args[0] options.allowedStartRules = args[0]
.split(",") .split(",")
.map(function(s) { return s.trim() }); .map(trim);
break; break;
case "-o": case "-o":
@ -146,14 +156,15 @@ while (args.length > 0 && isOption(args[0])) {
abort("Missing parameter of the --plugin option."); abort("Missing parameter of the --plugin option.");
} }
var id = /^(\.\/|\.\.\/)/.test(args[0]) ? path.resolve(args[0]) : args[0]; var id = /^(\.\/|\.\.\/)/.test(args[0]) ? path.resolve(args[0]) : args[0];
var mod;
try { try {
var module = require(id); mod = require(id);
} catch (e) { } catch (e) {
if (e.code !== "MODULE_NOT_FOUND") { throw e; } if (e.code !== "MODULE_NOT_FOUND") { throw e; }
abort("Can't load module \"" + id + "\"."); abort("Can't load module \"" + id + "\".");
} }
options.plugins.push(module); options.plugins.push(mod);
break; break;
case "--extra-options": case "--extra-options":
@ -214,7 +225,7 @@ switch (args.length) {
abort("Can't read from file \"" + inputFile + "\"."); abort("Can't read from file \"" + inputFile + "\".");
}); });
var outputFile = args.length == 1 var outputFile = args.length === 1
? args[0].replace(/\.[^.]*$/, ".js") ? args[0].replace(/\.[^.]*$/, ".js")
: args[1]; : args[1];
var outputStream = fs.createWriteStream(outputFile); var outputStream = fs.createWriteStream(outputFile);
@ -229,8 +240,10 @@ switch (args.length) {
} }
readStream(inputStream, function(input) { readStream(inputStream, function(input) {
var source;
try { try {
var source = PEG.buildParser(input, options); source = PEG.buildParser(input, options);
} catch (e) { } catch (e) {
if (e.line !== undefined && e.column !== undefined) { if (e.line !== undefined && e.column !== undefined) {
abort(e.line + ":" + e.column + ": " + e.message); abort(e.line + ":" + e.column + ": " + e.message);

Loading…
Cancel
Save