summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerman M. Bravo <german.mb@deipi.com>2013-08-17 17:54:19 -0500
committerGerman M. Bravo <german.mb@deipi.com>2013-08-17 17:54:19 -0500
commite340ad421b7e2bdc391acb9ddca5a5ae6309c7bc (patch)
treedf0608a1f5b0d6fdcd4caa8590f13b1570e24400
parent42884618361420e02ad27f95a9fa3dfbc7ad14a7 (diff)
downloadpyscss-e340ad421b7e2bdc391acb9ddca5a5ae6309c7bc.tar.gz
AST cache is in a per-target basis (also, cache is now in the Calculator class type
-rw-r--r--scss/expression.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/scss/expression.py b/scss/expression.py
index 0b55b0e..7dc1f71 100644
--- a/scss/expression.py
+++ b/scss/expression.py
@@ -24,7 +24,6 @@ except ImportError:
log = logging.getLogger(__name__)
FATAL_UNDEFINED = True
-ast_cache = {}
class Calculator(object):
@@ -115,10 +114,18 @@ class Calculator(object):
value = _vi
return value
+ def get_ast_cache(self, target):
+ if not hasattr(self, 'ast_cache'):
+ self.__class__.ast_cache = {}
+ if target not in self.ast_cache:
+ self.ast_cache[target] = {}
+ return self.ast_cache[target]
+
def evaluate_expression(self, expr, divide=False):
if not isinstance(expr, six.string_types):
raise TypeError("Expected string, got %r" % (expr,))
+ ast_cache = self.get_ast_cache('goal')
if expr in ast_cache:
ast = ast_cache[expr]
@@ -147,14 +154,14 @@ class Calculator(object):
return None
def parse_expression(self, expr, target='goal'):
+ ast_cache = self.get_ast_cache(target)
if expr in ast_cache:
return ast_cache[expr]
parser = SassExpression(SassExpressionScanner(expr))
ast = getattr(parser, target)()
- if target == 'goal':
- ast_cache[expr] = ast
+ ast_cache[expr] = ast
return ast