Skip to content

Commit a0975ec

Browse files
committed
fix: inline comment with immediate asterisk. fixes #135
1 parent b94e05d commit a0975ec

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/nodes/inline-comment.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable no-param-reassign */
2+
13
const tokenizer = require('postcss/lib/tokenize');
24
const Input = require('postcss/lib/input');
35

@@ -31,15 +33,26 @@ module.exports = {
3133

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

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

4041
this.inlineComment(newToken);
4142
return true;
43+
} else if (token[1] === '/') {
44+
// issue #135
45+
const next = this.tokenizer.nextToken({ ignoreUnclosed: true });
46+
47+
if (next[0] === 'comment' && /^\/\*/.test(next[1])) {
48+
next[0] = 'word';
49+
next[1] = next[1].slice(1);
50+
token[1] = '//';
51+
this.tokenizer.back(next);
52+
return module.exports.isInlineComment.bind(this)(token);
53+
}
4254
}
55+
4356
return false;
4457
}
4558
};

test/parser/comments.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,14 @@ test('newlines are put on the next node', (t) => {
155155
t.is(first.raws.right, '');
156156
t.is(last.raws.before, '\n');
157157
});
158+
159+
test('inline comments with asterisk are persisted (#135)', (t) => {
160+
const less = '//*batman';
161+
162+
const root = parse(less);
163+
const { first } = root;
164+
165+
t.is(first.type, 'comment');
166+
t.is(first.text, '*batman');
167+
t.is(nodeToString(root), less);
168+
});

0 commit comments

Comments
 (0)