Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Parse !important as a token in SassScript, rather than special-casing…

… it.

Closes gh-68
  • Loading branch information...
commit 850e3bf303df6c816696c7572d2dee52cb453d7b 1 parent b443ba0
Nathan Weizenbaum authored April 25, 2011
8  lib/sass/engine.rb
@@ -581,15 +581,9 @@ def parse_property(name, parsed_name, value, prop, line)
581 581
       if value.strip.empty?
582 582
         expr = Sass::Script::String.new("")
583 583
       else
584  
-        important = false
585  
-        if value =~ Sass::SCSS::RX::IMPORTANT
586  
-          important = true
587  
-          value = value.gsub(Sass::SCSS::RX::IMPORTANT,"")
588  
-        end
589 584
         expr = parse_script(value, :offset => line.offset + line.text.index(value))
590  
-
591 585
       end
592  
-      Tree::PropNode.new(parse_interp(name), expr, important, prop)
  586
+      Tree::PropNode.new(parse_interp(name), expr, prop)
593 587
     end
594 588
 
595 589
     def parse_variable(line)
2  lib/sass/less.rb
@@ -225,7 +225,7 @@ def to_sass_tree
225 225
     class Property
226 226
       def to_sass_tree
227 227
         return if hide_in_sass
228  
-        Sass::Tree::PropNode.new([self], @value.to_sass_tree, false, :new)
  228
+        Sass::Tree::PropNode.new([self], @value.to_sass_tree, :new)
229 229
       end
230 230
     end
231 231
 
7  lib/sass/script/lexer.rb
@@ -231,7 +231,7 @@ def token
231 231
 
232 232
         variable || string(:double, false) || string(:single, false) || number ||
233 233
           color || bool || string(:uri, false) || raw(UNICODERANGE) ||
234  
-          special_fun || ident_op || ident || op
  234
+          special_fun || special_val || ident_op || ident || op
235 235
       end
236 236
 
237 237
       def variable
@@ -302,6 +302,11 @@ def special_fun
302 302
           str1.size + str2.size]
303 303
       end
304 304
 
  305
+      def special_val
  306
+        return unless scan(/!important/i)
  307
+        [:string, Script::String.new("!important")]
  308
+      end
  309
+
305 310
       def ident_op
306 311
         return unless op = scan(REGULAR_EXPRESSIONS[:ident_op])
307 312
         [OPERATORS[op]]
4  lib/sass/scss/parser.rb
@@ -638,11 +638,9 @@ def declaration
638 638
         tok!(/:/)
639 639
         space, value = value!
640 640
         ss
641  
-        important = tok(IMPORTANT)
642  
-        ss
643 641
         require_block = tok?(/\{/)
644 642
 
645  
-        node = node(Sass::Tree::PropNode.new(name.flatten.compact, value, !!important, :new))
  643
+        node = node(Sass::Tree::PropNode.new(name.flatten.compact, value, :new))
646 644
 
647 645
         return node unless require_block
648 646
         nested_properties! node, space
2  lib/sass/scss/rx.rb
@@ -119,7 +119,7 @@ def self.quote(str, flags = 0)
119 119
       # We could use it for 1.9 only, but I don't want to introduce a cross-version
120 120
       # behavior difference.
121 121
       # In any case, almost all CSS idents will be matched by this.
122  
-      STATIC_VALUE = /(-?#{NMSTART}|#{STRING_NOINTERP}|\s(?!%)|#[a-f0-9]|[,%]|#{NUM})+(?=[;}])/i
  122
+      STATIC_VALUE = /(-?#{NMSTART}|#{STRING_NOINTERP}|\s(?!%)|#[a-f0-9]|[,%]|#{NUM}|\!important)+(?=[;}])/i
123 123
 
124 124
       STATIC_SELECTOR = /(#{NMCHAR}|\s|[,>+*]|[:#.]#{NMSTART})+(?=[{])/i
125 125
     end
11  lib/sass/tree/prop_node.rb
@@ -23,11 +23,6 @@ class PropNode < Node
23 23
     # @return [Sass::Script::Node]
24 24
     attr_accessor :value
25 25
 
26  
-    # Whether the property was marked as !important.
27  
-    #
28  
-    # @return [Boolean]
29  
-    attr_accessor :important
30  
-
31 26
     # The value of the property
32 27
     # after any interpolated SassScript has been resolved.
33 28
     # Only set once \{Tree::Visitors::Perform} has been run.
@@ -49,16 +44,14 @@ class PropNode < Node
49 44
 
50 45
     # @param name [Array<String, Sass::Script::Node>] See \{#name}
51 46
     # @param value [Sass::Script::Node] See \{#value}
52  
-    # @param important [Boolean] whether this is an !important property
53 47
     # @param prop_syntax [Symbol] `:new` if this property uses `a: b`-style syntax,
54 48
     #   `:old` if it uses `:a b`-style syntax
55  
-    def initialize(name, value, important, prop_syntax)
  49
+    def initialize(name, value, prop_syntax)
56 50
       @name = Sass::Util.strip_string_array(
57 51
         Sass::Util.merge_adjacent_strings(name))
58 52
       @value = value
59 53
       @tabs = 0
60 54
       @prop_syntax = prop_syntax
61  
-      @important = important
62 55
       super()
63 56
     end
64 57
 
@@ -96,7 +89,7 @@ def declaration(opts = {:old => @prop_syntax == :old}, fmt = :sass)
96 89
       old = opts[:old] && fmt == :sass
97 90
       initial = old ? ':' : ''
98 91
       mid = old ? '' : ':'
99  
-      "#{initial}#{name}#{mid} #{self.class.val_to_sass(value, opts)}#{' !important' if important}".rstrip
  92
+      "#{initial}#{name}#{mid} #{self.class.val_to_sass(value, opts)}".rstrip
100 93
     end
101 94
 
102 95
     private
6  lib/sass/tree/visitors/to_css.rb
@@ -122,9 +122,9 @@ def visit_media(node)
122 122
   def visit_prop(node)
123 123
     tab_str = '  ' * (@tabs + node.tabs)
124 124
     if node.style == :compressed
125  
-      "#{tab_str}#{node.resolved_name}:#{node.resolved_value}#{'!important' if node.important}"
  125
+      "#{tab_str}#{node.resolved_name}:#{node.resolved_value}"
126 126
     else
127  
-      "#{tab_str}#{node.resolved_name}: #{node.resolved_value}#{' !important' if node.important};"
  127
+      "#{tab_str}#{node.resolved_name}: #{node.resolved_value};"
128 128
     end
129 129
   end
130 130
 
@@ -204,7 +204,7 @@ def debug_info_rule(debug_info, options)
204 204
                 [Sass::Selector::Element.new(k.to_s.gsub(/[^\w-]/, "\\\\\\0"), nil)])
205 205
             ])
206 206
         ])
207  
-      prop = Sass::Tree::PropNode.new([""], "", false, :new)
  207
+      prop = Sass::Tree::PropNode.new([""], "", :new)
208 208
       prop.resolved_name = "font-family"
209 209
       prop.resolved_value = Sass::SCSS::RX.escape_ident(v.to_s)
210 210
       rule << prop
10  test/sass/engine_test.rb
@@ -2148,6 +2148,16 @@ def test_import_with_commas_in_url
2148 2148
 SASS
2149 2149
   end
2150 2150
 
  2151
+  def test_silent_comment_in_prop_val_after_important
  2152
+    assert_equal(<<CSS, render(<<SASS))
  2153
+.advanced {
  2154
+  display: none !important; }
  2155
+CSS
  2156
+.advanced
  2157
+  display: none !important // yeah, yeah. it's not really a style anyway.
  2158
+SASS
  2159
+  end
  2160
+
2151 2161
   def test_mixin_with_keyword_args
2152 2162
     assert_equal <<CSS, render(<<SASS)
2153 2163
 .mixed {

0 notes on commit 850e3bf

Please sign in to comment.
Something went wrong with that request. Please try again.