Skip to content

Commit

Permalink
Don't include "!important" in the :value of a :property node.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrove committed Oct 2, 2013
1 parent 70cb854 commit 52b2952
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ git
properly handle already-parsed `:simple_block` nodes in the input, which
occurs when parsing rules in the value of an `:at_rule` block.

* Fixed: "!important" is no longer included in the `:value` of a `:property`
node.


0.0.2 (2013-09-30)
------------------
Expand Down
36 changes: 25 additions & 11 deletions lib/crass/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,34 +162,48 @@ def consume_component_value(input = @tokens)

# Consumes a declaration and returns it, or `nil` on parse error.
#
# http://www.w3.org/TR/2013/WD-css-syntax-3-20130919/#consume-a-declaration0
# http://www.w3.org/TR/2013/WD-css-syntax-3-20130919/#consume-a-declaration
def consume_declaration(input = @tokens)
declaration = {}
value = []

declaration[:tokens] = input.collect do
declaration[:name] = input.consume[:value]

value = []
token = input.consume
token = input.consume while token[:node] == :whitespace

return nil if token[:node] != :colon # TODO: parse error

value << token while token = input.consume
declaration[:value] = value
end

# Look for !important.
pos = -1
while token = value[pos]
type = token[:node]

if type == :whitespace || type == :comment || type == :semicolon
pos -= 1
next
end

maybe_important = value.reject {|v| v[:node] == :whitespace }[-2, 2]
if type == :ident && token[:value].downcase == 'important'
prev_token = value[pos - 1]

if maybe_important &&
maybe_important[0][:node] == :delim &&
maybe_important[0][:value] == '!' &&
maybe_important[1][:node] == :ident &&
maybe_important[1][:value].downcase == 'important'
if prev_token && prev_token[:node] == :delim &&
prev_token[:value] == '!'

declaration[:important] = true
declaration[:important] = true
value.slice!(pos - 1, 2)
else
break
end
else
break
end
end

declaration[:value] = value
create_node(:declaration, declaration)
end

Expand Down

0 comments on commit 52b2952

Please sign in to comment.