summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerman M. Bravo <german.mb@deipi.com>2013-10-05 11:56:17 -0500
committerGerman M. Bravo <german.mb@deipi.com>2013-10-05 11:56:17 -0500
commite120411a9b45b525b38a2f797867567e339c1dfd (patch)
treecf19baaa825a5a6f459c5bdfbb32688e5c027b73
parent79b44c1ebeac2508c3c952dd5d2ba73450742cb7 (diff)
downloadpyscss-e120411a9b45b525b38a2f797867567e339c1dfd.tar.gz
Keep track of nesting descendants
-rw-r--r--scss/__init__.py2
-rw-r--r--scss/rule.py16
2 files changed, 11 insertions, 7 deletions
diff --git a/scss/__init__.py b/scss/__init__.py
index 5f194df..aedfb56 100644
--- a/scss/__init__.py
+++ b/scss/__init__.py
@@ -1258,6 +1258,7 @@ class Scss(object):
new_ancestry.append(block.header)
from scss.rule import RuleAncestry
+ rule.descendants += 1
new_rule = SassRule(
source_file=rule.source_file,
import_key=rule.import_key,
@@ -1293,6 +1294,7 @@ class Scss(object):
new_ancestry = rule.ancestry.with_nested_selectors(c_selectors)
+ rule.descendants += 1
new_rule = SassRule(
source_file=rule.source_file,
import_key=rule.import_key,
diff --git a/scss/rule.py b/scss/rule.py
index 3601a12..c901f41 100644
--- a/scss/rule.py
+++ b/scss/rule.py
@@ -269,6 +269,8 @@ class SassRule(object):
self.nested = nested
+ self.descendants = 0
+
def __repr__(self):
return "<SassRule %s, %d props>" % (
self.ancestry,
@@ -299,13 +301,13 @@ class SassRule(object):
# Rules containing CSS properties are never empty
return False
- if self.ancestry:
- header = self.ancestry[-1]
- if header.is_atrule and header.directive != '@media':
- # At-rules should always be preserved, UNLESS they are @media
- # blocks, which are known to be noise if they don't have any
- # contents of their own
- return False
+ if not self.descendants:
+ for header in self.ancestry.headers:
+ if header.is_atrule and header.directive != '@media':
+ # At-rules should always be preserved, UNLESS they are @media
+ # blocks, which are known to be noise if they don't have any
+ # contents of their own
+ return False
return True