123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- 'use strict';
-
- exports.__esModule = true;
-
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
-
- var defaultRaw = {
- colon: ': ',
- indent: ' ',
- commentLeft: ' ',
- commentRight: ' '
- };
-
- var Stringifier = function () {
- function Stringifier(builder) {
- _classCallCheck(this, Stringifier);
-
- this.builder = builder;
- }
-
- Stringifier.prototype.stringify = function stringify(node, semicolon) {
- this[node.type](node, semicolon);
- };
-
- Stringifier.prototype.root = function root(node) {
- this.body(node);
- if (node.raws.after) this.builder(node.raws.after);
- };
-
- Stringifier.prototype.comment = function comment(node) {
- var left = defaultRaw.commentLeft;
- var right = defaultRaw.commentRight;
- if (this.has(node.raws.left)) left = node.raws.left;
-
- if (node.raws.inline) {
- if (this.has(node.raws.inlineRight)) {
- right = node.raws.inlineRight;
- } else {
- right = '';
- }
- if (node.raws.extraIndent) {
- this.builder(node.raws.extraIndent);
- }
- this.builder('//' + left + node.text + right, node);
- } else {
- if (this.has(node.raws.right)) right = node.raws.right;
- this.builder('/*' + left + node.text + right + '*/', node);
- }
- };
-
- Stringifier.prototype.decl = function decl(node) {
- var between = node.raws.between || defaultRaw.colon;
- var string = node.prop + between + this.rawValue(node, 'value');
-
- if (node.important) {
- string += node.raws.important || ' !important';
- }
-
- this.builder(string, node);
- };
-
- Stringifier.prototype.rule = function rule(node) {
- this.block(node, this.rawValue(node, 'selector'));
- };
-
- Stringifier.prototype.atrule = function atrule(node) {
- var name = '@' + node.name;
- var params = node.params ? this.rawValue(node, 'params') : '';
-
- if (this.has(node.raws.afterName)) {
- name += node.raws.afterName;
- } else if (params) {
- name += ' ';
- }
-
- this.block(node, name + params);
- };
-
- Stringifier.prototype.body = function body(node) {
- var indent = node.root().raws.indent || defaultRaw.indent;
-
- for (var i = 0; i < node.nodes.length; i++) {
- var child = node.nodes[i];
- var before = child.raws.before.replace(/[^\n]*$/, '') + this.indent(node, indent);
- if (child.type === 'comment' && child.raws.before.indexOf('\n') === -1) {
- before = child.raws.before;
- }
- if (before) this.builder(before);
- this.stringify(child);
- }
- };
-
- Stringifier.prototype.block = function block(node, start) {
- var between = node.raws.sssBetween || '';
- this.builder(start + between, node, 'start');
- if (this.has(node.nodes)) this.body(node);
- };
-
- Stringifier.prototype.indent = function indent(node, step) {
- var result = '';
- while (node.parent) {
- result += step;
- node = node.parent;
- }
- return result;
- };
-
- Stringifier.prototype.has = function has(value) {
- return typeof value !== 'undefined';
- };
-
- Stringifier.prototype.rawValue = function rawValue(node, prop) {
- var value = node[prop];
- var raw = node.raws[prop];
- if (raw && raw.value === value) {
- return raw.sss || raw.raw;
- } else {
- return value;
- }
- };
-
- return Stringifier;
- }();
-
- exports.default = Stringifier;
- module.exports = exports['default'];
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0cmluZ2lmaWVyLmVzNiJdLCJuYW1lcyI6WyJkZWZhdWx0UmF3IiwiY29sb24iLCJpbmRlbnQiLCJjb21tZW50TGVmdCIsImNvbW1lbnRSaWdodCIsIlN0cmluZ2lmaWVyIiwiYnVpbGRlciIsInN0cmluZ2lmeSIsIm5vZGUiLCJzZW1pY29sb24iLCJ0eXBlIiwicm9vdCIsImJvZHkiLCJyYXdzIiwiYWZ0ZXIiLCJjb21tZW50IiwibGVmdCIsInJpZ2h0IiwiaGFzIiwiaW5saW5lIiwiaW5saW5lUmlnaHQiLCJleHRyYUluZGVudCIsInRleHQiLCJkZWNsIiwiYmV0d2VlbiIsInN0cmluZyIsInByb3AiLCJyYXdWYWx1ZSIsImltcG9ydGFudCIsInJ1bGUiLCJibG9jayIsImF0cnVsZSIsIm5hbWUiLCJwYXJhbXMiLCJhZnRlck5hbWUiLCJpIiwibm9kZXMiLCJsZW5ndGgiLCJ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