summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEevee (Alex Munroe) <eevee.git@veekun.com>2014-08-27 17:14:53 -0700
committerEevee (Alex Munroe) <eevee.git@veekun.com>2014-08-27 17:14:53 -0700
commit6e37ec624601508cb07d797c8902974661e4ea83 (patch)
tree2b16b0e4de66c1be0bfe7fd990b1a3053f439a50
parent4f7ae70be4a9216ab094add37c4df2c93f4fc07f (diff)
downloadpyscss-6e37ec624601508cb07d797c8902974661e4ea83.tar.gz
Remove compiler's reliance on config.CONTROL_SCOPING.
-rw-r--r--scss/compiler.py17
-rw-r--r--scss/legacy.py1
2 files changed, 14 insertions, 4 deletions
diff --git a/scss/compiler.py b/scss/compiler.py
index 9b82dcb..20a78dd 100644
--- a/scss/compiler.py
+++ b/scss/compiler.py
@@ -96,6 +96,7 @@ class Compiler(object):
output_style='nested', generate_source_map=False,
live_errors=False, warn_unused_imports=False,
ignore_parse_errors=False,
+ loops_have_own_scopes=True,
super_selector='',
):
"""Configure a compiler.
@@ -142,6 +143,7 @@ class Compiler(object):
self.live_errors = live_errors
self.warn_unused_imports = warn_unused_imports
self.ignore_parse_errors = ignore_parse_errors
+ self.loops_have_own_scopes = loops_have_own_scopes
self.super_selector = super_selector
def normalize_path(self, path):
@@ -199,6 +201,13 @@ class Compilation(object):
self.dependency_map = defaultdict(frozenset)
self.rules = []
+ def should_scope_loop_in_rule(self, rule):
+ """Return True iff a looping construct (@each, @for, @while, @if)
+ should get its own scope, as is standard Sass behavior.
+ """
+ return rule.legacy_compiler_options.get(
+ 'control_scoping', self.compiler.loops_have_own_scopes)
+
def add_source(self, source):
if source.path in self.source_index:
raise KeyError("Duplicate source %r" % source.path)
@@ -984,7 +993,7 @@ class Compilation(object):
if condition:
inner_rule = rule.copy()
inner_rule.unparsed_contents = block.unparsed_contents
- if not rule.legacy_compiler_options.get('control_scoping', config.CONTROL_SCOPING): # TODO: maybe make this scoping mode for contol structures as the default as a default deviation
+ if not self.should_scope_loop_in_rule(inner_rule):
# DEVIATION: Allow not creating a new namespace
inner_rule.namespace = rule.namespace
self.manage_children(inner_rule, scope)
@@ -1038,7 +1047,7 @@ class Compilation(object):
inner_rule = rule.copy()
inner_rule.unparsed_contents = block.unparsed_contents
- if not rule.legacy_compiler_options.get('control_scoping', config.CONTROL_SCOPING): # TODO: maybe make this scoping mode for contol structures as the default as a default deviation
+ if not self.should_scope_loop_in_rule(inner_rule):
# DEVIATION: Allow not creating a new namespace
inner_rule.namespace = rule.namespace
@@ -1071,7 +1080,7 @@ class Compilation(object):
inner_rule = rule.copy()
inner_rule.unparsed_contents = block.unparsed_contents
- if not rule.legacy_compiler_options.get('control_scoping', config.CONTROL_SCOPING): # TODO: maybe make this scoping mode for contol structures as the default as a default deviation
+ if not self.should_scope_loop_in_rule(inner_rule):
# DEVIATION: Allow not creating a new namespace
inner_rule.namespace = rule.namespace
@@ -1097,7 +1106,7 @@ class Compilation(object):
while condition:
inner_rule = rule.copy()
inner_rule.unparsed_contents = block.unparsed_contents
- if not rule.legacy_compiler_options.get('control_scoping', config.CONTROL_SCOPING): # TODO: maybe make this scoping mode for contol structures as the default as a default deviation
+ if not self.should_scope_loop_in_rule(inner_rule):
# DEVIATION: Allow not creating a new namespace
inner_rule.namespace = rule.namespace
self.manage_children(inner_rule, scope)
diff --git a/scss/legacy.py b/scss/legacy.py
index 8db2ee2..cd74895 100644
--- a/scss/legacy.py
+++ b/scss/legacy.py
@@ -137,6 +137,7 @@ class Scss(object):
output_style=output_style,
warn_unused_imports=self._scss_opts.get('warn_unused', False),
ignore_parse_errors=config.DEBUG,
+ loops_have_own_scopes=config.CONTROL_SCOPING,
super_selector=super_selector or self.super_selector,
)
# Gonna add the source files manually