Skip to content

Commit d365379

Browse files
Vilém Jenišshellscape
authored andcommitted
fix: windows eol and inline comments (#137)
1 parent 047f3f1 commit d365379

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/nodes/inline-comment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ module.exports = {
99
let last;
1010

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

test/parser/comments.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ test('inline comment', (t) => {
1515
t.is(nodeToString(root), less);
1616
});
1717

18+
test('two-line inline comment with a single quote and windows EOL', (t) => {
19+
const less = `// it's first comment (this line should end with Windows new line symbols)\r\n// it's second comment`;
20+
const root = parse(less);
21+
const [first, second, ...rest] = root.nodes;
22+
23+
t.truthy(root);
24+
t.true(first instanceof Comment);
25+
t.true(first.inline);
26+
t.is(first.text, `it's first comment (this line should end with Windows new line symbols)`);
27+
t.true(second instanceof Comment);
28+
t.true(second.inline);
29+
t.is(second.text, `it's second comment`);
30+
t.is(nodeToString(root), less);
31+
t.is(rest.length, 0);
32+
});
33+
1834
test('inline comment without leading space', (t) => {
1935
const less = '//batman';
2036
const root = parse(less);

0 commit comments

Comments
 (0)