Opal-Estate-Pro/node_modules/csso/lib/compressor/restructure/2-mergeAtrule.js
2019-09-13 11:27:52 +07:00

36 lines
839 B
JavaScript
Executable File

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);
}
});
};