@@ -954,7 +954,13 @@ namespace Sass {
954
954
return new (ctx.mem ) Declaration (prop->pstate (), prop, parse_static_value ()/* , lex<important>()*/ );
955
955
}
956
956
else {
957
- return new (ctx.mem ) Declaration (prop->pstate (), prop, parse_list ()/* , lex<important>()*/ );
957
+ Expression* list_ex = parse_list ();
958
+ if (List* list = dynamic_cast <List*>(list_ex)) {
959
+ if (list->length () == 0 && !peek< exactly <' {' > >()) {
960
+ css_error (" Invalid CSS" , " after " , " : expected expression (e.g. 1px, bold), was " );
961
+ }
962
+ }
963
+ return new (ctx.mem ) Declaration (prop->pstate (), prop, list_ex/* , lex<important>()*/ );
958
964
}
959
965
}
960
966
@@ -2191,4 +2197,39 @@ namespace Sass {
2191
2197
throw Sass_Error (Sass_Error::syntax, ParserState (path, pos.line ? pos : before_token, Offset (0 , 0 )), msg);
2192
2198
}
2193
2199
2200
+ // print a css parsing error with actual context information from parsed source
2201
+ void Parser::css_error (const string& msg, const string& prefix, const string& middle)
2202
+ {
2203
+ int max_len = 14 ;
2204
+ const char * pos = peek < optional_spaces >();
2205
+ bool ellipsis_left = false ;
2206
+ const char * pos_left (pos);
2207
+ while (*pos_left && pos_left >= source) {
2208
+ if (pos - pos_left > max_len) {
2209
+ ellipsis_left = true ;
2210
+ break ;
2211
+ }
2212
+ if (*pos_left == ' \r ' ) break ;
2213
+ if (*pos_left == ' \n ' ) break ;
2214
+ -- pos_left;
2215
+ }
2216
+ bool ellipsis_right = false ;
2217
+ const char * pos_right (pos);
2218
+ while (*pos_right && pos_right <= end) {
2219
+ if (pos_right - pos > max_len) {
2220
+ ellipsis_right = true ;
2221
+ break ;
2222
+ }
2223
+ if (*pos_right == ' \r ' ) break ;
2224
+ if (*pos_right == ' \n ' ) break ;
2225
+ ++ pos_right;
2226
+ }
2227
+ string left (pos_left, pos);
2228
+ string right (pos, pos_right);
2229
+ if (ellipsis_left) left = ellipsis + left;
2230
+ if (ellipsis_right) right = right + ellipsis;
2231
+ // now pass new message to the more generic error function
2232
+ error (msg + prefix + quote (left) + middle + quote (right), pstate);
2233
+ }
2234
+
2194
2235
}
0 commit comments