Skip to content

Commit 714ce13

Browse files
jwilssonshellscape
authored andcommitted
fix: Inline comments shouldn't include newlines (#131)
1 parent 6e7bf62 commit 714ce13

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/nodes/inline-comment.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ module.exports = {
55
const bits = [];
66
let last;
77

8-
while (token && !/\n/.test(token[1])) {
8+
while (token) {
9+
if (/\n/.test(token[1])) {
10+
this.tokenizer.back(token);
11+
break;
12+
}
13+
914
bits.push(token[1]);
1015
last = token;
1116
// eslint-disable-next-line no-param-reassign
1217
token = this.tokenizer.nextToken({ ignoreUnclosed: true });
1318
}
1419

15-
if (token) {
16-
bits.push(token[1]);
17-
}
18-
1920
const newToken = ['comment', bits.join(''), first[2], first[3], last[2], last[3]];
2021

2122
this.inlineComment(newToken);

test/parser/comments.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,13 @@ test('ignores pseudo-comments constructions', (t) => {
8686
t.false(first instanceof Comment);
8787
t.is(nodeToString(root), less);
8888
});
89+
90+
test('newlines are put on the next node', (t) => {
91+
const less = '// a comment\n.a {}';
92+
93+
const root = parse(less);
94+
const { first, last } = root;
95+
96+
t.is(first.raws.right, '');
97+
t.is(last.raws.before, '\n');
98+
});

0 commit comments

Comments
 (0)