diff options
author | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2014-08-24 14:12:54 -0700 |
---|---|---|
committer | Eevee (Alex Munroe) <eevee.git@veekun.com> | 2014-08-24 14:12:54 -0700 |
commit | fa72d19af800a9819464d4b56824f49256ff7af9 (patch) | |
tree | 3f3af04f1f3a5720a6d097eff8343fb27401a589 | |
parent | b41d38fde7cc8ef995f8ca0c9dbc0b973ca6c9aa (diff) | |
download | pyscss-fa72d19af800a9819464d4b56824f49256ff7af9.tar.gz |
Remove magical selector reordering with @extend. Fixes #269.
Turns out the @extend rewrite was already doing the right thing; the
only things keeping this logic around were a couple old xCSS tests that
expected output in the wrong order.
-rw-r--r-- | scss/compiler.py | 23 | ||||
-rw-r--r-- | scss/tests/files/bugs/extend-selector-order.css | 7 | ||||
-rw-r--r-- | scss/tests/files/bugs/extend-selector-order.scss | 17 | ||||
-rw-r--r-- | scss/tests/files/original-doctests/007-extends-3.css | 8 | ||||
-rw-r--r-- | scss/tests/test_misc.py | 8 |
5 files changed, 40 insertions, 23 deletions
diff --git a/scss/compiler.py b/scss/compiler.py index 73fd84d..0d0a62f 100644 --- a/scss/compiler.py +++ b/scss/compiler.py @@ -1197,6 +1197,12 @@ class Compilation(object): # DEVIATION: ruby sass doesn't support bare variables in selectors raw_selectors = calculator.apply_vars(raw_selectors) c_selectors, c_parents = self.parse_selectors(raw_selectors) + if c_parents: + warn_deprecated( + rule, + "The XCSS 'a extends b' syntax is deprecated. " + "Use 'a { @extend b; }' instead." + ) new_ancestry = rule.ancestry.with_nested_selectors(c_selectors) @@ -1236,19 +1242,7 @@ class Compilation(object): # them as a rough key. Ignore order and duplication for now. key_to_selectors = defaultdict(set) selector_to_rules = defaultdict(list) - # DEVIATION: These are used to rearrange rules in dependency order, so - # an @extended parent appears in the output before a child. Sass does - # not do this, and the results may be unexpected. Pending removal. - rule_order = dict() - rule_dependencies = dict() - order = 0 for rule in self.rules: - rule_order[rule] = order - # Rules are ultimately sorted by the earliest rule they must - # *precede*, so every rule should "depend" on the next one - rule_dependencies[rule] = [order + 1] - order += 1 - for selector in rule.selectors: for key in selector.lookup_key(): key_to_selectors[key].add(selector) @@ -1267,6 +1261,7 @@ class Compilation(object): if candidate.is_superset_of(selector)] if not extendable_selectors: + # TODO should be fatal, unless !optional given log.warn( "Can't find any matching rules to extend: %s" % selector.render()) @@ -1302,11 +1297,9 @@ class Compilation(object): parent_rule.ancestry = ( parent_rule.ancestry.with_more_selectors( more_parent_selectors)) - rule_dependencies[parent_rule].append(rule_order[rule]) - # clean up placeholder only rules + # Remove placeholder-only rules self.rules = [rule for rule in self.rules if not rule.is_pure_placeholder] - self.rules.sort(key=lambda rule: min(rule_dependencies[rule])) # @print_timing(3) def parse_properties(self): diff --git a/scss/tests/files/bugs/extend-selector-order.css b/scss/tests/files/bugs/extend-selector-order.css new file mode 100644 index 0000000..619fc57 --- /dev/null +++ b/scss/tests/files/bugs/extend-selector-order.css @@ -0,0 +1,7 @@ +.nav-pills > li { + float: left; +} + +.nav-justified > li, .nav-tabs.nav-justified > li { + float: none; +} diff --git a/scss/tests/files/bugs/extend-selector-order.scss b/scss/tests/files/bugs/extend-selector-order.scss new file mode 100644 index 0000000..9a54cb3 --- /dev/null +++ b/scss/tests/files/bugs/extend-selector-order.scss @@ -0,0 +1,17 @@ +.nav-tabs { + &.nav-justified { + @extend .nav-justified; + } +} + +.nav-pills { + > li { + float: left; + } +} + +.nav-justified { + > li { + float: none; + } +} diff --git a/scss/tests/files/original-doctests/007-extends-3.css b/scss/tests/files/original-doctests/007-extends-3.css index 1b17778..1bb67f4 100644 --- a/scss/tests/files/original-doctests/007-extends-3.css +++ b/scss/tests/files/original-doctests/007-extends-3.css @@ -1,3 +1,7 @@ +.specialClass { + padding: 10px; + font-size: 14px; +} .basicClass, .specialClass { padding: 20px; background-color: #FF0000; @@ -5,7 +9,3 @@ .basicClass a, .specialClass a, .specialLink { text-decoration: none; } -.specialClass { - padding: 10px; - font-size: 14px; -} diff --git a/scss/tests/test_misc.py b/scss/tests/test_misc.py index beb231a..0c6c140 100644 --- a/scss/tests/test_misc.py +++ b/scss/tests/test_misc.py @@ -84,14 +84,14 @@ def test_extend_across_files(): ''' actual = compiler.compile() expected = """\ -.basicClass, .specialClass { - padding: 20px; - background-color: #FF0000; -} .specialClass { padding: 10px; font-size: 14px; } +.basicClass, .specialClass { + padding: 20px; + background-color: #FF0000; +} """ assert expected == actual |