Skip to content

Commit 1a3c30d

Browse files
committed
Merge pull request #1197 from mgreter/bugfix/issue_593
Improve selectors parsing for nth-child binomials
2 parents fb33a2a + af234df commit 1a3c30d

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

ast.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,21 +1360,22 @@ namespace Sass {
13601360
////////////////////////////////////////////////////////
13611361
class String_Constant : public String {
13621362
ADD_PROPERTY(char, quote_mark);
1363+
ADD_PROPERTY(bool, can_compress_whitespace);
13631364
ADD_PROPERTY(string, value);
13641365
protected:
13651366
size_t hash_;
13661367
public:
13671368
String_Constant(ParserState pstate, string val)
1368-
: String(pstate), quote_mark_(0), value_(read_css_string(val)), hash_(0)
1369+
: String(pstate), quote_mark_(0), can_compress_whitespace_(false), value_(read_css_string(val)), hash_(0)
13691370
{ }
13701371
String_Constant(ParserState pstate, const char* beg)
1371-
: String(pstate), quote_mark_(0), value_(read_css_string(string(beg))), hash_(0)
1372+
: String(pstate), quote_mark_(0), can_compress_whitespace_(false), value_(read_css_string(string(beg))), hash_(0)
13721373
{ }
13731374
String_Constant(ParserState pstate, const char* beg, const char* end)
1374-
: String(pstate), quote_mark_(0), value_(read_css_string(string(beg, end-beg))), hash_(0)
1375+
: String(pstate), quote_mark_(0), can_compress_whitespace_(false), value_(read_css_string(string(beg, end-beg))), hash_(0)
13751376
{ }
13761377
String_Constant(ParserState pstate, const Token& tok)
1377-
: String(pstate), quote_mark_(0), value_(read_css_string(string(tok.begin, tok.end))), hash_(0)
1378+
: String(pstate), quote_mark_(0), can_compress_whitespace_(false), value_(read_css_string(string(tok.begin, tok.end))), hash_(0)
13781379
{ }
13791380
string type() { return "string"; }
13801381
static string type_name() { return "string"; }

debugger.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
444444
Binary_Expression* expression = dynamic_cast<Binary_Expression*>(node);
445445
cerr << ind << "Binary_Expression " << expression;
446446
cerr << " (" << pstate_source_position(node) << ")";
447-
cerr << " [" << expression->type() << "]" << endl;
447+
cerr << " [" << expression->type_name() << "]" << endl;
448448
debug_ast(expression->left(), ind + " left: ", env);
449449
debug_ast(expression->right(), ind + " right: ", env);
450450
} else if (dynamic_cast<Map*>(node)) {

output.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,16 @@ namespace Sass {
385385
{
386386
if (String_Quoted* quoted = dynamic_cast<String_Quoted*>(s)) {
387387
return Output::operator()(quoted);
388-
} else if (!in_comment) {
389-
append_token(string_to_output(s->value()), s);
390388
} else {
391-
append_token(s->value(), s);
389+
string value(s->value());
390+
if (s->can_compress_whitespace() && output_style() == COMPRESSED) {
391+
value.erase(std::remove_if(value.begin(), value.end(), ::isspace), value.end());
392+
}
393+
if (!in_comment) {
394+
append_token(string_to_output(value), s);
395+
} else {
396+
append_token(value, s);
397+
}
392398
}
393399
}
394400

parser.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -710,18 +710,9 @@ namespace Sass {
710710
if (lex< alternatives< even, odd > >()) {
711711
expr = new (ctx.mem) String_Quoted(p, lexed);
712712
}
713-
else if (peek< binomial >(position)) {
714-
lex< sequence< optional< coefficient >, exactly<'n'> > >();
715-
String_Constant* var_coef = new (ctx.mem) String_Quoted(p, lexed);
716-
lex< sign >();
717-
String_Constant* op = new (ctx.mem) String_Quoted(p, lexed);
718-
// Binary_Expression::Type op = (lexed == "+" ? Binary_Expression::ADD : Binary_Expression::SUB);
719-
lex< one_plus < digit > >();
720-
String_Constant* constant = new (ctx.mem) String_Quoted(p, lexed);
721-
// expr = new (ctx.mem) Binary_Expression(p, op, var_coef, constant);
722-
String_Schema* schema = new (ctx.mem) String_Schema(p, 3);
723-
*schema << var_coef << op << constant;
724-
expr = schema;
713+
else if (lex< binomial >(position)) {
714+
expr = new (ctx.mem) String_Constant(p, lexed);
715+
((String_Constant*)expr)->can_compress_whitespace(true);
725716
}
726717
else if (peek< sequence< optional<sign>,
727718
zero_plus<digit>,

0 commit comments

Comments
 (0)