Skip to content

Commit bcfebfd

Browse files
committed
Merge pull request #8 from calebthebrewer/immediate-code
Catch code that immediately follows a comment, fixes #9
2 parents 3b99584 + 3dda72e commit bcfebfd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var utils = require('./utils');
66
function Code(str, comment) {
77
str = utils.restore(str);
88
var start = comment.loc.end.pos;
9-
var lineno = comment.loc.end.line + 1;
9+
var lineno = comment.loc.end.line;
1010
var ctx = {};
1111

1212
var lines = str.split('\n').slice(lineno);

test/test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ describe('code', function() {
151151
assert.equal(actual[0].code.value, 'var foo = "bar";');
152152
});
153153

154+
it('should get a code line that immediately follows the comment', function() {
155+
var str = '/**\n * this is\n *\n * a comment\n*/\nvar foo = "bar";\n// var one = two';
156+
var actual = extract(str);
157+
assert.equal(actual[0].code.value, 'var foo = "bar";');
158+
});
159+
160+
it('should not get a comment following a comment', function() {
161+
var str = '/**\n * this is\n *\n * a comment\n*/\n// var one = two';
162+
var actual = extract(str);
163+
assert.equal(actual[0].code.value, '');
164+
});
165+
154166
it('should get the code starting and ending indices', function() {
155167
var str = '/**\n * this is\n *\n * a comment\n*/\n\n\nvar foo = "bar";\n';
156168
var actual = extract(str);

0 commit comments

Comments
 (0)