Permalink
Browse files

fixing code style inconsistencies and lint errors

  • Loading branch information...
1 parent f9f78e2 commit b514f004380ab815c019607e66e0bb8b1a3d1aae @thlorenz committed Mar 27, 2013
Showing with 21 additions and 16 deletions.
  1. +21 −16 lib/requirefy.js
View
37 lib/requirefy.js
@@ -19,15 +19,15 @@ module.exports = function requirefy(code, options, resolvePath) {
}
function generateHead(wrapper) {
- var requires = [];
+ var requires = [], i;
if (wrapper.paths.length !== wrapper.params.length) {
log.warn('browserify-ftw',
'number of paths [' + wrapper.paths + '] does not match number of parameters to callback [' + wrapper.params + ']'
);
}
- for (var i = 0; i < wrapper.paths.length; i++) {
+ for (i = 0; i < wrapper.paths.length; i++) {
var name = wrapper.params[i]
, resolvedPath = resolvePath(wrapper.paths[i]);
@@ -38,45 +38,50 @@ module.exports = function requirefy(code, options, resolvePath) {
}
var head;
+ var noname = [], str, r;
switch (options.style) {
case 'var':
head = requires.map(function (r) {
return r.named ? 'var ' + r.string + ';' : r.string + ';';
});
break;
case 'comma':
- var noname = [];
head = [];
- for( var i = 0; i < requires.length; i++ ) {
- var r = requires[i],
- str;
+
+ for(i = 0; i < requires.length; i++ ) {
+ r = requires[i];
+
if(r.named) {
head.push(i === 0 ? 'var ' + r.string + ',' : style.spaces(options.indent) + r.string + ',');
} else {
noname.push(r.string + ';');
}
}
+
str = head[head.length-1];
- head[head.length-1] = str.substr(0, str.length - 1) + ';';
- if(noname.length > 0) {
- head = head.concat(noname);
- }
+ head[head.length - 1] = str.slice(0, str.length - 1) + ';';
+
+ if(noname.length > 0) head = head.concat(noname);
+
break;
case 'comma-first':
- var noname = [];
+ noname = [];
head = [];
- for( var i = 0; i < requires.length; i++ ) {
- var r = requires[i];
+
+ for(i = 0; i < requires.length; i++ ) {
+ r = requires[i];
+
if(r.named) {
head.push(i === 0 ? 'var ' + r.string : style.spaces(options.indent) + ', ' + r.string);
} else {
noname.push(r.string + ';');
}
}
+
head[head.length-1] += ';';
- if(noname.length > 0) {
- head = head.concat(noname);
- }
+
+ if(noname.length > 0) head = head.concat(noname);
+
break;
}
return head.join('\n');

0 comments on commit b514f00

Please sign in to comment.