Skip to content

Commit

Permalink
Parse !important as a token in SassScript, rather than special-casing…
Browse files Browse the repository at this point in the history
… it.

Closes gh-68
  • Loading branch information
nex3 committed Apr 26, 2011
1 parent b443ba0 commit 850e3bf
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
8 changes: 1 addition & 7 deletions lib/sass/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,9 @@ def parse_property(name, parsed_name, value, prop, line)
if value.strip.empty?
expr = Sass::Script::String.new("")
else
important = false
if value =~ Sass::SCSS::RX::IMPORTANT
important = true
value = value.gsub(Sass::SCSS::RX::IMPORTANT,"")
end
expr = parse_script(value, :offset => line.offset + line.text.index(value))

end
Tree::PropNode.new(parse_interp(name), expr, important, prop)
Tree::PropNode.new(parse_interp(name), expr, prop)
end

def parse_variable(line)
Expand Down
2 changes: 1 addition & 1 deletion lib/sass/less.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def to_sass_tree
class Property
def to_sass_tree
return if hide_in_sass
Sass::Tree::PropNode.new([self], @value.to_sass_tree, false, :new)
Sass::Tree::PropNode.new([self], @value.to_sass_tree, :new)
end
end

Expand Down
7 changes: 6 additions & 1 deletion lib/sass/script/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def token

variable || string(:double, false) || string(:single, false) || number ||
color || bool || string(:uri, false) || raw(UNICODERANGE) ||
special_fun || ident_op || ident || op
special_fun || special_val || ident_op || ident || op
end

def variable
Expand Down Expand Up @@ -302,6 +302,11 @@ def special_fun
str1.size + str2.size]
end

def special_val
return unless scan(/!important/i)
[:string, Script::String.new("!important")]
end

def ident_op
return unless op = scan(REGULAR_EXPRESSIONS[:ident_op])
[OPERATORS[op]]
Expand Down
4 changes: 1 addition & 3 deletions lib/sass/scss/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,9 @@ def declaration
tok!(/:/)
space, value = value!
ss
important = tok(IMPORTANT)
ss
require_block = tok?(/\{/)

node = node(Sass::Tree::PropNode.new(name.flatten.compact, value, !!important, :new))
node = node(Sass::Tree::PropNode.new(name.flatten.compact, value, :new))

return node unless require_block
nested_properties! node, space
Expand Down
2 changes: 1 addition & 1 deletion lib/sass/scss/rx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def self.quote(str, flags = 0)
# We could use it for 1.9 only, but I don't want to introduce a cross-version
# behavior difference.
# In any case, almost all CSS idents will be matched by this.
STATIC_VALUE = /(-?#{NMSTART}|#{STRING_NOINTERP}|\s(?!%)|#[a-f0-9]|[,%]|#{NUM})+(?=[;}])/i
STATIC_VALUE = /(-?#{NMSTART}|#{STRING_NOINTERP}|\s(?!%)|#[a-f0-9]|[,%]|#{NUM}|\!important)+(?=[;}])/i

STATIC_SELECTOR = /(#{NMCHAR}|\s|[,>+*]|[:#.]#{NMSTART})+(?=[{])/i
end
Expand Down
11 changes: 2 additions & 9 deletions lib/sass/tree/prop_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ class PropNode < Node
# @return [Sass::Script::Node]
attr_accessor :value

# Whether the property was marked as !important.
#
# @return [Boolean]
attr_accessor :important

# The value of the property
# after any interpolated SassScript has been resolved.
# Only set once \{Tree::Visitors::Perform} has been run.
Expand All @@ -49,16 +44,14 @@ class PropNode < Node

# @param name [Array<String, Sass::Script::Node>] See \{#name}
# @param value [Sass::Script::Node] See \{#value}
# @param important [Boolean] whether this is an !important property
# @param prop_syntax [Symbol] `:new` if this property uses `a: b`-style syntax,
# `:old` if it uses `:a b`-style syntax
def initialize(name, value, important, prop_syntax)
def initialize(name, value, prop_syntax)
@name = Sass::Util.strip_string_array(
Sass::Util.merge_adjacent_strings(name))
@value = value
@tabs = 0
@prop_syntax = prop_syntax
@important = important
super()
end

Expand Down Expand Up @@ -96,7 +89,7 @@ def declaration(opts = {:old => @prop_syntax == :old}, fmt = :sass)
old = opts[:old] && fmt == :sass
initial = old ? ':' : ''
mid = old ? '' : ':'
"#{initial}#{name}#{mid} #{self.class.val_to_sass(value, opts)}#{' !important' if important}".rstrip
"#{initial}#{name}#{mid} #{self.class.val_to_sass(value, opts)}".rstrip
end

private
Expand Down
6 changes: 3 additions & 3 deletions lib/sass/tree/visitors/to_css.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ def visit_media(node)
def visit_prop(node)
tab_str = ' ' * (@tabs + node.tabs)
if node.style == :compressed
"#{tab_str}#{node.resolved_name}:#{node.resolved_value}#{'!important' if node.important}"
"#{tab_str}#{node.resolved_name}:#{node.resolved_value}"
else
"#{tab_str}#{node.resolved_name}: #{node.resolved_value}#{' !important' if node.important};"
"#{tab_str}#{node.resolved_name}: #{node.resolved_value};"
end
end

Expand Down Expand Up @@ -204,7 +204,7 @@ def debug_info_rule(debug_info, options)
[Sass::Selector::Element.new(k.to_s.gsub(/[^\w-]/, "\\\\\\0"), nil)])
])
])
prop = Sass::Tree::PropNode.new([""], "", false, :new)
prop = Sass::Tree::PropNode.new([""], "", :new)
prop.resolved_name = "font-family"
prop.resolved_value = Sass::SCSS::RX.escape_ident(v.to_s)
rule << prop
Expand Down
10 changes: 10 additions & 0 deletions test/sass/engine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,16 @@ def test_import_with_commas_in_url
SASS
end

def test_silent_comment_in_prop_val_after_important
assert_equal(<<CSS, render(<<SASS))
.advanced {
display: none !important; }
CSS
.advanced
display: none !important // yeah, yeah. it's not really a style anyway.
SASS
end

def test_mixin_with_keyword_args
assert_equal <<CSS, render(<<SASS)
.mixed {
Expand Down

0 comments on commit 850e3bf

Please sign in to comment.