Skip to content

Commit 69ae7ef

Browse files
glebmxzyfer
authored andcommitted
Error on incomplete @supports clause in parser (#2860)
Fixes #2786 Spec added in sass/sass-spec#1370
1 parent fef6c6a commit 69ae7ef

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/parser.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,10 +2415,7 @@ namespace Sass {
24152415
// these are very similar to media blocks
24162416
Supports_Block_Obj Parser::parse_supports_directive()
24172417
{
2418-
Supports_Condition_Obj cond = parse_supports_condition();
2419-
if (!cond) {
2420-
css_error("Invalid CSS", " after ", ": expected @supports condition (e.g. (display: flexbox)), was ", false);
2421-
}
2418+
Supports_Condition_Obj cond = parse_supports_condition(/*top_level=*/true);
24222419
// create the ast node object for the support queries
24232420
Supports_Block_Obj query = SASS_MEMORY_NEW(Supports_Block, pstate, cond);
24242421
// additional block is mandatory
@@ -2430,26 +2427,26 @@ namespace Sass {
24302427

24312428
// parse one query operation
24322429
// may encounter nested queries
2433-
Supports_Condition_Obj Parser::parse_supports_condition()
2430+
Supports_Condition_Obj Parser::parse_supports_condition(bool top_level)
24342431
{
24352432
lex < css_whitespace >();
24362433
Supports_Condition_Obj cond;
24372434
if ((cond = parse_supports_negation())) return cond;
2438-
if ((cond = parse_supports_operator())) return cond;
2435+
if ((cond = parse_supports_operator(top_level))) return cond;
24392436
if ((cond = parse_supports_interpolation())) return cond;
24402437
return cond;
24412438
}
24422439

24432440
Supports_Condition_Obj Parser::parse_supports_negation()
24442441
{
24452442
if (!lex < kwd_not >()) return {};
2446-
Supports_Condition_Obj cond = parse_supports_condition_in_parens();
2443+
Supports_Condition_Obj cond = parse_supports_condition_in_parens(/*parens_required=*/true);
24472444
return SASS_MEMORY_NEW(Supports_Negation, pstate, cond);
24482445
}
24492446

2450-
Supports_Condition_Obj Parser::parse_supports_operator()
2447+
Supports_Condition_Obj Parser::parse_supports_operator(bool top_level)
24512448
{
2452-
Supports_Condition_Obj cond = parse_supports_condition_in_parens();
2449+
Supports_Condition_Obj cond = parse_supports_condition_in_parens(/*parens_required=*/top_level);
24532450
if (cond.isNull()) return {};
24542451

24552452
while (true) {
@@ -2458,7 +2455,7 @@ namespace Sass {
24582455
else if(!lex < kwd_or >()) { break; }
24592456

24602457
lex < css_whitespace >();
2461-
Supports_Condition_Obj right = parse_supports_condition_in_parens();
2458+
Supports_Condition_Obj right = parse_supports_condition_in_parens(/*parens_required=*/true);
24622459

24632460
// Supports_Condition* cc = SASS_MEMORY_NEW(Supports_Condition, *static_cast<Supports_Condition*>(cond));
24642461
cond = SASS_MEMORY_NEW(Supports_Operator, pstate, cond, right, op);
@@ -2496,21 +2493,24 @@ namespace Sass {
24962493
return cond;
24972494
}
24982495

2499-
Supports_Condition_Obj Parser::parse_supports_condition_in_parens()
2496+
Supports_Condition_Obj Parser::parse_supports_condition_in_parens(bool parens_required)
25002497
{
25012498
Supports_Condition_Obj interp = parse_supports_interpolation();
25022499
if (interp != 0) return interp;
25032500

2504-
if (!lex < exactly <'('> >()) return {};
2501+
if (!lex < exactly <'('> >()) {
2502+
if (parens_required) {
2503+
css_error("Invalid CSS", " after ", ": expected @supports condition (e.g. (display: flexbox)), was ", /*trim=*/false);
2504+
} else {
2505+
return {};
2506+
}
2507+
}
25052508
lex < css_whitespace >();
25062509

2507-
Supports_Condition_Obj cond = parse_supports_condition();
2508-
if (cond != 0) {
2509-
if (!lex < exactly <')'> >()) error("unclosed parenthesis in @supports declaration");
2510-
} else {
2511-
cond = parse_supports_declaration();
2512-
if (!lex < exactly <')'> >()) error("unclosed parenthesis in @supports declaration");
2513-
}
2510+
Supports_Condition_Obj cond = parse_supports_condition(/*top_level=*/false);
2511+
if (cond.isNull()) cond = parse_supports_declaration();
2512+
if (!lex < exactly <')'> >()) error("unclosed parenthesis in @supports declaration");
2513+
25142514
lex < css_whitespace >();
25152515
return cond;
25162516
}

src/parser.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,12 @@ namespace Sass {
312312
Media_Query_Obj parse_media_query();
313313
Media_Query_Expression_Obj parse_media_expression();
314314
Supports_Block_Obj parse_supports_directive();
315-
Supports_Condition_Obj parse_supports_condition();
315+
Supports_Condition_Obj parse_supports_condition(bool top_level);
316316
Supports_Condition_Obj parse_supports_negation();
317-
Supports_Condition_Obj parse_supports_operator();
317+
Supports_Condition_Obj parse_supports_operator(bool top_level);
318318
Supports_Condition_Obj parse_supports_interpolation();
319319
Supports_Condition_Obj parse_supports_declaration();
320-
Supports_Condition_Obj parse_supports_condition_in_parens();
320+
Supports_Condition_Obj parse_supports_condition_in_parens(bool parens_required);
321321
At_Root_Block_Obj parse_at_root_block();
322322
At_Root_Query_Obj parse_at_root_query();
323323
String_Schema_Obj parse_almost_any_value();

0 commit comments

Comments
 (0)