Skip to content

Commit

Permalink
Fix @Keyframes parsing in CSS.
Browse files Browse the repository at this point in the history
Closes #1657
  • Loading branch information
nex3 committed Feb 27, 2015
1 parent c336507 commit 4e41909
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Expand Up @@ -7,6 +7,8 @@

* Be clearer in the reference about hyphen/underscore equivalence.

* `@keyframes` rules are now converted from CSS properly.

## 3.4.12 (13 February 2015)

[Tagged on GitHub](https://github.com/sass/sass/releases/tag/3.4.12).
Expand Down
15 changes: 15 additions & 0 deletions lib/sass/scss/css_parser.rb
Expand Up @@ -14,6 +14,13 @@ def parent_selector; nil; end
def interpolation(warn_for_color = false); nil; end
def use_css_import?; true; end

def block_contents(node, context)
if node.is_a?(Sass::Tree::DirectiveNode) && node.normalized_name == '@keyframes'
context = :keyframes
end
super(node, context)
end

def block_child(context)
case context
when :ruleset
Expand All @@ -22,6 +29,8 @@ def block_child(context)
directive || ruleset
when :directive
directive || declaration_or_ruleset
when :keyframes
keyframes_ruleset
end
end

Expand All @@ -35,6 +44,12 @@ def ruleset
block(node(Sass::Tree::RuleNode.new(selector, range(start_pos)), start_pos), :ruleset)
end

def keyframes_ruleset
start_pos = source_position
return unless (selector = keyframes_selector)
block(node(Sass::Tree::KeyframeRuleNode.new(selector.strip), start_pos), :ruleset)
end

@sass_script_parser = Class.new(Sass::Script::CssParser)
@sass_script_parser.send(:include, ScriptParser)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/sass/tree/visitors/convert.rb
Expand Up @@ -280,6 +280,10 @@ def visit_atroot(node)
end
end

def visit_keyframerule(node)
"#{tab_str}#{node.resolved_value}#{yield}\n"
end

private

def interp_to_src(interp)
Expand Down
32 changes: 32 additions & 0 deletions test/sass/css2sass_test.rb
Expand Up @@ -263,6 +263,38 @@ def test_subject
CSS
end

def test_keyframes
assert_equal(<<SASS, css2sass(<<CSS))
@keyframes dash
from
stroke-dasharray: 1,200
stroke-dashoffset: 0
50%
stroke-dasharray: 89,200
stroke-dashoffset: -35
to
stroke-dasharray: 89,200
stroke-dashoffset: -124
SASS
@keyframes dash {
from {
stroke-dasharray: 1,200;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 89,200;
stroke-dashoffset: -35;
}
to {
stroke-dasharray: 89,200;
stroke-dashoffset: -124;
}
}
CSS
end

# Regressions

def test_nesting_with_matching_property
Expand Down

0 comments on commit 4e41909

Please sign in to comment.