1 | const Stringifier = require('postcss/lib/stringifier');
|
2 |
|
3 | module.exports = class LessStringifier extends Stringifier {
|
4 | atrule(node, semicolon) {
|
5 | if (!node.mixin && !node.variable && !node.function) {
|
6 | super.atrule(node, semicolon);
|
7 | return;
|
8 | }
|
9 |
|
10 | const identifier = node.function ? '' : node.raws.identifier || '@';
|
11 | let name = `${identifier}${node.name}`;
|
12 | let params = node.params ? this.rawValue(node, 'params') : '';
|
13 | const important = node.raws.important || '';
|
14 |
|
15 | if (node.variable) {
|
16 | params = node.value;
|
17 | }
|
18 |
|
19 | if (typeof node.raws.afterName !== 'undefined') {
|
20 | name += node.raws.afterName;
|
21 | } else if (params) {
|
22 | name += ' ';
|
23 | }
|
24 |
|
25 | if (node.nodes) {
|
26 | this.block(node, name + params + important);
|
27 | } else {
|
28 | const end = (node.raws.between || '') + important + (semicolon ? ';' : '');
|
29 | this.builder(name + params + end, node);
|
30 | }
|
31 | }
|
32 |
|
33 | comment(node) {
|
34 | if (node.inline) {
|
35 | const left = this.raw(node, 'left', 'commentLeft');
|
36 | const right = this.raw(node, 'right', 'commentRight');
|
37 | this.builder(`//${left}${node.text}${right}`, node);
|
38 | } else {
|
39 | super.comment(node);
|
40 | }
|
41 | }
|
42 | };
|