protected function compileMedia(Block $media)
{
$this->pushEnv($media);
$mediaQuery = $this->compileMediaQuery($this->multiplyMedia($this->env));
if (!empty($mediaQuery)) {
$this->scope = $this->makeOutputBlock(Type::T_MEDIA, [$mediaQuery]);
$parentScope = $this->mediaParent($this->scope);
$parentScope->children[] = $this->scope;
// top level properties in a media cause it to be wrapped
$needsWrap = false;
foreach ($media->children as $child) {
$type = $child[0];
if ($type !== Type::T_BLOCK && $type !== Type::T_MEDIA && $type !== Type::T_DIRECTIVE && $type !== Type::T_IMPORT) {
$needsWrap = true;
break;
}
}
if ($needsWrap) {
$wrapped = new Block();
$wrapped->sourceIndex = $media->sourceIndex;
$wrapped->sourceLine = $media->sourceLine;
$wrapped->sourceColumn = $media->sourceColumn;
$wrapped->selectors = [];
$wrapped->comments = [];
$wrapped->parent = $media;
$wrapped->children = $media->children;
$media->children = [[Type::T_BLOCK, $wrapped]];
}
$this->compileChildrenNoReturn($media->children, $this->scope);
$this->scope = $this->scope->parent;
}
$this->popEnv();
}