summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEevee (Alex Munroe) <eevee.git@veekun.com>2014-08-27 17:20:38 -0700
committerEevee (Alex Munroe) <eevee.git@veekun.com>2014-08-27 17:20:38 -0700
commit99a5fbc99e72c04e4ca1e045e6a3e752d391aeea (patch)
treeed9a6145ed055a8cafb8aa4626b8ddbc597a5eaf
parent6e37ec624601508cb07d797c8902974661e4ea83 (diff)
downloadpyscss-99a5fbc99e72c04e4ca1e045e6a3e752d391aeea.tar.gz
Remove calculator's reliance on config.FATAL_UNDEFINED.
-rw-r--r--scss/compiler.py3
-rw-r--r--scss/expression.py20
-rw-r--r--scss/legacy.py1
3 files changed, 17 insertions, 7 deletions
diff --git a/scss/compiler.py b/scss/compiler.py
index 20a78dd..ac89a58 100644
--- a/scss/compiler.py
+++ b/scss/compiler.py
@@ -97,6 +97,7 @@ class Compiler(object):
live_errors=False, warn_unused_imports=False,
ignore_parse_errors=False,
loops_have_own_scopes=True,
+ undefined_variables_fatal=True,
super_selector='',
):
"""Configure a compiler.
@@ -144,6 +145,7 @@ class Compiler(object):
self.warn_unused_imports = warn_unused_imports
self.ignore_parse_errors = ignore_parse_errors
self.loops_have_own_scopes = loops_have_own_scopes
+ self.undefined_variables_fatal = undefined_variables_fatal
self.super_selector = super_selector
def normalize_path(self, path):
@@ -313,6 +315,7 @@ class Compilation(object):
return Calculator(
namespace,
ignore_parse_errors=self.ignore_parse_errors,
+ undefined_variables_fatal=self.compiler.undefined_variables_fatal,
)
# @print_timing(4)
diff --git a/scss/expression.py b/scss/expression.py
index 18ada87..465dfe4 100644
--- a/scss/expression.py
+++ b/scss/expression.py
@@ -34,13 +34,18 @@ class Calculator(object):
ast_cache = {}
- def __init__(self, namespace=None, ignore_parse_errors=False):
+ def __init__(
+ self, namespace=None,
+ ignore_parse_errors=False,
+ undefined_variables_fatal=True,
+ ):
if namespace is None:
self.namespace = Namespace()
else:
self.namespace = namespace
self.ignore_parse_errors = ignore_parse_errors
+ self.undefined_variables_fatal = undefined_variables_fatal
def _pound_substitute(self, result):
expr = result.group(1)
@@ -85,7 +90,7 @@ class Calculator(object):
try:
v = self.namespace.variable(n)
except KeyError:
- if config.FATAL_UNDEFINED:
+ if self.undefined_variables_fatal:
raise SyntaxError("Undefined variable: '%s'." % n)
else:
log.error("Undefined variable '%s'", n, extra={'stack': True})
@@ -356,12 +361,13 @@ class Literal(Expression):
return '<%s(%s)>' % (self.__class__.__name__, repr(self.value))
def __init__(self, value):
- if isinstance(value, Undefined) and config.FATAL_UNDEFINED:
- raise SyntaxError("Undefined literal.")
- else:
- self.value = value
+ self.value = value
def evaluate(self, calculator, divide=False):
+ if (isinstance(self.value, Undefined) and
+ calculator.undefined_variables_fatal):
+ raise SyntaxError("Undefined literal.")
+
return self.value
@@ -376,7 +382,7 @@ class Variable(Expression):
try:
value = calculator.namespace.variable(self.name)
except KeyError:
- if config.FATAL_UNDEFINED:
+ if calculator.undefined_variables_fatal:
raise SyntaxError("Undefined variable: '%s'." % self.name)
else:
log.error("Undefined variable '%s'", self.name, extra={'stack': True})
diff --git a/scss/legacy.py b/scss/legacy.py
index cd74895..1b7da84 100644
--- a/scss/legacy.py
+++ b/scss/legacy.py
@@ -138,6 +138,7 @@ class Scss(object):
warn_unused_imports=self._scss_opts.get('warn_unused', False),
ignore_parse_errors=config.DEBUG,
loops_have_own_scopes=config.CONTROL_SCOPING,
+ undefined_variables_fatal=config.FATAL_UNDEFINED,
super_selector=super_selector or self.super_selector,
)
# Gonna add the source files manually