From 20cb364f146e6e53a2308aa09adc6ddfa235ea43 Mon Sep 17 00:00:00 2001 From: "Eevee (Alex Munroe)" Date: Tue, 8 Oct 2013 12:00:24 -0700 Subject: Lists built from function calls are not "literal". --- scss/expression.py | 14 ++++++++++++-- scss/tests/files/general/null-values.css | 1 + scss/tests/files/general/null-values.scss | 2 ++ scss/types.py | 8 +++++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/scss/expression.py b/scss/expression.py index 8b42e7d..0c889b1 100644 --- a/scss/expression.py +++ b/scss/expression.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import print_function from functools import partial import logging @@ -378,8 +379,17 @@ class ListLiteral(Expression): def evaluate(self, calculator, divide=False): items = [item.evaluate(calculator, divide=divide) for item in self.items] - # TODO sort of overloading "divide" here... rename i think - return List(items, use_comma=self.comma, is_literal=not divide) + + # Whether this is a "plain" literal matters for null removal: nulls are + # left alone if this is a completely vanilla CSS property + is_literal = True + if divide: + # TODO sort of overloading "divide" here... rename i think + is_literal = False + elif not all(isinstance(item, Literal) for item in self.items): + is_literal = False + + return List(items, use_comma=self.comma, is_literal=is_literal) class MapLiteral(Expression): diff --git a/scss/tests/files/general/null-values.css b/scss/tests/files/general/null-values.css index 16deaae..b3e9775 100644 --- a/scss/tests/files/general/null-values.css +++ b/scss/tests/files/general/null-values.css @@ -2,4 +2,5 @@ div { a: 1, 2, 3; b: 1, null, 2, null, 3; c: 1 2; + e: 1, 2, 3, ; } diff --git a/scss/tests/files/general/null-values.scss b/scss/tests/files/general/null-values.scss index d657ab2..f64fecb 100644 --- a/scss/tests/files/general/null-values.scss +++ b/scss/tests/files/general/null-values.scss @@ -8,4 +8,6 @@ div { c: 1 (null, null) 2; // empty properties aren't printed d: (null, null); + // and it applies recursively + e: (((null, 1, null), (null, 2), null), (3, null, (null, null))); } diff --git a/scss/types.py b/scss/types.py index 4a027d7..aafbab4 100644 --- a/scss/types.py +++ b/scss/types.py @@ -685,7 +685,13 @@ class List(Value): max_list, min_list = (self, other) if len(self) > len(other) else (other, self) return List([item + max_list[i] for i, item in enumerate(min_list)], use_comma=self.use_comma) - return List([item + other for item in self], use_comma=self.use_comma) + elif isinstance(other, String): + # UN-DEVIATION: adding a string should fall back to canonical + # behavior of string addition + return super(List, self).__add__(other) + + else: + return List([item + other for item in self], use_comma=self.use_comma) def __sub__(self, other): if isinstance(other, List): -- cgit v1.2.1