text: var Visitor=require("./"),nodes=require("../nodes"),utils=require("../utils"),Normalizer=module.exports=function(o,e){e=e||{},Visitor.call(this,o),this.hoist=e["hoist atrules"],this.stack=[],this.map={},this.imports=[]};Normalizer.prototype.__proto__=Visitor.prototype,Normalizer.prototype.normalize=function(){var o=this.visit(this.root);return this.hoist&&(this.imports.length&&(o.nodes=this.imports.concat(o.nodes)),this.charset&&(o.nodes=[this.charset].concat(o.nodes))),o},Normalizer.prototype.bubble=function(o){function e(o){o.nodes.forEach(function(o){switch(o=i.visit(o),o.nodeName){case"property":t.push(o);break;case"block":e(o);break;default:n.push(o)}})}var t=[],n=[],i=this;if(e(o.block),t.length){var r=new nodes.Selector([new nodes.Literal("&")]);r.lineno=o.lineno,r.column=o.column,r.filename=o.filename,r.val="&";var s=new nodes.Group;s.lineno=o.lineno,s.column=o.column,s.filename=o.filename;var l=new nodes.Block(o.block,s);l.lineno=o.lineno,l.column=o.column,l.filename=o.filename,t.forEach(function(o){l.push(o)}),s.push(r),s.block=l,o.block.nodes=[],o.block.push(s),n.forEach(function(e){o.block.push(e)});var s=this.closestGroup(o.block);s&&(o.group=s.clone()),o.bubbled=!0}},Normalizer.prototype.closestGroup=function(o){for(var e,t=o.parent;t&&(e=t.node);){if("group"==e.nodeName)return e;t=e.block&&e.block.parent}},Normalizer.prototype.visitRoot=function(o){for(var e,t=new nodes.Root,n=0;n<o.nodes.length;++n)switch(e=o.nodes[n],e.nodeName){case"null":case"expression":case"function":case"unit":case"atblock":continue;default:this.rootIndex=n,t.push(this.visit(e))}return t},Normalizer.prototype.visitProperty=function(o){return this.visit(o.expr),o},Normalizer.prototype.visitExpression=function(o){return o.nodes=o.nodes.map(function(e){if("block"==e.nodeName){var t=new nodes.Literal("block");return t.lineno=o.lineno,t.column=o.column,t}return e}),o},Normalizer.prototype.visitBlock=function(o){var e;if(o.hasProperties)for(var t=0,n=o.nodes.length;t<n;++t)switch(e=o.nodes[t],e.nodeName){case"null":case"expression":case"function":case"group":case"unit":case"atblock":continue;default:o.nodes[t]=this.visit(e)}for(var t=0,n=o.nodes.length;t<n;++t)e=o.nodes[t],o.nodes[t]=this.visit(e);return o},Normalizer.prototype.visitGroup=function(o){var e,t=this.stack,n=this.map;o.nodes.forEach(function(t,n){if(~t.val.indexOf(",")){if(~t.val.indexOf("\\,"))return void(t.val=t.val.replace(/\\,/g,","));e=t.val.split(",");for(var i,r,s="/"==t.val.charAt(0),l=0,c=e.length;l<c;++l)i=e[l].trim(),s&&l>0&&!~i.indexOf("&")&&(i="/"+i),r=new nodes.Selector([new nodes.Literal(i)]),r.val=i,r.block=o.block,o.nodes[n++]=r}}),t.push(o.nodes);var i=utils.compileSelectors(t,!0);return i.forEach(function(e){n[e]=n[e]||[],n[e].push(o)}),this.extend(o,i),t.pop(),o},Normalizer.prototype.visitFunction=function(){return nodes.null},Normalizer.prototype.visitMedia=function(o){function e(t){t.nodes.forEach(function(i,r){switch(i.nodeName){case"media":i.val=o.val.merge(i.val),n.push(i),t.nodes[r]=nodes.null;break;case"block":e(i);break;default:i.block&&i.block.nodes&&e(i.block)}})}var t,n=[],i=this.closestGroup(o.block);return e(o.block),this.bubble(o),n.length&&n.forEach(function(o){i?i.block.push(o):this.root.nodes.splice(++this.rootIndex,0,o),o=this.visit(o),t=o.block.parent,!o.bubbled||i&&"group"!=t.node.nodeName||(o.group.block=o.block.nodes[0].block,o.block.nodes[0]=o.group)},this),o},Normalizer.prototype.visitSupports=function(o){return this.bubble(o),o},Normalizer.prototype.visitAtrule=function(o){return o.block&&(o.block=this.visit(o.block)),o},Normalizer.prototype.visitKeyframes=function(o){var e=o.block.nodes.filter(function(o){return o.block&&o.block.hasProperties});return o.frames=e.length,o},Normalizer.prototype.visitImport=function(o){return this.imports.push(o),this.hoist?nodes.null:o},Normalizer.prototype.visitCharset=function(o){return this.charset=o,this.hoist?nodes.null:o},Normalizer.prototype.extend=function(o,e){var t=this.map,n=this,i=this.closestGroup(o.block);o.extends.forEach(function(o){var r=t[o.selector];if(!r){if(o.optional)return;var s=new Error('Failed to @extend "'+o.selector+'"');throw s.lineno=o.lineno,s.column=o.column,s}e.forEach(function(o){var t=new nodes.Selector;t.val=o,t.inherits=!1,r.forEach(function(o){i&&i==o||n.extend(o,e),o.push(t)})})}),o.block=this.visit(o.block)};
  