Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'stable'

Conflicts:
	lib/sass/tree/visitors/cssize.rb
  • Loading branch information...
commit e19457847a465aac0afbf8610b65cf5ae2255ea2 2 parents f4b07be + 18ed5bc
@nex3 nex3 authored
View
2  doc-src/SASS_CHANGELOG.md
@@ -434,6 +434,8 @@ of all directives, but will preserve any CSS rules.
* Parse calls to functions named `true`, `false`, and `null` as function calls.
+* Don't move CSS `@import`s to the top of the file unless it's necessary.
+
## 3.2.13
* Numbers returned by user-defined functions now trigger division, just like
View
32 lib/sass/tree/visitors/cssize.rb
@@ -73,17 +73,29 @@ def visit_root(node)
node.children.unshift charset if charset
end
- imports = Sass::Util.extract!(node.children) do |c|
- c.is_a?(Sass::Tree::DirectiveNode) && !c.is_a?(Sass::Tree::MediaNode) &&
- c.resolved_value =~ /^@import /i
+ imports_to_move = []
+ import_limit = nil
+ i = -1
+ node.children.reject! do |n|
+ i += 1
+ if import_limit
+ next false unless n.is_a?(Sass::Tree::CssImportNode)
+ imports_to_move << n
+ next true
+ end
+
+ if !n.is_a?(Sass::Tree::CommentNode) &&
+ !n.is_a?(Sass::Tree::CharsetNode) &&
+ !n.is_a?(Sass::Tree::CssImportNode)
+ import_limit = i
+ end
+
+ false
end
- charset_and_index = Sass::Util.ruby1_8? &&
- node.children.each_with_index.find {|c, _| c.is_a?(Sass::Tree::CharsetNode)}
- if charset_and_index
- index = charset_and_index.last
- node.children = node.children[0..index] + imports + node.children[index + 1..-1]
- else
- node.children = imports + node.children
+
+ if import_limit
+ node.children = node.children[0...import_limit] + imports_to_move +
+ node.children[import_limit..-1]
end
end
View
38 test/sass/scss/scss_test.rb
@@ -392,6 +392,44 @@ def test_url_import
assert_equal("@import url(fonts.sass);\n", render("@import url(fonts.sass);"))
end
+ def test_css_import_doesnt_move_through_comments
+ assert_equal <<CSS, render(<<SCSS)
+/* Comment 1 */
+@import url("foo.css");
+/* Comment 2 */
+@import url("bar.css");
+CSS
+/* Comment 1 */
+@import url("foo.css");
+
+/* Comment 2 */
+@import url("bar.css");
+SCSS
+ end
+
+ def test_css_import_movement_stops_at_comments
+ assert_equal <<CSS, render(<<SCSS)
+/* Comment 1 */
+@import url("foo.css");
+/* Comment 2 */
+@import url("bar.css");
+.foo {
+ a: b; }
+
+/* Comment 3 */
+CSS
+/* Comment 1 */
+@import url("foo.css");
+
+/* Comment 2 */
+
+.foo {a: b}
+
+/* Comment 3 */
+@import url("bar.css");
+SCSS
+ end
+
def test_block_comment_in_script
assert_equal <<CSS, render(<<SCSS)
foo {
Please sign in to comment.
Something went wrong with that request. Please try again.