sassc 1.11.4 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +2 -2
  3. data/CODE_OF_CONDUCT.md +10 -0
  4. data/README.md +4 -1
  5. data/ext/libsass/.editorconfig +1 -1
  6. data/ext/libsass/.github/CONTRIBUTING.md +7 -7
  7. data/ext/libsass/.github/ISSUE_TEMPLATE.md +31 -6
  8. data/ext/libsass/.gitignore +3 -0
  9. data/ext/libsass/.travis.yml +37 -18
  10. data/ext/libsass/GNUmakefile.am +23 -37
  11. data/ext/libsass/Makefile +10 -6
  12. data/ext/libsass/Makefile.conf +3 -0
  13. data/ext/libsass/Readme.md +68 -63
  14. data/ext/libsass/appveyor.yml +7 -3
  15. data/ext/libsass/configure.ac +10 -14
  16. data/ext/libsass/docs/api-context-internal.md +29 -21
  17. data/ext/libsass/docs/api-context.md +26 -6
  18. data/ext/libsass/docs/api-doc.md +49 -16
  19. data/ext/libsass/docs/api-function-example.md +1 -1
  20. data/ext/libsass/docs/api-function.md +31 -7
  21. data/ext/libsass/docs/api-importer.md +19 -19
  22. data/ext/libsass/docs/api-value.md +4 -2
  23. data/ext/libsass/docs/build-on-windows.md +4 -4
  24. data/ext/libsass/docs/build-with-mingw.md +3 -3
  25. data/ext/libsass/docs/build.md +9 -9
  26. data/ext/libsass/docs/custom-functions-internal.md +10 -8
  27. data/ext/libsass/docs/implementations.md +20 -8
  28. data/ext/libsass/docs/unicode.md +16 -10
  29. data/ext/libsass/include/sass/base.h +0 -3
  30. data/ext/libsass/include/sass/context.h +20 -2
  31. data/ext/libsass/include/sass/functions.h +31 -0
  32. data/ext/libsass/include/sass/values.h +3 -1
  33. data/ext/libsass/include/sass/version.h +1 -1
  34. data/ext/libsass/include/sass/version.h.in +1 -1
  35. data/ext/libsass/include/sass2scss.h +1 -1
  36. data/ext/libsass/res/resource.rc +6 -6
  37. data/ext/libsass/script/ci-build-libsass +10 -5
  38. data/ext/libsass/script/ci-build-plugin +62 -0
  39. data/ext/libsass/script/ci-install-compiler +1 -1
  40. data/ext/libsass/script/ci-install-deps +4 -7
  41. data/ext/libsass/script/ci-report-coverage +13 -3
  42. data/ext/libsass/script/tap-driver +1 -1
  43. data/ext/libsass/script/tap-runner +1 -1
  44. data/ext/libsass/src/GNUmakefile.am +1 -1
  45. data/ext/libsass/src/ast.cpp +537 -762
  46. data/ext/libsass/src/ast.hpp +377 -419
  47. data/ext/libsass/src/ast_def_macros.hpp +26 -1
  48. data/ext/libsass/src/ast_fwd_decl.cpp +29 -0
  49. data/ext/libsass/src/ast_fwd_decl.hpp +94 -21
  50. data/ext/libsass/src/b64/encode.h +3 -1
  51. data/ext/libsass/src/backtrace.cpp +46 -0
  52. data/ext/libsass/src/backtrace.hpp +7 -54
  53. data/ext/libsass/src/bind.cpp +72 -50
  54. data/ext/libsass/src/bind.hpp +0 -1
  55. data/ext/libsass/src/cencode.c +6 -0
  56. data/ext/libsass/src/check_nesting.cpp +157 -135
  57. data/ext/libsass/src/check_nesting.hpp +11 -10
  58. data/ext/libsass/src/color_maps.cpp +10 -6
  59. data/ext/libsass/src/color_maps.hpp +6 -8
  60. data/ext/libsass/src/constants.cpp +4 -3
  61. data/ext/libsass/src/constants.hpp +4 -3
  62. data/ext/libsass/src/context.cpp +110 -47
  63. data/ext/libsass/src/context.hpp +11 -1
  64. data/ext/libsass/src/cssize.cpp +105 -94
  65. data/ext/libsass/src/cssize.hpp +4 -5
  66. data/ext/libsass/src/debugger.hpp +247 -244
  67. data/ext/libsass/src/emitter.cpp +30 -6
  68. data/ext/libsass/src/emitter.hpp +7 -0
  69. data/ext/libsass/src/environment.cpp +67 -16
  70. data/ext/libsass/src/environment.hpp +28 -7
  71. data/ext/libsass/src/error_handling.cpp +92 -64
  72. data/ext/libsass/src/error_handling.hpp +64 -43
  73. data/ext/libsass/src/eval.cpp +494 -544
  74. data/ext/libsass/src/eval.hpp +17 -23
  75. data/ext/libsass/src/expand.cpp +182 -154
  76. data/ext/libsass/src/expand.hpp +4 -5
  77. data/ext/libsass/src/extend.cpp +299 -291
  78. data/ext/libsass/src/extend.hpp +46 -11
  79. data/ext/libsass/src/file.cpp +103 -36
  80. data/ext/libsass/src/file.hpp +21 -4
  81. data/ext/libsass/src/functions.cpp +561 -312
  82. data/ext/libsass/src/functions.hpp +8 -5
  83. data/ext/libsass/src/inspect.cpp +108 -53
  84. data/ext/libsass/src/inspect.hpp +5 -2
  85. data/ext/libsass/src/lexer.cpp +15 -7
  86. data/ext/libsass/src/lexer.hpp +13 -4
  87. data/ext/libsass/src/listize.cpp +3 -2
  88. data/ext/libsass/src/listize.hpp +0 -1
  89. data/ext/libsass/src/memory/SharedPtr.cpp +16 -18
  90. data/ext/libsass/src/memory/SharedPtr.hpp +47 -43
  91. data/ext/libsass/src/node.cpp +34 -38
  92. data/ext/libsass/src/node.hpp +6 -8
  93. data/ext/libsass/src/operation.hpp +2 -2
  94. data/ext/libsass/src/operators.cpp +240 -0
  95. data/ext/libsass/src/operators.hpp +30 -0
  96. data/ext/libsass/src/output.cpp +22 -20
  97. data/ext/libsass/src/parser.cpp +719 -358
  98. data/ext/libsass/src/parser.hpp +57 -22
  99. data/ext/libsass/src/plugins.cpp +28 -10
  100. data/ext/libsass/src/position.cpp +21 -3
  101. data/ext/libsass/src/position.hpp +2 -1
  102. data/ext/libsass/src/prelexer.cpp +104 -19
  103. data/ext/libsass/src/prelexer.hpp +10 -3
  104. data/ext/libsass/src/remove_placeholders.cpp +9 -10
  105. data/ext/libsass/src/remove_placeholders.hpp +1 -5
  106. data/ext/libsass/src/sass.cpp +62 -4
  107. data/ext/libsass/src/sass.hpp +5 -2
  108. data/ext/libsass/src/sass_context.cpp +96 -58
  109. data/ext/libsass/src/sass_context.hpp +7 -5
  110. data/ext/libsass/src/sass_functions.cpp +63 -1
  111. data/ext/libsass/src/sass_functions.hpp +19 -1
  112. data/ext/libsass/src/sass_util.cpp +3 -3
  113. data/ext/libsass/src/sass_util.hpp +4 -4
  114. data/ext/libsass/src/sass_values.cpp +42 -39
  115. data/ext/libsass/src/sass_values.hpp +2 -1
  116. data/ext/libsass/src/source_map.cpp +16 -18
  117. data/ext/libsass/src/subset_map.cpp +6 -8
  118. data/ext/libsass/src/subset_map.hpp +6 -6
  119. data/ext/libsass/src/to_c.cpp +2 -2
  120. data/ext/libsass/src/to_value.cpp +8 -3
  121. data/ext/libsass/src/to_value.hpp +1 -0
  122. data/ext/libsass/src/units.cpp +349 -45
  123. data/ext/libsass/src/units.hpp +39 -22
  124. data/ext/libsass/src/utf8/checked.h +7 -0
  125. data/ext/libsass/src/utf8/unchecked.h +7 -0
  126. data/ext/libsass/src/utf8_string.cpp +1 -1
  127. data/ext/libsass/src/util.cpp +139 -45
  128. data/ext/libsass/src/util.hpp +4 -7
  129. data/ext/libsass/src/values.cpp +15 -23
  130. data/ext/libsass/win/libsass.sln +13 -2
  131. data/ext/libsass/win/libsass.sln.DotSettings +9 -0
  132. data/ext/libsass/win/libsass.targets +3 -0
  133. data/ext/libsass/win/libsass.vcxproj.filters +9 -0
  134. data/lib/sassc/version.rb +1 -1
  135. data/sassc.gemspec +1 -1
  136. data/test/native_test.rb +1 -1
  137. metadata +11 -4
@@ -6,7 +6,6 @@
6
6
  #include "ast_fwd_decl.hpp"
7
7
 
8
8
  namespace Sass {
9
- typedef Environment<AST_Node_Obj> Env;
10
9
 
11
10
  void bind(std::string type, std::string name, Parameters_Obj, Arguments_Obj, Context*, Env*, Eval*);
12
11
  }
@@ -46,6 +46,9 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out,
46
46
  result = (fragment & 0x0fc) >> 2;
47
47
  *codechar++ = base64_encode_value(result);
48
48
  result = (fragment & 0x003) << 4;
49
+ #ifndef _MSC_VER
50
+ __attribute__ ((fallthrough));
51
+ #endif
49
52
  case step_B:
50
53
  if (plainchar == plaintextend)
51
54
  {
@@ -57,6 +60,9 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out,
57
60
  result |= (fragment & 0x0f0) >> 4;
58
61
  *codechar++ = base64_encode_value(result);
59
62
  result = (fragment & 0x00f) << 2;
63
+ #ifndef _MSC_VER
64
+ __attribute__ ((fallthrough));
65
+ #endif
60
66
  case step_C:
61
67
  if (plainchar == plaintextend)
62
68
  {
@@ -7,15 +7,20 @@ namespace Sass {
7
7
 
8
8
  CheckNesting::CheckNesting()
9
9
  : parents(std::vector<Statement_Ptr>()),
10
- parent(0),
11
- current_mixin_definition(0)
10
+ traces(std::vector<Backtrace>()),
11
+ parent(0), current_mixin_definition(0)
12
12
  { }
13
13
 
14
+ void error(AST_Node_Ptr node, Backtraces traces, std::string msg) {
15
+ traces.push_back(Backtrace(node->pstate()));
16
+ throw Exception::InvalidSass(node->pstate(), traces, msg);
17
+ }
18
+
14
19
  Statement_Ptr CheckNesting::visit_children(Statement_Ptr parent)
15
20
  {
16
21
  Statement_Ptr old_parent = this->parent;
17
22
 
18
- if (At_Root_Block_Ptr root = SASS_MEMORY_CAST_PTR(At_Root_Block, parent)) {
23
+ if (At_Root_Block_Ptr root = Cast<At_Root_Block>(parent)) {
19
24
  std::vector<Statement_Ptr> old_parents = this->parents;
20
25
  std::vector<Statement_Ptr> new_parents;
21
26
 
@@ -39,8 +44,14 @@ namespace Sass {
39
44
  }
40
45
  }
41
46
 
42
- At_Root_Block_Ptr ar = SASS_MEMORY_CAST_PTR(At_Root_Block, parent);
43
- Statement_Ptr ret = this->visit_children(&ar->block());
47
+ At_Root_Block_Ptr ar = Cast<At_Root_Block>(parent);
48
+ Block_Ptr ret = ar->block();
49
+
50
+ if (ret != NULL) {
51
+ for (auto n : ret->elements()) {
52
+ n->perform(this);
53
+ }
54
+ }
44
55
 
45
56
  this->parent = old_parent;
46
57
  this->parents = old_parents;
@@ -54,11 +65,17 @@ namespace Sass {
54
65
 
55
66
  this->parents.push_back(parent);
56
67
 
57
- Block_Ptr b = SASS_MEMORY_CAST_PTR(Block, parent);
68
+ Block_Ptr b = Cast<Block>(parent);
69
+
70
+ if (Trace_Ptr trace = Cast<Trace>(parent)) {
71
+ if (trace->type() == 'i') {
72
+ this->traces.push_back(Backtrace(trace->pstate()));
73
+ }
74
+ }
58
75
 
59
76
  if (!b) {
60
- if (Has_Block_Ptr bb = SASS_MEMORY_CAST(Has_Block, *parent)) {
61
- b = &bb->block();
77
+ if (Has_Block_Ptr bb = Cast<Has_Block>(parent)) {
78
+ b = bb->block();
62
79
  }
63
80
  }
64
81
 
@@ -67,9 +84,16 @@ namespace Sass {
67
84
  n->perform(this);
68
85
  }
69
86
  }
87
+
70
88
  this->parent = old_parent;
71
89
  this->parents.pop_back();
72
90
 
91
+ if (Trace_Ptr trace = Cast<Trace>(parent)) {
92
+ if (trace->type() == 'i') {
93
+ this->traces.pop_back();
94
+ }
95
+ }
96
+
73
97
  return b;
74
98
  }
75
99
 
@@ -97,10 +121,21 @@ namespace Sass {
97
121
  return n;
98
122
  }
99
123
 
124
+ Statement_Ptr CheckNesting::operator()(If_Ptr i)
125
+ {
126
+ this->visit_children(i);
127
+
128
+ if (Block_Ptr b = Cast<Block>(i->alternative())) {
129
+ for (auto n : b->elements()) n->perform(this);
130
+ }
131
+
132
+ return i;
133
+ }
134
+
100
135
  Statement_Ptr CheckNesting::fallback_impl(Statement_Ptr s)
101
136
  {
102
- Block_Ptr b1 = SASS_MEMORY_CAST_PTR(Block, s);
103
- Has_Block_Ptr b2 = SASS_MEMORY_CAST_PTR(Has_Block, s);
137
+ Block_Ptr b1 = Cast<Block>(s);
138
+ Has_Block_Ptr b2 = Cast<Has_Block>(s);
104
139
  return b1 || b2 ? visit_children(s) : s;
105
140
  }
106
141
 
@@ -108,91 +143,82 @@ namespace Sass {
108
143
  {
109
144
  if (!this->parent) return true;
110
145
 
111
- if (SASS_MEMORY_CAST_PTR(Content, node))
112
- { this->invalid_content_parent(this->parent); }
146
+ if (Cast<Content>(node))
147
+ { this->invalid_content_parent(this->parent, node); }
113
148
 
114
149
  if (is_charset(node))
115
- { this->invalid_charset_parent(this->parent); }
150
+ { this->invalid_charset_parent(this->parent, node); }
116
151
 
117
- if (SASS_MEMORY_CAST_PTR(Extension, node))
118
- { this->invalid_extend_parent(this->parent); }
152
+ if (Cast<Extension>(node))
153
+ { this->invalid_extend_parent(this->parent, node); }
119
154
 
120
- // if (SASS_MEMORY_CAST(Import, node))
155
+ // if (Cast<Import>(node))
121
156
  // { this->invalid_import_parent(this->parent); }
122
157
 
123
158
  if (this->is_mixin(node))
124
- { this->invalid_mixin_definition_parent(this->parent); }
159
+ { this->invalid_mixin_definition_parent(this->parent, node); }
125
160
 
126
161
  if (this->is_function(node))
127
- { this->invalid_function_parent(this->parent); }
162
+ { this->invalid_function_parent(this->parent, node); }
128
163
 
129
164
  if (this->is_function(this->parent))
130
165
  { this->invalid_function_child(node); }
131
166
 
132
- if (SASS_MEMORY_CAST_PTR(Declaration, node))
133
- { this->invalid_prop_parent(this->parent); }
167
+ if (Declaration_Ptr d = Cast<Declaration>(node))
168
+ {
169
+ this->invalid_prop_parent(this->parent, node);
170
+ this->invalid_value_child(d->value());
171
+ }
134
172
 
135
- if (SASS_MEMORY_CAST_PTR(Declaration, this->parent))
173
+ if (Cast<Declaration>(this->parent))
136
174
  { this->invalid_prop_child(node); }
137
175
 
138
- if (SASS_MEMORY_CAST_PTR(Return, node))
139
- { this->invalid_return_parent(this->parent); }
176
+ if (Cast<Return>(node))
177
+ { this->invalid_return_parent(this->parent, node); }
140
178
 
141
179
  return true;
142
180
  }
143
181
 
144
- void CheckNesting::invalid_content_parent(Statement_Ptr parent)
182
+ void CheckNesting::invalid_content_parent(Statement_Ptr parent, AST_Node_Ptr node)
145
183
  {
146
184
  if (!this->current_mixin_definition) {
147
- throw Exception::InvalidSass(
148
- parent->pstate(),
149
- "@content may only be used within a mixin."
150
- );
185
+ error(node, traces, "@content may only be used within a mixin.");
151
186
  }
152
187
  }
153
188
 
154
- void CheckNesting::invalid_charset_parent(Statement_Ptr parent)
189
+ void CheckNesting::invalid_charset_parent(Statement_Ptr parent, AST_Node_Ptr node)
155
190
  {
156
191
  if (!(
157
192
  is_root_node(parent)
158
193
  )) {
159
- throw Exception::InvalidSass(
160
- parent->pstate(),
161
- "@charset may only be used at the root of a document."
162
- );
194
+ error(node, traces, "@charset may only be used at the root of a document.");
163
195
  }
164
196
  }
165
197
 
166
- void CheckNesting::invalid_extend_parent(Statement_Ptr parent)
198
+ void CheckNesting::invalid_extend_parent(Statement_Ptr parent, AST_Node_Ptr node)
167
199
  {
168
200
  if (!(
169
- SASS_MEMORY_CAST_PTR(Ruleset, parent) ||
170
- SASS_MEMORY_CAST_PTR(Mixin_Call, parent) ||
201
+ Cast<Ruleset>(parent) ||
202
+ Cast<Mixin_Call>(parent) ||
171
203
  is_mixin(parent)
172
204
  )) {
173
- throw Exception::InvalidSass(
174
- parent->pstate(),
175
- "Extend directives may only be used within rules."
176
- );
205
+ error(node, traces, "Extend directives may only be used within rules.");
177
206
  }
178
207
  }
179
208
 
180
- // void CheckNesting::invalid_import_parent(Statement_Ptr parent)
209
+ // void CheckNesting::invalid_import_parent(Statement_Ptr parent, AST_Node_Ptr node)
181
210
  // {
182
211
  // for (auto pp : this->parents) {
183
212
  // if (
184
- // SASS_MEMORY_CAST(Each, pp) ||
185
- // SASS_MEMORY_CAST(For, pp) ||
186
- // SASS_MEMORY_CAST(If, pp) ||
187
- // SASS_MEMORY_CAST(While, pp) ||
188
- // SASS_MEMORY_CAST(Trace, pp) ||
189
- // SASS_MEMORY_CAST(Mixin_Call, pp) ||
213
+ // Cast<Each>(pp) ||
214
+ // Cast<For>(pp) ||
215
+ // Cast<If>(pp) ||
216
+ // Cast<While>(pp) ||
217
+ // Cast<Trace>(pp) ||
218
+ // Cast<Mixin_Call>(pp) ||
190
219
  // is_mixin(pp)
191
220
  // ) {
192
- // throw Exception::InvalidSass(
193
- // parent->pstate(),
194
- // "Import directives may not be defined within control directives or other mixins."
195
- // );
221
+ // error(node, traces, "Import directives may not be defined within control directives or other mixins.");
196
222
  // }
197
223
  // }
198
224
 
@@ -201,49 +227,40 @@ namespace Sass {
201
227
  // }
202
228
 
203
229
  // if (false/*n.css_import?*/) {
204
- // throw Exception::InvalidSass(
205
- // parent->pstate(),
206
- // "CSS import directives may only be used at the root of a document."
207
- // );
230
+ // error(node, traces, "CSS import directives may only be used at the root of a document.");
208
231
  // }
209
232
  // }
210
233
 
211
- void CheckNesting::invalid_mixin_definition_parent(Statement_Ptr parent)
234
+ void CheckNesting::invalid_mixin_definition_parent(Statement_Ptr parent, AST_Node_Ptr node)
212
235
  {
213
236
  for (Statement_Ptr pp : this->parents) {
214
237
  if (
215
- SASS_MEMORY_CAST_PTR(Each, pp) ||
216
- SASS_MEMORY_CAST_PTR(For, pp) ||
217
- SASS_MEMORY_CAST_PTR(If, pp) ||
218
- SASS_MEMORY_CAST_PTR(While, pp) ||
219
- SASS_MEMORY_CAST_PTR(Trace, pp) ||
220
- SASS_MEMORY_CAST_PTR(Mixin_Call, pp) ||
238
+ Cast<Each>(pp) ||
239
+ Cast<For>(pp) ||
240
+ Cast<If>(pp) ||
241
+ Cast<While>(pp) ||
242
+ Cast<Trace>(pp) ||
243
+ Cast<Mixin_Call>(pp) ||
221
244
  is_mixin(pp)
222
245
  ) {
223
- throw Exception::InvalidSass(
224
- parent->pstate(),
225
- "Mixins may not be defined within control directives or other mixins."
226
- );
246
+ error(node, traces, "Mixins may not be defined within control directives or other mixins.");
227
247
  }
228
248
  }
229
249
  }
230
250
 
231
- void CheckNesting::invalid_function_parent(Statement_Ptr parent)
251
+ void CheckNesting::invalid_function_parent(Statement_Ptr parent, AST_Node_Ptr node)
232
252
  {
233
253
  for (Statement_Ptr pp : this->parents) {
234
254
  if (
235
- SASS_MEMORY_CAST_PTR(Each, pp) ||
236
- SASS_MEMORY_CAST_PTR(For, pp) ||
237
- SASS_MEMORY_CAST_PTR(If, pp) ||
238
- SASS_MEMORY_CAST_PTR(While, pp) ||
239
- SASS_MEMORY_CAST_PTR(Trace, pp) ||
240
- SASS_MEMORY_CAST_PTR(Mixin_Call, pp) ||
255
+ Cast<Each>(pp) ||
256
+ Cast<For>(pp) ||
257
+ Cast<If>(pp) ||
258
+ Cast<While>(pp) ||
259
+ Cast<Trace>(pp) ||
260
+ Cast<Mixin_Call>(pp) ||
241
261
  is_mixin(pp)
242
262
  ) {
243
- throw Exception::InvalidSass(
244
- parent->pstate(),
245
- "Functions may not be defined within control directives or other mixins."
246
- );
263
+ error(node, traces, "Functions may not be defined within control directives or other mixins.");
247
264
  }
248
265
  }
249
266
  }
@@ -251,70 +268,75 @@ namespace Sass {
251
268
  void CheckNesting::invalid_function_child(Statement_Ptr child)
252
269
  {
253
270
  if (!(
254
- SASS_MEMORY_CAST_PTR(Each, child) ||
255
- SASS_MEMORY_CAST_PTR(For, child) ||
256
- SASS_MEMORY_CAST_PTR(If, child) ||
257
- SASS_MEMORY_CAST_PTR(While, child) ||
258
- SASS_MEMORY_CAST_PTR(Trace, child) ||
259
- SASS_MEMORY_CAST_PTR(Comment, child) ||
260
- SASS_MEMORY_CAST_PTR(Debug, child) ||
261
- SASS_MEMORY_CAST_PTR(Return, child) ||
262
- SASS_MEMORY_CAST_PTR(Variable, child) ||
271
+ Cast<Each>(child) ||
272
+ Cast<For>(child) ||
273
+ Cast<If>(child) ||
274
+ Cast<While>(child) ||
275
+ Cast<Trace>(child) ||
276
+ Cast<Comment>(child) ||
277
+ Cast<Debug>(child) ||
278
+ Cast<Return>(child) ||
279
+ Cast<Variable>(child) ||
263
280
  // Ruby Sass doesn't distinguish variables and assignments
264
- SASS_MEMORY_CAST_PTR(Assignment, child) ||
265
- SASS_MEMORY_CAST_PTR(Warning, child) ||
266
- SASS_MEMORY_CAST_PTR(Error, child)
281
+ Cast<Assignment>(child) ||
282
+ Cast<Warning>(child) ||
283
+ Cast<Error>(child)
267
284
  )) {
268
- throw Exception::InvalidSass(
269
- child->pstate(),
270
- "Functions can only contain variable declarations and control directives."
271
- );
285
+ error(child, traces, "Functions can only contain variable declarations and control directives.");
272
286
  }
273
287
  }
274
288
 
275
289
  void CheckNesting::invalid_prop_child(Statement_Ptr child)
276
290
  {
277
291
  if (!(
278
- SASS_MEMORY_CAST_PTR(Each, child) ||
279
- SASS_MEMORY_CAST_PTR(For, child) ||
280
- SASS_MEMORY_CAST_PTR(If, child) ||
281
- SASS_MEMORY_CAST_PTR(While, child) ||
282
- SASS_MEMORY_CAST_PTR(Trace, child) ||
283
- SASS_MEMORY_CAST_PTR(Comment, child) ||
284
- SASS_MEMORY_CAST_PTR(Declaration, child) ||
285
- SASS_MEMORY_CAST_PTR(Mixin_Call, child)
292
+ Cast<Each>(child) ||
293
+ Cast<For>(child) ||
294
+ Cast<If>(child) ||
295
+ Cast<While>(child) ||
296
+ Cast<Trace>(child) ||
297
+ Cast<Comment>(child) ||
298
+ Cast<Declaration>(child) ||
299
+ Cast<Mixin_Call>(child)
286
300
  )) {
287
- throw Exception::InvalidSass(
288
- child->pstate(),
289
- "Illegal nesting: Only properties may be nested beneath properties."
290
- );
301
+ error(child, traces, "Illegal nesting: Only properties may be nested beneath properties.");
291
302
  }
292
303
  }
293
304
 
294
- void CheckNesting::invalid_prop_parent(Statement_Ptr parent)
305
+ void CheckNesting::invalid_prop_parent(Statement_Ptr parent, AST_Node_Ptr node)
295
306
  {
296
307
  if (!(
297
308
  is_mixin(parent) ||
298
309
  is_directive_node(parent) ||
299
- SASS_MEMORY_CAST_PTR(Ruleset, parent) ||
300
- SASS_MEMORY_CAST_PTR(Keyframe_Rule, parent) ||
301
- SASS_MEMORY_CAST_PTR(Declaration, parent) ||
302
- SASS_MEMORY_CAST_PTR(Mixin_Call, parent)
310
+ Cast<Ruleset>(parent) ||
311
+ Cast<Keyframe_Rule>(parent) ||
312
+ Cast<Declaration>(parent) ||
313
+ Cast<Mixin_Call>(parent)
303
314
  )) {
304
- throw Exception::InvalidSass(
305
- parent->pstate(),
306
- "Properties are only allowed within rules, directives, mixin includes, or other properties."
307
- );
315
+ error(node, traces, "Properties are only allowed within rules, directives, mixin includes, or other properties.");
308
316
  }
309
317
  }
310
318
 
311
- void CheckNesting::invalid_return_parent(Statement_Ptr parent)
319
+ void CheckNesting::invalid_value_child(AST_Node_Ptr d)
320
+ {
321
+ if (Map_Ptr m = Cast<Map>(d)) {
322
+ traces.push_back(Backtrace(m->pstate()));
323
+ throw Exception::InvalidValue(traces, *m);
324
+ }
325
+ if (Number_Ptr n = Cast<Number>(d)) {
326
+ if (!n->is_valid_css_unit()) {
327
+ traces.push_back(Backtrace(n->pstate()));
328
+ throw Exception::InvalidValue(traces, *n);
329
+ }
330
+ }
331
+
332
+ // error(dbg + " isn't a valid CSS value.", m->pstate(),);
333
+
334
+ }
335
+
336
+ void CheckNesting::invalid_return_parent(Statement_Ptr parent, AST_Node_Ptr node)
312
337
  {
313
338
  if (!this->is_function(parent)) {
314
- throw Exception::InvalidSass(
315
- parent->pstate(),
316
- "@return may only be used within a function."
317
- );
339
+ error(node, traces, "@return may only be used within a function.");
318
340
  }
319
341
  }
320
342
 
@@ -326,51 +348,51 @@ namespace Sass {
326
348
  !is_root_node(grandparent) &&
327
349
  !is_at_root_node(grandparent);
328
350
 
329
- return SASS_MEMORY_CAST_PTR(Import, parent) ||
330
- SASS_MEMORY_CAST_PTR(Each, parent) ||
331
- SASS_MEMORY_CAST_PTR(For, parent) ||
332
- SASS_MEMORY_CAST_PTR(If, parent) ||
333
- SASS_MEMORY_CAST_PTR(While, parent) ||
334
- SASS_MEMORY_CAST_PTR(Trace, parent) ||
351
+ return Cast<Import>(parent) ||
352
+ Cast<Each>(parent) ||
353
+ Cast<For>(parent) ||
354
+ Cast<If>(parent) ||
355
+ Cast<While>(parent) ||
356
+ Cast<Trace>(parent) ||
335
357
  valid_bubble_node;
336
358
  }
337
359
 
338
360
  bool CheckNesting::is_charset(Statement_Ptr n)
339
361
  {
340
- Directive_Ptr d = SASS_MEMORY_CAST_PTR(Directive, n);
362
+ Directive_Ptr d = Cast<Directive>(n);
341
363
  return d && d->keyword() == "charset";
342
364
  }
343
365
 
344
366
  bool CheckNesting::is_mixin(Statement_Ptr n)
345
367
  {
346
- Definition_Ptr def = SASS_MEMORY_CAST_PTR(Definition, n);
368
+ Definition_Ptr def = Cast<Definition>(n);
347
369
  return def && def->type() == Definition::MIXIN;
348
370
  }
349
371
 
350
372
  bool CheckNesting::is_function(Statement_Ptr n)
351
373
  {
352
- Definition_Ptr def = SASS_MEMORY_CAST_PTR(Definition, n);
374
+ Definition_Ptr def = Cast<Definition>(n);
353
375
  return def && def->type() == Definition::FUNCTION;
354
376
  }
355
377
 
356
378
  bool CheckNesting::is_root_node(Statement_Ptr n)
357
379
  {
358
- if (SASS_MEMORY_CAST_PTR(Ruleset, n)) return false;
380
+ if (Cast<Ruleset>(n)) return false;
359
381
 
360
- Block_Ptr b = SASS_MEMORY_CAST_PTR(Block, n);
382
+ Block_Ptr b = Cast<Block>(n);
361
383
  return b && b->is_root();
362
384
  }
363
385
 
364
386
  bool CheckNesting::is_at_root_node(Statement_Ptr n)
365
387
  {
366
- return SASS_MEMORY_CAST_PTR(At_Root_Block, n) != NULL;
388
+ return Cast<At_Root_Block>(n) != NULL;
367
389
  }
368
390
 
369
391
  bool CheckNesting::is_directive_node(Statement_Ptr n)
370
392
  {
371
- return SASS_MEMORY_CAST_PTR(Directive, n) ||
372
- SASS_MEMORY_CAST_PTR(Import, n) ||
373
- SASS_MEMORY_CAST_PTR(Media_Block, n) ||
374
- SASS_MEMORY_CAST_PTR(Supports_Block, n);
393
+ return Cast<Directive>(n) ||
394
+ Cast<Import>(n) ||
395
+ Cast<Media_Block>(n) ||
396
+ Cast<Supports_Block>(n);
375
397
  }
376
398
  }