Skip to content

Commit

Permalink
Merge pull request #15 from ltegman/fix/multiline-comment-scenarios
Browse files Browse the repository at this point in the history
Fix two multiline comment scenarios, jshint errors
  • Loading branch information
remy authored Oct 17, 2016
2 parents 335856f + f70a1ce commit 7eb9db8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/loop-protect.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* true, preventing the loop from running again.
*/

if (typeof DEBUG === 'undefined') { DEBUG = true; }
if (typeof DEBUG === 'undefined') { DEBUG = true; } //jshint ignore:line

(function (root, factory) {
'use strict';
Expand Down Expand Up @@ -79,7 +79,7 @@ if (typeof DEBUG === 'undefined') { DEBUG = true; }
}
}
j -= 1;
} while (j !== 0);
} while (j >= 0);

return false;
}
Expand All @@ -95,8 +95,8 @@ if (typeof DEBUG === 'undefined') { DEBUG = true; }
}
if (character === '/' || character === '*') {
// looks like a comment, go back one to confirm or not
--index;
if (character === '/') {
var prevCharacter = line.substr(index - 1, 1);
if (prevCharacter === '/') {
// we've found a comment, so let's exit and ignore this line
DEBUG && debug('- exit: part of a comment'); // jshint ignore:line
return true;
Expand Down
14 changes: 11 additions & 3 deletions test/loop-protect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ var code = {
cs: 'var bar, foo;\n\nfoo = function(i) {\n return {\n id: i\n };\n};\n\nbar = function(i) {\n\n var j, _i, _results;\n\n _results = [];\n for (j = _i = 1; 1 <= i ? _i < i : _i > i; j = 1 <= i ? ++_i : --_i) {\n _results.push(j);\n }\n return _results;\n};',
loopbehindif: 'if (false) {for (var i = 1; i--;) {throw Error;}}',
badloopbehindif: 'if (false) for (var i = 1; i--;) {throw Error;}',
singlelinemultiline: '/* reverse palinWord doe comparison*/'
singlelinemultiline: '/* reverse palinWord doe comparison*/',
complexmultiline: '/* This was a tough one for me.\nLet\'s use the Euclidean Algorithm to first get the GCD and\nthen use that to calculate the LCM\nThis below function for obtaining the gcd was posted on StackOverflow by "alex" at\nhttps://stackoverflow.com/questions/17445231/js-how-to-find-the-greatest-common-divisor/.\n*/'
};

var spy;
Expand Down Expand Up @@ -289,10 +290,17 @@ describe('labels', function () {
});

it('should handle single line "/* comment */"', function() {
var c = code.singlelinemultiline
var c = code.singlelinemultiline;
var compiled = loopProtect(c);
assert(compiled === c);
run(compiled);
})
});

it('should handle complex multiline "/* comment */"', function() {
var c = code.complexmultiline;
var compiled = loopProtect(c);
assert(compiled === c);
run(compiled);
});

});

0 comments on commit 7eb9db8

Please sign in to comment.