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
16 changes: 10 additions & 6 deletions lib/nodes/inline-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
const first = token;
const bits = [];
let last;
let remainingInput;

while (token) {
if (/\r?\n/.test(token[1])) {
Expand All @@ -18,12 +19,8 @@ module.exports = {
bits.push(token[1].substring(0, token[1].indexOf('\n')));

// Get remaining input and retokenize
let remainingInput = token[1].substring(token[1].indexOf('\n'));
remainingInput = token[1].substring(token[1].indexOf('\n'));
remainingInput += this.input.css.valueOf().substring(this.tokenizer.position());

// Replace tokenizer to retokenize the rest of the string
this.input = new Input(remainingInput);
this.tokenizer = tokenizer(this.input);
} else {
// If the tokenizer went to the next line go back
this.tokenizer.back(token);
Expand All @@ -37,8 +34,15 @@ module.exports = {
}

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

this.inlineComment(newToken);

// Replace tokenizer to retokenize the rest of the string
// we need replace it after we added new token with inline comment because token position is calculated for old input (#145)
if (remainingInput) {
this.input = new Input(remainingInput);
this.tokenizer = tokenizer(this.input);
}

return true;
} else if (token[1] === '/') {
// issue #135
Expand Down
13 changes: 13 additions & 0 deletions test/parser/comments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ test('two subsequent inline comments with unmatched quotes', (t) => {
t.is(nodeToString(root), less);
});

test('inline comments with quotes and new line(#145)', (t) => {
const less = `
// batman'
`;

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

t.is(first.type, 'comment');
t.is(first.text, `batman'`);
t.is(nodeToString(root), less);
});

test('close empty', (t) => {
const less = '// \n//';
const root = parse(less);
Expand Down