1 |
|
2 |
|
3 | const tokenizer = require('postcss/lib/tokenize');
|
4 | const Input = require('postcss/lib/input');
|
5 |
|
6 | module.exports = {
|
7 | isInlineComment(token) {
|
8 | if (token[0] === 'word' && token[1].slice(0, 2) === '//') {
|
9 | const first = token;
|
10 | const bits = [];
|
11 | let last;
|
12 | let remainingInput;
|
13 |
|
14 | while (token) {
|
15 | if (/\r?\n/.test(token[1])) {
|
16 |
|
17 | if (/['"].*\r?\n/.test(token[1])) {
|
18 |
|
19 | bits.push(token[1].substring(0, token[1].indexOf('\n')));
|
20 |
|
21 |
|
22 | remainingInput = token[1].substring(token[1].indexOf('\n'));
|
23 | remainingInput += this.input.css.valueOf().substring(this.tokenizer.position());
|
24 | } else {
|
25 |
|
26 | this.tokenizer.back(token);
|
27 | }
|
28 | break;
|
29 | }
|
30 |
|
31 | bits.push(token[1]);
|
32 | last = token;
|
33 | token = this.tokenizer.nextToken({ ignoreUnclosed: true });
|
34 | }
|
35 |
|
36 | const newToken = ['comment', bits.join(''), first[2], last[2]];
|
37 | this.inlineComment(newToken);
|
38 |
|
39 |
|
40 |
|
41 | if (remainingInput) {
|
42 | this.input = new Input(remainingInput);
|
43 | this.tokenizer = tokenizer(this.input);
|
44 | }
|
45 |
|
46 | return true;
|
47 | } else if (token[1] === '/') {
|
48 |
|
49 | const next = this.tokenizer.nextToken({ ignoreUnclosed: true });
|
50 |
|
51 | if (next[0] === 'comment' && /^\/\*/.test(next[1])) {
|
52 | next[0] = 'word';
|
53 | next[1] = next[1].slice(1);
|
54 | token[1] = '//';
|
55 | this.tokenizer.back(next);
|
56 | return module.exports.isInlineComment.bind(this)(token);
|
57 | }
|
58 | }
|
59 |
|
60 | return false;
|
61 | }
|
62 | };
|