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, "immed": true,
"latedef": "nofunc", "latedef": "nofunc",
"laxbreak": true, "laxbreak": true,
"loopfunc": true,
"noarg": true, "noarg": true,
"noempty": true, "noempty": true,
"nonew": true, "nonew": true,

@ -32,14 +32,6 @@ module.exports = {
var options = arguments.length > 2 ? utils.clone(arguments[2]) : {}, var options = arguments.length > 2 ? utils.clone(arguments[2]) : {},
stage; 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, { utils.defaults(options, {
allowedStartRules: [ast.rules[0].name], allowedStartRules: [ast.rules[0].name],
cache: false, cache: false,
@ -49,7 +41,7 @@ module.exports = {
for (stage in passes) { for (stage in passes) {
if (passes.hasOwnProperty(stage)) { 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]) + '(' var value = c(bc[ip + 1]) + '('
+ utils.map( + utils.map(
bc.slice(ip + baseLength, ip + baseLength + paramsLength), bc.slice(ip + baseLength, ip + baseLength + paramsLength),
stackIndex function(p) { return stack.index(p); }
).join(', ') ).join(', ')
+ ')'; + ')';
stack.pop(bc[ip + 2]); stack.pop(bc[ip + 2]);
@ -443,14 +443,6 @@ module.exports = function(ast, options) {
ip += baseLength + paramsLength; 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) { while (ip < end) {
switch (bc[ip]) { switch (bc[ip]) {
case op.PUSH: // PUSH c case op.PUSH: // PUSH c

@ -76,24 +76,8 @@ describe("generated parser", function() {
var options = arguments.length > 2 ? arguments[1] : {}, var options = arguments.length > 2 ? arguments[1] : {},
details = arguments.length > 1 details = arguments.length > 1
? arguments[arguments.length - 1] ? arguments[arguments.length - 1]
: undefined; : undefined,
result;
/*
* 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;
try { try {
result = this.actual.parse(input, options); result = this.actual.parse(input, options);
@ -127,7 +111,14 @@ describe("generated parser", function() {
for (key in details) { for (key in details) {
if (details.hasOwnProperty(key)) { if (details.hasOwnProperty(key)) {
if (!this.env.equals_(e[key], details[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; return false;
} }

@ -127,19 +127,6 @@ describe("PEG.js grammar parser", function() {
}, },
toFailToParse: function(details) { 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; var result;
try { try {
@ -170,7 +157,12 @@ describe("PEG.js grammar parser", function() {
for (key in details) { for (key in details) {
if (details.hasOwnProperty(key)) { if (details.hasOwnProperty(key)) {
if (!this.env.equals_(e[key], details[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; return false;
} }

Loading…
Cancel
Save