sass 3.1.0.alpha.17 → 3.1.0.alpha.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- 3.1.0.alpha.17
1
+ 3.1.0.alpha.18
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0.alpha.17
1
+ 3.1.0.alpha.18
@@ -36,8 +36,8 @@ module Sass::Script
36
36
  # @see Node#to_sass
37
37
  def to_sass(opts = {})
38
38
  pred = Sass::Script::Parser.precedence_of(@operator)
39
- o1 = operand_to_sass pred, @operand1, opts
40
- o2 = operand_to_sass pred, @operand2, opts
39
+ o1 = operand_to_sass @operand1, :left, opts
40
+ o2 = operand_to_sass @operand2, :right, opts
41
41
  sep =
42
42
  case @operator
43
43
  when :comma; ", "
@@ -81,9 +81,14 @@ module Sass::Script
81
81
 
82
82
  private
83
83
 
84
- def operand_to_sass(pred, op, opts = {})
85
- return "(#{op.to_sass(opts)})" if op.is_a?(Operation) &&
86
- Sass::Script::Parser.precedence_of(op.operator) < pred
84
+ def operand_to_sass(op, side, opts)
85
+ return op.to_sass(opts) unless op.is_a?(Operation)
86
+
87
+ pred = Sass::Script::Parser.precedence_of(@operator)
88
+ sub_pred = Sass::Script::Parser.precedence_of(op.operator)
89
+ assoc = Sass::Script::Parser.associative?(@operator)
90
+ return "(#{op.to_sass(opts)})" if sub_pred < pred ||
91
+ (side == :right && sub_pred == pred && !assoc)
87
92
  op.to_sass(opts)
88
93
  end
89
94
  end
@@ -130,6 +130,8 @@ module Sass
130
130
  [:times, :div, :mod],
131
131
  ]
132
132
 
133
+ ASSOCIATIVE = [:plus, :times]
134
+
133
135
  class << self
134
136
  # Returns an integer representing the precedence
135
137
  # of the given operator.
@@ -143,6 +145,13 @@ module Sass
143
145
  raise "[BUG] Unknown operator #{op}"
144
146
  end
145
147
 
148
+ # Returns whether or not the given operation is associative.
149
+ #
150
+ # @private
151
+ def associative?(op)
152
+ ASSOCIATIVE.include?(op)
153
+ end
154
+
146
155
  private
147
156
 
148
157
  # Defines a simple left-associative production.
@@ -123,6 +123,44 @@ WARN
123
123
  RUBY
124
124
  end
125
125
 
126
+ def self.assert_associative(op_name, sibling_name)
127
+ op = Sass::Script::Lexer::OPERATORS_REVERSE[op_name]
128
+ sibling = Sass::Script::Lexer::OPERATORS_REVERSE[sibling_name]
129
+ class_eval <<RUBY
130
+ def test_associative_#{op_name}_#{sibling_name}
131
+ assert_renders "$foo #{op} $bar #{op} $baz"
132
+
133
+ assert_equal "$foo #{op} $bar #{op} $baz",
134
+ render("$foo #{op} ($bar #{op} $baz)")
135
+ assert_equal "$foo #{op} $bar #{op} $baz",
136
+ render("($foo #{op} $bar) #{op} $baz")
137
+
138
+ assert_equal "$foo #{op} $bar #{sibling} $baz",
139
+ render("$foo #{op} ($bar #{sibling} $baz)")
140
+ assert_equal "$foo #{sibling} $bar #{op} $baz",
141
+ render("($foo #{sibling} $bar) #{op} $baz")
142
+ end
143
+ RUBY
144
+ end
145
+
146
+ def self.assert_non_associative(op_name, sibling_name)
147
+ op = Sass::Script::Lexer::OPERATORS_REVERSE[op_name]
148
+ sibling = Sass::Script::Lexer::OPERATORS_REVERSE[sibling_name]
149
+ class_eval <<RUBY
150
+ def test_non_associative_#{op_name}_#{sibling_name}
151
+ assert_renders "$foo #{op} $bar #{op} $baz"
152
+
153
+ assert_renders "$foo #{op} ($bar #{op} $baz)"
154
+ assert_equal "$foo #{op} $bar #{op} $baz",
155
+ render("($foo #{op} $bar) #{op} $baz")
156
+
157
+ assert_renders "$foo #{op} ($bar #{sibling} $baz)"
158
+ assert_equal "$foo #{sibling} $bar #{op} $baz",
159
+ render("($foo #{sibling} $bar) #{op} $baz")
160
+ end
161
+ RUBY
162
+ end
163
+
126
164
  test_precedence :or, :and
127
165
  test_precedence :and, :eq
128
166
  test_precedence :and, :neq
@@ -136,6 +174,18 @@ RUBY
136
174
  test_precedence :plus, :div
137
175
  test_precedence :plus, :mod
138
176
 
177
+ assert_associative :plus, :minus
178
+ assert_associative :times, :div
179
+ assert_associative :times, :mod
180
+
181
+ assert_non_associative :minus, :plus
182
+ assert_non_associative :div, :times
183
+ assert_non_associative :mod, :times
184
+ assert_non_associative :gt, :gte
185
+ assert_non_associative :gte, :lt
186
+ assert_non_associative :lt, :lte
187
+ assert_non_associative :lte, :gt
188
+
139
189
  def test_unary_op
140
190
  assert_renders "-12px"
141
191
  assert_renders '/"foo"'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sass
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.alpha.17
4
+ version: 3.1.0.alpha.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2010-10-05 00:00:00 -04:00
14
+ date: 2010-10-12 00:00:00 -04:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency