From 99d826ea01739a83e55478fb00da8275d75df986 Mon Sep 17 00:00:00 2001 From: "Eevee (Alex Munroe)" Date: Fri, 23 Aug 2013 19:47:57 -0700 Subject: Cheap heuristic for whether +foo is an @include or a selector. --- scss/rule.py | 11 ++++++----- scss/tests/files/bugs/selectors-adjacent-is-not-include.css | 3 +++ scss/tests/files/bugs/selectors-adjacent-is-not-include.scss | 5 +++++ 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 scss/tests/files/bugs/selectors-adjacent-is-not-include.css create mode 100644 scss/tests/files/bugs/selectors-adjacent-is-not-include.scss diff --git a/scss/rule.py b/scss/rule.py index 4ddb625..a2694a8 100644 --- a/scss/rule.py +++ b/scss/rule.py @@ -256,12 +256,13 @@ class BlockHeader(object): is_selector = False @classmethod - def parse(cls, prop): + def parse(cls, prop, has_contents=False): # Simple pre-processing - if prop.startswith('+'): - # Expand '+' at the beginning of a rule as @include + if prop.startswith('+') and not has_contents: + # Expand '+' at the beginning of a rule as @include. But not if + # there's a block, because that's probably a CSS selector. + # DEVIATION: this is some semi hybrid of Sass and xCSS syntax prop = '@include ' + prop[1:] - # TODO what is this, partial sass syntax? try: if '(' not in prop or prop.index(':') < prop.index('('): prop = prop.replace(':', '(', 1) @@ -366,7 +367,7 @@ class UnparsedBlock(object): def __init__(self, parent_rule, lineno, prop, unparsed_contents): self.parent_rule = parent_rule - self.header = BlockHeader.parse(prop) + self.header = BlockHeader.parse(prop, has_contents=bool(unparsed_contents)) # Basic properties self.lineno = lineno diff --git a/scss/tests/files/bugs/selectors-adjacent-is-not-include.css b/scss/tests/files/bugs/selectors-adjacent-is-not-include.css new file mode 100644 index 0000000..ea0d7b3 --- /dev/null +++ b/scss/tests/files/bugs/selectors-adjacent-is-not-include.css @@ -0,0 +1,3 @@ +p + h4 { + margin-top: 28px; +} diff --git a/scss/tests/files/bugs/selectors-adjacent-is-not-include.scss b/scss/tests/files/bugs/selectors-adjacent-is-not-include.scss new file mode 100644 index 0000000..84fef9a --- /dev/null +++ b/scss/tests/files/bugs/selectors-adjacent-is-not-include.scss @@ -0,0 +1,5 @@ +p { + + h4 { + margin-top: 28px; + } +} -- cgit v1.2.1