From 6e37ec624601508cb07d797c8902974661e4ea83 Mon Sep 17 00:00:00 2001 From: "Eevee (Alex Munroe)" Date: Wed, 27 Aug 2014 17:14:53 -0700 Subject: Remove compiler's reliance on config.CONTROL_SCOPING. --- scss/compiler.py | 17 +++++++++++++---- scss/legacy.py | 1 + 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 -- cgit v1.2.1