Inline functions extracted just because of JSHint

Rather than extracting functions just because JSHint complained about
defining functions inside a loop, let's inline then and silence the
warning.
redux
David Majda 10 years ago
parent 46ac1bf171
commit f3a83788aa

@ -7,6 +7,7 @@
"immed": true,
"latedef": "nofunc",
"laxbreak": true,
"loopfunc": true,
"noarg": true,
"noempty": true,
"nonew": true,

@ -32,14 +32,6 @@ module.exports = {
var options = arguments.length > 2 ? utils.clone(arguments[2]) : {},
stage;
/*
* Extracted into a function just to silence JSHint complaining about
* creating functions in a loop.
*/
function runPass(pass) {
pass(ast, options);
}
utils.defaults(options, {
allowedStartRules: [ast.rules[0].name],
cache: false,
@ -49,7 +41,7 @@ module.exports = {
for (stage in passes) {
if (passes.hasOwnProperty(stage)) {
utils.each(passes[stage], runPass);
utils.each(passes[stage], function(p) { p(ast, options); });
}
}

@ -435,7 +435,7 @@ module.exports = function(ast, options) {
var value = c(bc[ip + 1]) + '('
+ utils.map(
bc.slice(ip + baseLength, ip + baseLength + paramsLength),
stackIndex
function(p) { return stack.index(p); }
).join(', ')
+ ')';
stack.pop(bc[ip + 2]);
@ -443,14 +443,6 @@ module.exports = function(ast, options) {
ip += baseLength + paramsLength;
}
/*
* Extracted into a function just to silence JSHint complaining about
* creating functions in a loop.
*/
function stackIndex(p) {
return stack.index(p);
}
while (ip < end) {
switch (bc[ip]) {
case op.PUSH: // PUSH c

@ -76,24 +76,8 @@ describe("generated parser", function() {
var options = arguments.length > 2 ? arguments[1] : {},
details = arguments.length > 1
? arguments[arguments.length - 1]
: undefined;
/*
* Extracted into a function just to silence JSHint complaining about
* creating functions in a loop.
*/
function buildKeyMessage(key, value) {
return function() {
return "Expected " + jasmine.pp(input) + " "
+ "with options " + jasmine.pp(options) + " "
+ "to fail to parse"
+ (details ? " with details " + jasmine.pp(details) : "") + ", "
+ "but " + jasmine.pp(key) + " "
+ "is " + jasmine.pp(value) + ".";
};
}
var result;
: undefined,
result;
try {
result = this.actual.parse(input, options);
@ -127,7 +111,14 @@ describe("generated parser", function() {
for (key in details) {
if (details.hasOwnProperty(key)) {
if (!this.env.equals_(e[key], details[key])) {
this.message = buildKeyMessage(key, e[key]);
this.message = function() {
return "Expected " + jasmine.pp(input) + " "
+ "with options " + jasmine.pp(options) + " "
+ "to fail to parse"
+ (details ? " with details " + jasmine.pp(details) : "") + ", "
+ "but " + jasmine.pp(key) + " "
+ "is " + jasmine.pp(e[key]) + ".";
};
return false;
}

@ -127,19 +127,6 @@ describe("PEG.js grammar parser", function() {
},
toFailToParse: function(details) {
/*
* Extracted into a function just to silence JSHint complaining about
* creating functions in a loop.
*/
function buildKeyMessage(key, value) {
return function() {
return "Expected " + jasmine.pp(this.actual) + " to fail to parse"
+ (details ? " with details " + jasmine.pp(details) : "") + ", "
+ "but " + jasmine.pp(key) + " "
+ "is " + jasmine.pp(value) + ".";
};
}
var result;
try {
@ -170,7 +157,12 @@ describe("PEG.js grammar parser", function() {
for (key in details) {
if (details.hasOwnProperty(key)) {
if (!this.env.equals_(e[key], details[key])) {
this.message = buildKeyMessage(key, e[key]);
this.message = function() {
return "Expected " + jasmine.pp(this.actual) + " to fail to parse"
+ (details ? " with details " + jasmine.pp(details) : "") + ", "
+ "but " + jasmine.pp(key) + " "
+ "is " + jasmine.pp(e[key]) + ".";
};
return false;
}

Loading…
Cancel
Save