Skip to content

Commit

Permalink
fixed triggering on valid comments
Browse files Browse the repository at this point in the history
  • Loading branch information
patsul12 committed Jan 7, 2016
1 parent 453a13e commit f6dcb82
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/loop-protect.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ if (typeof DEBUG === 'undefined') { DEBUG = true; }
var openPos = -1;

do {
j -= 1;
DEBUG && debug('looking backwards ' + lines[j]); // jshint ignore:line
closePos = lines[j].indexOf('*/');
openPos = lines[j].indexOf('/*');
Expand All @@ -66,6 +65,11 @@ if (typeof DEBUG === 'undefined') { DEBUG = true; }
closeCommentTags++;
}

//check for single line /* comment */ formatted comments.
if (closePos === lines[j].length - 2 && openPos !== -1) {
closeCommentTags--;
}

if (openPos !== -1) {
closeCommentTags--;

Expand All @@ -74,6 +78,7 @@ if (typeof DEBUG === 'undefined') { DEBUG = true; }
return true;
}
}
j -= 1;
} while (j !== 0);

return false;
Expand Down
8 changes: 8 additions & 0 deletions test/loop-protect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ 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*/'
};

var spy;
Expand Down Expand Up @@ -287,4 +288,11 @@ describe('labels', function () {
run(compiled);
})

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

});

0 comments on commit f6dcb82

Please sign in to comment.