sass 3.2.0.alpha.274 → 3.2.0.alpha.275

Sign up to get free protection for your applications and to get access to all the features.
data/REVISION CHANGED
@@ -1 +1 @@
1
- 0bba15c5b6c701c739c3b40b0e78c1655a27be6f
1
+ 1edbe5841971a4cdab0ac63de360973289e700ec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.0.alpha.274
1
+ 3.2.0.alpha.275
@@ -73,6 +73,20 @@ class Sass::Tree::Visitors::CheckNesting < Sass::Tree::Visitors::Base
73
73
  end
74
74
  end
75
75
 
76
+ def invalid_function_parent?(parent, child)
77
+ "Functions may only be defined at the root of a document." unless parent.is_a?(Sass::Tree::RootNode)
78
+ end
79
+
80
+ VALID_FUNCTION_CHILDREN = [
81
+ Sass::Tree::CommentNode, Sass::Tree::DebugNode, Sass::Tree::ReturnNode,
82
+ Sass::Tree::VariableNode, Sass::Tree::WarnNode
83
+ ] + CONTROL_NODES
84
+ def invalid_function_child?(parent, child)
85
+ unless is_any_of?(child, VALID_FUNCTION_CHILDREN)
86
+ "Functions can only contain variable declarations and control directives."
87
+ end
88
+ end
89
+
76
90
  INVALID_IMPORT_PARENTS = CONTROL_NODES +
77
91
  [Sass::Tree::MixinDefNode, Sass::Tree::MixinNode]
78
92
  def invalid_import_parent?(parent, child)
@@ -81,6 +95,10 @@ class Sass::Tree::Visitors::CheckNesting < Sass::Tree::Visitors::Base
81
95
  end
82
96
  return if parent.is_a?(Sass::Tree::RootNode)
83
97
  return "CSS import directives may only be used at the root of a document." if child.css_import?
98
+ # If this is a nested @import, we need to make sure it doesn't have anything
99
+ # that's legal at top-level but not in the current context (e.g. mixin defs).
100
+ child.imported_file.to_tree.children.each {|c| visit(c)}
101
+ nil
84
102
  rescue Sass::SyntaxError => e
85
103
  e.modify_backtrace(:filename => child.imported_file.options[:filename])
86
104
  e.add_backtrace(:filename => child.filename, :line => child.line)
@@ -88,25 +106,7 @@ class Sass::Tree::Visitors::CheckNesting < Sass::Tree::Visitors::Base
88
106
  end
89
107
 
90
108
  def invalid_mixindef_parent?(parent, child)
91
- unless (@parents.map {|p| p.class} & INVALID_IMPORT_PARENTS).empty?
92
- return "Mixins may not be defined within control directives or other mixins."
93
- end
94
- end
95
-
96
- def invalid_function_parent?(parent, child)
97
- unless (@parents.map {|p| p.class} & INVALID_IMPORT_PARENTS).empty?
98
- return "Functions may not be defined within control directives or other mixins."
99
- end
100
- end
101
-
102
- VALID_FUNCTION_CHILDREN = [
103
- Sass::Tree::CommentNode, Sass::Tree::DebugNode, Sass::Tree::ReturnNode,
104
- Sass::Tree::VariableNode, Sass::Tree::WarnNode
105
- ] + CONTROL_NODES
106
- def invalid_function_child?(parent, child)
107
- unless is_any_of?(child, VALID_FUNCTION_CHILDREN)
108
- "Functions can only contain variable declarations and control directives."
109
- end
109
+ "Mixins may only be defined at the root of a document." unless parent.is_a?(Sass::Tree::RootNode)
110
110
  end
111
111
 
112
112
  VALID_PROP_CHILDREN = [Sass::Tree::CommentNode, Sass::Tree::PropNode, Sass::Tree::MixinNode] + CONTROL_NODES
@@ -148,7 +148,7 @@ class Sass::Tree::Visitors::Convert < Sass::Tree::Visitors::Base
148
148
  end
149
149
 
150
150
  def visit_media(node)
151
- "#{tab_str}@media #{media_interp_to_src(node.query)}#{yield}"
151
+ "#{tab_str}@media #{interp_to_src(node.query)}#{yield}"
152
152
  end
153
153
 
154
154
  def visit_supports(node)
@@ -243,22 +243,6 @@ class Sass::Tree::Visitors::Convert < Sass::Tree::Visitors::Base
243
243
  end.join
244
244
  end
245
245
 
246
- # Like interp_to_src, but removes the unnecessary `#{}` around the keys and
247
- # values in media expressions.
248
- def media_interp_to_src(interp)
249
- Sass::Util.enum_with_index(interp).map do |r, i|
250
- next r if r.is_a?(String)
251
- before, after = interp[i-1], interp[i+1]
252
- if before.is_a?(String) && after.is_a?(String) &&
253
- ((before[-1] == ?( && after[0] == ?:) ||
254
- (before =~ /:\s*/ && after[0] == ?)))
255
- r.to_sass(@options)
256
- else
257
- "\#{#{r.to_sass(@options)}}"
258
- end
259
- end.join
260
- end
261
-
262
246
  def selector_to_src(sel)
263
247
  @format == :sass ? selector_to_sass(sel) : selector_to_scss(sel)
264
248
  end
@@ -113,7 +113,7 @@ class Sass::Tree::Visitors::Perform < Sass::Tree::Visitors::Base
113
113
 
114
114
  # Loads the function into the environment.
115
115
  def visit_function(node)
116
- @environment.set_local_function(node.name,
116
+ @environment.set_function(node.name,
117
117
  Sass::Callable.new(node.name, node.args, @environment, node.children, !:has_content))
118
118
  []
119
119
  end
@@ -155,7 +155,7 @@ class Sass::Tree::Visitors::Perform < Sass::Tree::Visitors::Base
155
155
 
156
156
  # Loads a mixin into the environment.
157
157
  def visit_mixindef(node)
158
- @environment.set_local_mixin(node.name,
158
+ @environment.set_mixin(node.name,
159
159
  Sass::Callable.new(node.name, node.args, @environment, node.children, node.has_content))
160
160
  []
161
161
  end
@@ -1160,13 +1160,14 @@ SCSS
1160
1160
  end
1161
1161
 
1162
1162
  def test_media_with_expressions
1163
+ # TODO: get rid of the #{} in the expression output
1163
1164
  assert_sass_to_scss <<SCSS, <<SASS
1164
1165
  $media1: screen;
1165
1166
  $media2: print;
1166
1167
  $var: -webkit-min-device-pixel-ratio;
1167
1168
  $val: 20;
1168
1169
 
1169
- @media \#{$media1} and ($var + "-foo": $val + 5), only \#{$media2} {
1170
+ @media \#{$media1} and (\#{$var + "-foo"}: \#{$val + 5}), only \#{$media2} {
1170
1171
  a: b;
1171
1172
  }
1172
1173
  SCSS
@@ -1185,7 +1186,7 @@ $media2: print
1185
1186
  $var: -webkit-min-device-pixel-ratio
1186
1187
  $val: 20
1187
1188
 
1188
- @media \#{$media1} and ($var + "-foo": $val + 5), only \#{$media2}
1189
+ @media \#{$media1} and (\#{$var + "-foo"}: \#{$val + 5}), only \#{$media2}
1189
1190
  a: b
1190
1191
  SASS
1191
1192
  $media1: screen;
@@ -1564,16 +1565,6 @@ SCSS
1564
1565
 
1565
1566
  ## Regression Tests
1566
1567
 
1567
- def test_media_query_with_expr
1568
- assert_scss_to_sass <<SASS, <<SCSS
1569
- @media foo and (bar: baz)
1570
- a: b
1571
- SASS
1572
- @media foo and (bar: baz) {
1573
- a: b; }
1574
- SCSS
1575
- end
1576
-
1577
1568
  def test_empty_lists
1578
1569
  assert_renders(<<SASS, <<SCSS)
1579
1570
  $foo: ()
@@ -73,7 +73,7 @@ MSG
73
73
  "=foo\n :color red\n.bar\n +bang" => "Undefined mixin 'bang'.",
74
74
  "=foo\n :color red\n.bar\n +bang_bop" => "Undefined mixin 'bang_bop'.",
75
75
  "=foo\n :color red\n.bar\n +bang-bop" => "Undefined mixin 'bang-bop'.",
76
- ".foo\n =foo\n :color red\n.bar\n +foo" => "Undefined mixin 'foo'.",
76
+ ".bar\n =foo\n :color red\n" => ["Mixins may only be defined at the root of a document.", 2],
77
77
  " a\n b: c" => ["Indenting at the beginning of the document is illegal.", 1],
78
78
  " \n \n\t\n a\n b: c" => ["Indenting at the beginning of the document is illegal.", 4],
79
79
  "a\n b: c\n b: c" => ["Inconsistent indentation: 1 space was used for indentation, but the rest of the document was indented using 2 spaces.", 3],
@@ -105,6 +105,7 @@ MSG
105
105
  "@function foo($)\n @return 1" => ['Invalid CSS after "(": expected variable (e.g. $foo), was "$)"', 1],
106
106
  "@function foo()\n @return" => 'Invalid @return: expected expression.',
107
107
  "@function foo()\n @return 1\n $var: val" => 'Illegal nesting: Nothing may be nested beneath return directives.',
108
+ "foo\n @function bar()\n @return 1" => ['Functions may only be defined at the root of a document.', 2],
108
109
  "@function foo($a)\n @return 1\na\n b: foo()" => 'Function foo is missing argument $a',
109
110
  "@function foo()\n @return 1\na\n b: foo(2)" => 'Wrong number of arguments (1 for 0) for `foo\'',
110
111
  "@function foo()\n @return 1\na\n b: foo($a: 1)" => "Function foo doesn't have an argument named $a",
@@ -273,7 +274,7 @@ SASS
273
274
  end
274
275
 
275
276
  def test_imported_exception
276
- [1, 2, 3, 4].each do |i|
277
+ [1, 2, 3, 4, 5].each do |i|
277
278
  begin
278
279
  Sass::Engine.new("@import bork#{i}", :load_paths => [File.dirname(__FILE__) + '/templates/']).render
279
280
  rescue Sass::SyntaxError => err
@@ -295,7 +296,7 @@ SASS
295
296
  end
296
297
 
297
298
  def test_double_imported_exception
298
- [1, 2, 3, 4].each do |i|
299
+ [1, 2, 3, 4, 5].each do |i|
299
300
  begin
300
301
  Sass::Engine.new("@import nested_bork#{i}", :load_paths => [File.dirname(__FILE__) + '/templates/']).render
301
302
  rescue Sass::SyntaxError => err
@@ -722,6 +723,24 @@ CSS
722
723
  SASS
723
724
  end
724
725
 
726
+ def test_nested_import_with_toplevel_constructs
727
+ Sass::Engine.new(".foo\n @import importee", :load_paths => [File.dirname(__FILE__) + '/templates/']).render
728
+ rescue Sass::SyntaxError => err
729
+ assert_equal(3, err.sass_line)
730
+ assert_match(/(\/|^)importee\.sass$/, err.sass_filename)
731
+
732
+ assert_hash_has(err.sass_backtrace.first,
733
+ :filename => err.sass_filename, :line => err.sass_line)
734
+
735
+ assert_nil(err.sass_backtrace[1][:filename])
736
+ assert_equal(2, err.sass_backtrace[1][:line])
737
+
738
+ assert_match(/(\/|^)importee\.sass:3$/, err.backtrace.first)
739
+ assert_equal("(sass):2", err.backtrace[1])
740
+ else
741
+ assert(false, "Exception not raised for importing mixins nested")
742
+ end
743
+
725
744
  def test_units
726
745
  renders_correctly "units"
727
746
  end
@@ -1073,83 +1073,17 @@ $domain: "sass-lang.com";
1073
1073
  SCSS
1074
1074
  end
1075
1075
 
1076
- def test_nested_mixin_def
1077
- assert_equal <<CSS, render(<<SCSS)
1078
- foo {
1079
- a: b; }
1080
- CSS
1081
- foo {
1082
- @mixin bar {a: b}
1083
- @include bar; }
1084
- SCSS
1085
- end
1086
-
1087
- def test_nested_mixin_shadow
1088
- assert_equal <<CSS, render(<<SCSS)
1089
- foo {
1090
- c: d; }
1091
-
1092
- baz {
1093
- a: b; }
1094
- CSS
1095
- @mixin bar {a: b}
1096
-
1097
- foo {
1098
- @mixin bar {c: d}
1099
- @include bar;
1100
- }
1101
-
1102
- baz {@include bar}
1103
- SCSS
1104
- end
1105
-
1106
- def test_nested_function_def
1107
- assert_equal <<CSS, render(<<SCSS)
1108
- foo {
1109
- a: 1; }
1110
-
1111
- bar {
1112
- b: foo(); }
1113
- CSS
1114
- foo {
1115
- @function foo() {@return 1}
1116
- a: foo(); }
1117
-
1118
- bar {b: foo()}
1119
- SCSS
1120
- end
1121
-
1122
- def test_nested_function_shadow
1123
- assert_equal <<CSS, render(<<SCSS)
1124
- foo {
1125
- a: 2; }
1126
-
1127
- baz {
1128
- b: 1; }
1129
- CSS
1130
- @function foo() {@return 1}
1131
-
1132
- foo {
1133
- @function foo() {@return 2}
1134
- a: foo();
1135
- }
1136
-
1137
- baz {b: foo()}
1138
- SCSS
1139
- end
1140
-
1141
1076
  ## Errors
1142
1077
 
1143
- def test_nested_mixin_def_is_scoped
1078
+ def test_mixin_defs_only_at_toplevel
1144
1079
  render <<SCSS
1145
1080
  foo {
1146
1081
  @mixin bar {a: b}}
1147
- bar {@include bar}
1148
1082
  SCSS
1149
1083
  assert(false, "Expected syntax error")
1150
1084
  rescue Sass::SyntaxError => e
1151
- assert_equal "Undefined mixin 'bar'.", e.message
1152
- assert_equal 3, e.sass_line
1085
+ assert_equal "Mixins may only be defined at the root of a document.", e.message
1086
+ assert_equal 2, e.sass_line
1153
1087
  end
1154
1088
 
1155
1089
  def test_rules_beneath_properties
@@ -0,0 +1,3 @@
1
+ foo
2
+ @function bar($a)
3
+ @return $a
@@ -0,0 +1,2 @@
1
+
2
+ @import bork5
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sass
3
3
  version: !ruby/object:Gem::Version
4
- hash: 592302393
4
+ hash: 592302395
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 2
9
9
  - 0
10
10
  - alpha
11
- - 274
12
- version: 3.2.0.alpha.274
11
+ - 275
12
+ version: 3.2.0.alpha.275
13
13
  platform: ruby
14
14
  authors:
15
15
  - Nathan Weizenbaum
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2012-07-20 00:00:00 -04:00
22
+ date: 2012-07-16 00:00:00 -04:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
@@ -110,10 +110,10 @@ files:
110
110
  - lib/sass/script/list.rb
111
111
  - lib/sass/script/literal.rb
112
112
  - lib/sass/script/node.rb
113
+ - lib/sass/script/null.rb
113
114
  - lib/sass/script/number.rb
114
115
  - lib/sass/script/operation.rb
115
116
  - lib/sass/script/parser.rb
116
- - lib/sass/script/null.rb
117
117
  - lib/sass/script/string.rb
118
118
  - lib/sass/script/string_interpolation.rb
119
119
  - lib/sass/script/unary_operation.rb
@@ -275,6 +275,7 @@ files:
275
275
  - test/sass/templates/bork2.sass
276
276
  - test/sass/templates/bork3.sass
277
277
  - test/sass/templates/bork4.sass
278
+ - test/sass/templates/bork5.sass
278
279
  - test/sass/templates/compact.sass
279
280
  - test/sass/templates/complex.sass
280
281
  - test/sass/templates/compressed.sass
@@ -297,6 +298,7 @@ files:
297
298
  - test/sass/templates/nested_bork2.sass
298
299
  - test/sass/templates/nested_bork3.sass
299
300
  - test/sass/templates/nested_bork4.sass
301
+ - test/sass/templates/nested_bork5.sass
300
302
  - test/sass/templates/nested_import.sass
301
303
  - test/sass/templates/nested_mixin_bork.sass
302
304
  - test/sass/templates/options.sass