LessStringifier.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* eslint-disable import/no-extraneous-dependencies */
  2. const Stringifier = require('postcss/lib/stringifier');
  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. const identifier = node.function ? '' : node.raws.identifier || '@';
  10. let name = `${identifier}${node.name}`;
  11. let params = node.params ? this.rawValue(node, 'params') : '';
  12. const important = node.raws.important || '';
  13. if (node.variable) {
  14. params = node.value;
  15. }
  16. if (typeof node.raws.afterName !== 'undefined') {
  17. name += node.raws.afterName;
  18. } else if (params) {
  19. name += ' ';
  20. }
  21. if (node.nodes) {
  22. this.block(node, name + params + important);
  23. } else {
  24. const end = (node.raws.between || '') + important + (semicolon ? ';' : '');
  25. this.builder(name + params + end, node);
  26. }
  27. }
  28. comment(node) {
  29. if (node.inline) {
  30. const left = this.raw(node, 'left', 'commentLeft');
  31. const right = this.raw(node, 'right', 'commentRight');
  32. this.builder(`//${left}${node.text}${right}`, node);
  33. } else {
  34. super.comment(node);
  35. }
  36. }
  37. };