Skip to content

Commit 99f60f8

Browse files
committed
Fix a few list output edge cases
Don't add parentheses for nested lists in declarations.
1 parent 348fde8 commit 99f60f8

File tree

6 files changed

+35
-10
lines changed

6 files changed

+35
-10
lines changed

emitter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ namespace Sass {
1818
in_wrapped(false),
1919
in_media_block(false),
2020
in_declaration(false),
21-
in_declaration_list(false)
21+
in_space_array(false),
22+
in_comma_array(false)
2223
{ }
2324

2425
// return buffer as string

emitter.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ namespace Sass {
4141
bool in_wrapped;
4242
bool in_media_block;
4343
bool in_declaration;
44-
bool in_declaration_list;
44+
bool in_space_array;
45+
bool in_comma_array;
4546

4647
public:
4748
// return buffer as string

functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ namespace Sass {
15541554
Output_Style old_style;
15551555
old_style = ctx.output_style;
15561556
ctx.output_style = NESTED;
1557-
To_String to_string(&ctx);
1557+
To_String to_string(&ctx, false);
15581558
string inspect = v->perform(&to_string);
15591559
ctx.output_style = old_style;
15601560
return new (ctx.mem) String_Constant(pstate, inspect);

inspect.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ namespace Sass {
114114
void Inspect::operator()(Declaration* dec)
115115
{
116116
if (dec->value()->concrete_type() == Expression::NULL_VAL) return;
117+
bool was_decl = in_declaration;
117118
in_declaration = true;
118119
if (output_style() == NESTED)
119120
indentation += dec->tabs();
@@ -128,7 +129,7 @@ namespace Sass {
128129
append_delimiter();
129130
if (output_style() == NESTED)
130131
indentation -= dec->tabs();
131-
in_declaration = false;
132+
in_declaration = was_decl;
132133
}
133134

134135
void Inspect::operator()(Assignment* assn)
@@ -346,7 +347,19 @@ namespace Sass {
346347
else if (in_media_block && sep != " ") sep += " "; // verified
347348
if (list->empty()) return;
348349
bool items_output = false;
349-
in_declaration_list = in_declaration;
350+
351+
bool was_space_array = in_space_array;
352+
bool was_comma_array = in_comma_array;
353+
if (!in_declaration && (
354+
(list->separator() == List::SPACE && in_space_array) ||
355+
(list->separator() == List::COMMA && in_comma_array)
356+
)) {
357+
append_string("(");
358+
}
359+
360+
if (list->separator() == List::SPACE) in_space_array = true;
361+
else if (list->separator() == List::COMMA) in_comma_array = true;
362+
350363
for (size_t i = 0, L = list->length(); i < L; ++i) {
351364
Expression* list_item = (*list)[i];
352365
if (list_item->is_invisible()) {
@@ -360,7 +373,16 @@ namespace Sass {
360373
list_item->perform(this);
361374
items_output = true;
362375
}
363-
in_declaration_list = false;
376+
377+
in_comma_array = was_comma_array;
378+
in_space_array = was_space_array;
379+
if (!in_declaration && (
380+
(list->separator() == List::SPACE && in_space_array) ||
381+
(list->separator() == List::COMMA && in_comma_array)
382+
)) {
383+
append_string(")");
384+
}
385+
364386
}
365387

366388
void Inspect::operator()(Binary_Expression* expr)

to_string.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
namespace Sass {
1212
using namespace std;
1313

14-
To_String::To_String(Context* ctx)
15-
: ctx(ctx) { }
14+
To_String::To_String(Context* ctx, bool in_declaration)
15+
: ctx(ctx), in_declaration(in_declaration) { }
1616
To_String::~To_String() { }
1717

1818
inline string To_String::fallback_impl(AST_Node* n)
1919
{
2020
Emitter emitter(ctx);
2121
Inspect i(emitter);
22-
i.in_declaration_list = true;
22+
i.in_declaration = in_declaration;
2323
n->perform(&i);
2424
return i.get_buffer();
2525
}

to_string.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ namespace Sass {
1818
string fallback_impl(AST_Node* n);
1919

2020
Context* ctx;
21+
bool in_declaration;
2122

2223
public:
23-
To_String(Context* ctx = 0);
24+
To_String(Context* ctx = 0, bool in_declaration = true);
2425
virtual ~To_String();
2526

2627
string operator()(Null* n);

0 commit comments

Comments
 (0)