summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEevee (Alex Munroe) <eevee.git@veekun.com>2014-08-24 13:43:14 -0700
committerEevee (Alex Munroe) <eevee.git@veekun.com>2014-08-24 13:43:14 -0700
commitc65d78ec66f24d8a5ee506c8b6568c2bbbcb6086 (patch)
tree02fffe24d20df03fe996452c544210e351958855
parent450b8579f11e6de93b2236a927796b78d5e30667 (diff)
downloadpyscss-c65d78ec66f24d8a5ee506c8b6568c2bbbcb6086.tar.gz
for...to excludes the upper bound. Fixes #275.
-rw-r--r--scss/compiler.py9
-rw-r--r--scss/tests/files/bugs/for-to-vs-through.css14
-rw-r--r--scss/tests/files/bugs/for-to-vs-through.scss12
3 files changed, 33 insertions, 2 deletions
diff --git a/scss/compiler.py b/scss/compiler.py
index 23b9487..942de82 100644
--- a/scss/compiler.py
+++ b/scss/compiler.py
@@ -941,7 +941,10 @@ class Compilation(object):
"""
var, _, name = block.argument.partition(' from ')
frm, _, through = name.partition(' through ')
- if not through:
+ if through:
+ inclusive = True
+ else:
+ inclusive = False
frm, _, through = frm.partition(' to ')
frm = calculator.calculate(frm)
through = calculator.calculate(through)
@@ -967,7 +970,9 @@ class Compilation(object):
# DEVIATION: Allow not creating a new namespace
inner_rule.namespace = rule.namespace
- for i in rev(range(frm, through + 1)):
+ if inclusive:
+ through += 1
+ for i in rev(range(frm, through)):
inner_rule.namespace.set_variable(var, Number(i))
self.manage_children(inner_rule, scope)
diff --git a/scss/tests/files/bugs/for-to-vs-through.css b/scss/tests/files/bugs/for-to-vs-through.css
new file mode 100644
index 0000000..3d50671
--- /dev/null
+++ b/scss/tests/files/bugs/for-to-vs-through.css
@@ -0,0 +1,14 @@
+a {
+ prop: 1;
+ prop: 2;
+ prop: 3;
+ prop: 4;
+}
+
+b {
+ prop: 1;
+ prop: 2;
+ prop: 3;
+ prop: 4;
+ prop: 5;
+}
diff --git a/scss/tests/files/bugs/for-to-vs-through.scss b/scss/tests/files/bugs/for-to-vs-through.scss
new file mode 100644
index 0000000..c5af514
--- /dev/null
+++ b/scss/tests/files/bugs/for-to-vs-through.scss
@@ -0,0 +1,12 @@
+// `to` excludes the upper bound, but `through` does not
+a {
+ @for $var from 1 to 5 {
+ prop: $var;
+ }
+}
+
+b {
+ @for $var from 1 through 5 {
+ prop: $var;
+ }
+}