Opal-Estate-Pro/node_modules/csso/lib/compressor/restructure/2-mergeAtrule.js

36 lines
839 B
JavaScript
Raw Normal View History

2019-09-13 06:27:52 +02:00
var walkRulesRight = require('../../utils/walk.js').rulesRight;
function isMediaRule(node) {
return node.type === 'Atrule' && node.name === 'media';
}
function processAtrule(node, item, list) {
if (!isMediaRule(node)) {
return;
}
var prev = item.prev && item.prev.data;
if (!prev || !isMediaRule(prev)) {
return;
}
// merge @media with same query
if (node.expression.id === prev.expression.id) {
prev.block.rules.appendList(node.block.rules);
prev.info = {
primary: prev.info,
merged: node.info
};
list.remove(item);
}
};
module.exports = function rejoinAtrule(ast) {
walkRulesRight(ast, function(node, item, list) {
if (node.type === 'Atrule') {
processAtrule(node, item, list);
}
});
};