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
4 changes: 2 additions & 2 deletions lib/nodes/inline-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module.exports = {
let last;

while (token) {
if (/\n/.test(token[1])) {
if (/\r?\n/.test(token[1])) {
// If there are quotes, fix tokenizer creating one token from start quote to end quote
if (/['"].*\n/.test(token[1])) {
if (/['"].*\r?\n/.test(token[1])) {
// Add string before newline to inline comment token
bits.push(token[1].substring(0, token[1].indexOf('\n')));

Expand Down
16 changes: 16 additions & 0 deletions test/parser/comments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ test('inline comment', (t) => {
t.is(nodeToString(root), less);
});

test('two-line inline comment with a single quote and windows EOL', (t) => {
const less = `// it's first comment (this line should end with Windows new line symbols)\r\n// it's second comment`;
const root = parse(less);
const [first, second, ...rest] = root.nodes;

t.truthy(root);
t.true(first instanceof Comment);
t.true(first.inline);
t.is(first.text, `it's first comment (this line should end with Windows new line symbols)`);
t.true(second instanceof Comment);
t.true(second.inline);
t.is(second.text, `it's second comment`);
t.is(nodeToString(root), less);
t.is(rest.length, 0);
});

test('inline comment without leading space', (t) => {
const less = '//batman';
const root = parse(less);
Expand Down