1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-01 01:37:37 -04:00
notes/node_modules/sugarss/stringifier.js

124 lines
12 KiB
JavaScript
Raw Normal View History

2017-03-09 13:16:08 -05:00
'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 = '';
}
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;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0cmluZ2lmaWVyLmVzNiJdLCJuYW1lcyI6WyJkZWZhdWx0UmF3IiwiY29sb24iLCJpbmRlbnQiLCJjb21tZW50TGVmdCIsImNvbW1lbnRSaWdodCIsIlN0cmluZ2lmaWVyIiwiYnVpbGRlciIsInN0cmluZ2lmeSIsIm5vZGUiLCJzZW1pY29sb24iLCJ0eXBlIiwicm9vdCIsImJvZHkiLCJyYXdzIiwiYWZ0ZXIiLCJjb21tZW50IiwibGVmdCIsInJpZ2h0IiwiaGFzIiwiaW5saW5lIiwiaW5saW5lUmlnaHQiLCJ0ZXh0IiwiZGVjbCIsImJldHdlZW4iLCJzdHJpbmciLCJwcm9wIiwicmF3VmFsdWUiLCJpbXBvcnRhbnQiLCJydWxlIiwiYmxvY2siLCJhdHJ1bGUiLCJuYW1lIiwicGFyYW1zIiwiYWZ0ZXJOYW1lIiwiaSIsIm5vZGVzIiwibGVuZ3RoIiwiY2hpbGQiLCJiZWZvcmUiLCJyZXBsYWNlIiwiaW5kZXhPZiIsInN0YXJ0Iiwic3NzQmV0d2VlbiIsInN0ZXAiLCJyZXN1bHQiLCJwYXJlbnQiLCJ2YWx1ZSIsInJhdyIsInNzcyJdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEsSUFBTUEsYUFBYTt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