Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/nodes/inline-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ module.exports = {
const bits = [];
let last;

while (token && !/\n/.test(token[1])) {
while (token) {
if (/\n/.test(token[1])) {
this.tokenizer.back(token);
break;
}

bits.push(token[1]);
last = token;
// eslint-disable-next-line no-param-reassign
token = this.tokenizer.nextToken({ ignoreUnclosed: true });
}

if (token) {
bits.push(token[1]);
}

const newToken = ['comment', bits.join(''), first[2], first[3], last[2], last[3]];

this.inlineComment(newToken);
Expand Down
10 changes: 10 additions & 0 deletions test/parser/comments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ test('ignores pseudo-comments constructions', (t) => {
t.false(first instanceof Comment);
t.is(nodeToString(root), less);
});

test('newlines are put on the next node', (t) => {
const less = '// a comment\n.a {}';

const root = parse(less);
const { first, last } = root;

t.is(first.raws.right, '');
t.is(last.raws.before, '\n');
});